summaryrefslogtreecommitdiff
path: root/src/bots.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bots.cpp')
-rw-r--r--src/bots.cpp93
1 files changed, 46 insertions, 47 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 37cd553d1..e9021b188 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -10,6 +10,18 @@
#include "services.h"
#include "modules.h"
+#include "commands.h"
+
+botinfo_map BotListByNick;
+botinfo_uid_map BotListByUID;
+
+BotInfo *BotServ = NULL;
+BotInfo *ChanServ = NULL;
+BotInfo *Global = NULL;
+BotInfo *HostServ = NULL;
+BotInfo *MemoServ = NULL;
+BotInfo *NickServ = NULL;
+BotInfo *OperServ = NULL;
BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal)
{
@@ -19,100 +31,87 @@ 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)
{
- this->cmdTable = CHANSERV;
- this->SetFlag(BI_CHANSERV);
+ ChanServ = this;
}
else if (Config.s_BotServ && ci_nick == Config.s_BotServ)
{
- this->cmdTable = BOTSERV;
- this->SetFlag(BI_BOTSERV);
+ BotServ = this;
}
else if (Config.s_HostServ && ci_nick == Config.s_HostServ)
{
- this->cmdTable = HOSTSERV;
- this->SetFlag(BI_HOSTSERV);
+ HostServ = this;
}
else if (Config.s_OperServ && ci_nick == Config.s_OperServ)
{
- this->cmdTable = OPERSERV;
- this->SetFlag(BI_OPERSERV);
+ OperServ = this;
}
else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ)
{
- this->cmdTable = MEMOSERV;
- this->SetFlag(BI_MEMOSERV);
+ MemoServ = this;
}
else if (Config.s_NickServ && ci_nick == Config.s_NickServ)
{
- this->cmdTable = NICKSERV;
- this->SetFlag(BI_NICKSERV);
+ NickServ = this;
}
else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer)
{
- this->SetFlag(BI_GLOBAL);
+ Global = this;
}
- insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL.
+ BotListByNick[this->nick.c_str()] = this;
+ if (!this->uid.empty())
+ BotListByUID[this->uid] = this;
// If we're synchronised with the uplink already, call introduce_user() for this bot.
- if (serv_uplink && serv_uplink->sync == SSYNC_DONE)
+ if (Me && Me->GetUplink()->IsSynced())
{
ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid);
- ircdproto->SendSQLine(this->nick, "Reserved for services");
+ XLine x(this->nick.c_str(), "Reserved for services");
+ ircdproto->SendSQLine(&x);
}
}
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;
+ }
+ }
+
+ BotListByNick.erase(this->nick.c_str());
+ if (!this->uid.empty())
+ BotListByUID.erase(this->uid);
}
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;
+ BotListByNick.erase(this->nick.c_str());
this->nick = newnick;
- insert_bot(this);
+ BotListByNick[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)