From f049124905bd9f53439293e873003cb027a17b91 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 14 May 2010 20:35:38 -0400 Subject: Rewrote the hashing system to use std::tr1::unordered_map --- src/Makefile | 2 +- src/actions.c | 26 +- src/bots.cpp | 67 ++--- src/botserv.c | 90 ++---- src/channels.c | 151 ++++------ src/chanserv.c | 282 +++++++++---------- src/command.cpp | 10 +- src/commands.c | 113 +++----- src/config.c | 8 +- src/core/bs_act.c | 2 +- src/core/bs_assign.c | 2 +- src/core/bs_badwords.c | 2 +- src/core/bs_bot.c | 2 +- src/core/bs_botlist.c | 44 +-- src/core/bs_help.c | 4 +- src/core/bs_info.c | 27 +- src/core/bs_kick.c | 2 +- src/core/bs_say.c | 2 +- src/core/bs_set.c | 2 +- src/core/bs_unassign.c | 2 +- src/core/cs_access.c | 4 +- src/core/cs_akick.c | 49 ++-- src/core/cs_ban.c | 4 +- src/core/cs_clear.c | 2 +- src/core/cs_drop.c | 4 +- src/core/cs_forbid.c | 6 +- src/core/cs_getkey.c | 2 +- src/core/cs_help.c | 4 +- src/core/cs_info.c | 2 +- src/core/cs_invite.c | 2 +- src/core/cs_kick.c | 4 +- src/core/cs_list.c | 88 +++--- src/core/cs_modes.c | 32 +-- src/core/cs_register.c | 4 +- src/core/cs_set.c | 8 +- src/core/cs_status.c | 2 +- src/core/cs_suspend.c | 8 +- src/core/cs_topic.c | 10 +- src/core/cs_unban.c | 2 +- src/core/cs_xop.c | 14 +- src/core/db_plain.cpp | 444 ++++++++++++++--------------- src/core/hs_del.c | 2 +- src/core/hs_delall.c | 2 +- src/core/hs_group.c | 2 +- src/core/hs_help.c | 4 +- src/core/hs_list.c | 69 +++-- src/core/hs_off.c | 2 +- src/core/hs_on.c | 2 +- src/core/hs_set.c | 2 +- src/core/hs_setall.c | 2 +- src/core/ms_cancel.c | 2 +- src/core/ms_check.c | 2 +- src/core/ms_del.c | 2 +- src/core/ms_help.c | 4 +- src/core/ms_info.c | 2 +- src/core/ms_list.c | 2 +- src/core/ms_read.c | 2 +- src/core/ms_rsend.c | 2 +- src/core/ms_send.c | 2 +- src/core/ms_sendall.c | 20 +- src/core/ms_set.c | 2 +- src/core/ms_staff.c | 17 +- src/core/ns_access.c | 2 +- src/core/ns_alist.c | 36 ++- src/core/ns_drop.c | 6 +- src/core/ns_forbid.c | 4 +- src/core/ns_getemail.c | 23 +- src/core/ns_getpass.c | 6 +- src/core/ns_ghost.c | 2 +- src/core/ns_group.c | 8 +- src/core/ns_help.c | 4 +- src/core/ns_identify.c | 4 +- src/core/ns_info.c | 2 +- src/core/ns_list.c | 95 +++---- src/core/ns_logout.c | 2 +- src/core/ns_recover.c | 2 +- src/core/ns_register.c | 6 +- src/core/ns_release.c | 2 +- src/core/ns_resetpass.c | 2 +- src/core/ns_saset.c | 4 +- src/core/ns_sendpass.c | 2 +- src/core/ns_set.c | 2 +- src/core/ns_status.c | 2 +- src/core/ns_suspend.c | 8 +- src/core/ns_update.c | 2 +- src/core/os_akill.c | 4 +- src/core/os_chankill.c | 4 +- src/core/os_chanlist.c | 31 +-- src/core/os_clearmodes.c | 4 +- src/core/os_defcon.c | 24 +- src/core/os_global.c | 4 +- src/core/os_help.c | 4 +- src/core/os_ignore.c | 2 +- src/core/os_jupe.c | 4 +- src/core/os_kick.c | 6 +- src/core/os_mode.c | 6 +- src/core/os_modinfo.c | 49 ++-- src/core/os_modlist.c | 109 ++++---- src/core/os_modload.c | 12 +- src/core/os_modunload.c | 12 +- src/core/os_news.c | 6 +- src/core/os_noop.c | 12 +- src/core/os_oline.c | 8 +- src/core/os_quit.c | 2 +- src/core/os_reload.c | 2 +- src/core/os_restart.c | 2 +- src/core/os_session.c | 19 +- src/core/os_set.c | 10 +- src/core/os_sgline.c | 4 +- src/core/os_shutdown.c | 2 +- src/core/os_sqline.c | 4 +- src/core/os_staff.c | 6 +- src/core/os_stats.c | 2 +- src/core/os_svsnick.c | 4 +- src/core/os_szline.c | 4 +- src/core/os_umode.c | 6 +- src/core/os_update.c | 2 +- src/core/os_userlist.c | 32 +-- src/core/ss_main.c | 19 +- src/hashcomp.cpp | 43 +++ src/hostserv.c | 33 +-- src/init.c | 90 +++--- src/log.c | 2 +- src/main.c | 19 +- src/memoserv.c | 4 +- src/messages.c | 22 +- src/misc.c | 21 +- src/module.cpp | 151 +++++----- src/modulemanager.cpp | 35 ++- src/modules.c | 496 +++++---------------------------- src/modules/cs_appendtopic.c | 2 +- src/modules/cs_enforce.c | 2 +- src/modules/cs_tban.c | 2 +- src/modules/hs_request.c | 10 +- src/modules/mysql/db_mysql.h | 7 - src/modules/mysql/db_mysql_execute.cpp | 25 +- src/modules/mysql/db_mysql_read.cpp | 8 +- src/modules/mysql/db_mysql_write.cpp | 174 +++++------- src/modules/ns_maxemail.c | 13 +- src/modules/os_info.c | 27 +- src/nickalias.cpp | 24 +- src/nickcore.cpp | 13 +- src/nickserv.c | 343 ++++++++--------------- src/operserv.c | 60 ++-- src/process.c | 29 +- src/protocol/bahamut.c | 62 ++--- src/protocol/inspircd11.c | 79 +++--- src/protocol/inspircd12.cpp | 103 ++++--- src/protocol/ratbox.c | 60 ++-- src/protocol/unreal32.c | 139 +++++---- src/regchannel.cpp | 14 +- src/servers.cpp | 10 +- src/sessions.c | 78 ++---- src/users.c | 210 +++++--------- 154 files changed, 1913 insertions(+), 2825 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index c82f9f5b4..1756e6702 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,7 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o command.o comm INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \ ../include/pseudo.h ../include/sysconf.h ../include/config.h \ - ../include/messages.h ../include/services.h \ + ../include/services.h \ ../include/timers.h ../include/extern.h \ ../include/modules.h ../include/slist.h ../include/hashcomp.h \ ../include/threadengine.h ../include/mail.h diff --git a/src/actions.c b/src/actions.c index 471e1273f..e3f199e80 100644 --- a/src/actions.c +++ b/src/actions.c @@ -77,32 +77,26 @@ void kill_user(const std::string &source, const std::string &user, const std::st */ void sqline(const std::string &mask, const std::string &reason) { - int i; - Channel *c, *next; - if (ircd->chansqline) { if (mask[0] == '#') { ircdproto->SendSQLine(mask, reason); - for (i = 0; i < 1024; ++i) + for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) { - for (c = chanlist[i]; c; c = next) + Channel *c = cit->second; + + if (!Anope::Match(c->name, mask, false)) + continue; + for (CUserList::iterator it = c->users.begin(); it != c->users.end();) { - next = c->next; + UserContainer *uc = *it; + ++it; - if (!Anope::Match(c->name, mask, false)) + if (is_oper(uc->user)) continue; - for (CUserList::iterator it = c->users.begin(); it != c->users.end();) - { - UserContainer *uc = *it; - ++it; - - if (is_oper(uc->user)) - continue; - c->Kick(NULL, uc->user, "%s", reason.c_str()); - } + c->Kick(NULL, uc->user, "%s", reason.c_str()); } } } diff --git a/src/bots.cpp b/src/bots.cpp index 6f544a64a..a8cc86654 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -12,6 +12,8 @@ #include "modules.h" #include "commands.h" +botinfo_map BotList; + BotInfo *BotServ = NULL; BotInfo *ChanServ = NULL; BotInfo *Global = NULL; @@ -28,54 +30,39 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: this->real = nreal; this->lastmsg = this->created = time(NULL); this->uid = ts6_uid_retrieve(); - this->cmdTable = NULL; - ++nbots; this->chancount = 0; ci::string ci_nick(nnick.c_str()); if (Config.s_ChanServ && ci_nick == Config.s_ChanServ) { ChanServ = this; - this->cmdTable = CHANSERV; - this->SetFlag(BI_CHANSERV); } else if (Config.s_BotServ && ci_nick == Config.s_BotServ) { BotServ = this; - this->cmdTable = BOTSERV; - this->SetFlag(BI_BOTSERV); } else if (Config.s_HostServ && ci_nick == Config.s_HostServ) { HostServ = this; - this->cmdTable = HOSTSERV; - this->SetFlag(BI_HOSTSERV); } else if (Config.s_OperServ && ci_nick == Config.s_OperServ) { OperServ = this; - this->cmdTable = OPERSERV; - this->SetFlag(BI_OPERSERV); } else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ) { MemoServ = this; - this->cmdTable = MEMOSERV; - this->SetFlag(BI_MEMOSERV); } else if (Config.s_NickServ && ci_nick == Config.s_NickServ) { NickServ = this; - this->cmdTable = NICKSERV; - this->SetFlag(BI_NICKSERV); } else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer) { Global = this; - this->SetFlag(BI_GLOBAL); } - insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL. + BotList[this->nick.c_str()] = this; // If we're synchronised with the uplink already, call introduce_user() for this bot. if (Me && Me->GetUplink()->IsSynced()) @@ -86,48 +73,38 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std:: BotInfo::~BotInfo() { - int i; - ChannelInfo *ci; - - for (i = 0; i < 256; ++i) - for (ci = chanlists[i]; ci; ci = ci->next) - if (ci->bi == this) - ci->bi = NULL; - - if (this->next) - this->next->prev = this->prev; - if (this->prev) - this->prev->next = this->next; - else - botlists[tolower(this->nick[0])] = this->next; - - --nbots; + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + { + ChannelInfo *ci = it->second; + + if (ci->bi == this) + { + ci->bi = NULL; + } + } + + BotList.erase(this->nick.c_str()); } void BotInfo::ChangeNick(const char *newnick) { - if (this->next) - this->next->prev = this->prev; - if (this->prev) - this->prev->next = this->next; - else - botlists[tolower(this->nick[0])] = this->next; + BotList.erase(this->nick.c_str()); this->nick = newnick; - insert_bot(this); + BotList[this->nick.c_str()] = this; } void BotInfo::RejoinAll() { - int i; - ChannelInfo *ci; + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + { + ChannelInfo *ci = it->second; - for (i = 0; i < 256; ++i) - for (ci = chanlists[i]; ci; ci = ci->next) - if (ci->bi == this && ci->c && (ci->c->users.size() >= Config.BSMinUsers)) - bot_join(ci); + if (ci->bi == this && ci->c && ci->c->users.size() >= Config.BSMinUsers) + bot_join(ci); + } } void BotInfo::Assign(User *u, ChannelInfo *ci) diff --git a/src/botserv.c b/src/botserv.c index d0862c119..ea675ea60 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -18,11 +18,6 @@ /*************************************************************************/ -BotInfo *botlists[256]; /* Hash list of bots */ -int nbots = 0; - -/*************************************************************************/ - static UserData *get_user_data(Channel * c, User * u); static void check_ban(ChannelInfo * ci, User * u, int ttbtype); @@ -44,18 +39,17 @@ void moduleAddBotServCmds() { void get_botserv_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - int i; - BotInfo *bi; - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - count++; - mem += sizeof(*bi); - mem += bi->nick.size() + 1; - mem += bi->user.size() + 1; - mem += bi->host.size() + 1; - mem += bi->real.size() + 1; - } + + for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) + { + BotInfo *bi = it->second; + + count++; + mem += sizeof(*bi); + mem += bi->nick.size() + 1; + mem += bi->user.size() + 1; + mem += bi->host.size() + 1; + mem += bi->real.size() + 1; } *nrec = count; @@ -90,9 +84,9 @@ void botserv(User * u, char *buf) if (!(s = strtok(NULL, ""))) { *s = 0; } - ircdproto->SendCTCP(findbot(Config.s_BotServ), u->nick.c_str(), "PING %s", s); + ircdproto->SendCTCP(BotServ, u->nick.c_str(), "PING %s", s); } else { - mod_run_cmd(Config.s_BotServ, u, BOTSERV, cmd); + mod_run_cmd(BotServ, u, cmd); } } @@ -106,7 +100,7 @@ void botmsgs(User * u, BotInfo * bi, char *buf) char *cmd = strtok(buf, " "); char *s; - if (!cmd || !u) + if (!cmd || !u || !bi) return; if (!stricmp(cmd, "\1PING")) { @@ -115,9 +109,9 @@ void botmsgs(User * u, BotInfo * bi, char *buf) } ircdproto->SendCTCP(bi, u->nick.c_str(), "PING %s", s); } - else if (cmd && bi->cmdTable) + else if (cmd && !bi->Commands.empty()) { - mod_run_cmd(bi->nick, u, bi->cmdTable, cmd); + mod_run_cmd(bi, u, cmd); } } @@ -134,7 +128,6 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) char *cmd; UserData *ud; bool was_action = false; - Command *command; std::string bbuf; if (!u || !buf || !ci || !ci->c) @@ -424,7 +417,7 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) if (check_access(u, ci, CA_FANTASIA)) { - command = findCommand(CHANSERV, cmd); + Command *command = FindCommand(ChanServ, cmd); /* Command exists and can not be called by fantasy */ if (command && !command->HasFlag(CFLAG_DISABLE_FANTASY)) @@ -459,53 +452,22 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) /*************************************************************************/ -/* Inserts a bot in the bot list. I can't be much explicit mh? */ - -void insert_bot(BotInfo *bi) +BotInfo *findbot(const char *nick) { - BotInfo *ptr, *prev; - - ci::string ci_bi_nick(bi->nick.c_str()); - for (prev = NULL, ptr = botlists[tolower(bi->nick[0])]; - ptr != NULL && ci_bi_nick > ptr->nick.c_str(); - prev = ptr, ptr = ptr->next); - bi->prev = prev; - bi->next = ptr; - if (!prev) - botlists[tolower(bi->nick[0])] = bi; - else - prev->next = bi; - if (ptr) - ptr->prev = bi; + return findbot(ci::string(nick)); } -/*************************************************************************/ -/*************************************************************************/ - BotInfo *findbot(const std::string &nick) { - BotInfo *bi; - - if (nick.empty()) - return NULL; - - ci::string ci_nick(nick.c_str()); - - /* - * XXX Less than efficient, but we need to do this for good TS6 support currently. This *will* improve. -- w00t - */ - for (int i = 0; i < 256; i++) - { - for (bi = botlists[i]; bi; bi = bi->next) - { - if (ci_nick == bi->nick) - return bi; + return findbot(ci::string(nick.c_str())); +} - if (ci_nick == bi->uid) - return bi; - } - } +BotInfo *findbot(const ci::string &nick) +{ + botinfo_map::const_iterator it = BotList.find(nick); + if (it != BotList.end()) + return it->second; return NULL; } diff --git a/src/channels.c b/src/channels.c index a4cf3b167..6250d2342 100644 --- a/src/channels.c +++ b/src/channels.c @@ -15,11 +15,7 @@ #include "language.h" #include "modules.h" -Channel *chanlist[1024]; - -#define HASH(chan) ((chan)[1] ? ((chan)[1]&31)<<5 | ((chan)[2]&31) : 0) - -/*************************************************************************/ +channel_map ChannelList; /** Default constructor * @param name The channel name @@ -27,18 +23,12 @@ Channel *chanlist[1024]; */ Channel::Channel(const std::string &name, time_t ts) { - Channel **list; - if (name.empty()) throw CoreException("A channel without a name ?"); this->name = name; - list = &chanlist[HASH(this->name)]; - this->prev = NULL; - this->next = *list; - if (*list) - (*list)->prev = this; - *list = this; + + ChannelList[this->name.c_str()] = this; this->creation_time = ts; this->topic = NULL; @@ -102,12 +92,7 @@ Channel::~Channel() } } - if (this->next) - this->next->prev = this->prev; - if (this->prev) - this->prev->next = this->next; - else - chanlist[HASH(this->name)] = this->next; + ChannelList.erase(this->name.c_str()); } void Channel::Sync() @@ -1051,61 +1036,23 @@ char *chan_get_modes(Channel * chan, int complete, int plus) /*************************************************************************/ -/* Return the Channel structure corresponding to the named channel, or NULL - * if the channel was not found. chan is assumed to be non-NULL and valid - * (i.e. pointing to a channel name of 2 or more characters). */ - Channel *findchan(const char *chan) { - Channel *c; - - if (!chan || !*chan) - { - Alog(LOG_DEBUG) << "findchan() called with NULL values"; - return NULL; - } - - c = chanlist[HASH(chan)]; - while (c) - { - if (stricmp(c->name.c_str(), chan) == 0) - { - Alog(LOG_DEBUG_3) << "findchan(" << chan << ") -> " << static_cast(c); - return c; - } - c = c->next; - } - return NULL; + return findchan(ci::string(chan)); } -/*************************************************************************/ - -/* Iterate over all channels in the channel list. Return NULL at end of - * list. - */ - -static Channel *current; -static int next_index; - -Channel *firstchan() +Channel *findchan(const std::string &chan) { - next_index = 0; - while (next_index < 1024 && current == NULL) - current = chanlist[next_index++]; - Alog(LOG_DEBUG_3) << "firstchan() returning " << (current ? current->name : "NULL (end of list)"); - return current; + return findchan(ci::string(chan.c_str())); } -Channel *nextchan() +Channel *findchan(const ci::string &chan) { - if (current) - current = current->next; - if (!current && next_index < 1024) { - while (next_index < 1024 && current == NULL) - current = chanlist[next_index++]; - } - Alog(LOG_DEBUG_3) << "nextchan() returning " << (current ? current->name : "NULL (end of list)"); - return current; + channel_map::const_iterator it = ChannelList.find(chan); + + if (it != ChannelList.end()) + return it->second; + return NULL; } /*************************************************************************/ @@ -1115,40 +1062,39 @@ Channel *nextchan() void get_channel_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - Channel *chan; BanData *bd; - int i; std::string buf; - for (i = 0; i < 1024; i++) { - for (chan = chanlist[i]; chan; chan = chan->next) { - count++; - mem += sizeof(*chan); - if (chan->topic) - mem += strlen(chan->topic) + 1; - if (chan->GetParam(CMODE_KEY, buf)) - mem += buf.length() + 1; - if (chan->GetParam(CMODE_FLOOD, buf)) - mem += buf.length() + 1; - if (chan->GetParam(CMODE_REDIRECT, buf)) - mem += buf.length() + 1; - mem += get_memuse(chan->bans); - if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) - 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) - { - 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) { - if (bd->mask) - mem += strlen(bd->mask) + 1; - mem += sizeof(*bd); - } + for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) + { + Channel *chan = cit->second; + + count++; + mem += sizeof(*chan); + if (chan->topic) + mem += strlen(chan->topic) + 1; + if (chan->GetParam(CMODE_KEY, buf)) + mem += buf.length() + 1; + if (chan->GetParam(CMODE_FLOOD, buf)) + mem += buf.length() + 1; + if (chan->GetParam(CMODE_REDIRECT, buf)) + mem += buf.length() + 1; + mem += get_memuse(chan->bans); + if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) + 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) + { + 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) { + if (bd->mask) + mem += strlen(bd->mask) + 1; + mem += sizeof(*bd); } } *nrec = count; @@ -1542,10 +1488,10 @@ void chan_set_correct_modes(User * user, Channel * c, int give_modes) */ void MassChannelModes(BotInfo *bi, const std::string &modes) { - Channel *c; - - for (c = firstchan(); c; c = nextchan()) + for (channel_map::const_iterator it = ChannelList.begin(); it != ChannelList.end(); ++it) { + Channel *c = it->second; + if (c->bouncy_modes) return; c->SetModes(bi, false, modes.c_str()); @@ -1556,9 +1502,10 @@ void MassChannelModes(BotInfo *bi, const std::string &modes) void restore_unsynced_topics() { - Channel *c; + for (channel_map::const_iterator it = ChannelList.begin(); it != ChannelList.end(); ++it) + { + Channel *c = it->second; - for (c = firstchan(); c; c = nextchan()) { if (!(c->topic_sync)) restore_topic(c->name.c_str()); } diff --git a/src/chanserv.c b/src/chanserv.c index 377a04323..872055df1 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -19,7 +19,7 @@ /*************************************************************************/ /* *INDENT-OFF* */ -ChannelInfo *chanlists[256]; +registered_channel_map RegisteredChannelList; static int def_levels[][2] = { { CA_AUTOOP, 5 }, @@ -195,51 +195,51 @@ char *get_mlock_modes(ChannelInfo * ci, int complete) void get_chanserv_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - unsigned i, j; - ChannelInfo *ci; std::string param; - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = ci->next) { - count++; - mem += sizeof(*ci); - if (ci->desc) - mem += strlen(ci->desc) + 1; - if (ci->url) - mem += strlen(ci->url) + 1; - if (ci->email) - mem += strlen(ci->email) + 1; - mem += ci->GetAccessCount() * sizeof(ChanAccess); - mem += ci->GetAkickCount() * sizeof(AutoKick); - - if (ci->GetParam(CMODE_KEY, param)) - mem += param.length() + 1; - - if (ci->GetParam(CMODE_FLOOD, param)) - mem += param.length() + 1; - - if (ci->GetParam(CMODE_REDIRECT, param)) - mem += param.length() + 1; - - if (ci->last_topic) - mem += strlen(ci->last_topic) + 1; - if (ci->entry_message) - mem += strlen(ci->entry_message) + 1; - if (ci->forbidby) - mem += strlen(ci->forbidby) + 1; - if (ci->forbidreason) - mem += strlen(ci->forbidreason) + 1; - if (ci->levels) - mem += sizeof(*ci->levels) * CA_SIZE; - mem += ci->memos.memos.size() * sizeof(Memo); - for (j = 0; j < ci->memos.memos.size(); j++) { - if (ci->memos.memos[j]->text) - mem += strlen(ci->memos.memos[j]->text) + 1; - } - if (ci->ttb) - mem += sizeof(*ci->ttb) * TTB_SIZE; - mem += ci->GetBadWordCount() * sizeof(BadWord); + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + { + ChannelInfo *ci = it->second; + + count++; + mem += sizeof(*ci); + if (ci->desc) + mem += strlen(ci->desc) + 1; + if (ci->url) + mem += strlen(ci->url) + 1; + if (ci->email) + mem += strlen(ci->email) + 1; + mem += ci->GetAccessCount() * sizeof(ChanAccess); + mem += ci->GetAkickCount() * sizeof(AutoKick); + + if (ci->GetParam(CMODE_KEY, param)) + mem += param.length() + 1; + + if (ci->GetParam(CMODE_FLOOD, param)) + mem += param.length() + 1; + + if (ci->GetParam(CMODE_REDIRECT, param)) + mem += param.length() + 1; + + if (ci->last_topic) + mem += strlen(ci->last_topic) + 1; + if (ci->entry_message) + mem += strlen(ci->entry_message) + 1; + if (ci->forbidby) + mem += strlen(ci->forbidby) + 1; + if (ci->forbidreason) + mem += strlen(ci->forbidreason) + 1; + if (ci->levels) + mem += sizeof(*ci->levels) * CA_SIZE; + mem += ci->memos.memos.size() * sizeof(Memo); + for (unsigned j = 0; j < ci->memos.memos.size(); j++) + { + if (ci->memos.memos[j]->text) + mem += strlen(ci->memos.memos[j]->text) + 1; } + if (ci->ttb) + mem += sizeof(*ci->ttb) * TTB_SIZE; + mem += ci->GetBadWordCount() * sizeof(BadWord); } *nrec = count; *memuse = mem; @@ -271,9 +271,9 @@ void chanserv(User * u, char *buf) if (!(s = strtok(NULL, ""))) { *s = 0; } - ircdproto->SendCTCP(findbot(Config.s_ChanServ), u->nick.c_str(), "PING %s", s); + ircdproto->SendCTCP(ChanServ, u->nick.c_str(), "PING %s", s); } else { - mod_run_cmd(Config.s_ChanServ, u, CHANSERV, cmd); + mod_run_cmd(ChanServ, u, cmd); } } @@ -632,15 +632,15 @@ void restore_topic(const char *chan) c->topic_setter = whosends(ci)->nick; } if (ircd->join2set) { - if (whosends(ci) == findbot(Config.s_ChanServ)) { - ircdproto->SendJoin(findbot(Config.s_ChanServ), chan, c->creation_time); + if (whosends(ci) == ChanServ) { + ircdproto->SendJoin(ChanServ, chan, c->creation_time); c->SetMode(NULL, CMODE_OP, Config.s_ChanServ); } } ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : ""); if (ircd->join2set) { - if (whosends(ci) == findbot(Config.s_ChanServ)) { - ircdproto->SendPart(findbot(Config.s_ChanServ), c, NULL); + if (whosends(ci) == ChanServ) { + ircdproto->SendPart(ChanServ, c, NULL); } } } @@ -692,8 +692,8 @@ int check_topiclock(Channel * c, time_t topic_time) } if (ircd->join2set) { - if (whosends(ci) == findbot(Config.s_ChanServ)) { - ircdproto->SendJoin(findbot(Config.s_ChanServ), c->name.c_str(), c->creation_time); + if (whosends(ci) == ChanServ) { + ircdproto->SendJoin(ChanServ, c->name.c_str(), c->creation_time); c->SetMode(NULL, CMODE_OP, Config.s_ChanServ); } } @@ -701,8 +701,8 @@ int check_topiclock(Channel * c, time_t topic_time) ircdproto->SendTopic(whosends(ci), c, c->topic_setter.c_str(), c->topic ? c->topic : ""); if (ircd->join2set) { - if (whosends(ci) == findbot(Config.s_ChanServ)) { - ircdproto->SendPart(findbot(Config.s_ChanServ), c, NULL); + if (whosends(ci) == ChanServ) { + ircdproto->SendPart(ChanServ, c, NULL); } } return 1; @@ -714,118 +714,113 @@ int check_topiclock(Channel * c, time_t topic_time) void expire_chans() { - ChannelInfo *ci, *next; - int i; - time_t now = time(NULL); - if (!Config.CSExpire) return; + + time_t now = time(NULL); - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = next) { - next = ci->next; - if (!ci->c && now - ci->last_used >= Config.CSExpire && !ci->HasFlag(CI_FORBIDDEN) && !ci->HasFlag(CI_NO_EXPIRE) && !ci->HasFlag(CI_SUSPENDED)) - { - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreChanExpire, OnPreChanExpire(ci)); - if (MOD_RESULT == EVENT_STOP) - continue; + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end();) + { + ChannelInfo *ci = it->second; + ++it; - char *chname = sstrdup(ci->name.c_str()); - Alog() << "Expiring channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << " )"; - delete ci; - FOREACH_MOD(I_OnChanExpire, OnChanExpire(chname)); - delete [] chname; - } + if (!ci->c && now - ci->last_used >= Config.CSExpire && !ci->HasFlag(CI_FORBIDDEN) && !ci->HasFlag(CI_NO_EXPIRE) && !ci->HasFlag(CI_SUSPENDED)) + { + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnPreChanExpire, OnPreChanExpire(ci)); + if (MOD_RESULT == EVENT_STOP) + continue; + + char *chname = sstrdup(ci->name.c_str()); + Alog() << "Expiring channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << " )"; + delete ci; + FOREACH_MOD(I_OnChanExpire, OnChanExpire(chname)); + delete [] chname; } } } /*************************************************************************/ -/* Remove a (deleted or expired) nickname from all channel lists. */ - +// XXX this is slightly inefficient void cs_remove_nick(const NickCore * nc) { - int i, j; - ChannelInfo *ci, *next; + int j; ChanAccess *ca; AutoKick *akick; - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = next) { - next = ci->next; - if (ci->founder == nc) { - if (ci->successor) { - NickCore *nc2 = ci->successor; - if (!nc2->IsServicesOper() && Config.CSMaxReg && nc2->channelcount >= Config.CSMaxReg) { - Alog() << Config.s_ChanServ << ": Successor (" << nc2->display << " ) of " << ci->name << " owns too many channels, deleting channel", - delete ci; - continue; - } else { - Alog() << Config.s_ChanServ << ": Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to successor " << nc2->display; - ci->founder = nc2; - ci->successor = NULL; - nc2->channelcount++; - } + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + { + ChannelInfo *ci = it->second; + + if (ci->founder == nc) { + if (ci->successor) { + NickCore *nc2 = ci->successor; + if (!nc2->IsServicesOper() && Config.CSMaxReg && nc2->channelcount >= Config.CSMaxReg) { + Alog() << Config.s_ChanServ << ": Successor (" << nc2->display << " ) of " << ci->name << " owns too many channels, deleting channel", + delete ci; + continue; } else { - Alog() << Config.s_ChanServ << ": Deleting channel " << ci->name << "owned by deleted nick " << nc->display; + Alog() << Config.s_ChanServ << ": Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to successor " << nc2->display; + ci->founder = nc2; + ci->successor = NULL; + nc2->channelcount++; + } + } else { + Alog() << Config.s_ChanServ << ": Deleting channel " << ci->name << "owned by deleted nick " << nc->display; - if ((ModeManager::FindChannelModeByName(CMODE_REGISTERED))) + if ((ModeManager::FindChannelModeByName(CMODE_REGISTERED))) + { + /* Maybe move this to delchan() ? */ + if (ci->c && ci->c->HasMode(CMODE_REGISTERED)) { - /* Maybe move this to delchan() ? */ - if (ci->c && ci->c->HasMode(CMODE_REGISTERED)) - { - ci->c->RemoveMode(NULL, CMODE_REGISTERED); - } + ci->c->RemoveMode(NULL, CMODE_REGISTERED); } - - delete ci; - continue; } + + delete ci; + continue; } + } - if (ci->successor == nc) - ci->successor = NULL; + if (ci->successor == nc) + ci->successor = NULL; - for (j = ci->GetAccessCount(); j > 0; --j) - { - ca = ci->GetAccess(j - 1); + for (j = ci->GetAccessCount(); j > 0; --j) + { + ca = ci->GetAccess(j - 1); - if (ca->in_use && ca->nc == nc) - ci->EraseAccess(j - 1); - } + if (ca->in_use && ca->nc == nc) + ci->EraseAccess(j - 1); + } - for (j = ci->GetAkickCount(); j > 0; --j) - { - akick = ci->GetAkick(j - 1); - if (akick->InUse && akick->HasFlag(AK_ISNICK) && akick->nc == nc) - ci->EraseAkick(akick); - } + for (j = ci->GetAkickCount(); j > 0; --j) + { + akick = ci->GetAkick(j - 1); + if (akick->InUse && akick->HasFlag(AK_ISNICK) && akick->nc == nc) + ci->EraseAkick(akick); } } } /*************************************************************************/ -/* Return the ChannelInfo structure for the given channel, or NULL if the - * channel isn't registered. */ +ChannelInfo *cs_findchan(const char *chan) +{ + return cs_findchan(ci::string(chan)); +} ChannelInfo *cs_findchan(const std::string &chan) { - ChannelInfo *ci; + return cs_findchan(ci::string(chan.c_str())); +} - if (chan.empty()) - { - Alog(LOG_DEBUG) << "cs_findchan() called with NULL values"; - return NULL; - } +ChannelInfo *cs_findchan(const ci::string &chan) +{ + registered_channel_map::const_iterator it = RegisteredChannelList.find(chan); - for (ci = chanlists[static_cast(tolower(chan[1]))]; ci; - ci = ci->next) { - if (ci::string(ci->name.c_str()) == chan) - return ci; - } + if (it != RegisteredChannelList.end()) + return it->second; return NULL; } @@ -872,33 +867,6 @@ int check_access(User * user, ChannelInfo * ci, int what) /*********************** ChanServ private routines ***********************/ /*************************************************************************/ -/* Insert a channel alphabetically into the database. */ - -void alpha_insert_chan(ChannelInfo * ci) -{ - ChannelInfo *ptr, *prev; - - if (!ci) - { - Alog(LOG_DEBUG) << "alpha_insert_chan() called with NULL values"; - return; - } - - const char *chan = ci->name.c_str(); - - for (prev = NULL, ptr = chanlists[static_cast(tolower(chan[1]))]; - ptr != NULL && stricmp(ptr->name.c_str(), chan) < 0; - prev = ptr, ptr = ptr->next); - ci->prev = prev; - ci->next = ptr; - if (!prev) - chanlists[static_cast(tolower(chan[1]))] = ci; - else - prev->next = ci; - if (ptr) - ptr->prev = ci; -} - /* Reset channel access level values to their default state. */ void reset_levels(ChannelInfo * ci) @@ -1204,7 +1172,7 @@ void ChanServTimer::Tick(time_t) if (!c->users.empty()) return; - ircdproto->SendPart(findbot(Config.s_ChanServ), c, NULL); + ircdproto->SendPart(ChanServ, c, NULL); /* Now delete the channel as it is empty */ if (!c->HasFlag(CH_PERSIST) && !c->ci->HasFlag(CI_PERSIST)) diff --git a/src/command.cpp b/src/command.cpp index fc745fe46..b440c741f 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -12,20 +12,12 @@ Command::Command(const ci::string &sname, size_t min_params, size_t max_params, const std::string &spermission) : MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission) { - this->core = 0; - this->mod_name = NULL; + this->module = NULL; this->service = NULL; - this->next = NULL; } Command::~Command() { - if (this->mod_name) { - delete [] this->mod_name; - } - if (this->service) { - delete [] this->service; - } } CommandReturn Command::Execute(User *u, const std::vector &) { return MOD_CONT; } diff --git a/src/commands.c b/src/commands.c index 40363a7d1..71c4c986a 100644 --- a/src/commands.c +++ b/src/commands.c @@ -16,75 +16,36 @@ #include "language.h" #include "hashcomp.h" -/*************************************************************************/ - -/** - * Search the command table gieven for a command. - * @param cmdTable the name of the command table to search - * @param name the name of the command to look for - * @return returns a pointer to the found command struct, or NULL - */ -Command *findCommand(CommandHash * cmdTable[], const char *name) +Command *FindCommand(BotInfo *bi, const ci::string &name) { - int idx; - CommandHash *current = NULL; - if (!cmdTable || !name) { + if (!bi || bi->Commands.empty() || name.empty()) return NULL; - } + + std::map::iterator it = bi->Commands.find(name); - idx = CMD_HASH(name); + if (it != bi->Commands.end()) + return it->second; - for (current = cmdTable[idx]; current; current = current->next) { - if (stricmp(name, current->name) == 0) { - return current->c; - } - } return NULL; } -/** - * Return the Command corresponding to the given name, or NULL if no such - * command exists. - * @param list Command struct - * @param cmd Command to look up - * @return Command Struct for the given cmd - */ -Command *lookup_cmd(Command * list, char *cmd) +void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd) { - Command *c; - - for (c = list; ; c++) { - if (stricmp(c->name.c_str(), cmd) == 0) { - return c; - } - } -} - -/*************************************************************************/ + if (!bi || !u || cmd.empty()) + return; -/** - * Run the routine for the given command, if it exists and the user has - * privilege to do so; if not, print an appropriate error message. - * @param services Services Client - * @param u User Struct - * @param Command Hash Table - * @param cmd Command - * @return void - */ -void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], const char *cmd) -{ - Command *c = findCommand(cmdTable, cmd); + Command *c = FindCommand(bi, cmd); int retVal = MOD_CONT; ChannelInfo *ci; - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(service, u, cmd, c)); + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(bi, u, cmd, c)); if (MOD_RESULT == EVENT_STOP) return; if (!c) { - notice_lang(service, u, UNKNOWN_COMMAND_HELP, cmd, service.c_str()); + notice_lang(bi->nick, u, UNKNOWN_COMMAND_HELP, cmd.c_str(), bi->nick.c_str()); return; } @@ -93,8 +54,8 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], // Command requires registered users only if (!u->IsIdentified()) { - notice_lang(service, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); - Alog() << "Access denied for unregistered user " << u->nick << " with service " << service << " and command " << cmd; + notice_lang(bi->nick, u, NICK_IDENTIFY_REQUIRED, Config.s_NickServ); + Alog() << "Access denied for unregistered user " << u->nick << " with service " << bi->nick << " and command " << cmd; return; } } @@ -131,11 +92,11 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], return; } - FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->service, c->name.c_str(), params)); + FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->service, c->name, params)); if (MOD_RESULT == EVENT_STOP) return; - if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (cmdTable == CHANSERV || cmdTable == BOTSERV)) + if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ)) { if (ircdproto->IsChannelValid(params[0].c_str())) { @@ -143,29 +104,29 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], { if ((ci->HasFlag(CI_FORBIDDEN)) && (!c->HasFlag(CFLAG_ALLOW_FORBIDDEN))) { - notice_lang(service, u, CHAN_X_FORBIDDEN, ci->name.c_str()); - Alog() << "Access denied for user " << u->nick << " with service " << service + notice_lang(bi->nick, u, CHAN_X_FORBIDDEN, ci->name.c_str()); + Alog() << "Access denied for user " << u->nick << " with service " << bi->nick << " and command " << cmd << " because of FORBIDDEN channel " << ci->name; return; } else if ((ci->HasFlag(CI_SUSPENDED)) && (!c->HasFlag(CFLAG_ALLOW_SUSPENDED))) { - notice_lang(service, u, CHAN_X_FORBIDDEN, ci->name.c_str()); - Alog() << "Access denied for user " << u->nick << " with service " << service + notice_lang(bi->nick, u, CHAN_X_FORBIDDEN, ci->name.c_str()); + Alog() << "Access denied for user " << u->nick << " with service " << bi->nick <<" and command " << cmd << " because of SUSPENDED channel " << ci->name; return; } } else if (!c->HasFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL)) { - notice_lang(service, u, CHAN_X_NOT_REGISTERED, params[0].c_str()); + notice_lang(bi->nick, u, CHAN_X_NOT_REGISTERED, params[0].c_str()); return; } } /* A user not giving a channel name for a param that should be a channel */ else { - notice_lang(service, u, CHAN_X_INVALID, params[0].c_str()); + notice_lang(bi->nick, u, CHAN_X_INVALID, params[0].c_str()); return; } } @@ -175,8 +136,8 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], { if (!u->Account()->HasCommand(c->permission)) { - notice_lang(service, u, ACCESS_DENIED); - Alog() << "Access denied for user " << u->nick << " with service " << service << " and command " << cmd; + notice_lang(bi->nick, u, ACCESS_DENIED); + Alog() << "Access denied for user " << u->nick << " with service " << bi->nick << " and command " << cmd; return; } @@ -190,8 +151,6 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], } } -/*************************************************************************/ - /** * Prints the help message for a given command. * @param services Services Client @@ -200,36 +159,38 @@ void mod_run_cmd(const std::string &service, User * u, CommandHash * cmdTable[], * @param cmd Command * @return void */ -void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[], const char *cmd) +void mod_help_cmd(BotInfo *bi, User *u, const ci::string &cmd) { + if (!bi || !u || cmd.empty()) + return; + spacesepstream tokens(cmd); - std::string token; + ci::string token; tokens.GetToken(token); - Command *c = findCommand(cmdTable, token.c_str()); + Command *c = FindCommand(bi, token); ci::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining().c_str(); if (!c || !c->OnHelp(u, subcommand)) - notice_lang(service, u, NO_HELP_AVAILABLE, cmd); + notice_lang(bi->nick, u, NO_HELP_AVAILABLE, cmd.c_str()); else { - u->SendMessage(service, " "); + u->SendMessage(bi->nick, " "); /* Inform the user what permission is required to use the command */ if (!c->permission.empty()) - notice_lang(service, u, COMMAND_REQUIRES_PERM, c->permission.c_str()); + notice_lang(bi->nick, u, COMMAND_REQUIRES_PERM, c->permission.c_str()); /* User isn't identified and needs to be to use this command */ if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified()) - notice_lang(service, u, COMMAND_IDENTIFY_REQUIRED); + notice_lang(bi->nick, u, COMMAND_IDENTIFY_REQUIRED); /* User doesn't have the proper permission to use this command */ else if (!c->permission.empty() && (!u->Account() || (!u->Account()->HasCommand(c->permission)))) - notice_lang(service, u, COMMAND_CANNOT_USE); + notice_lang(bi->nick, u, COMMAND_CANNOT_USE); /* User can use this command */ else - notice_lang(service, u, COMMAND_CAN_USE); + notice_lang(bi->nick, u, COMMAND_CAN_USE); } } -/*************************************************************************/ diff --git a/src/config.c b/src/config.c index 82a92bc70..1dd312723 100644 --- a/src/config.c +++ b/src/config.c @@ -474,13 +474,9 @@ static bool DoneOperTypes(ServerConfig *, const char *, bool) static bool InitOpers(ServerConfig *, const char *, bool) { - int i; - NickCore *nc; + for (nickcore_map::const_iterator it = NickCoreList.begin(); it != NickCoreList.end(); ++it) + it->second->ot = NULL; - for (i = 0; i < 1024; ++i) - for (nc = nclists[i]; nc; nc = nc->next) - nc->ot = NULL; - Config.Opers.clear(); return true; diff --git a/src/core/bs_act.c b/src/core/bs_act.c index d0b9c8b08..1bf11e078 100644 --- a/src/core/bs_act.c +++ b/src/core/bs_act.c @@ -75,7 +75,7 @@ class BSAct : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSAct()); + this->AddCommand(BotServ, new CommandBSAct()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_assign.c b/src/core/bs_assign.c index f37db9aca..dc847eb66 100644 --- a/src/core/bs_assign.c +++ b/src/core/bs_assign.c @@ -85,7 +85,7 @@ class BSAssign : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSAssign); + this->AddCommand(BotServ, new CommandBSAssign); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_badwords.c b/src/core/bs_badwords.c index af616c41a..3db6f1e42 100644 --- a/src/core/bs_badwords.c +++ b/src/core/bs_badwords.c @@ -229,7 +229,7 @@ class BSBadwords : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSBadwords); + this->AddCommand(BotServ, new CommandBSBadwords); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_bot.c b/src/core/bs_bot.c index 8abfecde8..d8cb3db6d 100644 --- a/src/core/bs_bot.c +++ b/src/core/bs_bot.c @@ -414,7 +414,7 @@ class BSBot : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSBot()); + this->AddCommand(BotServ, new CommandBSBot()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_botlist.c b/src/core/bs_botlist.c index 540cac30d..935e6d18a 100644 --- a/src/core/bs_botlist.c +++ b/src/core/bs_botlist.c @@ -23,34 +23,39 @@ class CommandBSBotList : public Command CommandReturn Execute(User *u, const std::vector ¶ms) { - int i, count = 0; - BotInfo *bi; + unsigned count = 0; - if (!nbots) { + if (BotList.empty()) + { notice_lang(Config.s_BotServ, u, BOT_BOTLIST_EMPTY); return MOD_CONT; } - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - if (!(bi->HasFlag(BI_PRIVATE))) { - if (!count) - notice_lang(Config.s_BotServ, u, BOT_BOTLIST_HEADER); - count++; - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->user.c_str(), bi->host.c_str()); - } + for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) + { + BotInfo *bi = it->second; + + if (!bi->HasFlag(BI_PRIVATE)) + { + if (!count) + notice_lang(Config.s_BotServ, u, BOT_BOTLIST_HEADER); + count++; + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->user.c_str(), bi->host.c_str()); } } - if (u->Account()->HasCommand("botserv/botlist") && count < nbots) { + if (u->Account()->HasCommand("botserv/botlist") && count < BotList.size()) + { notice_lang(Config.s_BotServ, u, BOT_BOTLIST_PRIVATE_HEADER); - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - if (bi->HasFlag(BI_PRIVATE)) { - u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->user.c_str(), bi->host.c_str()); - count++; - } + for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) + { + BotInfo *bi = it->second; + + if (bi->HasFlag(BI_PRIVATE)) + { + u->SendMessage(Config.s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->user.c_str(), bi->host.c_str()); + count++; } } } @@ -59,6 +64,7 @@ class CommandBSBotList : public Command notice_lang(Config.s_BotServ, u, BOT_BOTLIST_EMPTY); else notice_lang(Config.s_BotServ, u, BOT_BOTLIST_FOOTER, count); + return MOD_CONT; } @@ -77,7 +83,7 @@ class BSBotList : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSBotList()); + this->AddCommand(BotServ, new CommandBSBotList()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_help.c b/src/core/bs_help.c index d28595986..a3e53df5c 100644 --- a/src/core/bs_help.c +++ b/src/core/bs_help.c @@ -25,7 +25,7 @@ class CommandBSHelp : public Command CommandReturn Execute(User *u, const std::vector ¶ms) { - mod_help_cmd(Config.s_BotServ, u, BOTSERV, params[0].c_str()); + mod_help_cmd(findbot(Config.s_BotServ), u, params[0].c_str()); return MOD_CONT; } @@ -46,7 +46,7 @@ class BSHelp : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSHelp()); + this->AddCommand(BotServ, new CommandBSHelp()); } }; diff --git a/src/core/bs_info.c b/src/core/bs_info.c index 3ac3e9540..3f873aafd 100644 --- a/src/core/bs_info.c +++ b/src/core/bs_info.c @@ -19,25 +19,24 @@ class CommandBSInfo : public Command private: void send_bot_channels(User * u, BotInfo * bi) { - int i; - ChannelInfo *ci; char buf[307], *end; *buf = 0; end = buf; - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = ci->next) { - if (ci->bi == bi) { - if (strlen(buf) + strlen(ci->name.c_str()) > 300) { - u->SendMessage(Config.s_BotServ, "%s", buf); - *buf = 0; - end = buf; - } - end += - snprintf(end, sizeof(buf) - (end - buf), " %s ", - ci->name.c_str()); + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) + { + ChannelInfo *ci = it->second; + + if (ci->bi == bi) + { + if (strlen(buf) + strlen(ci->name.c_str()) > 300) + { + u->SendMessage(Config.s_BotServ, "%s", buf); + *buf = 0; + end = buf; } + end += snprintf(end, sizeof(buf) - (end - buf), " %s ", ci->name.c_str()); } } @@ -251,7 +250,7 @@ class BSInfo : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSInfo()); + this->AddCommand(BotServ, new CommandBSInfo()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_kick.c b/src/core/bs_kick.c index 766239c73..ab2782c8d 100644 --- a/src/core/bs_kick.c +++ b/src/core/bs_kick.c @@ -335,7 +335,7 @@ class BSKick : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSKick()); + this->AddCommand(BotServ, new CommandBSKick()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_say.c b/src/core/bs_say.c index 9cd630eb8..8dfc55115 100644 --- a/src/core/bs_say.c +++ b/src/core/bs_say.c @@ -81,7 +81,7 @@ class BSSay : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSSay()); + this->AddCommand(BotServ, new CommandBSSay()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_set.c b/src/core/bs_set.c index 0614651cc..3468198a2 100644 --- a/src/core/bs_set.c +++ b/src/core/bs_set.c @@ -185,7 +185,7 @@ class BSSet : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSSet()); + this->AddCommand(BotServ, new CommandBSSet()); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/bs_unassign.c b/src/core/bs_unassign.c index e053f75d7..067e4cc14 100644 --- a/src/core/bs_unassign.c +++ b/src/core/bs_unassign.c @@ -63,7 +63,7 @@ class BSUnassign : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(BOTSERV, new CommandBSUnassign); + this->AddCommand(BotServ, new CommandBSUnassign); ModuleManager::Attach(I_OnBotServHelp, this); } diff --git a/src/core/cs_access.c b/src/core/cs_access.c index e4e1d0e4b..718a7dc0f 100644 --- a/src/core/cs_access.c +++ b/src/core/cs_access.c @@ -573,8 +573,8 @@ class CSAccess : public Module this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSAccess()); - this->AddCommand(CHANSERV, new CommandCSLevels()); + this->AddCommand(ChanServ, new CommandCSAccess()); + this->AddCommand(ChanServ, new CommandCSLevels()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_akick.c b/src/core/cs_akick.c index ac17ef504..abd00be6a 100644 --- a/src/core/cs_akick.c +++ b/src/core/cs_akick.c @@ -152,7 +152,6 @@ class CommandCSAKick : public Command NickAlias *na = findnick(mask.c_str()); NickCore *nc = NULL; AutoKick *akick; - int i; if (!na) { @@ -197,42 +196,40 @@ class CommandCSAKick : public Command } else if ((ci->HasFlag(CI_PEACE))) { - char buf[BUFSIZE]; /* Match against all currently online users with equal or * higher access. - Viper */ - for (i = 0; i < 1024; i++) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { - for (User *u2 = userlist[i]; u2; u2 = u2->next) + User *u2 = it->second; + + if (IsFounder(u2, ci) || (get_access(u2, ci) >= get_access(u, ci))) { - if (IsFounder(u2, ci) || (get_access(u2, ci) >= get_access(u, ci))) + if (match_usermask(mask.c_str(), u2)) { - if (match_usermask(mask.c_str(), u2)) - { - notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - return; - } + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + return; } } - } - + } - /* Match against the lastusermask of all nickalias's with equal - * or higher access. - Viper */ - for (i = 0; i < 1024; i++) + /* Match against the lastusermask of all nickalias's with equal + * or higher access. - Viper */ + for (nickalias_map::const_iterator it = NickAliasList.begin(); it != NickAliasList.end(); ++it) { - for (NickAlias *na2 = nalists[i]; na2; na2 = na2->next) + NickAlias *na2 = it->second; + + if (na2->HasFlag(NS_FORBIDDEN)) + continue; + + if (na2->nc && ((na2->nc == ci->founder) || (get_access_nc(na2->nc, ci) >= get_access(u, ci)))) { - if (na2->HasFlag(NS_FORBIDDEN)) - continue; + char buf[BUFSIZE]; - if (na2->nc && ((na2->nc == ci->founder) || (get_access_nc(na2->nc, ci) >= get_access(u, ci)))) + snprintf(buf, BUFSIZE, "%s!%s", na2->nick, na2->last_usermask); + if (Anope::Match(buf, mask.c_str(), false)) { - snprintf(buf, BUFSIZE, "%s!%s", na2->nick, na2->last_usermask); - if (Anope::Match(buf, mask.c_str(), false)) - { - notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); - return; - } + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + return; } } } @@ -577,7 +574,7 @@ class CSAKick : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSAKick()); + this->AddCommand(ChanServ, new CommandCSAKick()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_ban.c b/src/core/cs_ban.c index 95c5c6556..39f290d98 100644 --- a/src/core/cs_ban.c +++ b/src/core/cs_ban.c @@ -104,8 +104,8 @@ class CSBan : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSBan("BAN")); - this->AddCommand(CHANSERV, new CommandCSBan("KB")); + this->AddCommand(ChanServ, new CommandCSBan("BAN")); + this->AddCommand(ChanServ, new CommandCSBan("KB")); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_clear.c b/src/core/cs_clear.c index bb86e3b74..5e7ef2674 100644 --- a/src/core/cs_clear.c +++ b/src/core/cs_clear.c @@ -171,7 +171,7 @@ class CSClear : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSClear()); + this->AddCommand(ChanServ, new CommandCSClear()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_drop.c b/src/core/cs_drop.c index b91fdc846..f7c7a8571 100644 --- a/src/core/cs_drop.c +++ b/src/core/cs_drop.c @@ -79,7 +79,7 @@ class CommandCSDrop : public Command */ if (Config.WallDrop) { if ((level < ACCESS_FOUNDER) || (!IsRealFounder(u, ci) && ci->HasFlag(CI_SECUREFOUNDER))) - ircdproto->SendGlobops(findbot(Config.s_ChanServ), "\2%s\2 used DROP on channel \2%s\2", u->nick.c_str(), chan); + ircdproto->SendGlobops(ChanServ, "\2%s\2 used DROP on channel \2%s\2", u->nick.c_str(), chan); } notice_lang(Config.s_ChanServ, u, CHAN_DROPPED, chan); @@ -113,7 +113,7 @@ class CSDrop : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSDrop()); + this->AddCommand(ChanServ, new CommandCSDrop()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c index b47982a7e..06447c800 100644 --- a/src/core/cs_forbid.c +++ b/src/core/cs_forbid.c @@ -78,12 +78,12 @@ class CommandCSForbid : public Command if (is_oper(uc->user)) continue; - c->Kick(findbot(Config.s_ChanServ), uc->user, "%s", reason ? reason : getstring(uc->user->Account(), CHAN_FORBID_REASON)); + c->Kick(ChanServ, uc->user, "%s", reason ? reason : getstring(uc->user->Account(), CHAN_FORBID_REASON)); } } if (Config.WallForbid) - ircdproto->SendGlobops(findbot(Config.s_ChanServ), "\2%s\2 used FORBID on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); + ircdproto->SendGlobops(ChanServ, "\2%s\2 used FORBID on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); if (ircd->chansqline) { @@ -118,7 +118,7 @@ class CSForbid : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSForbid()); + this->AddCommand(ChanServ, new CommandCSForbid()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_getkey.c b/src/core/cs_getkey.c index a0937911b..935a2bdbe 100644 --- a/src/core/cs_getkey.c +++ b/src/core/cs_getkey.c @@ -66,7 +66,7 @@ class CSGetKey : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSGetKey()); + this->AddCommand(ChanServ, new CommandCSGetKey()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_help.c b/src/core/cs_help.c index d975647b2..941634483 100644 --- a/src/core/cs_help.c +++ b/src/core/cs_help.c @@ -46,7 +46,7 @@ class CommandCSHelp : public Command } } else - mod_help_cmd(Config.s_ChanServ, u, CHANSERV, cmd.c_str()); + mod_help_cmd(ChanServ, u, cmd.c_str()); return MOD_CONT; } @@ -71,7 +71,7 @@ class CSHelp : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSHelp()); + this->AddCommand(ChanServ, new CommandCSHelp()); } }; diff --git a/src/core/cs_info.c b/src/core/cs_info.c index b3e7a1077..c0c99c856 100644 --- a/src/core/cs_info.c +++ b/src/core/cs_info.c @@ -168,7 +168,7 @@ class CSInfo : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSInfo()); + this->AddCommand(ChanServ, new CommandCSInfo()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_invite.c b/src/core/cs_invite.c index b71e487cc..2abcf82bb 100644 --- a/src/core/cs_invite.c +++ b/src/core/cs_invite.c @@ -84,7 +84,7 @@ class CSInvite : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSInvite()); + this->AddCommand(ChanServ, new CommandCSInvite()); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_kick.c b/src/core/cs_kick.c index 42059a01b..1c05ea77e 100644 --- a/src/core/cs_kick.c +++ b/src/core/cs_kick.c @@ -89,8 +89,8 @@ class CSKick : public Module this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); this->SetType(CORE); - this->AddCommand(CHANSERV, new CommandCSKick("KICK")); - this->AddCommand(CHANSERV, new CommandCSKick("K")); + this->AddCommand(ChanServ, new CommandCSKick("KICK")); + this->AddCommand(ChanServ, new CommandCSKick("K")); ModuleManager::Attach(I_OnChanServHelp, this); } diff --git a/src/core/cs_list.c b/src/core/cs_list.c index cb86bb300..4b6f1d242 100644 --- a/src/core/cs_list.c +++ b/src/core/cs_list.c @@ -28,8 +28,7 @@ public: const char *pattern = params[0].c_str(); int spattern_size; char *spattern; - ChannelInfo *ci; - unsigned nchans, i; + unsigned nchans; char buf[BUFSIZE]; bool is_servadmin = u->Account()->HasCommand("chanserv/list"); int count = 0, from = 0, to = 0, tofree = 0; @@ -111,55 +110,56 @@ public: snprintf(spattern, spattern_size, "#%s", pattern); notice_lang(Config.s_ChanServ, u, CHAN_LIST_HEADER, pattern); - for (i = 0; i < 256; i++) + + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) { - for (ci = chanlists[i]; ci; ci = ci->next) + ChannelInfo *ci = it->second; + + if (!is_servadmin && ((ci->HasFlag(CI_PRIVATE)) + || (ci->HasFlag(CI_FORBIDDEN)) || (ci->HasFlag(CI_SUSPENDED)))) + continue; + if (forbidden && !ci->HasFlag(CI_FORBIDDEN)) + continue; + else if (suspended && !ci->HasFlag(CI_SUSPENDED)) + continue; + else if (channoexpire && !ci->HasFlag(CI_NO_EXPIRE)) + continue; + + if ((stricmp(pattern, ci->name.c_str()) == 0) + || (stricmp(spattern, ci->name.c_str()) == 0) + || Anope::Match(ci->name, pattern, false) + || Anope::Match(ci->name, spattern, false)) { - if (!is_servadmin && ((ci->HasFlag(CI_PRIVATE)) - || (ci->HasFlag(CI_FORBIDDEN)) || (ci->HasFlag(CI_SUSPENDED)))) - continue; - if (forbidden && !ci->HasFlag(CI_FORBIDDEN)) - continue; - else if (suspended && !ci->HasFlag(CI_SUSPENDED)) - continue; - else if (channoexpire && !ci->HasFlag(CI_NO_EXPIRE)) - continue; - - if ((stricmp(pattern, ci->name.c_str()) == 0) - || (stricmp(spattern, ci->name.c_str()) == 0) - || Anope::Match(ci->name, pattern, false) - || Anope::Match(ci->name, spattern, false)) + if ((((count + 1 >= from) && (count + 1 <= to)) + || ((from == 0) && (to == 0))) + && (++nchans <= Config.CSListMax)) { - if ((((count + 1 >= from) && (count + 1 <= to)) - || ((from == 0) && (to == 0))) - && (++nchans <= Config.CSListMax)) + char noexpire_char = ' '; + if (is_servadmin && (ci->HasFlag(CI_NO_EXPIRE))) + noexpire_char = '!'; + + if (ci->HasFlag(CI_FORBIDDEN)) + { + snprintf(buf, sizeof(buf), + "%-20s [Forbidden]", ci->name.c_str()); + } + else if (ci->HasFlag(CI_SUSPENDED)) { - char noexpire_char = ' '; - if (is_servadmin && (ci->HasFlag(CI_NO_EXPIRE))) - noexpire_char = '!'; - - if (ci->HasFlag(CI_FORBIDDEN)) - { - snprintf(buf, sizeof(buf), - "%-20s [Forbidden]", ci->name.c_str()); - } - else if (ci->HasFlag(CI_SUSPENDED)) - { - snprintf(buf, sizeof(buf), - "%-20s [Suspended]", ci->name.c_str()); - } - else - { - snprintf(buf, sizeof(buf), "%-20s %s", - ci->name.c_str(), ci->desc ? ci->desc : ""); - } - - u->SendMessage(Config.s_ChanServ, " %c%s", noexpire_char, buf); + snprintf(buf, sizeof(b