summaryrefslogtreecommitdiff
path: root/src/bots.cpp
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-04 06:40:24 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-04 06:40:24 +0000
commitb462814760cb7c0830072275acc97291a9fb905b (patch)
tree56cfe6caee408eb852f728cd8aaa2d18e4365228 /src/bots.cpp
parent2708eea5d13c249143b83fbaa8b552992f0ac8b6 (diff)
Changed 'char *' fields in BotInfo to 'std::string', cleanup of bots.cpp, changed many other functions to use 'const std::string &' arguments as a chain reaction.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2733 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/bots.cpp')
-rw-r--r--src/bots.cpp97
1 files changed, 25 insertions, 72 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index ddd517b77..bb8b8a06f 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -12,75 +12,42 @@
#include "services.h"
#include "modules.h"
-BotInfo::BotInfo(const char *nnick)
+BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::string &nhost, const std::string &nreal)
{
- this->nick = sstrdup(nnick);
+ this->nick = nnick;
+ this->user = nuser;
+ this->host = nhost;
+ this->real = nreal;
this->lastmsg = this->created = time(NULL);
this->uid = ts6_uid_retrieve(); // XXX is this safe? has ts6 been setup yet?
- nbots++;
+ ++nbots;
this->cmdTable = NULL;
this->chancount = 0;
- if (Config.s_ChanServ && !stricmp(Config.s_ChanServ, nnick))
+ ci::string ci_nick(nnick.c_str());
+ if (Config.s_ChanServ && ci_nick == Config.s_ChanServ)
this->SetFlag(BI_CHANSERV);
- else if (Config.s_BotServ && !stricmp(Config.s_BotServ, nnick))
+ else if (Config.s_BotServ && ci_nick == Config.s_BotServ)
this->SetFlag(BI_BOTSERV);
- else if (Config.s_HostServ && !stricmp(Config.s_HostServ, nnick))
+ else if (Config.s_HostServ && ci_nick == Config.s_HostServ)
this->SetFlag(BI_HOSTSERV);
- else if (Config.s_OperServ && !stricmp(Config.s_OperServ, nnick))
+ else if (Config.s_OperServ && ci_nick == Config.s_OperServ)
this->SetFlag(BI_OPERSERV);
- else if (Config.s_MemoServ && !stricmp(Config.s_MemoServ, nnick))
+ else if (Config.s_MemoServ && ci_nick == Config.s_MemoServ)
this->SetFlag(BI_MEMOSERV);
- else if (Config.s_NickServ && !stricmp(Config.s_NickServ, nnick))
+ else if (Config.s_NickServ && ci_nick == Config.s_NickServ)
this->SetFlag(BI_NICKSERV);
- else if (Config.s_GlobalNoticer && !stricmp(Config.s_GlobalNoticer, nnick))
+ else if (Config.s_GlobalNoticer && ci_nick == Config.s_GlobalNoticer)
this->SetFlag(BI_GLOBAL);
-
- FOREACH_MOD(I_OnBotPreLoad, OnBotPreLoad(this));
-
- insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL.
-
- // If we're synchronised with the uplink already, call introduce_user() for this bot.
- alog("serv_uplink is %p and status is %d", static_cast<void *>(serv_uplink), serv_uplink ? serv_uplink->sync == SSYNC_DONE : 0);
- if (serv_uplink && serv_uplink->sync == SSYNC_DONE)
- ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid.c_str());
-}
-BotInfo::BotInfo(const char *nnick, const char *nuser, const char *nhost, const char *nreal)
-{
- this->nick = sstrdup(nnick);
- this->user = sstrdup(nuser);
- this->host = sstrdup(nhost);
- this->real = sstrdup(nreal);
- this->lastmsg = this->created = time(NULL);
- this->uid = ts6_uid_retrieve(); // XXX is this safe? has ts6 been setup yet?
- nbots++;
- this->cmdTable = NULL;
- this->chancount = 0;
-
- if (Config.s_ChanServ && !stricmp(Config.s_ChanServ, nnick))
- this->SetFlag(BI_CHANSERV);
- else if (Config.s_BotServ && !stricmp(Config.s_BotServ, nnick))
- this->SetFlag(BI_BOTSERV);
- else if (Config.s_HostServ && !stricmp(Config.s_HostServ, nnick))
- this->SetFlag(BI_HOSTSERV);
- else if (Config.s_OperServ && !stricmp(Config.s_OperServ, nnick))
- this->SetFlag(BI_OPERSERV);
- else if (Config.s_MemoServ && !stricmp(Config.s_MemoServ, nnick))
- this->SetFlag(BI_MEMOSERV);
- else if (Config.s_NickServ && !stricmp(Config.s_NickServ, nnick))
- this->SetFlag(BI_NICKSERV);
- else if (Config.s_GlobalNoticer && !stricmp(Config.s_GlobalNoticer, nnick))
- this->SetFlag(BI_GLOBAL);
-
FOREACH_MOD(I_OnBotPreLoad, OnBotPreLoad(this));
-
+
insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL.
// If we're synchronised with the uplink already, call introduce_user() for this bot.
alog("serv_uplink is %p and status is %d", static_cast<void *>(serv_uplink), serv_uplink ? serv_uplink->sync == SSYNC_DONE : 0);
if (serv_uplink && serv_uplink->sync == SSYNC_DONE)
- ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid.c_str());
+ ircdproto->SendClientIntroduction(this->nick, this->user, this->host, this->real, ircd->pseudoclient_mode, this->uid);
}
BotInfo::~BotInfo()
@@ -88,7 +55,7 @@ BotInfo::~BotInfo()
int i;
ChannelInfo *ci;
- for (i = 0; i < 256; i++)
+ for (i = 0; i < 256; ++i)
for (ci = chanlists[i]; ci; ci = ci->next)
if (ci->bi == this)
ci->bi = NULL;
@@ -98,14 +65,9 @@ BotInfo::~BotInfo()
if (this->prev)
this->prev->next = this->next;
else
- botlists[tolower(*this->nick)] = this->next;
+ botlists[tolower(this->nick[0])] = this->next;
- nbots--;
-
- delete [] this->nick;
- delete [] this->user;
- delete [] this->host;
- delete [] this->real;
+ --nbots;
}
@@ -116,11 +78,9 @@ void BotInfo::ChangeNick(const char *newnick)
if (this->prev)
this->prev->next = this->next;
else
- botlists[tolower(*this->nick)] = this->next;
+ botlists[tolower(this->nick[0])] = this->next;
- if (this->nick)
- delete [] this->nick;
- this->nick = sstrdup(newnick);
+ this->nick = newnick;
insert_bot(this);
}
@@ -130,7 +90,7 @@ void BotInfo::RejoinAll()
int i;
ChannelInfo *ci;
- for (i = 0; i < 256; i++)
+ for (i = 0; i < 256; ++i)
for (ci = chanlists[i]; ci; ci = ci->next)
if (ci->bi == this && ci->c && (ci->c->usercount >= Config.BSMinUsers))
bot_join(ci);
@@ -144,15 +104,10 @@ void BotInfo::Assign(User *u, ChannelInfo *ci)
return;
if (ci->bi)
- {
- if (u)
- ci->bi->UnAssign(u, ci);
- else
- ci->bi->UnAssign(NULL, ci);
- }
+ ci->bi->UnAssign(u, ci);
ci->bi = this;
- this->chancount++;
+ ++this->chancount;
if (ci->c && ci->c->usercount >= Config.BSMinUsers)
bot_join(ci);
}
@@ -172,8 +127,6 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci)
ircdproto->SendPart(ci->bi, ci->c, "");
}
- ci->bi->chancount--;
+ --ci->bi->chancount;
ci->bi = NULL;
}
-
-