summaryrefslogtreecommitdiff
path: root/src/bots.cpp
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-14 20:35:38 -0400
committerAdam <Adam@anope.org>2010-06-18 21:01:53 -0400
commitf049124905bd9f53439293e873003cb027a17b91 (patch)
tree352ed9251fd47055dd770aa2d5eabb20247e4b43 /src/bots.cpp
parent81a45520a773732c9f46785f27aa1956150775d7 (diff)
Rewrote the hashing system to use std::tr1::unordered_map
Diffstat (limited to 'src/bots.cpp')
-rw-r--r--src/bots.cpp67
1 files changed, 22 insertions, 45 deletions
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)