From 381c9c8870fad4c544f29deec22ba4be3549a731 Mon Sep 17 00:00:00 2001 From: Naram Qashat Date: Sun, 20 Jun 2010 18:42:58 -0400 Subject: The first of a few "CBX OCDing over code style" commits, focusing on include/* and src/* but not src/core/* or src/modules/*. --- src/actions.cpp | 6 +- src/base64.cpp | 37 +- src/bots.cpp | 23 +- src/botserv.cpp | 252 +++++------ src/channels.cpp | 324 ++++++-------- src/chanserv.cpp | 406 +++++++++--------- src/command.cpp | 9 +- src/commands.cpp | 50 +-- src/compat.cpp | 26 +- src/config.cpp | 566 ++++++++++++++---------- src/configreader.cpp | 12 +- src/core/cs_set_bantype.cpp | 2 +- src/core/cs_set_description.cpp | 4 +- src/core/cs_set_email.cpp | 2 +- src/core/cs_set_entrymsg.cpp | 2 +- src/core/cs_set_founder.cpp | 4 +- src/core/cs_set_keeptopic.cpp | 2 +- src/core/cs_set_mlock.cpp | 2 +- src/core/cs_set_opnotice.cpp | 4 +- src/core/cs_set_peace.cpp | 2 +- src/core/cs_set_persist.cpp | 6 +- src/core/cs_set_private.cpp | 2 +- src/core/cs_set_restricted.cpp | 2 +- src/core/cs_set_secure.cpp | 2 +- src/core/cs_set_securefounder.cpp | 2 +- src/core/cs_set_secureops.cpp | 4 +- src/core/cs_set_signkick.cpp | 2 +- src/core/cs_set_successor.cpp | 2 +- src/core/cs_set_topiclock.cpp | 2 +- src/core/cs_set_url.cpp | 2 +- src/core/cs_set_xop.cpp | 4 +- src/core/enc_md5.cpp | 4 +- src/core/enc_none.cpp | 6 +- src/core/enc_old.cpp | 4 +- src/core/enc_sha1.cpp | 4 +- src/core/enc_sha256.cpp | 12 +- src/core/ns_group.cpp | 8 +- src/core/ns_register.cpp | 6 +- src/core/os_staff.cpp | 4 +- src/encrypt.cpp | 20 +- src/hashcomp.cpp | 9 +- src/hostserv.cpp | 24 +- src/init.cpp | 87 ++-- src/ircd.cpp | 7 +- src/language.cpp | 151 ++++--- src/log.cpp | 51 +-- src/mail.cpp | 31 +- src/main.cpp | 86 ++-- src/memory.cpp | 26 +- src/memoserv.cpp | 276 ++++++------ src/messages.cpp | 102 ++--- src/misc.cpp | 874 ++++++++++++++++++-------------------- src/modes.cpp | 70 ++- src/module.cpp | 29 +- src/modulemanager.cpp | 143 ++++--- src/modules.cpp | 158 ++++--- src/modules/hs_request.cpp | 4 +- src/nickalias.cpp | 21 +- src/nickcore.cpp | 18 +- src/nickserv.cpp | 68 ++- src/operserv.cpp | 73 +--- src/opertype.cpp | 28 +- src/process.cpp | 148 ++++--- src/regchannel.cpp | 73 +--- src/send.cpp | 38 +- src/servers.cpp | 61 +-- src/sessions.cpp | 97 +++-- src/sockets.cpp | 37 +- src/threadengine.cpp | 1 - src/threadengine_pthread.cpp | 5 - src/threadengine_win32.cpp | 3 - src/timers.cpp | 10 +- src/users.cpp | 153 +++---- src/wildcard.cpp | 18 +- src/win32_memory.cpp | 7 +- src/windows.cpp | 23 +- 76 files changed, 2240 insertions(+), 2603 deletions(-) (limited to 'src') diff --git a/src/actions.cpp b/src/actions.cpp index 00ed01100..bff5b36fa 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ #include "services.h" @@ -91,7 +89,7 @@ void common_unban(ChannelInfo *ci, const std::string &nick) if (!ci->c->bans || !ci->c->bans->count) return; - if (u->hostip == NULL) + if (!u->hostip) { host = host_resolve(u->host); /* we store the just resolved hostname so we don't @@ -108,14 +106,12 @@ void common_unban(ChannelInfo *ci, const std::string &nick) if (ircd->svsmode_unban) ircdproto->SendBanDel(ci->c, nick); else - { for (ban = ci->c->bans->entries; ban; ban = next) { next = ban->next; if (entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->host, ip) || entry_match(ban, u->nick.c_str(), u->GetIdent().c_str(), u->GetDisplayedHost().c_str(), ip)) ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask); } - } /* host_resolve() sstrdup us this info so we gotta free it */ if (host) delete [] host; diff --git a/src/base64.cpp b/src/base64.cpp index 3f576e96a..2071ad40a 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ /* @@ -35,8 +33,7 @@ long base64dec(const char *b64) return 0; } -static const char Base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) @@ -109,7 +106,7 @@ int b64_encode(const char *src, size_t srclength, char *target, size_t targsize) unsigned char output[4]; size_t i; - while (2 < srclength) + while (srclength > 2) { input[0] = *src++; input[1] = *src++; @@ -173,14 +170,14 @@ int b64_decode(const char *src, char *target, size_t targsize) while ((ch = *src++) != '\0') { - if (isspace(ch)) /* Skip whitespace anywhere. */ + if (isspace(ch)) /* Skip whitespace anywhere. */ continue; if (ch == Pad64) break; pos = const_cast(strchr(Base64, ch)); - if (!pos) /* A non-base64 character. */ + if (!pos) /* A non-base64 character. */ return -1; switch (state) @@ -236,16 +233,16 @@ int b64_decode(const char *src, char *target, size_t targsize) * on a byte boundary, and/or with erroneous trailing characters. */ - if (ch == Pad64) /* We got a pad char. */ + if (ch == Pad64) /* We got a pad char. */ { - ch = *src++; /* Skip it, get next. */ + ch = *src++; /* Skip it, get next. */ switch (state) { - case 0: /* Invalid = in first position */ - case 1: /* Invalid = in second position */ + case 0: /* Invalid = in first position */ + case 1: /* Invalid = in second position */ return -1; - case 2: /* Valid, means one byte of info */ + case 2: /* Valid, means one byte of info */ /* Skip any number of spaces. */ for (; ch != '\0'; ch = *src++) if (!isspace(ch)) @@ -253,11 +250,11 @@ int b64_decode(const char *src, char *target, size_t targsize) /* Make sure there is another trailing = sign. */ if (ch != Pad64) return -1; - ch = *src++; /* Skip the = */ + ch = *src++; /* Skip the = */ /* Fall through to "single trailing =" case. */ /* FALLTHROUGH */ - case 3: /* Valid, means two bytes of info */ + case 3: /* Valid, means two bytes of info */ /* * We know this char is an =. Is there anything but * whitespace after it? @@ -289,12 +286,12 @@ int b64_decode(const char *src, char *target, size_t targsize) return tarindex; } -const char* encode_ip(unsigned char *ip) +const char *encode_ip(unsigned char *ip) { static char buf[25]; unsigned char *cp; - struct in_addr ia; /* For IPv4 */ - char *s_ip; /* Signed ip string */ + struct in_addr ia; /* For IPv4 */ + char *s_ip; /* Signed ip string */ if (!ip) return "*"; @@ -319,11 +316,11 @@ int decode_ip(const char *buf) b64_decode(buf, targ, 25); ia = *reinterpret_cast(targ); - if (len == 24) /* IPv6 */ + if (len == 24) /* IPv6 */ return 0; - else if (len == 8) /* IPv4 */ + else if (len == 8) /* IPv4 */ return ia.s_addr; - else /* Error?? */ + else /* Error?? */ return 0; } diff --git a/src/bots.cpp b/src/bots.cpp index e9021b188..424120d2d 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -3,9 +3,6 @@ * Copyright (C) 2008-2010 Anope Team * * Please read COPYING and README for further details. - * - * - * */ #include "services.h" @@ -35,33 +32,19 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: ci::string ci_nick(nnick.c_str()); if (Config.s_ChanServ && ci_nick == Config.s_ChanServ) - { ChanServ = this; - } else if (Config.s_BotServ && ci_nick == Config.s_BotServ) - { BotServ = this; - } else if (Config.s_HostServ && ci_nick == Config.s_HostServ) - { HostServ = this; - } else if (Config.s_OperServ && ci_nick == Config.s_OperServ) - { OperServ = this; - } else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ) - { MemoServ = this; - } else if (Config.s_NickServ && ci_nick == Config.s_NickServ) - { NickServ = this; - } else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer) - { Global = this; - } BotListByNick[this->nick.c_str()] = this; if (!this->uid.empty()) @@ -78,14 +61,12 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: BotInfo::~BotInfo() { - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { ChannelInfo *ci = it->second; if (ci->bi == this) - { ci->bi = NULL; - } } BotListByNick.erase(this->nick.c_str()); @@ -105,7 +86,7 @@ void BotInfo::ChangeNick(const char *newnick) void BotInfo::RejoinAll() { - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { ChannelInfo *ci = it->second; diff --git a/src/botserv.cpp b/src/botserv.cpp index 2dd96706d..624d1df83 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ /*************************************************************************/ @@ -17,19 +15,20 @@ #include "modules.h" #include "language.h" -static UserData *get_user_data(Channel * c, User * u); +static UserData *get_user_data(Channel *c, User *u); -static void check_ban(ChannelInfo * ci, User * u, int ttbtype); -static void bot_kick(ChannelInfo * ci, User * u, int message, ...); +static void check_ban(ChannelInfo *ci, User *u, int ttbtype); +static void bot_kick(ChannelInfo *ci, User *u, int message, ...); E void moduleAddBotServCmds(); /*************************************************************************/ -/* *INDENT-OFF* */ -void moduleAddBotServCmds() { + +void moduleAddBotServCmds() +{ ModuleManager::LoadModuleList(Config.BotServCoreModules); } -/* *INDENT-ON* */ + /*************************************************************************/ /*************************************************************************/ @@ -39,7 +38,7 @@ void get_botserv_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it) + for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) { BotInfo *bi = it->second; @@ -62,9 +61,8 @@ void get_botserv_stats(long *nrec, long *memuse) void bs_init() { - if (Config.s_BotServ) { + if (Config.s_BotServ) moduleAddBotServCmds(); - } } /*************************************************************************/ @@ -75,7 +73,7 @@ void botserv(User *u, BotInfo *bi, const std::string &buf) { if (!u || !bi || buf.empty()) return; - + if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') { std::string command = buf; @@ -84,23 +82,20 @@ void botserv(User *u, BotInfo *bi, const std::string &buf) ircdproto->SendCTCP(bi, u->nick.c_str(), "%s", command.c_str()); } else - { mod_run_cmd(bi, u, buf); - } } /*************************************************************************/ /* Handles all messages that are sent to registered channels where a * bot is on. - * */ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { if (!u || !ci || !ci->c || buf.empty()) return; - + /* Answer to ping if needed */ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1') { @@ -180,17 +175,16 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) /* Caps kicker */ if (ci->botflags.HasFlag(BS_KICK_CAPS) && realbuf.length() >= ci->capsmin) { - int i = 0; - int l = 0; + int i = 0, l = 0; - for (unsigned j = 0; j < realbuf.length(); ++j) + for (unsigned j = 0, end = realbuf.length(); j < end; ++j) { if (isupper(realbuf[j])) ++i; else if (islower(realbuf[j])) ++l; } - + /* i counts uppercase chars, l counts lowercase chars. Only * alphabetic chars (so islower || isupper) qualify for the * percentage of caps to kick for; the rest is ignored. -GD @@ -212,33 +206,24 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) /* Normalize the buffer */ const char *nbuf = normalizeBuffer(realbuf.c_str()); - for (unsigned i = 0; i < ci->GetBadWordCount(); ++i) + for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) { BadWord *bw = ci->GetBadWord(i); if (bw->type == BW_ANY && ((Config.BSCaseSensitive && strstr(nbuf, bw->word.c_str())) || (!Config.BSCaseSensitive && stristr(nbuf, bw->word.c_str())))) - { mustkick = true; - } else if (bw->type == BW_SINGLE) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (!stricmp(nbuf, bw->word.c_str())))) - { + if ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (!stricmp(nbuf, bw->word.c_str())))) mustkick = true; - } - else if ((strchr(nbuf, ' ') == nbuf + len) && ((Config.BSCaseSensitive && nbuf == bw->word) - || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf)))) - { + else if ((strchr(nbuf, ' ') == nbuf + len) && ((Config.BSCaseSensitive && nbuf == bw->word) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf)))) mustkick = true; - } else { if ((strrchr(nbuf, ' ') == nbuf + strlen(nbuf) - len - 1) && ((Config.BSCaseSensitive && (strstr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)) || (!Config.BSCaseSensitive && (stristr(nbuf, bw->word.c_str()) == nbuf + strlen(nbuf) - len)))) - { mustkick = true; - } else { char *wordbuf = new char[len + 3]; @@ -248,10 +233,8 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) wordbuf[len + 2] = '\0'; memcpy(wordbuf + 1, bw->word.c_str(), len); - if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf)))) - { + if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) mustkick = true; - } delete [] wordbuf; } @@ -261,10 +244,8 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && (!strncmp(nbuf, bw->word.c_str(), len))) || (!Config.BSCaseSensitive && (!strnicmp(nbuf, bw->word.c_str(), len)))) - { + if ((Config.BSCaseSensitive && !strncmp(nbuf, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf, bw->word.c_str(), len))) mustkick = true; - } else { char *wordbuf = new char[len + 2]; @@ -273,10 +254,8 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) wordbuf[0] = ' '; wordbuf[len + 1] = '\0'; - if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf)))) - { + if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) mustkick = true; - } delete [] wordbuf; } @@ -285,11 +264,8 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { size_t len = bw->word.length(); - if ((Config.BSCaseSensitive && (!strncmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len))) - || (!Config.BSCaseSensitive && (!strnicmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len)))) - { + if ((Config.BSCaseSensitive && !strncmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len)) || (!Config.BSCaseSensitive && !strnicmp(nbuf + strlen(nbuf) - len, bw->word.c_str(), len))) mustkick = true; - } else { char *wordbuf = new char[len + 2]; @@ -298,10 +274,8 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) wordbuf[len] = ' '; wordbuf[len + 1] = '\0'; - if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf)))) - { + if ((Config.BSCaseSensitive && strstr(nbuf, wordbuf)) || (!Config.BSCaseSensitive && stristr(nbuf, wordbuf))) mustkick = true; - } delete [] wordbuf; } @@ -341,7 +315,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) ud->lines = 0; } - ud->lines++; + ++ud->lines; if (ud->lines >= ci->floodlines) { check_ban(ci, u, TTB_FLOOD); @@ -356,7 +330,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) UserData *ud = get_user_data(ci->c, u); if (!ud) return; - + if (ud->lastline && stricmp(ud->lastline, buf.c_str())) { delete [] ud->lastline; @@ -367,7 +341,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) { if (!ud->lastline) ud->lastline = sstrdup(buf.c_str()); - ud->times++; + ++ud->times; } if (ud->times >= ci->repeattimes) @@ -381,9 +355,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) /* return if the user is on the ignore list */ if (get_ignore(u->nick.c_str()) != NULL) - { return; - } /* Fantaisist commands */ if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == *Config.BSFantasyCharacter && !was_action) @@ -391,7 +363,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf) spacesepstream sep(buf); std::string token; - if (sep.GetToken(token) && (token[0] == *Config.BSFantasyCharacter)) + if (sep.GetToken(token) && token[0] == *Config.BSFantasyCharacter) { /* Strip off the fantasy character */ token.erase(token.begin()); @@ -461,13 +433,12 @@ BotInfo *findbot(const ci::string &nick) return NULL; } - /*************************************************************************/ /* Returns ban data associated with an user if it exists, allocates it otherwise. */ -static BanData *get_ban_data(Channel * c, User * u) +static BanData *get_ban_data(Channel *c, User *u) { char mask[BUFSIZE]; BanData *bd, *next; @@ -476,11 +447,12 @@ static BanData *get_ban_data(Channel * c, User * u) if (!c || !u) return NULL; - snprintf(mask, sizeof(mask), "%s@%s", u->GetIdent().c_str(), - u->GetDisplayedHost().c_str()); + snprintf(mask, sizeof(mask), "%s@%s", u->GetIdent().c_str(), u->GetDisplayedHost().c_str()); - for (bd = c->bd; bd; bd = next) { - if (now - bd->last_use > Config.BSKeepData) { + for (bd = c->bd; bd; bd = next) + { + if (now - bd->last_use > Config.BSKeepData) + { if (bd->next) bd->next->prev = bd->prev; if (bd->prev) @@ -493,7 +465,8 @@ static BanData *get_ban_data(Channel * c, User * u) delete bd; continue; } - if (!stricmp(bd->mask, mask)) { + if (!stricmp(bd->mask, mask)) + { bd->last_use = now; return bd; } @@ -527,7 +500,7 @@ static UserData *get_user_data(Channel *c, User *u) if (!c || !u) return NULL; - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -574,31 +547,22 @@ void bot_join(ChannelInfo * ci) next = ban->next; if (entry_match(ban, ci->bi->nick.c_str(), ci->bi->user.c_str(), ci->bi->host.c_str(), 0)) - { ci->c->RemoveMode(NULL, CMODE_BAN, ban->mask); - } } } std::string Limit; int limit = 0; if (ci->c->GetParam(CMODE_LIMIT, Limit)) - { limit = atoi(Limit.c_str()); - } /* Should we be invited? */ - if (ci->c->HasMode(CMODE_INVITE) - || (limit && ci->c->users.size() >= limit)) - ircdproto->SendNoticeChanops(ci->bi, ci->c, - "%s invited %s into the channel.", - ci->bi->nick.c_str(), ci->bi->nick.c_str()); + if (ci->c->HasMode(CMODE_INVITE) || (limit && ci->c->users.size() >= limit)) + ircdproto->SendNoticeChanops(ci->bi, ci->c, "%s invited %s into the channel.", ci->bi->nick.c_str(), ci->bi->nick.c_str()); } ircdproto->SendJoin(ci->bi, ci->c->name.c_str(), ci->c->creation_time); - for (std::list::iterator it = BotModes.begin(); it != BotModes.end(); ++it) - { + for (std::list::iterator it = BotModes.begin(), it_end = BotModes.end(); it != it_end; ++it) ci->c->SetMode(ci->bi, *it, ci->bi->nick, false); - } FOREACH_MOD(I_OnBotJoin, OnBotJoin(ci, ci->bi)); } @@ -620,7 +584,7 @@ static void check_ban(ChannelInfo *ci, User *u, int ttbtype) if (u->server->IsULined()) return; - bd->ttb[ttbtype]++; + ++bd->ttb[ttbtype]; if (ci->ttb[ttbtype] && bd->ttb[ttbtype] >= ci->ttb[ttbtype]) { /* Should not use == here because bd->ttb[ttbtype] could possibly be > ci->ttb[ttbtype] @@ -642,7 +606,7 @@ static void check_ban(ChannelInfo *ci, User *u, int ttbtype) /* This makes a bot kick an user. Works somewhat like notice_lang in fact ;) */ -static void bot_kick(ChannelInfo * ci, User * u, int message, ...) +static void bot_kick(ChannelInfo *ci, User *u, int message, ...) { va_list args; char buf[1024]; @@ -665,7 +629,7 @@ static void bot_kick(ChannelInfo * ci, User * u, int message, ...) /* Makes a simple ban and kicks the target */ -void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, const char *reason) +void bot_raw_ban(User *requester, ChannelInfo *ci, char *nick, const char *reason) { char mask[BUFSIZE]; User *u = finduser(nick); @@ -673,23 +637,19 @@ void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, const char *rea if (!u) return; - if ((ModeManager::FindUserModeByName(UMODE_PROTECTED))) + if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - if (u->IsProtected() && (requester != u)) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); - return; - } + ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && (get_access(u, ci) >= get_access(requester, ci))) + if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) return; - if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) + if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u) == 1) { - if (is_excepted(ci, u) == 1) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(BOT_EXCEPT)); - return; - } + ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(BOT_EXCEPT)); + return; } get_idealban(ci, u, mask, sizeof(mask)); @@ -707,22 +667,20 @@ void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, const char *rea /* Makes a kick with a "dynamic" reason ;) */ -void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, const char *reason) +void bot_raw_kick(User *requester, ChannelInfo *ci, char *nick, const char *reason) { User *u = finduser(nick); if (!u || !ci->c->FindUser(u)) return; - if ((ModeManager::FindUserModeByName(UMODE_PROTECTED))) + if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - if (u->IsProtected() && (requester != u)) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); - return; - } + ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + return; } - if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && (get_access(u, ci) >= get_access(requester, ci))) + if (ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) return; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !check_access(requester, ci, CA_SIGNKICK))) @@ -735,12 +693,11 @@ void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, const char *re /* Makes a mode operation on a channel for a nick */ -void bot_raw_mode(User * requester, ChannelInfo * ci, const char *mode, char *nick) +void bot_raw_mode(User *requester, ChannelInfo *ci, const char *mode, char *nick) { - char buf[BUFSIZE]; + char buf[BUFSIZE] = ""; User *u; - *buf = '\0'; u = finduser(nick); if (!u || !ci->c->FindUser(u)) @@ -748,15 +705,13 @@ void bot_raw_mode(User * requester, ChannelInfo * ci, const char *mode, char *ni snprintf(buf, BUFSIZE - 1, "%ld", static_cast(time(NULL))); - if ((ModeManager::FindUserModeByName(UMODE_PROTECTED))) { - if (u->IsProtected() && *mode == '-' && (requester != u)) { - ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); - return; - } + if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && *mode == '-' && requester != u) + { + ircdproto->SendPrivmsg(ci->bi, ci->name.c_str(), "%s", getstring(ACCESS_DENIED)); + return; } - if (*mode == '-' && ci->HasFlag(CI_PEACE) - && stricmp(requester->nick.c_str(), nick) && (get_access(u, ci) >= get_access(requester, ci))) + if (*mode == '-' && ci->HasFlag(CI_PEACE) && stricmp(requester->nick.c_str(), nick) && get_access(u, ci) >= get_access(requester, ci)) return; ci->c->SetModes(NULL, "%s %s", mode, nick); @@ -776,69 +731,70 @@ char *normalizeBuffer(const char *buf) len = strlen(buf); newbuf = new char[len + 1]; - for (i = 0; i < len; i++) { - switch (buf[i]) { + for (i = 0; i < len; ++i) + { + switch (buf[i]) + { /* ctrl char */ - case 1: - break; + case 1: + break; /* Bold ctrl char */ - case 2: - break; + case 2: + break; /* Color ctrl char */ - case 3: - /* If the next character is a digit, its also removed */ - if (isdigit(buf[i + 1])) { - i++; - - /* not the best way to remove colors - * which are two digit but no worse then - * how the Unreal does with +S - TSL - */ - if (isdigit(buf[i + 1])) { - i++; - } - - /* Check for background color code - * and remove it as well - */ - if (buf[i + 1] == ',') { - i++; + case 3: + /* If the next character is a digit, its also removed */ + if (isdigit(buf[i + 1])) + { + ++i; - if (isdigit(buf[i + 1])) { - i++; - } /* not the best way to remove colors * which are two digit but no worse then * how the Unreal does with +S - TSL */ - if (isdigit(buf[i + 1])) { - i++; + if (isdigit(buf[i + 1])) + ++i; + + /* Check for background color code + * and remove it as well + */ + if (buf[i + 1] == ',') + { + ++i; + + if (isdigit(buf[i + 1])) + ++i; + /* not the best way to remove colors + * which are two digit but no worse then + * how the Unreal does with +S - TSL + */ + if (isdigit(buf[i + 1])) + ++i; } } - } - break; + break; /* line feed char */ - case 10: - break; + case 10: + break; /* carriage returns char */ - case 13: - break; + case 13: + break; /* Reverse ctrl char */ - case 22: - break; + case 22: + break; /* Underline ctrl char */ - case 31: - break; + case 31: + break; /* A valid char gets copied into the new buffer */ - default: - newbuf[j] = buf[i]; - j++; + default: + newbuf[j] = buf[i]; + ++j; } } /* Terminate the string */ newbuf[j] = 0; - return (newbuf); + return newbuf; } diff --git a/src/channels.cpp b/src/channels.cpp index b2c839083..1a846d1bd 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ #include "services.h" @@ -69,28 +67,16 @@ Channel::~Channel() delete [] this->topic; if (this->bans && this->bans->count) - { while (this->bans->entries) entry_delete(this->bans, this->bans->entries); - } - if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) - { - if (this->excepts && this->excepts->count) - { - while (this->excepts->entries) - entry_delete(this->excepts, this->excepts->entries); - } - } + if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && this->excepts && this->excepts->count) + while (this->excepts->entries) + entry_delete(this->excepts, this->excepts->entries); - if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)) - { - if (this->invites && this->invites->count) - { - while (this->invites->entries) - entry_delete(this->invites, this->invites->entries); - } - } + if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE) && this->invites && this->invites->count) + while (this->invites->entries) + entry_delete(this->invites, this->invites->entries); ChannelList.erase(this->name.c_str()); } @@ -120,9 +106,9 @@ void Channel::JoinUser(User *user) uc->Status = Status; this->users.push_back(uc); - if (get_ignore(user->nick.c_str()) == NULL) + if (!get_ignore(user->nick.c_str())) { - if (this->ci && (check_access(user, this->ci, CA_MEMO)) && (this->ci->memos.memos.size() > 0)) + if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) { if (this->ci->memos.memos.size() == 1) notice_lang(Config.s_MemoServ, user, MEMO_X_ONE_NOTICE, this->ci->memos.memos.size(), this->ci->name.c_str()); @@ -143,26 +129,17 @@ void Channel::JoinUser(User *user) * But don't join the bot if the channel is persistant - Adam * But join persistant channels when syncing with our uplink- DP **/ - if (Config.s_BotServ && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST))) - { - if (this->users.size() == Config.BSMinUsers) - bot_join(this->ci); - } - if (Config.s_BotServ && this->ci && this->ci->bi) + if (Config.s_BotServ && this->ci && this->ci->bi && (!Me->IsSynced() || !this->ci->HasFlag(CI_PERSIST)) && this->users.size() == Config.BSMinUsers) + bot_join(this->ci); + /* Only display the greet if the main uplink we're connected + * to has synced, or we'll get greet-floods when the net + * recovers from a netsplit. -GD + */ + if (Config.s_BotServ && this->ci && this->ci->bi && this->users.size() >= Config.BSMinUsers && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && user->Account()->greet && + check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) { - if (this->users.size() >= Config.BSMinUsers && (this->ci->botflags.HasFlag(BS_GREET)) - && user->Account() && user->Account()->greet && check_access(user, this->ci, CA_GREET)) - { - /* Only display the greet if the main uplink we're connected - * to has synced, or we'll get greet-floods when the net - * recovers from a netsplit. -GD - */ - if (user->server->IsSynced()) - { - ircdproto->SendPrivmsg(this->ci->bi, this->name.c_str(), "[%s] %s", user->Account()->display, user->Account()->greet); - this->ci->bi->lastmsg = time(NULL); - } - } + ircdproto->SendPrivmsg(this->ci->bi, this->name.c_str(), "[%s] %s", user->Account()->display, user->Account()->greet); + this->ci->bi->lastmsg = time(NULL); } } @@ -174,9 +151,9 @@ void Channel::DeleteUser(User *user) if (this->ci) update_cs_lastseen(user, this->ci); - CUserList::iterator cit; - for (cit = this->users.begin(); (*cit)->user != user && cit != this->users.end(); ++cit); - if (cit == this->users.end()) + CUserList::iterator cit, cit_end = this->users.end(); + for (cit = this->users.begin(); (*cit)->user != user && cit != cit_end; ++cit); + if (cit == cit_end) { Alog(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistant user " << user->nick << " from channel " << this->name; return; @@ -186,9 +163,9 @@ void Channel::DeleteUser(User *user) delete *cit; this->users.erase(cit); - UChannelList::iterator uit; - for (uit = user->chans.begin(); (*uit)->chan != this && uit != user->chans.end(); ++uit); - if (uit == user->chans.end()) + UChannelList::iterator uit, uit_end = user->chans.end(); + for (uit = user->chans.begin(); (*uit)->chan != this && uit != uit_end; ++uit); + if (uit == uit_end) { Alog(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistant channel " << this->name << " from " << user->nick << "'s channel list"; return; @@ -200,20 +177,20 @@ void Channel::DeleteUser(User *user) /* Channel is persistant, it shouldn't be deleted and the service bot should stay */ if (this->HasFlag(CH_PERSIST) || (this->ci && this->ci->HasFlag(CI_PERSIST))) return; - + /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediatly * We also don't part the bot here either, if necessary we will part it after the sync */ if (this->HasFlag(CH_SYNCING)) return; - + /* Additionally, do not delete this channel if ChanServ/a BotServ bot is inhabiting it */ if (this->ci && this->ci->HasFlag(CI_INHABIT)) return; if (Config.s_BotServ && this->ci && this->ci->bi && this->users.size() <= Config.BSMinUsers - 1) ircdproto->SendPart(this->ci->bi, this, NULL); - + if (this->users.empty()) delete this; } @@ -224,7 +201,7 @@ void Channel::DeleteUser(User *user) */ UserContainer *Channel::FindUser(User *u) { - for (CUserList::iterator it = this->users.begin(); it != this->users.end(); ++it) + for (CUserList::iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) if ((*it)->user == u) return *it; return NULL; @@ -312,9 +289,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* Set the status on the user */ ChannelContainer *cc = u->FindChannel(this); if (cc) - { cc->Status->SetFlag(cm->Name); - } /* Enforce secureops, etc */ chan_set_correct_modes(u, this, 0); @@ -347,9 +322,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* They could be resetting the mode to change its params */ std::map::iterator it = Params.find(cm->Name); if (it != Params.end()) - { Params.erase(it); - } Params.insert(std::make_pair(cm->Name, param)); } @@ -368,15 +341,11 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* Non registered channels can not be +r */ if (!ci && HasMode(CMODE_REGISTERED)) - { RemoveMode(NULL, CMODE_REGISTERED); - } /* Non registered channel has no mlock */ if (!ci) - { return; - } /* If this channel has this mode locked negative */ if (ci->HasMLock(cm->Name, false)) @@ -403,10 +372,8 @@ void Channel::SetModeInternal(ChannelMode *cm, const std::string ¶m, bool En /* We have the wrong param set */ if (cparam.empty() || ciparam.empty() || cparam != ciparam) - { /* Reset the mode with the correct param */ SetMode(NULL, cm, ciparam); - } } } @@ -437,9 +404,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool if (bi) { if (std::find(BotModes.begin(), BotModes.end(), cm) != BotModes.end()) - { this->SetMode(bi, cm, bi->nick); - } /* We don't track bots */ return; } @@ -456,9 +421,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool /* Remove the status on the user */ ChannelContainer *cc = u->FindChannel(this); if (cc) - { cc->Status->UnsetFlag(cm->Name); - } return; } @@ -482,9 +445,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const std::string ¶m, bool { std::map::iterator it = Params.find(cm->Name); if (it != Params.end()) - { Params.erase(it); - } } if (cm->Name == CMODE_PERM) @@ -547,13 +508,8 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const std::string ¶m, bo else if (cm->Type == MODE_PARAM && HasMode(cm->Name)) { std::string cparam; - if (GetParam(cm->Name, cparam)) - { - if (cparam == param) - { - return; - } - } + if (GetParam(cm->Name, cparam) && cparam == param) + return; } else if (cm->Type == MODE_STATUS) { @@ -684,9 +640,7 @@ const bool Channel::HasParam(ChannelModeName Name) std::map::iterator it = Params.find(Name); if (it != Params.end()) - { return true; - } return false; } @@ -707,9 +661,7 @@ void Channel::ClearModes(BotInfo *bi) if (cm && this->HasMode(cm->Name)) { if (cm->Type == MODE_REGULAR) - { this->RemoveMode(NULL, cm); - } else if (cm->Type == MODE_PARAM) { std::string param; @@ -733,14 +685,12 @@ void Channel::ClearBans(BotInfo *bi) cml = dynamic_cast(ModeManager::FindChannelModeByName(CMODE_BAN)); if (cml && this->bans && this->bans->count) - { for (entry = this->bans->entries; entry; entry = nexte) { nexte = entry->next; this->RemoveMode(bi, CMODE_BAN, entry->mask); } - } } /** Clear all the excepts from the channel @@ -754,14 +704,12 @@ void Channel::ClearExcepts(BotInfo *bi) cml = dynamic_cast(ModeManager::FindChannelModeByName(CMODE_EXCEPT)); if (cml && this->excepts && this->excepts->count) - { for (entry = this->excepts->entries; entry; entry = nexte) { nexte = entry->next; this->RemoveMode(bi, CMODE_EXCEPT, entry->mask); } - } } /** Clear all the invites from the channel @@ -775,14 +723,12 @@ void Channel::ClearInvites(BotInfo *bi) cml = dynamic_cast(ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)); if (cml && this->invites && this->invites->count) - { for (entry = this->invites->entries; entry; entry = nexte) { nexte = entry->next; this->RemoveMode(bi, CMODE_INVITEOVERRIDE, entry->mask); } - } } /** Set a string of modes on the channel @@ -802,7 +748,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0; i < modebuf.size(); ++i) + for (unsigned i = 0, end = modebuf.size(); i < end; ++i) { ChannelMode *cm; @@ -829,7 +775,7 @@ void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...) else this->SetMode(bi, cm, "", EnforceMLock); } - else if (add == 0) + else if (!add) { if (cm->Type != MODE_REGULAR && sep.GetToken(sbuf)) this->RemoveMode(bi, cm, sbuf, EnforceMLock); @@ -852,7 +798,7 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av) return; int k = 0, j = 0, add = -1; - for (unsigned int i = 0; i < strlen(av[0]); ++i) + for (unsigned int i = 0, end = strlen(av[0]); i < end; ++i) { ChannelMode *cm; @@ -899,15 +845,11 @@ void ChanSetInternalModes(Channel *c, int ac, const char **av) c->RemoveModeInternal(cm, av[j]); } else - { Alog() << "warning: ChanSetInternalModes() recieved more modes requiring params than params, modes: " << merge_args(ac, av) << ", ac: " << ac << ", j: " << j; - } } if (j + k + 1 < ac) - { Alog() << "warning: ChanSetInternalModes() recieved more params than modes requiring them, modes: " << merge_args(ac, av) << ", ac: " << ac << ", j: " << j << " k: " << k; - } } /** Kick a user from a channel internally @@ -935,7 +877,7 @@ void Channel::KickInternal(const std::string &source, const std::string &nick, c } Alog(LOG_DEBUG) << "Channel::KickInternal kicking " << user->nick << " from " << this->name; - + if (user->FindChannel(this)) { FOREACH_MOD(I_OnUserKicked, OnUserKicked(this, user, source, reason)); @@ -962,7 +904,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) /* May not kick ulines */ if (u->server->IsULined()) return false; - + /* Do not kick protected clients */ if (u->IsProtected()) return false; @@ -989,7 +931,7 @@ char *chan_get_modes(Channel * chan, int complete, int plus) if (chan->HasModes()) { - for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) + for (std::list::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) { if ((*it)->Class != MC_CHANNEL) continue; @@ -1069,7 +1011,7 @@ void get_channel_stats(long *nrec, long *memuse) { Channel *chan = cit->second; - count++; + ++count; mem += sizeof(*chan); if (chan->topic) mem += strlen(chan->topic) + 1; @@ -1084,14 +1026,15 @@ void get_channel_stats(long *nrec, long *memuse) mem += get_memuse(chan->excepts); if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)) mem += get_memuse(chan->invites); - for (CUserList::iterator it = chan->users.begin(); it != chan->users.end(); ++it) + for (CUserList::iterator it = chan->users.begin(), it_end = chan->users.end(); it != it_end; ++it) { mem += sizeof(*it); mem += sizeof((*it)->ud); if ((*it)->ud.lastline) mem += strlen((*it)->ud.lastline) + 1; } - for (bd = chan->bd; bd; bd = bd->next) { + for (bd = chan->bd; bd; bd = bd->next) + { if (bd->mask) mem += strlen(bd->mask) + 1; mem += sizeof(*bd); @@ -1106,12 +1049,12 @@ void get_channel_stats(long *nrec, long *memuse) /* Is the given nick on the given channel? This function supports links. */ -User *nc_on_chan(Channel * c, NickCore * nc) +User *nc_on_chan(Channel *c, NickCore *nc) { if (!c || !nc) return NULL; - for (CUserList::iterator it = c->users.begin(); it != c->users.end(); ++it) + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { UserContainer *uc = *it; @@ -1148,7 +1091,7 @@ void do_join(const char *source, int ac, const char **av) { if (buf[0] == '0') { - for (UChannelList::iterator it = user->chans.begin(); it != user->chans.end();) + for (UChannelList::iterator it = user->chans.begin(), it_end = user->chans.end(); it != it_end; ) { ChannelContainer *cc = *it++; @@ -1165,9 +1108,7 @@ void do_join(const char *source, int ac, const char **av) /* Channel doesn't exist, create it */ if (!chan) - { chan = new Channel(av[0], ctime); - } /* Join came with a TS */ if (ac == 2) @@ -1231,9 +1172,7 @@ void do_kick(const std::string &source, int ac, const char **av) std::string buf; commasepstream sep(av[1]); while (sep.GetToken(buf)) - { c->KickInternal(source, buf, av[2]); - } } /*************************************************************************/ @@ -1246,7 +1185,7 @@ void do_kick(const std::string &source, int ac, const char **av) void do_part(const char *source, int ac, const char **av) { User *user = finduser(source); - if (!user) + if (!user) { Alog(LOG_DEBUG) << "PART from nonexistent user " << source << ": " << merge_args(ac, av); return; @@ -1257,11 +1196,9 @@ void do_part(const char *source, int ac, const char **av) while (sep.GetToken(buf)) { Channel *c = findchan(buf); - + if (!c) - { Alog(LOG_DEBUG) << "Recieved PART from " << user->nick << " for nonexistant channel " << buf; - } Alog(LOG_DEBUG) << source << " leaves " << buf; @@ -1289,34 +1226,31 @@ void do_cmode(const char *source, int ac, const char **av) { Channel *c; ChannelInfo *ci; - unsigned int i; + unsigned i, end; const char *t; if (Capab.HasFlag(CAPAB_TSMODE) || UseTSMODE) { - for (i = 0; i < strlen(av[1]); i++) + for (i = 0, end = strlen(av[1]); i < end; ++i) if (!isdigit(av[1][i])) break; - if (av[1][i] == '\0') + if (!av[1][i]) { t = av[0]; av[0] = av[1]; av[1] = t; - ac--; - av++; + --ac; + ++av; } else Alog() << "TSMODE enabled but MODE has no valid TS"; } /* :42XAAAAAO TMODE 1106409026 #ircops +b *!*@*.aol.com */ - if (ircd->ts6) + if (ircd->ts6 && isdigit(av[0][0])) { - if (isdigit(av[0][0])) - { - ac--; - av++; - } + --ac; + ++av; } c = findchan(av[0]); @@ -1338,11 +1272,11 @@ void do_cmode(const char *source, int ac, const char **av) c->server_modecount = 0; c->server_modetime = time(NULL); } - c->server_modecount++; + ++c->server_modecount; } - ac--; - av++; + --ac; + ++av; ChanSetInternalModes(c, ac, av); } @@ -1358,16 +1292,17 @@ void do_topic(const char *source, int ac, const char **av) time_t topic_time; char *topicsetter; - if (ircd->sjb64) { + if (ircd->sjb64) + { ts = base64dects(av[2]); Alog(LOG_DEBUG) << "encoded TOPIC TS " << av[2] << " converted to " << ts; - } else { - ts = strtoul(av[2], NULL, 10); } + else + ts = strtoul(av[2], NULL, 10); topic_time = ts; - if (!c) + if (!c) { Alog(LOG_DEBUG) << "TOPIC " << merge_args(ac - 1, av + 1) << " for nonexistent channel " << av[0]; return; @@ -1387,25 +1322,25 @@ void do_topic(const char *source, int ac, const char **av) * channel exactly, there's no need to update anything and we can as * well just return silently without updating anything. -GD */ - if ((ac > 3) && *av[3] && ci && ci->last_topic - && (strcmp(av[3], ci->last_topic) == 0) - && (strcmp(topicsetter, ci->last_topic_setter.c_str()) == 0)) { + if (ac > 3 && *av[3] && ci && ci->last_topic && !strcmp(av[3], ci->last_topic) && !strcmp(topicsetter, ci->last_topic_setter.c_str())) + { delete [] topicsetter; return; } - if (check_topiclock(c, topic_time)) { + if (check_topiclock(c, topic_time)) + { delete [] topicsetter; return; } - if (c->topic) { + if (c->topic) + { delete [] c->topic; c->topic = NULL; } - if (ac > 3 && *av[3]) { + if (ac > 3 && *av[3]) c->topic = sstrdup(av[3]); - } c->topic_setter = topicsetter; c->topic_time = topic_time; @@ -1429,7 +1364,7 @@ void do_topic(const char *source, int ac, const char **av) * @param give_modes Set to 1 to give modes, 0 to not give modes * @return void **/ -void chan_set_correct_modes(User * user, Channel * c, int give_modes) +void chan_set_correct_modes(User *user, Channel *c, int give_modes) { ChannelInfo *ci; ChannelMode *owner, *admin, *op, *halfop, *voice; @@ -1443,7 +1378,7 @@ void chan_set_correct_modes(User * user, Channel * c, int give_modes) if (!c || !(ci = c->ci)) return; - if ((ci->HasFlag(CI_FORBIDDEN)) || (*(c->name.c_str()) == '+')) + if (ci->HasFlag(CI_FORBIDDEN) || *(c->name.c_str()) == '+') return; Alog(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << c->name << " (" << (give_modes ? "" : "not ") << "giving modes)"; @@ -1488,7 +1423,7 @@ void chan_set_correct_modes(User * user, Channel * c, int give_modes) */ void MassChannelModes(BotInfo *bi, const std::string &modes) { - for (channel_map::const_iterator it = ChannelList.begin(); it != ChannelList.end(); ++it) + for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { Channel *c = it->second; @@ -1502,11 +1437,11 @@ void MassChannelModes(BotInfo *bi, const std::string &modes) void restore_unsynced_topics() { - for (channel_map::const_iterator it = ChannelList.begin(); it != ChannelList.end(); ++it) + for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { Channel *c = it->second; - if (!(c->topic_sync)) + if (!c->topic_sync) restore_topic(c->name.c_str()); } } @@ -1535,28 +1470,34 @@ Entry *entry_create(char *mask) entry->mask = sstrdup(mask); host = strchr(mask, '@'); - if (host) { + if (host) + { *host++ = '\0'; /* If the user is purely a wildcard, ignore it */ if (str_is_pure_wildcard(mask)) user = NULL; - else { - + else + { /* There might be a nick too */ user = strchr(mask, '!'); - if (user) { + if (user) + { *user++ = '\0'; /* If the nick is purely a wildcard, ignore it */ if (str_is_pure_wildcard(mask)) nick = NULL; else nick = mask; - } else { + } + else + { nick = NULL; user = mask; } } - } else { + } + else + { /* It is possibly an extended ban/invite mask, but we do * not support these at this point.. ~ Viper */ /* If there's no user in the mask, assume a pure wildcard */ @@ -1564,7 +1505,8 @@ Entry *entry_create(char *mask) host = mask; } - if (nick) { + if (nick) + { entry->nick = sstrdup(nick); /* Check if we have a wildcard user */ if (str_is_wildcard(nick)) @@ -1573,7 +1515,8 @@ Entry *entry_create(char *mask) entry->SetFlag(ENTRYTYPE_NICK); } - if (user) { + if (user) + { entry->user = sstrdup(user); /* Check if we have a wildcard user */ if (str_is_wildcard(user)) @@ -1583,13 +1526,17 @@ Entry *entry_create(char *mask) } /* Only check the host if it's not a pure wildcard */ - if (*host && !str_is_pure_wildcard(host)) { - if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, &cidrhost)) { + if (*host && !str_is_pure_wildcard(host)) + { + if (ircd->cidrchanbei && str_is_cidr(host, &ip, &cidr, &cidrhost)) + { entry->cidr_ip = ip; entry->cidr_mask = cidr; entry->SetFlag(ENTRYTYPE_CIDR4); host = cidrhost; - } else if (ircd->cidrchanbei && strchr(host, '/')) { + } + else if (ircd->cidrchanbei && strchr(host, '/')) + { /* Most IRCd's don't enforce sane bans therefore it is not * so unlikely we will encounter this. * Currently we only support strict CIDR without taking into @@ -1600,7 +1547,9 @@ Entry *entry_create(char *mask) * but do not use if during matching.. ~ Viper */ entry->ClearFlags(); entry->SetFlag(ENTRYTYPE_NONE); - } else { + } + else + { entry->host = sstrdup(host); if (str_is_wildcard(host)) entry->SetFlag(ENTRYTYPE_HOST_WILD); @@ -1613,14 +1562,13 @@ Entry *entry_create(char *mask) return entry; } - /** * Create an entry and add it at the beginning of given list. * @param list The List the mask should be added to * @param mask The mask to parse and add to the list * @return Pointer to newly added entry. NULL if it fails. */ -Entry *entry_add(EList * list, const char *mask) +Entry *entry_add(EList *list, const char *mask) { Entry *e; char *hostmask; @@ -1637,18 +1585,17 @@ Entry *entry_add(EList * list, const char *mask) if (list->entries) list->entries->prev = e; list->entries = e; - list->count++; + ++list->count; return e; } - /** * Delete the given entry from a given list. * @param list Linked list from which entry needs to be removed. * @param e The entry to be deleted, must be member of list. */ -void entry_delete(EList * list, Entry * e) +void entry_delete(EList *list, Entry *e) { if (!list || !e) return; @@ -1670,10 +1617,9 @@ void entry_delete(EList * list, Entry * e) delete [] e->mask; delete e; - list->count--; + --list->count; } - /** * Create and initialize a new entrylist * @return Pointer to the created EList object @@ -1689,7 +1635,6 @@ EList *list_create() return list; } - /** * Match the given Entry to the given user/host and optional IP addy * @param e Entry struct to match against @@ -1731,7 +1676,7 @@ int entry_match(Entry *e, const ci::string &nick, const ci::string &user, const * @param ip IP to match against, set to 0 to not match this * @return 1 for a match, 0 for no match */ -int entry_match_mask(Entry * e, const char *mask, uint32 ip) +int entry_match_mask(Entry *e, const char *mask, uint32 ip) { char *hostmask, *nick, *user, *host; int res; @@ -1739,17 +1684,23 @@ int entry_match_mask(Entry * e, const char *mask, uint32 ip) hostmask = sstrdup(mask); host = strchr(hostmask, '@'); - if (host) { + if (host) + { *host++ = '\0'; user = strchr(hostmask, '!'); - if (user) { + if (user) + { *user++ = '\0'; nick = hostmask; - } else { + } + else + { nick = NULL; user = hostmask; } - } else { + } + else + { nick = NULL; user = NULL; host = hostmask; @@ -1772,18 +1723,16 @@ int entry_match_mask(Entry * e, const char *mask, uint32 ip) * @param ip The ip to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_match(EList * list, const char *nick, const char *user, const char *host, - uint32 ip) +Entry *elist_match(EList *list, const char *nick, const char *user, const char *host, uint32 ip) { Entry *e; if (!list || !list->entries) return NULL; - for (e = list->entries; e; e = e->next) { + for (e = list->entries; e; e = e->next) if (entry_match(e, nick ? nick : "", user ? user : "", host ? host : "", ip)) return e; - } /* We matched none */ return NULL; @@ -1796,7 +1745,7 @@ Entry *elist_match(EList * list, const char *nick, const char *user, const char * @param ip The ip to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_match_mask(EList * list, const char *mask, uint32 ip) +Entry *elist_match_mask(EList *list, const char *mask, uint32 ip) { char *hostmask, *nick, *user, *host; Entry *res; @@ -1807,17 +1756,23 @@ Entry *elist_match_mask(EList * list, const char *mask, uint32 ip) hostmask = sstrdup(mask); host = strchr(hostmask, '@'); - if (host) { + if (host) + { *host++ = '\0'; user = strchr(hostmask, '!'); - if (user) { + if (user) + { *user++ = '\0'; nick = hostmask; - } else { + } + else + { nick = NULL; user = hostmask; } - } else { + } + else + { nick = NULL; user = NULL; host = hostmask; @@ -1837,7 +1792,7 @@ Entry *elist_match_mask(EList * list, const char *mask, uint32 ip) * @param user The user to match against the entries * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_match_user(EList * list, User * u) +Entry *elist_match_user(EList *list, User *u) { Entry *res; char *host; @@ -1846,16 +1801,16 @@ Entry *elist_match_user(EList * list, User * u) if (!list || !list->entries || !u) return NULL; - if (u->hostip == NULL) { + if (u->hostip == NULL) + { host = host_resolve(u->host); /* we store the just resolved hostname so we don't * need to do this again */ - if (host) { + if (host) u->hostip = sstrdup(host); - } - } else { - host = sstrdup(u->hostip); } + else + host = sstrdup(u->hostip); /* Convert the host to an IP.. */ if (host) @@ -1880,17 +1835,16 @@ Entry *elist_match_user(EList * list, User * u) * @param mask The *!*@* mask to match * @return Returns the first matching entry, if none, NULL is returned. */ -Entry *elist_find_mask(EList * list, const char *mask) +Entry *elist_find_mask(EList *list, const char *mask) { Entry *e; if (!list || !list->entries || !mask) return NULL; - for (e = list->entries; e; e = e->next) { + for (e = list->entries; e; e = e->next) if (!stricmp(e->mask, mask)) return e; - } return NULL; } @@ -1900,7 +1854,7 @@ Entry *elist_find_mask(EList * list, const char *mask) * @param list The list we should estimate the mem use of. * @return Returns the memory useage of the given list. */ -long get_memuse(EList * list) +long get_memuse(EList *list) { Entry *e; long mem = 0; @@ -1910,8 +1864,10 @@ long get_memuse(EList * list) mem += sizeof(EList *); mem += sizeof(Entry *) * list->count; - if (list->entries) { - for (e = list->entries; e; e = e->next) { + if (list->entries) + { + for (e = list->entries; e; e = e->next) + { if (e->nick) mem += strlen(e->nick) + 1; if (e->user) diff --git a/src/chanserv.cpp b/src/chanserv.cpp index 10acd3731..ff698d68f 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -7,8 +7,6 @@ * * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. - * - * */ /*************************************************************************/ @@ -20,113 +18,112 @@ registered_channel_map RegisteredChannelList; static int def_levels[][2] = { - { CA_AUTOOP, 5 }, - { CA_AUTOVOICE, 3 }, - { CA_AUTODEOP, -1 }, - { CA_NOJOIN, -2 }, - { CA_INVITE, 5 }, - { CA_AKICK, 10 }, - { CA_SET, ACCESS_QOP }, - { CA_CLEAR, ACCESS_FOUNDER }, - { CA_UNBAN, 5 }, - { CA_OPDEOP, 5 }, - { CA_ACCESS_LIST, 1 }, - { CA_ACCESS_CHANGE, 10 }, - { CA_MEMO, 10 }, - { CA_ASSIGN, ACCESS_FOUNDER }, - { CA_BADWORDS, 10 }, - { CA_NOKICK, 1 }, - { CA_FANTASIA, 3 }, - { CA_SAY, 5 }, - { CA_GREET, 5 }, - { CA_VOICEME, 3 }, - { CA_VOICE, 5 }, - { CA_GETKEY, 5 }, - { CA_AUTOHALFOP, 4 }, - { CA_AUTOPROTECT, 10 }, - { CA_OPDEOPME, 5 }, - { CA_HALFOPME, 4 }, - { CA_HALFOP, 5 }, - { CA_PROTECTME, 10 }, - { CA_PROTECT, ACCESS_QOP }, - { CA_KICKME, 5 }, - { CA_KICK, 5 }, - { CA_SIGNKICK, ACCESS_FOUNDER }, - { CA_BANME, 5 }, - { CA_BAN, 5 }, - { CA_TOPIC, ACCESS_FOUNDER }, - { CA_INFO, ACCESS_QOP }, + { CA_AUTOOP, 5 }, + { CA_AUTOVOICE, 3 }, + { CA_AUTODEOP, -1 }, + { CA_NOJOIN, -2 }, + { CA_INVITE, 5 }, + { CA_AKICK, 10 }, + { CA_SET, ACCESS_QOP }, + { CA_CLEAR, ACCESS_FOUNDER }, + { CA_UNBAN, 5 }, + { CA_OPDEOP, 5 }, + { CA_ACCESS_LIST, 1 }, + { CA_ACCESS_CHANGE, 10 }, + { CA_MEMO, 10 }, + { CA_ASSIGN, ACCESS_FOUNDER }, + { CA_BADWORDS, 10 }, + { CA_NOKICK, 1 }, + { CA_FANTASIA, 3 }, + { CA_SAY, 5 }, + { CA_GREET, 5 }, + { CA_VOICEME, 3 }, + { CA_VOICE, 5 }, + { CA_GETKEY, 5 }, + { CA_AUTOHALFOP, 4 }, + { CA_AUTOPROTECT, 10 }, + { CA_OPDEOPME, 5 }, + { CA_HALFOPME, 4 }, + { CA_HALFOP, 5 }, + { CA_PROTECTME, 10 }, + { CA_PROTECT, ACCESS_QOP }, + { CA_KICKME, 5 }, + { CA_KICK, 5 }, + { CA_SIGNKICK, ACCESS_FOUNDER }, + { CA_BANME, 5 }, + { CA_BAN, 5 }, + { CA_TOPIC, ACCESS_FOUNDER }, + { CA_INFO, ACCESS_QOP }, { CA_AUTOOWNER, ACCESS_QOP }, - { CA_OWNER, ACCESS_FOUNDER }, + { CA_OWNER, ACCESS_FOUNDER }, { CA_OWNERME, ACCESS_QOP }, { CA_FOUNDER, ACCESS_QOP }, { -1 } }; - LevelInfo levelinfo[] = { - { CA_AUTODEOP, "AUTODEOP", CHAN_LEVEL_AUTODEOP }, - { CA_AUTOHALFOP, "AUTOHALFOP", CHAN_LEVEL_AUTOHALFOP }, - { CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP }, - { CA_AUTOPROTECT, "AUTOPROTECT", CHAN_LEVEL_AUTOPROTECT }, - { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE }, - { CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN }, - { CA_SIGNKICK, "SIGNKICK", CHAN_LEVEL_SIGNKICK }, - { CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST }, - { CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE }, - { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK }, - { CA_SET, "SET", CHAN_LEVEL_SET }, - { CA_BAN, "BAN", CHAN_LEVEL_BAN }, - { CA_BANME, "BANME", CHAN_LEVEL_BANME }, - { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR }, - { CA_GETKEY, "GETKEY", CHAN_LEVEL_GETKEY }, - { CA_HALFOP, "HALFOP", CHAN_LEVEL_HALFOP }, - { CA_HALFOPME, "HALFOPME", CHAN_LEVEL_HALFOPME }, - { CA_INFO, "INFO", CHAN_LEVEL_INFO }, - { CA_KICK, "KICK", CHAN_LEVEL_KICK }, - { CA_KICKME, "KICKME", CHAN_LEVEL_KICKME }, - { CA_INVITE, "INVITE", CHAN_LEVEL_INVITE }, - { CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP }, - { CA_OPDEOPME, "OPDEOPME", CHAN_LEVEL_OPDEOPME }, - { CA_PROTECT, "PROTECT", CHAN_LEVEL_PROTECT }, - { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME }, - { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC }, - { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN }, - { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE }, - { CA_VOICEME, "VOICEME", CHAN_LEVEL_VOICEME }, - { CA_MEMO, "MEMO", CHAN_LEVEL_MEMO }, - { CA_ASSIGN, "ASSIGN", CHAN_LEVEL_ASSIGN }, - { CA_BADWORDS, "BADWORDS", CHAN_LEVEL_BADWORDS }, - { CA_FANTASIA, "FANTASIA", CHAN_LEVEL_FANTASIA }, - { CA_GREET, "GREET", CHAN_LEVEL_GREET }, - { CA_NOKICK, "NOKICK", CHAN_LEVEL_NOKICK }, - { CA_SAY, "SAY", CHAN_LEVEL_SAY }, + { CA_AUTODEOP, "AUTODEOP", CHAN_LEVEL_AUTODEOP }, + { CA_AUTOHALFOP, "AUTOHALFOP", CHAN_LEVEL_AUTOHALFOP }, + { CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP }, + { CA_AUTOPROTECT, "AUTOPROTECT", CHAN_LEVEL_AUTOPROTECT }, + { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE }, + { CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN }, + { CA_SIGNKICK, "SIGNKICK", CHAN_LEVEL_SIGNKICK }, + { CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST }, + { CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE }, + { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK }, + { CA_SET, "SET", CHAN_LEVEL_SET }, + { CA_BAN, "BAN", CHAN_LEVEL_BAN }, + { CA_BANME, "BANME", CHAN_LEVEL_BANME }, + { CA_CLEAR, "CLEAR", CHAN_LEVEL_CLEAR }, + { CA_GETKEY, "GETKEY", CHAN_LEVEL_GETKEY }, + { CA_HALFOP, "HALFOP", CHAN_LEVEL_HALFOP }, + { CA_HALFOPME, "HALFOPME", CHAN_LEVEL_HALFOPME }, + { CA_INFO, "INFO", CHAN_LEVEL_INFO }, + { CA_KICK, "KICK", CHAN_LEVEL_KICK }, + { CA_KICKME, "KICKME", CHAN_LEVEL_KICKME }, + { CA_INVITE, "INVITE", CHAN_LEVEL_INVITE }, + { CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP }, + { CA_OPDEOPME, "OPDEOPME", CHAN_LEVEL_OPDEOPME }, + { CA_PROTECT, "PROTECT", CHAN_LEVEL_PROTECT }, + { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME }, + { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC }, + { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN }, + { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE }, + { CA_VOICEME, "VOICEME", CHAN_LEVEL_VOICEME }, + { CA_MEMO, "MEMO", CHAN_LEVEL_MEMO }, + { CA_ASSIGN, "ASSIGN", CHAN_LEVEL_ASSIGN }, + { CA_BADWORDS, "BADWORDS", CHAN_LEVEL_BADWORDS }, + { CA_FANTASIA, "FANTASIA", CHAN_LEVEL_FANTASIA }, + { CA_GREET, "GREET", CHAN_LEVEL_GREET }, + { CA_NOKICK, "NOKICK", CHAN_LEVEL_NOKICK }, + { CA_SAY, "SAY", CHAN_LEVEL_SAY }, { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER }, - { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER }, - { CA_OWNERME, "OWNERME", CHAN_LEVEL_OWNERME }, - { CA_FOUNDER, "FOUNDER", CHAN_LEVEL_FOUNDER }, - { -1 } + { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER }, + { CA_OWNERME, "OWNERME", CHAN_LEVEL_OWNERME }, + { CA_FOUNDER, "FOUNDER", CHAN_LEVEL_FOUNDER }, + { -1 } }; int levelinfo_maxwidth = 0; /*************************************************************************/ -void moduleAddChanServCmds() { +void moduleAddChanServCmds() +{ ModuleManager::LoadModuleList(Config.ChanServCoreModules); } -/* *INDENT-ON* */ /*************************************************************************/ /* Returns modes for mlock in a nice way. */ -char *get_mlock_modes(ChannelInfo * ci, int complete) +char *get_mlock_modes(ChannelInfo *ci, int complete) { static char res[BUFSIZE]; char *end, *value; ChannelMode *cm; ChannelModeParam *cmp; - std::map::iterator it; + std::map::iterator it, it_end; std::string param; memset(&res, '\0', sizeof(res)); @@ -138,7 +135,7 @@ char *get_mlock_modes(ChannelInfo * ci, int complete) { *end++ = '+'; - for (it = ModeManager::ChannelModesByChar.begin(); it != ModeManager::ChannelModesByChar.end(); ++it) + for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it) { cm = it->second; @@ -151,7 +148,7 @@ char *get_mlock_modes(ChannelInfo * ci, int complete) { *end++ = '-'; - for (it = ModeManager::ChannelModesByChar.begin(); it != ModeManager::ChannelModesByChar.end(); ++it) + for (it = ModeManager::ChannelModesByChar.begin(), it_end = ModeManager::ChannelModesByChar.end(); it != it_end; ++it) { cm = it->second; @@ -162,7 +159,7 @@ char *get_