summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-29 20:44:31 -0400
committerAdam <Adam@anope.org>2010-06-18 21:04:08 -0400
commitb8f9116b19eb511c4f5e6a683725f50bf732a7dd (patch)
treea5848c9797ec4dc3477621fc42211f4985eaec7b /src
parent435c9116e9997634eb7215e998c8f01a5e46fb2c (diff)
Rewrote all of the command handling to get rid of all the nasty strtoks() everywhere, and added a bot map by uid
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp15
-rw-r--r--src/botserv.cpp351
-rw-r--r--src/chanserv.cpp26
-rw-r--r--src/commands.cpp51
-rw-r--r--src/core/bs_botlist.cpp8
-rw-r--r--src/core/db_plain.cpp2
-rw-r--r--src/core/os_defcon.cpp4
-rw-r--r--src/hostserv.cpp34
-rw-r--r--src/init.cpp2
-rw-r--r--src/main.cpp4
-rw-r--r--src/memoserv.cpp25
-rw-r--r--src/messages.cpp84
-rw-r--r--src/misc.cpp2
-rw-r--r--src/modules/mysql/db_mysql_execute.cpp6
-rw-r--r--src/modules/mysql/db_mysql_write.cpp4
-rw-r--r--src/nickserv.cpp24
-rw-r--r--src/operserv.cpp24
-rw-r--r--src/protocol/inspircd12.cpp19
-rw-r--r--src/protocol/ratbox.cpp16
-rw-r--r--src/users.cpp38
20 files changed, 356 insertions, 383 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 3c23da7d4..e9021b188 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -12,7 +12,8 @@
#include "modules.h"
#include "commands.h"
-botinfo_map BotList;
+botinfo_map BotListByNick;
+botinfo_uid_map BotListByUID;
BotInfo *BotServ = NULL;
BotInfo *ChanServ = NULL;
@@ -62,7 +63,9 @@ BotInfo::BotInfo(const std::string &nnick, const std::string &nuser, const std::
Global = this;
}
- BotList[this->nick.c_str()] = this;
+ 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 (Me && Me->GetUplink()->IsSynced())
@@ -85,17 +88,19 @@ BotInfo::~BotInfo()
}
}
- BotList.erase(this->nick.c_str());
+ BotListByNick.erase(this->nick.c_str());
+ if (!this->uid.empty())
+ BotListByUID.erase(this->uid);
}
void BotInfo::ChangeNick(const char *newnick)
{
- BotList.erase(this->nick.c_str());
+ BotListByNick.erase(this->nick.c_str());
this->nick = newnick;
- BotList[this->nick.c_str()] = this;
+ BotListByNick[this->nick.c_str()] = this;
}
void BotInfo::RejoinAll()
diff --git a/src/botserv.cpp b/src/botserv.cpp
index aefe37b08..7f64c0c63 100644
--- a/src/botserv.cpp
+++ b/src/botserv.cpp
@@ -39,7 +39,7 @@ void get_botserv_stats(long *nrec, long *memuse)
{
long count = 0, mem = 0;
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
@@ -71,46 +71,21 @@ void bs_init()
/* Main BotServ routine. */
-void botserv(User * u, char *buf)
+void botserv(User *u, BotInfo *bi, const std::string &buf)
{
- char *cmd, *s;
-
- cmd = strtok(buf, " ");
-
- if (!cmd) {
- return;
- } else if (stricmp(cmd, "\1PING") == 0) {
- if (!(s = strtok(NULL, ""))) {
- *s = 0;
- }
- ircdproto->SendCTCP(BotServ, u->nick.c_str(), "PING %s", s);
- } else {
- mod_run_cmd(BotServ, u, cmd);
- }
-
-}
-
-/*************************************************************************/
-
-/* Handles all messages sent to bots. (Currently only answers to pings ;) */
-
-void botmsgs(User * u, BotInfo * bi, char *buf)
-{
- char *cmd = strtok(buf, " ");
- char *s;
-
- if (!cmd || !u || !bi)
+ if (!u || !bi || buf.empty())
return;
-
- if (!stricmp(cmd, "\1PING")) {
- if (!(s = strtok(NULL, ""))) {
- *s = 0;
- }
- ircdproto->SendCTCP(bi, u->nick.c_str(), "PING %s", s);
+
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(bi, u->nick.c_str(), "%s", command.c_str());
}
- else if (cmd && !bi->Commands.empty())
+ else
{
- mod_run_cmd(bi, u, cmd);
+ mod_run_cmd(bi, u, buf.c_str());
}
}
@@ -121,32 +96,36 @@ void botmsgs(User * u, BotInfo * bi, char *buf)
*
*/
-void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
+void botchanmsgs(User *u, ChannelInfo *ci, const std::string &buf)
{
- int c;
- char *cmd;
- UserData *ud;
- bool was_action = false;
- std::string bbuf;
-
- if (!u || !buf || !ci || !ci->c)
+ if (!u || !ci || !ci->c || buf.empty())
return;
-
- /* Answer to ping if needed, without breaking the buffer. */
- if (!strnicmp(buf, "\1PING", 5)) {
- ircdproto->SendCTCP(ci->bi, u->nick.c_str(), "PING %s", buf);
+
+ /* Answer to ping if needed */
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string ctcp = buf;
+ ctcp.erase(ctcp.begin());
+ ctcp.erase(ctcp.end());
+ ircdproto->SendCTCP(ci->bi, u->nick.c_str(), "%s", ctcp.c_str());
}
- /* If it's a /me, cut the CTCP part at the beginning (not
- * at the end, because one character just doesn't matter,
- * but the ACTION may create strange behaviours with the
- * caps or badwords kickers */
- if (!strnicmp(buf, "\1ACTION ", 8))
+ bool was_action = false;
+ std::string realbuf = buf;
+
+ /* If it's a /me, cut the CTCP part because the ACTION will cause
+ * problems with the caps or badwords kicker
+ */
+ if (realbuf.find("\1ACTION ", 0, 8) && realbuf[buf.length() - 1] == '\1')
{
- buf += 8;
+ realbuf.erase(0, 8);
+ realbuf.erase(realbuf.end());
was_action = true;
}
+ if (realbuf.empty())
+ return;
+
/* Now we can make kicker stuff. We try to order the checks
* from the fastest one to the slowest one, since there's
* no need to process other kickers if an user is kicked before
@@ -164,56 +143,61 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
else if (ci->botflags.HasFlag(BS_DONTKICKVOICES) && ci->c->HasUserStatus(u, CMODE_VOICE))
Allow = true;
- if (buf && !check_access(u, ci, CA_NOKICK) && Allow)
+ if (!check_access(u, ci, CA_NOKICK) && Allow)
{
/* Bolds kicker */
- if (ci->botflags.HasFlag(BS_KICK_BOLDS) && strchr(buf, 2)) {
+ if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find_first_of(2) != std::string::npos)
+ {
check_ban(ci, u, TTB_BOLDS);
bot_kick(ci, u, BOT_REASON_BOLD);
return;
}
/* Color kicker */
- if (ci->botflags.HasFlag(BS_KICK_COLORS) && strchr(buf, 3)) {
+ if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find_first_of(3) != std::string::npos)
+ {
check_ban(ci, u, TTB_COLORS);
bot_kick(ci, u, BOT_REASON_COLOR);
return;
}
/* Reverses kicker */
- if (ci->botflags.HasFlag(BS_KICK_REVERSES) && strchr(buf, 22)) {
+ if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find_first_of(22) != std::string::npos)
+ {
check_ban(ci, u, TTB_REVERSES);
bot_kick(ci, u, BOT_REASON_REVERSE);
return;
}
/* Underlines kicker */
- if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && strchr(buf, 31)) {
+ if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find_first_of(31) != std::string::npos)
+ {
check_ban(ci, u, TTB_UNDERLINES);
bot_kick(ci, u, BOT_REASON_UNDERLINE);
return;
}
/* Caps kicker */
- if (ci->botflags.HasFlag(BS_KICK_CAPS)
- && ((c = strlen(buf)) >= ci->capsmin)) {
+ if (ci->botflags.HasFlag(BS_KICK_CAPS) && realbuf.length() >= ci->capsmin)
+ {
int i = 0;
int l = 0;
- char *s = buf;
-
- do {
- if (isupper(*s))
- i++;
- else if (islower(*s))
- l++;
- } while (*s++);
+ for (unsigned j = 0; j < realbuf.length(); ++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
*/
- if (i && l && i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) {
+ if (i && l && i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent)
+ {
check_ban(ci, u, TTB_CAPS);
bot_kick(ci, u, BOT_REASON_CAPS);
return;
@@ -221,49 +205,42 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
}
/* Bad words kicker */
- if (ci->botflags.HasFlag(BS_KICK_BADWORDS)) {
- int mustkick = 0;
- char *nbuf;
- BadWord *bw;
+ if (ci->botflags.HasFlag(BS_KICK_BADWORDS))
+ {
+ bool mustkick = false;
/* Normalize the buffer */
- nbuf = normalizeBuffer(buf);
+ const char *nbuf = normalizeBuffer(realbuf.c_str());
for (unsigned i = 0; i < ci->GetBadWordCount(); ++i)
{
- 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 = 1;
- } else if (bw->type == BW_SINGLE) {
- int len = bw->word.length();
-
- if ((Config.BSCaseSensitive && nbuf == bw->word)
- || (!Config.BSCaseSensitive
- && (!stricmp(nbuf, bw->word.c_str())))) {
- mustkick = 1;
- /* two next if are quite odd isn't it? =) */
- } else if ((strchr(nbuf, ' ') == nbuf + len)
- &&
- ((Config.BSCaseSensitive && nbuf == bw->word)
- || (!Config.BSCaseSensitive
- && (stristr(nbuf, bw->word.c_str()) ==
- nbuf)))) {
- mustkick = 1;
- } 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 = 1;
- } else {
+ 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()))))
+ {
+ mustkick = true;
+ }
+ 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];
wordbuf[0] = ' ';
@@ -271,69 +248,67 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
wordbuf[len + 2] = '\0';
memcpy(wordbuf + 1, bw->word.c_str(), len);
- if ((Config.BSCaseSensitive
- && (strstr(nbuf, wordbuf)))
- || (!Config.BSCaseSensitive
- && (stristr(nbuf, wordbuf)))) {
- mustkick = 1;
+ if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf))))
+ {
+ mustkick = true;
}
- /* free previous (sc)allocated memory (#850) */
delete [] wordbuf;
}
}
- } else if (bw->type == BW_START) {
- int len = bw->word.length();
-
- if ((Config.BSCaseSensitive
- && (!strncmp(nbuf, bw->word.c_str(), len)))
- || (!Config.BSCaseSensitive
- && (!strnicmp(nbuf, bw->word.c_str(), len)))) {
- mustkick = 1;
- } else {
+ }
+ else if (bw->type == BW_START)
+ {
+ 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))))
+ {
+ mustkick = true;
+ }
+ else
+ {
char *wordbuf = new char[len + 2];
memcpy(wordbuf + 1, bw->word.c_str(), len);
wordbuf[0] = ' ';
wordbuf[len + 1] = '\0';
- if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf)))
- || (!Config.BSCaseSensitive
- && (stristr(nbuf, wordbuf))))
- mustkick = 1;
+ if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf))))
+ {
+ mustkick = true;
+ }
delete [] wordbuf;
}
- } else if (bw->type == BW_END) {
- int 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)))) {
- mustkick = 1;
- } else {
+ }
+ else if (bw->type == BW_END)
+ {
+ 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))))
+ {
+ mustkick = true;
+ }
+ else
+ {
char *wordbuf = new char[len + 2];
memcpy(wordbuf, bw->word.c_str(), len);
wordbuf[len] = ' ';
wordbuf[len + 1] = '\0';
- if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf)))
- || (!Config.BSCaseSensitive
- && (stristr(nbuf, wordbuf))))
- mustkick = 1;
+ if ((Config.BSCaseSensitive && (strstr(nbuf, wordbuf))) || (!Config.BSCaseSensitive && (stristr(nbuf, wordbuf))))
+ {
+ mustkick = true;
+ }
delete [] wordbuf;
}
}
- if (mustkick) {
+ if (mustkick)
+ {
check_ban(ci, u, TTB_BADWORDS);
if (Config.BSGentleBWReason)
bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE);
@@ -352,21 +327,23 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
}
/* Flood kicker */
- if (ci->botflags.HasFlag(BS_KICK_FLOOD)) {
+ if (ci->botflags.HasFlag(BS_KICK_FLOOD))
+ {
time_t now = time(NULL);
- ud = get_user_data(ci->c, u);
- if (!ud) {
+ UserData *ud = get_user_data(ci->c, u);
+ if (!ud)
return;
- }
- if (now - ud->last_start > ci->floodsecs) {
+ if (now - ud->last_start > ci->floodsecs)
+ {
ud->last_start = time(NULL);
ud->lines = 0;
}
ud->lines++;
- if (ud->lines >= ci->floodlines) {
+ if (ud->lines >= ci->floodlines)
+ {
check_ban(ci, u, TTB_FLOOD);
bot_kick(ci, u, BOT_REASON_FLOOD);
return;
@@ -374,22 +351,27 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
}
/* Repeat kicker */
- if (ci->botflags.HasFlag(BS_KICK_REPEAT)) {
- ud = get_user_data(ci->c, u);
- if (!ud) {
+ if (ci->botflags.HasFlag(BS_KICK_REPEAT))
+ {
+ UserData *ud = get_user_data(ci->c, u);
+ if (!ud)
return;
- }
- if (ud->lastline && stricmp(ud->lastline, buf)) {
+
+ if (ud->lastline && stricmp(ud->lastline, buf.c_str()))
+ {
delete [] ud->lastline;
- ud->lastline = sstrdup(buf);
+ ud->lastline = sstrdup(buf.c_str());
ud->times = 0;
- } else {
+ }
+ else
+ {
if (!ud->lastline)
- ud->lastline = sstrdup(buf);
+ ud->lastline = sstrdup(buf.c_str());
ud->times++;
}
- if (ud->times >= ci->repeattimes) {
+ if (ud->times >= ci->repeattimes)
+ {
check_ban(ci, u, TTB_REPEAT);
bot_kick(ci, u, BOT_REASON_REPEAT);
return;
@@ -397,31 +379,31 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
}
}
-
/* return if the user is on the ignore list */
- if (get_ignore(u->nick.c_str()) != NULL) {
+ if (get_ignore(u->nick.c_str()) != NULL)
+ {
return;
}
/* Fantaisist commands */
+ if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == *Config.BSFantasyCharacter && !was_action)
+ {
+ spacesepstream sep(buf);
+ std::string token;
- if (buf && ci->botflags.HasFlag(BS_FANTASY) && *buf == *Config.BSFantasyCharacter && !was_action) {
- cmd = strtok(buf, " ");
-
- if (cmd && (cmd[0] == *Config.BSFantasyCharacter)) {
- char *params = strtok(NULL, "");
-
+ if (sep.GetToken(token) && (token[0] == *Config.BSFantasyCharacter))
+ {
/* Strip off the fantasy character */
- cmd++;
+ token.erase(token.begin());
if (check_access(u, ci, CA_FANTASIA))
{
- Command *command = FindCommand(ChanServ, cmd);
+ Command *command = FindCommand(ChanServ, token.c_str());
/* Command exists and can not be called by fantasy */
if (command && !command->HasFlag(CFLAG_DISABLE_FANTASY))
{
- bbuf = std::string(cmd);
+ std::string bbuf = std::string(token);
/* Some commands don't need the channel name added.. eg !help */
if (!command->HasFlag(CFLAG_STRIP_CHANNEL))
@@ -430,20 +412,20 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
bbuf += ci->name;
}
- if (params)
+ if (!sep.StreamEnd())
{
bbuf += " ";
- bbuf += params;
+ bbuf += sep.GetRemaining();
}
- chanserv(u, const_cast<char *>(bbuf.c_str())); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ chanserv(u, bbuf);
}
- FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(cmd, u, ci, params));
+ FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(token, u, ci, sep.GetRemaining()));
}
else
{
- FOREACH_MOD(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(cmd, u, ci, params));
+ FOREACH_MOD(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(token, u, ci, sep.GetRemaining()));
}
}
}
@@ -463,9 +445,18 @@ BotInfo *findbot(const std::string &nick)
BotInfo *findbot(const ci::string &nick)
{
- botinfo_map::const_iterator it = BotList.find(nick);
+ if (isdigit(nick[0]) && ircd->ts6)
+ {
+ botinfo_uid_map::const_iterator it = BotListByUID.find(nick.c_str());
+
+ if (it != BotListByUID.end())
+ return it->second;
+ return NULL;
+ }
+
+ botinfo_map::const_iterator it = BotListByNick.find(nick);
- if (it != BotList.end())
+ if (it != BotListByNick.end())
return it->second;
return NULL;
}
diff --git a/src/chanserv.cpp b/src/chanserv.cpp
index 36e82f6b9..256909bb9 100644
--- a/src/chanserv.cpp
+++ b/src/chanserv.cpp
@@ -259,21 +259,21 @@ void cs_init()
/* Main ChanServ routine. */
-void chanserv(User * u, char *buf)
+void chanserv(User *u, const std::string &buf)
{
- char *cmd, *s;
-
- cmd = strtok(buf, " ");
-
- if (!cmd) {
+ if (!u || buf.empty())
return;
- } else if (stricmp(cmd, "\1PING") == 0) {
- if (!(s = strtok(NULL, ""))) {
- *s = 0;
- }
- ircdproto->SendCTCP(ChanServ, u->nick.c_str(), "PING %s", s);
- } else {
- mod_run_cmd(ChanServ, u, cmd);
+
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(ChanServ, u->nick.c_str(), "%s", command.c_str());
+ }
+ else
+ {
+ mod_run_cmd(ChanServ, u, buf.c_str());
}
}
diff --git a/src/commands.cpp b/src/commands.cpp
index c767f8cd1..3226bff59 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -29,23 +29,28 @@ Command *FindCommand(BotInfo *bi, const ci::string &name)
return NULL;
}
-void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd)
+void mod_run_cmd(BotInfo *bi, User *u, const ci::string &message)
{
- if (!bi || !u || cmd.empty())
+ if (!bi || !u || message.empty())
+ return;
+
+ spacesepstream sep(message);
+ ci::string command;
+
+ if (!sep.GetToken(command))
return;
- Command *c = FindCommand(bi, cmd);
- int retVal = MOD_CONT;
- ChannelInfo *ci;
+ Command *c = FindCommand(bi, command);
+ CommandReturn ret = MOD_CONT;
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(bi, u, cmd, c));
+ FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, sep.GetRemaining().c_str(), c));
if (MOD_RESULT == EVENT_STOP)
return;
if (!c)
{
- notice_lang(bi->nick, u, UNKNOWN_COMMAND_HELP, cmd.c_str(), bi->nick.c_str());
+ notice_lang(bi->nick, u, UNKNOWN_COMMAND_HELP, command.c_str(), bi->nick.c_str());
return;
}
@@ -55,35 +60,34 @@ void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd)
if (!u->IsIdentified())
{
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;
+ Alog() << "Access denied for unregistered user " << u->nick << " with service " << bi->nick << " and command " << command;
return;
}
}
std::vector<ci::string> params;
- std::string curparam;
- char *s = NULL;
- while ((s = strtok(NULL, " ")))
+ ci::string curparam, endparam;
+ while (sep.GetToken(curparam))
{
// - 1 because params[0] corresponds with a maxparam of 1.
if (params.size() >= (c->MaxParams - 1))
{
- curparam += s;
- curparam += " ";
+ endparam += curparam;
+ endparam += " ";
}
else
{
- params.push_back(s);
+ params.push_back(curparam);
}
}
- if (!curparam.empty())
+ if (!endparam.empty())
{
// Remove trailing space
- curparam.erase(curparam.size() - 1, curparam.size());
+ endparam.erase(endparam.size() - 1, endparam.size());
// Add it
- params.push_back(curparam.c_str());
+ params.push_back(endparam);
}
if (params.size() < c->MinParams)
@@ -100,20 +104,21 @@ void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd)
{
if (ircdproto->IsChannelValid(params[0].c_str()))
{
- if ((ci = cs_findchan(params[0])))
+ ChannelInfo *ci = cs_findchan(params[0]);
+ if (ci)
{
if ((ci->HasFlag(CI_FORBIDDEN)) && (!c->HasFlag(CFLAG_ALLOW_FORBIDDEN)))
{
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;
+ << " and command " << command << " because of FORBIDDEN channel " << ci->name;
return;
}
else if ((ci->HasFlag(CI_SUSPENDED)) && (!c->HasFlag(CFLAG_ALLOW_SUSPENDED)))
{
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;
+ <<" and command " << command << " because of SUSPENDED channel " << ci->name;
return;
}
}
@@ -137,15 +142,15 @@ void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd)
if (!u->Account()->HasCommand(c->permission))
{
notice_lang(bi->nick, u, ACCESS_DENIED);
- Alog() << "Access denied for user " << u->nick << " with service " << bi->nick << " and command " << cmd;
+ Alog() << "Access denied for user " << u->nick << " with service " << bi->nick << " and command " << command;
return;
}
}
- retVal = c->Execute(u, params);
+ ret = c->Execute(u, params);
- if (retVal == MOD_CONT)
+ if (ret == MOD_CONT)
{
FOREACH_MOD(I_OnPostCommand, OnPostCommand(u, c->service, c->name.c_str(), params));
}
diff --git a/src/core/bs_botlist.cpp b/src/core/bs_botlist.cpp
index 935e6d18a..12c90ab8b 100644
--- a/src/core/bs_botlist.cpp
+++ b/src/core/bs_botlist.cpp
@@ -25,13 +25,13 @@ class CommandBSBotList : public Command
{
unsigned count = 0;
- if (BotList.empty())
+ if (BotListByNick.empty())
{
notice_lang(Config.s_BotServ, u, BOT_BOTLIST_EMPTY);
return MOD_CONT;
}
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
@@ -44,11 +44,11 @@ class CommandBSBotList : public Command
}
}
- if (u->Account()->HasCommand("botserv/botlist") && count < BotList.size())
+ if (u->Account()->HasCommand("botserv/botlist") && count < BotListByNick.size())
{
notice_lang(Config.s_BotServ, u, BOT_BOTLIST_PRIVATE_HEADER);
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp
index 8808539bd..98e055ee8 100644
--- a/src/core/db_plain.cpp
+++ b/src/core/db_plain.cpp
@@ -1006,7 +1006,7 @@ class DBPlain : public Module
FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na));
}
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
diff --git a/src/core/os_defcon.cpp b/src/core/os_defcon.cpp
index 6f9197a2b..5945ad3ba 100644
--- a/src/core/os_defcon.cpp
+++ b/src/core/os_defcon.cpp
@@ -211,7 +211,7 @@ class OSDEFCON : public Module
return EVENT_CONTINUE;
}
- EventReturn OnPreCommandRun(const std::string &service, User *u, const char *cmd, Command *c)
+ EventReturn OnPreCommandRun(User *u, BotInfo *bi, const ci::string &command, const ci::string &message, Command *c)
{
if (!c)
{
@@ -222,7 +222,7 @@ class OSDEFCON : public Module
{
if (!CheckDefCon(DEFCON_SILENT_OPER_ONLY))
{
- notice_lang(service, u, OPER_DEFCON_DENIED);
+ notice_lang(bi->nick.c_str(), u, OPER_DEFCON_DENIED);
}
return EVENT_STOP;
diff --git a/src/hostserv.cpp b/src/hostserv.cpp
index 9d7362903..04bb61e4c 100644
--- a/src/hostserv.cpp
+++ b/src/hostserv.cpp
@@ -79,25 +79,25 @@ void hostserv_init()
* @param buf Buffer holding the message
* @return void
*/
-void hostserv(User * u, char *buf)
+void hostserv(User *u, const std::string &buf)
{
- const char *cmd, *s;
-
- cmd = strtok(buf, " ");
-
- if (!cmd) {
+ if (!u || buf.empty())
return;
- } else if (stricmp(cmd, "\1PING") == 0) {
- if (!(s = strtok(NULL, ""))) {
- s = "";
- }
- ircdproto->SendCTCP(HostServ, u->nick.c_str(), "PING %s", s);
- } else {
- if (ircd->vhost) {
- mod_run_cmd(HostServ, u, cmd);
- } else {
- notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ);
- }
+
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(HostServ, u->nick.c_str(), "%s", command.c_str());
+ }
+ else if (!ircd->vhost)
+ {
+ notice_lang(Config.s_HostServ, u, SERVICE_OFFLINE, Config.s_HostServ);
+ }
+ else
+ {
+ mod_run_cmd(HostServ, u, buf.c_str());
}
}
diff --git a/src/init.cpp b/src/init.cpp
index 2c2a64ed4..5bc9f01d1 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -35,7 +35,7 @@ void introduce_user(const std::string &user)
/* We make the bots go online */
/* XXX: it might be nice to have this inside BotInfo's constructor, or something? */
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
diff --git a/src/main.cpp b/src/main.cpp
index d4746cf93..70c7f9e7e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -188,7 +188,7 @@ void do_restart_services()
if (!quitmsg)
quitmsg = "Restarting";
/* Send a quit for all of our bots */
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
ircdproto->SendQuit(it->second, "Restarting");
@@ -228,7 +228,7 @@ static void services_shutdown()
if (started && UplinkSock)
{
/* Send a quit for all of our bots */
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
ircdproto->SendQuit(it->second, "Shutting down");
diff --git a/src/memoserv.cpp b/src/memoserv.cpp
index 4d33bde3e..b4d33fdd0 100644
--- a/src/memoserv.cpp
+++ b/src/memoserv.cpp
@@ -51,20 +51,21 @@ void ms_init()
* @param buf Buffer containing the privmsg
* @return void
*/
-void memoserv(User * u, char *buf)
+void memoserv(User *u, const std::string &buf)
{
- const char *cmd, *s;
-
- cmd = strtok(buf, " ");
- if (!cmd) {
+ if (!u || buf.empty())
return;
- } else if (stricmp(cmd, "\1PING") == 0) {
- if (!(s = strtok(NULL, ""))) {
- s = "";
- }
- ircdproto->SendCTCP(MemoServ, u->nick.c_str(), "PING %s", s);
- } else {
- mod_run_cmd(MemoServ, u, cmd);
+
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(MemoServ, u->nick.c_str(), "%s", command.c_str());
+ }
+ else
+ {
+ mod_run_cmd(MemoServ, u, buf.c_str());
}
}
diff --git a/src/messages.cpp b/src/messages.cpp
index 3af7d9d40..81c64b1fb 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -101,44 +101,51 @@ int m_motd(const char *source)
/*************************************************************************/
-int m_privmsg(const char *source, const std::string &receiver, const char *msg)
+int m_privmsg(const std::string &source, const std::string &receiver, const std::string &message)
{
char *target;
time_t starttime, stoptime; /* When processing started and finished */
- BotInfo *bi;
- ChannelInfo *ci;
- User *u;
-
- if (!source || !*source || receiver.empty() || !msg) {
+ if (source.empty() || receiver.empty() || message.empty())
+ {
return MOD_CONT;
}
- u = finduser(source);
+ User *u = finduser(source);
+
+ if (!u)
+ {
+ Alog() << message << ": user record for " << source << " not found";
- if (!u) {
- Alog() << msg << ": user record for " << source << " not found";
- /* Two lookups naughty, however, this won't happen often. -- w00t */
- if (findbot(receiver))
+ BotInfo *bi = findbot(receiver);
+ if (bi)
{
- ircdproto->SendMessage(findbot(receiver), source, "%s", getstring(USER_RECORD_NOT_FOUND));
+ ircdproto->SendMessage(bi, source.c_str(), "%s", getstring(USER_RECORD_NOT_FOUND));
}
+
return MOD_CONT;
}
- if (receiver[0] == '#') {
- if (Config.s_BotServ && (ci = cs_findchan(receiver))) {
+ if (receiver[0] == '#' && Config.s_BotServ)
+ {
+ ChannelInfo *ci = cs_findchan(receiver);
+ if (ci)
+ {
/* Some paranoia checks */
- if (!ci->HasFlag(CI_FORBIDDEN) && ci->c && ci->bi) {
- botchanmsgs(u, ci, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ if (!ci->HasFlag(CI_FORBIDDEN) && ci->c && ci->bi)
+ {
+ botchanmsgs(u, ci, message);
}
}
- } else {
+ }
+ else
+ {
/* Check if we should ignore. Operators always get through. */
- if (allow_ignore && !is_oper(u)) {
- IgnoreData *ign = get_ignore(source);
- if (ign) {
- target = myStrGetToken(msg, ' ', 0);
+ if (allow_ignore && !is_oper(u))
+ {
+ if (get_ignore(source.c_str()))
+ {
+ target = myStrGetToken(message.c_str(), ' ', 0);
Alog() << "Ignored message from " << source << " to " << receiver << " using command " << target;
delete [] target;
return MOD_CONT;
@@ -156,16 +163,18 @@ int m_privmsg(const char *source, const std::string &receiver, const char *msg)
if (servername != Config.ServerName)
return MOD_CONT;
}
- else if (Config.UseStrictPrivMsg) {
+ else if (Config.UseStrictPrivMsg)
+ {
Alog(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source;
notice_lang(receiver, u, INVALID_TARGET, receiver.c_str(), receiver.c_str(),
Config.ServerName, receiver.c_str());
return MOD_CONT;
}
- starttime = time(NULL);
+ if (allow_ignore)
+ starttime = time(NULL);
- bi = findbot(botname);
+ BotInfo *bi = findbot(botname);
if (bi)
{
@@ -179,37 +188,34 @@ int m_privmsg(const char *source, const std::string &receiver, const char *msg)
ircdproto->SendGlobops(OperServ, "Denied access to %s from %s!%s@%s (non-oper)", Config.s_OperServ, u->nick.c_str(), u->GetIdent().c_str(), u->host);
}
else
- operserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ operserv(u, message);
}
else if (ci_bi_nick == Config.s_NickServ)
- nickserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
- else if (ci_bi_nick== Config.s_ChanServ)
+ nickserv(u, message);
+ else if (ci_bi_nick == Config.s_ChanServ)
{
if (!is_oper(u) && Config.CSOpersOnly)
notice_lang(Config.s_ChanServ, u, ACCESS_DENIED);
else
- chanserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ chanserv(u, message);
}
else if (ci_bi_nick == Config.s_MemoServ)
- memoserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ memoserv(u, message);
else if (Config.s_HostServ && ci_bi_nick == Config.s_HostServ)
- hostserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
+ hostserv(u, message);
else if (Config.s_BotServ)
- {
- if (ci_bi_nick == Config.s_BotServ)
- botserv(u, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
- else
- botmsgs(u, bi, const_cast<char *>(msg)); // XXX Unsafe cast, this needs reviewing -- CyberBotX
- }
+ botserv(u, bi, message);
}
/* Add to ignore list if the command took a significant amount of time. */
- if (allow_ignore) {
+ if (allow_ignore)
+ {
stoptime = time(NULL);
- if (stoptime > starttime && *source && !strchr(source, '.'))
- add_ignore(source, stoptime - starttime);
+ if (stoptime > starttime && source.find('.') == std::string::npos)
+ add_ignore(source.c_str(), stoptime - starttime);
}
}
+
return MOD_CONT;
}
diff --git a/src/misc.cpp b/src/misc.cpp
index 1cdaf923d..51ff5e97c 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -830,7 +830,7 @@ int nickIsServices(const char *tempnick, int bot)
found++;
else if (Config.s_BotServ && bot)
{
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
BotInfo *bi = it->second;
diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp
index 572dd2917..2313edd37 100644
--- a/src/modules/mysql/db_mysql_execute.cpp
+++ b/src/modules/mysql/db_mysql_execute.cpp
@@ -129,11 +129,7 @@ class SQLTimer : public Timer
continue;
}
- // XXX this whole strtok thing needs to die
- char *cmdbuf = sstrdup(qres[i]["command"].c_str());
- char *cmd = strtok(cmdbuf, " ");
- mod_run_cmd(bi, u, cmd);
- delete [] cmdbuf;
+ mod_run_cmd(bi, u, qres[i]["command"].c_str());
if (logout)
u->Logout();
diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp
index 4c9772eef..fdb11562f 100644
--- a/src/modules/mysql/db_mysql_write.cpp
+++ b/src/modules/mysql/db_mysql_write.cpp
@@ -265,7 +265,7 @@ static void SaveDatabases()
query << "TRUNCATE TABLE `anope_bs_core`";
ExecuteQuery(query);
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
me->OnBotCreate(it->second);
}
@@ -472,7 +472,7 @@ class DBMySQLWrite : public DBMySQL
FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel));
}
- for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it)
+ for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
{
CurBot = it->second;
FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot));
diff --git a/src/nickserv.cpp b/src/nickserv.cpp
index db2817af1..ce574b098 100644
--- a/src/nickserv.cpp
+++ b/src/nickserv.cpp
@@ -168,27 +168,21 @@ void ns_init()
/* Main NickServ routine. */
-void nickserv(User * u, char *buf)
+void nickserv(User *u, const std::string &buf)
{
- const char *cmd, *s;
-
- cmd = strtok(buf, " ");
-
- if (!cmd)
- {
+ if (!u || buf.empty())
return;
- }
- else if (stricmp(cmd, "\1PING") == 0)
+
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
{
- if (!(s = strtok(NULL, "")))
- {
- s = "";
- }
- ircdproto->SendCTCP(NickServ, u->nick.c_str(), "PING %s", s);
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(NickServ, u->nick.c_str(), "%s", command.c_str());
}
else
{
- mod_run_cmd(NickServ, u, cmd);
+ mod_run_cmd(NickServ, u, buf.c_str());
}
}
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 346914b15..863fb459e 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -39,23 +39,23 @@ void os_init()
XLineManager::RegisterXLineManager(SNLine = new SNLineManager());
}
-void operserv(User * u, char *buf)
+void operserv(User *u, const std::string &buf)
{
- const char *cmd, *s;
+ if (!u || buf.empty())
+ return;
Alog() << Config.s_OperServ << ": " << u->nick << ": " << buf;
- cmd = strtok(buf, " ");
- if (!cmd)
- return;
- else if (!stricmp(cmd, "\1PING")) {
- if (!(s = strtok(NULL, ""))) {
- s = "";
- }
- ircdproto->SendCTCP(OperServ, u->nick.c_str(), "PING %s", s);
+ if (buf.find("\1PING ", 0, 6) != std::string::npos && buf[buf.length() - 1] == '\1')
+ {
+ std::string command = buf;
+ command.erase(command.begin());
+ command.erase(command.end());
+ ircdproto->SendCTCP(OperServ, u->nick.c_str(), "%s", command.c_str());
}
- else {
- mod_run_cmd(OperServ, u, cmd);
+ else
+ {
+ mod_run_cmd(OperServ, u, buf.c_str());
}
}
diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp
index 5fa330197..3690fcea6 100644
--- a/src/protocol/inspircd12.cpp
+++ b/src/protocol/inspircd12.cpp
@@ -393,8 +393,8 @@ int anope_event_mode(const char *source, int ac, const char **av)
users modes, we have to kludge this
as it slightly breaks RFC1459
*/
- User *u = find_byuid(source);
- User *u2 = find_byuid(av[0]);
+ User *u = finduser(source);
+ User *u2 = finduser(av[0]);
// This can happen with server-origin modes.
if (u == NULL)
@@ -550,7 +550,7 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
buf.erase(buf.begin());
- User *u = find_byuid(buf);
+ User *u = finduser(buf);
if (!u)
{
Alog(LOG_DEBUG) << "FJOIN for nonexistant user " << buf << " on " << c->name;
@@ -642,7 +642,7 @@ int anope_event_topic(const char *source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
time_t topic_time = time(NULL);
- User *u = find_byuid(source);
+ User *u = finduser(source);
if (!c)
{
@@ -704,7 +704,7 @@ int anope_event_quit(const char *source, int ac, const char **av)
int anope_event_kill(const char *source, int ac, const char **av)
{
- User *u = find_byuid(av[0]);
+ User *u = finduser(av[0]);
BotInfo *bi = findbot(av[0]);
m_kill(u ? u->nick.c_str() : (bi ? bi->nick : av[0]), av[1]);
return MOD_CONT;
@@ -904,13 +904,10 @@ int anope_event_server(const char *source, int ac, const char **av)
int anope_event_privmsg(const char *source, int ac, const char **av)
{
- User *u = find_byuid(source);
- BotInfo *bi = findbot(av[0]);
-
- if (!u)
+ if (!finduser(source))
return MOD_CONT; // likely a message from a server, which can happen.
- m_privmsg(u->nick.c_str(), bi ? bi->nick: av[0], av[1]);
+ m_privmsg(source, av[0], av[1]);
return MOD_CONT;
}
@@ -934,7 +931,7 @@ int anope_event_metadata(const char *source, int ac, const char **av)
return MOD_CONT;
else if (!strcmp(av[1], "accountname"))
{
- if ((u = find_byuid(av[0])))
+ if ((u = finduser(av[0])))
{
/* Identify the user for this account - Adam */
u->AutoID(av[2]);
diff --git a/src/protocol/ratbox.cpp b/src/protocol/ratbox.cpp
index 95ccf6392..339113e33 100644
--- a/src/protocol/ratbox.cpp
+++ b/src/protocol/ratbox.cpp
@@ -378,7 +378,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
Status.push_back(cm);
}
- User *u = find_byuid(buf);
+ User *u = finduser(buf);
if (!u)
{
Alog(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name;
@@ -507,7 +507,7 @@ int anope_event_topic(const char *source, int ac, const char **av)
if (ac > 1 && *av[1])
c->topic = sstrdup(av[1]);
- u = find_byuid(source);
+ u = finduser(source);
c->topic_setter = u ? u->nick : source;
c->topic_time = topic_time;
@@ -590,7 +590,7 @@ int anope_event_away(const char *source, int ac, const char **av)
{
User *u = NULL;
- u = find_byuid(source);
+ u = finduser(source);
m_away(u ? u->nick.c_str() : source, (ac ? av[0] : NULL));
return MOD_CONT;
}
@@ -642,7 +642,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
- u = find_byuid(source);
+ u = finduser(source);
bi = findbot(av[0]);
// XXX: this is really the same as charybdis
m_privmsg(source, av[0], av[1]);
@@ -657,7 +657,7 @@ int anope_event_part(const char *source, int ac, const char **av)
return MOD_CONT;
}
- u = find_byuid(source);
+ u = finduser(source);
do_part(u ? u->nick.c_str() : source, ac, av);
return MOD_CONT;
@@ -715,7 +715,7 @@ int anope_event_quit(const char *source, int ac, const char **av)
return MOD_CONT;
}
- u = find_byuid(source);
+ u = finduser(source);
do_quit(u ? u->nick.c_str() : source, ac, av);
return MOD_CONT;
@@ -732,8 +732,8 @@ int anope_event_mode(const char *source, int ac, const char **av)
if (*av[0] == '#' || *av[0] == '&') {
do_cmode(source, ac, av);
} else {
- u = find_byuid(source);
- u2 = find_byuid(av[0]);
+ u = finduser(source);
+ u2 = finduser(av[0]);
av[0] = u2->nick.c_str();
do_umode(u->nick.c_str(), ac, av);
}
diff --git a/src/users.cpp b/src/users.cpp
index b01862479..5c88f9666 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -503,7 +503,6 @@ void User::UpdateHost()
return;
NickAlias *na = findnick(this->nick);
-
OnAccess = false;
if (na)
OnAccess = is_on_access(this, na->nc);
@@ -743,10 +742,14 @@ User *finduser(const std::string &nick)
User *finduser(const ci::string &nick)
{
- Alog(LOG_DEBUG_3) << "finduser("<< nick << ")";
-
if (isdigit(nick[0]) && ircd->ts6)
- return find_byuid(nick);
+ {
+ user_uid_map::const_iterator it = UserListByUID.find(nick.c_str());
+
+ if (it != UserListByUID.end())
+ return it->second;
+ return NULL;
+ }
user_map::const_iterator it = UserListByNick.find(nick);
@@ -755,27 +758,6 @@ User *finduser(const ci::string &nick)
return NULL;
}
-User *find_byuid(const char *uid)
-{
- return find_byuid(std::string(uid));
-}
-
-User *find_byuid(const ci::string &uid)
-{
- return find_byuid(std::string(uid.c_str()));
-}
-
-User *find_byuid(const std::string &uid)
-{
- Alog(LOG_DEBUG_3) << "finduser_byuid(" << uid << ")";
-
- user_uid_map::iterator it = UserListByUID.find(uid);
-
- if (it != UserListByUID.end())
- return it->second;
- return NULL;
-}
-
/*************************************************************************/
/* Handle a server NICK command. */
@@ -874,11 +856,7 @@ User *do_nick(const char *source, const char *nick, const char *username, const
else
{
/* An old user changing nicks. */
- if (ircd->ts6)
- user = find_byuid(source);
-
- if (!user)
- user = finduser(source);
+ user = finduser(source);
if (!user) {
Alog() << "user: NICK from nonexistent nick " << source;