summaryrefslogtreecommitdiff
path: root/modules/protocol
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-07-25 21:58:20 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-07-25 21:58:20 -0400
commitae38212c1ce829c783edf971081c90137abb49a0 (patch)
tree5c652d9cdc38103dec6fa112d57fca882b4e3e44 /modules/protocol
parent15d7f0f6fe8bb903275f603f734c13f65f3aa906 (diff)
Epic commit to replace most of the strings in Anope with a single Anope::string class, plus some other little fixes here and there. If you follow 1.9.x development and are testing things, THIS is one of those things that NEEDS testing.
Diffstat (limited to 'modules/protocol')
-rw-r--r--modules/protocol/bahamut.cpp202
-rw-r--r--modules/protocol/inspircd11.cpp297
-rw-r--r--modules/protocol/inspircd12.cpp349
-rw-r--r--modules/protocol/inspircd20.cpp509
-rw-r--r--modules/protocol/ratbox.cpp300
-rw-r--r--modules/protocol/unreal32.cpp372
6 files changed, 897 insertions, 1132 deletions
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index d7849c940..1f8b70ef7 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -7,8 +7,6 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
- *
- *
*/
/*************************************************************************/
@@ -45,7 +43,6 @@ IRCDVar myIrcd[] = {
0, /* Change RealName */
1, /* No Knock requires +i */
0, /* We support TOKENS */
- 0, /* TIME STAMPS are BASE64 */
0, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
0, /* ts6 */
@@ -60,7 +57,7 @@ IRCDVar myIrcd[] = {
void bahamut_cmd_burst()
{
- send_cmd(NULL, "BURST");
+ send_cmd("", "BURST");
}
/*
@@ -73,138 +70,131 @@ void bahamut_cmd_burst()
*/
void bahamut_cmd_svinfo()
{
- send_cmd(NULL, "SVINFO 3 1 0 :%ld", static_cast<long>(time(NULL)));
+ send_cmd("", "SVINFO 3 1 0 :%ld", static_cast<long>(time(NULL)));
}
/* PASS */
-void bahamut_cmd_pass(const char *pass)
+void bahamut_cmd_pass(const Anope::string &pass)
{
- send_cmd(NULL, "PASS %s :TS", pass);
+ send_cmd("", "PASS %s :TS", pass.c_str());
}
/* CAPAB */
void bahamut_cmd_capab()
{
- send_cmd(NULL, "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3");
-}
-
-/* this avoids "undefined symbol" messages of those whom try to load mods that
- call on this function */
-void bahamut_cmd_chghost(const char *nick, const char *vhost)
-{
- Alog(LOG_DEBUG) << "This IRCD does not support vhosting";
+ send_cmd("", "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3");
}
class BahamutIRCdProto : public IRCDProto
{
- void SendModeInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
if (Capab.HasFlag(CAPAB_TSMODE))
- send_cmd(source->nick, "MODE %s 0 %s", dest->name.c_str(), buf);
+ send_cmd(source->nick, "MODE %s 0 %s", dest->name.c_str(), buf.c_str());
else
- send_cmd(source->nick, "MODE %s %s", dest->name.c_str(), buf);
+ send_cmd(source->nick, "MODE %s %s", dest->name.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->nick : Config.ServerName, "SVSMODE %s %ld %s", u->nick.c_str(), static_cast<long>(u->timestamp), buf);
+ send_cmd(bi ? bi->nick : Config.ServerName, "SVSMODE %s %ld %s", u->nick.c_str(), static_cast<long>(u->timestamp), buf.c_str());
}
/* SVSHOLD - set */
- void SendSVSHold(const char *nick)
+ void SendSVSHold(const Anope::string &nick)
{
- send_cmd(Config.ServerName, "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user");
+ send_cmd(Config.ServerName, "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout));
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const char *nick)
+ void SendSVSHoldDel(const Anope::string &nick)
{
- send_cmd(Config.ServerName, "SVSHOLD %s 0", nick);
+ send_cmd(Config.ServerName, "SVSHOLD %s 0", nick.c_str());
}
/* SVSMODE -b */
- void SendBanDel(Channel *c, const std::string &nick)
+ void SendBanDel(Channel *c, const Anope::string &nick)
{
- SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str());
+ SendSVSModeChan(c, "-b", nick);
}
/* SVSMODE channel modes */
- void SendSVSModeChan(Channel *c, const char *mode, const char *nick)
+ void SendSVSModeChan(Channel *c, const Anope::string &mode, const Anope::string &nick)
{
- if (nick)
- send_cmd(Config.ServerName, "SVSMODE %s %s %s", c->name.c_str(), mode, nick);
+ if (!nick.empty())
+ send_cmd(Config.ServerName, "SVSMODE %s %s %s", c->name.c_str(), mode.c_str(), nick.c_str());
else
- send_cmd(Config.ServerName, "SVSMODE %s %s", c->name.c_str(), mode);
+ send_cmd(Config.ServerName, "SVSMODE %s %s", c->name.c_str(), mode.c_str());
}
/* SQLINE */
void SendSQLine(XLine *x)
{
- send_cmd(NULL, "SQLINE %s :%s", x->Mask.c_str(), x->Reason.c_str());
+ send_cmd("", "SQLINE %s :%s", x->Mask.c_str(), x->Reason.c_str());
}
/* UNSLINE */
void SendSGLineDel(XLine *x)
{
- send_cmd(NULL, "UNSGLINE 0 :%s", x->Mask.c_str());
+ send_cmd("", "UNSGLINE 0 :%s", x->Mask.c_str());
}
/* UNSZLINE */
void SendSZLineDel(XLine *x)
{
/* this will likely fail so its only here for legacy */
- send_cmd(NULL, "UNSZLINE 0 %s", x->Mask.c_str());
+ send_cmd("", "UNSZLINE 0 %s", x->Mask.c_str());
/* this is how we are supposed to deal with it */
- send_cmd(NULL, "RAKILL %s *", x->Mask.c_str());
+ send_cmd("", "RAKILL %s *", x->Mask.c_str());
}
/* SZLINE */
void SendSZLine(XLine *x)
{
/* this will likely fail so its only here for legacy */
- send_cmd(NULL, "SZLINE %s :%s", x->Mask.c_str(), x->Reason.c_str());
+ send_cmd("", "SZLINE %s :%s", x->Mask.c_str(), x->Reason.c_str());
/* this is how we are supposed to deal with it */
- send_cmd(NULL, "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd("", "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/* SVSNOOP */
- void SendSVSNOOP(const char *server, int set)
+ void SendSVSNOOP(const Anope::string &server, int set)
{
- send_cmd(NULL, "SVSNOOP %s %s", server, set ? "+" : "-");
+ send_cmd("", "SVSNOOP %s %s", server.c_str(), set ? "+" : "-");
}
/* SGLINE */
void SendSGLine(XLine *x)
{
- send_cmd(NULL, "SGLINE %d :%s:%s", static_cast<int>(x->Mask.length()), x->Mask.c_str(), x->Reason.c_str());
+ send_cmd("", "SGLINE %d :%s:%s", static_cast<int>(x->Mask.length()), x->Mask.c_str(), x->Reason.c_str());
}
/* RAKILL */
void SendAkillDel(XLine *x)
{
- send_cmd(NULL, "RAKILL %s %s", x->GetHost().c_str(), x->GetUser().c_str());
+ send_cmd("", "RAKILL %s %s", x->GetHost().c_str(), x->GetUser().c_str());
}
/* TOPIC */
- void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic)
{
- send_cmd(whosets->nick, "TOPIC %s %s %lu :%s", c->name.c_str(), whosetit, static_cast<unsigned long>(c->topic_time), topic);
+ send_cmd(whosets->nick, "TOPIC %s %s %lu :%s", c->name.c_str(), whosetit.c_str(), static_cast<unsigned long>(c->topic_time), topic.c_str());
}
/* UNSQLINE */
void SendSQLineDel(XLine *x)
{
- send_cmd(NULL, "UNSQLINE %s", x->Mask.c_str());
+ send_cmd("", "UNSQLINE %s", x->Mask.c_str());
}
/* JOIN - SJOIN */
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(user->nick, "SJOIN %ld %s", static_cast<long>(chantime), channel);
+ send_cmd(user->nick, "SJOIN %ld %s", static_cast<long>(chantime), channel.c_str());
}
void SendAkill(XLine *x)
@@ -213,15 +203,15 @@ class BahamutIRCdProto : public IRCDProto
time_t timeleft = x->Expires - time(NULL);
if (timeleft > 172800)
timeleft = 172800;
- send_cmd(NULL, "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd("", "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/*
Note: if the stamp is null 0, the below usage is correct of Bahamut
*/
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->nick : NULL, "SVSKILL %s :%s", user->nick.c_str(), buf);
+ send_cmd(source ? source->nick : "", "SVSKILL %s :%s", user->nick.c_str(), buf.c_str());
}
/* SVSMODE */
@@ -238,28 +228,28 @@ class BahamutIRCdProto : public IRCDProto
void SendEOB()
{
- send_cmd(NULL, "BURST 0");
+ send_cmd("", "BURST 0");
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(NULL, "NOTICE @%s :%s", dest->name.c_str(), buf);
+ send_cmd("", "NOTICE @%s :%s", dest->name.c_str(), buf.c_str());
}
- void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf);
+ if (!buf.empty())
+ send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str());
else
send_cmd(source->nick, "KICK %s %s", chan->name.c_str(), user->nick.c_str());
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &)
{
EnforceQlinedNick(nick, Config.s_BotServ);
- send_cmd(NULL, "NICK %s 1 %ld %s %s %s %s 0 0 :%s", nick.c_str(), static_cast<long>(time(NULL)), modes, user.c_str(), host.c_str(), Config.ServerName, real.c_str());
+ send_cmd("", "NICK %s 1 %ld %s %s %s %s 0 0 :%s", nick.c_str(), static_cast<long>(time(NULL)), modes.c_str(), user.c_str(), host.c_str(), Config.ServerName.c_str(), real.c_str());
}
/* SVSMODE +d */
@@ -274,7 +264,7 @@ class BahamutIRCdProto : public IRCDProto
/* SERVER */
void SendServer(Server *server)
{
- send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
+ send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
}
void SendConnect()
@@ -288,28 +278,26 @@ class BahamutIRCdProto : public IRCDProto
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15];
-
if (!u->Account())
return;
srand(time(NULL));
- snprintf(svidbuf, sizeof(svidbuf), "%d", rand());
+ Anope::string svidbuf = stringify(rand());
u->Account()->Shrink("authenticationtoken");
- u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
+ u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf));
BotInfo *bi = NickServ;
u->SetMode(bi, UMODE_REGISTERED);
- ircdproto->SendMode(bi, u, "+d %s", svidbuf);
+ ircdproto->SendMode(bi, u, "+d %s", svidbuf.c_str());
}
} ircd_proto;
/* EVENT: SJOIN */
-int anope_event_sjoin(const char *source, int ac, const char **av)
+int anope_event_sjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[1]);
- time_t ts = atol(av[0]);
+ time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0;
bool was_created = false;
bool keep_their_modes = false;
@@ -399,11 +387,10 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
else
{
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
std::list<ChannelMode *> Status;
- Status.clear();
char ch;
/* Get prefixes from the nick */
@@ -488,13 +475,13 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
** parv[0] = new nickname
** parv[1] = hopcount
*/
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
User *user;
if (ac != 2)
{
- user = do_nick(source, av[0], av[4], av[5], av[6], av[9], strtoul(av[2], NULL, 10), strtoul(av[8], NULL, 0), NULL, NULL);
+ user = do_nick(source, av[0], av[4], av[5], av[6], av[9], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, Anope::string(av[8]).is_number_only() ? convertTo<uint32>(av[8]) : 0, "", "");
if (user)
{
/* Check to see if the user should be identified because their
@@ -506,19 +493,19 @@ int anope_event_nick(const char *source, int ac, const char **av)
}
}
else
- do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", "");
return MOD_CONT;
}
/* EVENT : CAPAB */
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
CapabParse(ac, av);
return MOD_CONT;
}
/* EVENT : OS */
-int anope_event_os(const char *source, int ac, const char **av)
+int anope_event_os(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -527,7 +514,7 @@ int anope_event_os(const char *source, int ac, const char **av)
}
/* EVENT : NS */
-int anope_event_ns(const char *source, int ac, const char **av)
+int anope_event_ns(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -536,7 +523,7 @@ int anope_event_ns(const char *source, int ac, const char **av)
}
/* EVENT : MS */
-int anope_event_ms(const char *source, int ac, const char **av)
+int anope_event_ms(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -545,7 +532,7 @@ int anope_event_ms(const char *source, int ac, const char **av)
}
/* EVENT : HS */
-int anope_event_hs(const char *source, int ac, const char **av)
+int anope_event_hs(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -554,7 +541,7 @@ int anope_event_hs(const char *source, int ac, const char **av)
}
/* EVENT : CS */
-int anope_event_cs(const char *source, int ac, const char **av)
+int anope_event_cs(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -562,7 +549,7 @@ int anope_event_cs(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -572,14 +559,14 @@ int anope_event_436(const char *source, int ac, const char **av)
}
/* EVENT : SERVER */
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
- do_server(source, av[0], atoi(av[1]), av[2], "");
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], "");
return MOD_CONT;
}
/* EVENT : PRIVMSG */
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -587,7 +574,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
if (ac < 1 || ac > 2)
return MOD_CONT;
@@ -595,14 +582,14 @@ int anope_event_part(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
- if (source && ac >= 1)
+ if (!source.empty() && ac >= 1)
m_whois(source, av[0]);
return MOD_CONT;
}
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
if (ac != 4)
return MOD_CONT;
@@ -610,7 +597,7 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -618,7 +605,7 @@ int anope_event_squit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
return MOD_CONT;
@@ -627,7 +614,7 @@ int anope_event_quit(const char *source, int ac, const char **av)
}
/* EVENT: MODE */
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
if (ac < 2)
return MOD_CONT;
@@ -640,7 +627,7 @@ int anope_event_mode(const char *source, int ac, const char **av)
}
/* EVENT: KILL */
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -650,7 +637,7 @@ int anope_event_kill(const char *source, int ac, const char **av)
}
/* EVENT: KICK */
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
if (ac != 3)
return MOD_CONT;
@@ -659,7 +646,7 @@ int anope_event_kick(const char *source, int ac, const char **av)
}
/* EVENT: JOIN */
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
return MOD_CONT;
@@ -668,24 +655,24 @@ int anope_event_join(const char *source, int ac, const char **av)
}
/* EVENT: MOTD */
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
m_motd(source);
return MOD_CONT;
}
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
- m_away(source, (ac ? av[0] : NULL));
+ m_away(source, ac ? av[0] : "");
return MOD_CONT;
}
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -693,16 +680,16 @@ int anope_event_ping(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_error(const char *source, int ac, const char **av)
+int anope_event_error(const Anope::string &source, int ac, const char **av)
{
if (ac >= 1)
Alog(LOG_DEBUG) << av[0];
return MOD_CONT;
}
-int anope_event_burst(const char *source, int ac, const char **av)
+int anope_event_burst(const Anope::string &source, int ac, const char **av)
{
- Server *s = Server::Find(source ? source : "");
+ Server *s = Server::Find(source);
if (!ac)
{
@@ -722,11 +709,10 @@ int anope_event_burst(const char *source, int ac, const char **av)
return MOD_CONT;
}
-bool ChannelModeFlood::IsValid(const std::string &value)
+bool ChannelModeFlood::IsValid(const Anope::string &value)
{
- char *dp, *end;
-
- if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end)
+ Anope::string rest;
+ if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
return true;
return false;
@@ -769,7 +755,7 @@ static void AddModes()
ModeManager::AddUserMode(new UserMode(UMODE_REGPRIV, "UMODE_REGPRIV", 'R'));
ModeManager::AddUserMode(new UserMode(UMODE_ADMIN, "UMODE_ADMIN", 'a'));
ModeManager::AddUserMode(new UserMode(UMODE_INVIS, "UMODE_INVIS", 'i'));
- ModeManager::AddUserMode(new UserMode(UMODE_OPER,"UMODE_OPER", 'o'));
+ ModeManager::AddUserMode(new UserMode(UMODE_OPER, "UMODE_OPER", 'o'));
ModeManager::AddUserMode(new UserMode(UMODE_REGISTERED, "UMODE_REGISTERED", 'r'));
ModeManager::AddUserMode(new UserMode(UMODE_SNOMASK, "UMODE_SNOMASK", 's'));
ModeManager::AddUserMode(new UserMode(UMODE_WALLOPS, "UMODE_WALLOPS", 'w'));
@@ -802,7 +788,7 @@ static void AddModes()
class ProtoBahamut : public Module
{
public:
- ProtoBahamut(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
@@ -823,7 +809,7 @@ class ProtoBahamut : public Module
ModuleManager::Attach(I_OnUserNickChange, this);
}
- void OnUserNickChange(User *u, const std::string &)
+ void OnUserNickChange(User *u, const Anope::string &)
{
u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED));
}
diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp
index ac50f64b9..9e21516e6 100644
--- a/modules/protocol/inspircd11.cpp
+++ b/modules/protocol/inspircd11.cpp
@@ -15,22 +15,6 @@
#include "modules.h"
#include "hashcomp.h"
-#ifndef _WIN32
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <arpa/inet.h>
-#endif
-
-#ifdef _WIN32
-# include <winsock.h>
-int inet_aton(const char *name, struct in_addr *addr)
-{
- uint32 a = inet_addr(name);
- addr->s_addr = a;
- return a != (uint32) - 1;
-}
-#endif
-
IRCDVar myIrcd[] = {
{"InspIRCd 1.1", /* ircd name */
"+I", /* Modes used by pseudoclients */
@@ -60,7 +44,6 @@ IRCDVar myIrcd[] = {
0, /* Change RealName */
1, /* No Knock requires +i */
0, /* We support inspircd TOKENS */
- 0, /* TIME STAMPS are BASE64 */
0, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
0, /* ts6 */
@@ -81,31 +64,31 @@ static bool has_chgidentmod = false;
static bool has_hidechansmod = false;
/* CHGHOST */
-void inspircd_cmd_chghost(const char *nick, const char *vhost)
+void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
if (has_chghostmod)
{
- if (!nick || !vhost)
+ if (nick.empty() || vhost.empty())
return;
- send_cmd(Config.s_OperServ, "CHGHOST %s %s", nick, vhost);
+ send_cmd(Config.s_OperServ, "CHGHOST %s %s", nick.c_str(), vhost.c_str());
}
else
ircdproto->SendGlobops(OperServ, "CHGHOST not loaded!");
}
-int anope_event_idle(const char *source, int ac, const char **av)
+int anope_event_idle(const Anope::string &source, int ac, const char **av)
{
if (ac == 1)
- send_cmd(av[0], "IDLE %s %ld 0", source, static_cast<long>(time(NULL)));
+ send_cmd(av[0], "IDLE %s %ld 0", source.c_str(), static_cast<long>(time(NULL)));
return MOD_CONT;
}
-static char currentpass[1024];
+static Anope::string currentpass;
/* PASS */
-void inspircd_cmd_pass(const char *pass)
+void inspircd_cmd_pass(const Anope::string &pass)
{
- strlcpy(currentpass, pass, sizeof(currentpass));
+ currentpass = pass;
}
class InspIRCdProto : public IRCDProto
@@ -115,20 +98,20 @@ class InspIRCdProto : public IRCDProto
send_cmd(Config.s_OperServ, "GLINE %s", x->Mask.c_str());
}
- void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic)
{
- send_cmd(whosets->nick, "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic);
+ send_cmd(whosets->nick, "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str());
}
void SendVhostDel(User *u)
{
if (u->HasMode(UMODE_CLOAK))
- inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str());
+ inspircd_cmd_chghost(u->nick, u->chost);
else
- inspircd_cmd_chghost(u->nick.c_str(), u->host);
+ inspircd_cmd_chghost(u->nick, u->host);
if (has_chgidentmod && u->GetIdent() != u->GetVIdent())
- inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str());
+ inspircd_cmd_chgident(u->nick, u->GetIdent());
}
void SendAkill(XLine *x)
@@ -140,9 +123,9 @@ class InspIRCdProto : public IRCDProto
send_cmd(Config.ServerName, "ADDLINE G %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str());
}
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->nick : Config.ServerName, "KILL %s :%s", user->nick.c_str(), buf);
+ send_cmd(source ? source->nick : Config.ServerName, "KILL %s :%s", user->nick.c_str(), buf.c_str());
}
void SendSVSMode(User *u, int ac, const char **av)
@@ -150,61 +133,56 @@ class InspIRCdProto : public IRCDProto
this->SendModeInternal(NULL, u, merge_args(ac, av));
}
- void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf)
- {
- send_cmd(source, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf);
- }
-
- void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes)
+ void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf)
{
- send_cmd(Config.ServerName, "NICK %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real);
+ send_cmd(source, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(source ? source->nick : Config.s_OperServ, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf);
+ send_cmd(source ? source->nick : Config.s_OperServ, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->nick : Config.ServerName, "MODE %s %s", u->nick.c_str(), buf);
+ send_cmd(bi ? bi->nick : Config.ServerName, "MODE %s %s", u->nick.c_str(), buf.c_str());
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &)
{
- send_cmd(Config.ServerName, "NICK %ld %s %s %s %s %s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), modes, real.c_str());
+ send_cmd(Config.ServerName, "NICK %ld %s %s %s %s %s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), modes.c_str(), real.c_str());
send_cmd(nick, "OPERTYPE Service");
}
- void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf);
+ if (!buf.empty())
+ send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str());
else
send_cmd(source->nick, "KICK %s %s :%s", chan->name.c_str(), user->nick.c_str(), user->nick.c_str());
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(Config.ServerName, "NOTICE @%s :%s", dest->name.c_str(), buf);
+ send_cmd(Config.ServerName, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str());
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(Server *server)
{
- send_cmd(Config.ServerName, "SERVER %s %s %d :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetDescription().c_str());
+ send_cmd(Config.ServerName, "SERVER %s %s %d :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetDescription().c_str());
}
/* JOIN */
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(user->nick, "JOIN %s %ld", channel, static_cast<long>(chantime));
+ send_cmd(user->nick, "JOIN %s %ld", channel.c_str(), static_cast<long>(chantime));
}
/* UNSQLINE */
@@ -216,58 +194,58 @@ class InspIRCdProto : public IRCDProto
/* SQLINE */
void SendSQLine(XLine *x)
{
- send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd(Config.ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/* SQUIT */
- void SendSquit(const char *servname, const char *message)
+ void SendSquit(const Anope::string &servname, const Anope::string &message)
{
- if (!servname || !message)
+ if (servname.empty() || message.empty())
return;
- send_cmd(Config.ServerName, "SQUIT %s :%s", servname, message);
+ send_cmd(Config.ServerName, "SQUIT %s :%s", servname.c_str(), message.c_str());
}
/* Functions that use serval cmd functions */
- void SendVhost(User *u, const std::string &vIdent, const std::string &vhost)
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost)
{
if (!vIdent.empty())
- inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str());
+ inspircd_cmd_chgident(u->nick, vIdent);
if (!vhost.empty())
- inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str());
+ inspircd_cmd_chghost(u->nick, vhost);
}
void SendConnect()
{
inspircd_cmd_pass(uplink_server->password);
SendServer(Me);
- send_cmd(NULL, "BURST");
- send_cmd(Config.ServerName, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
+ send_cmd("", "BURST");
+ send_cmd(Config.ServerName, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
}
/* CHGIDENT */
- void inspircd_cmd_chgident(const char *nick, const char *vIdent)
+ void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent)
{
if (has_chgidentmod)
{
- if (!nick || !vIdent || !*vIdent)
+ if (nick.empty() || vIdent.empty())
return;
- send_cmd(Config.s_OperServ, "CHGIDENT %s %s", nick, vIdent);
+ send_cmd(Config.s_OperServ, "CHGIDENT %s %s", nick.c_str(), vIdent.c_str());
}
else
ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!");
}
/* SVSHOLD - set */
- void SendSVSHold(const char *nick)
+ void SendSVSHold(const Anope::string &nick)
{
- send_cmd(Config.s_OperServ, "SVSHOLD %s %ds :%s", nick, static_cast<int>(Config.NSReleaseTimeout), "Being held for registered user");
+ send_cmd(Config.s_OperServ, "SVSHOLD %s %ds :Being held for registered user", nick.c_str(), static_cast<int>(Config.NSReleaseTimeout));
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const char *nick)
+ void SendSVSHoldDel(const Anope::string &nick)
{
- send_cmd(Config.s_OperServ, "SVSHOLD %s", nick);
+ send_cmd(Config.s_OperServ, "SVSHOLD %s", nick.c_str());
}
/* UNSZLINE */
@@ -288,38 +266,37 @@ class InspIRCdProto : public IRCDProto
u->RemoveMode(NickServ, UMODE_REGISTERED);
}
- void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param)
+ void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &)
{
- send_cmd(source, "SVSJOIN %s %s", nick, chan);
+ send_cmd(source, "SVSJOIN %s %s", nick.c_str(), chan.c_str());
}
- void SendSVSPart(const char *source, const char *nick, const char *chan)
+ void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan)
{
- send_cmd(source, "SVSPART %s %s", nick, chan);
+ send_cmd(source, "SVSPART %s %s", nick.c_str(), chan.c_str());
}
void SendEOB()
{
- send_cmd(NULL, "ENDBURST");
+ send_cmd("", "ENDBURST");
}
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15];
if (!u->Account())
return;
- snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp));
+ Anope::string svidbuf = stringify(u->timestamp);
u->Account()->Shrink("authenticationtoken");
- u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
+ u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf));
u->SetMode(NickServ, UMODE_REGISTERED);
}
} ircd_proto;
-int anope_event_ftopic(const char *source, int ac, const char **av)
+int anope_event_ftopic(const Anope::string &source, int ac, const char **av)
{
/* :source FTOPIC channel ts setby :topic */
const char *temp;
@@ -332,7 +309,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
if (ac < 2)
return MOD_CONT;
@@ -345,7 +322,7 @@ int anope_event_mode(const char *source, int ac, const char **av)
users modes, we have to kludge this
as it slightly breaks RFC1459
*/
- if (!strcasecmp(source, av[0]))
+ if (source.equals_ci(av[0]))
do_umode(source, ac, av);
else
do_umode(av[0], ac, av);
@@ -353,7 +330,7 @@ int anope_event_mode(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_opertype(const char *source, int ac, const char **av)
+int anope_event_opertype(const Anope::string &source, int ac, const char **av)
{
/* opertype is equivalent to mode +o because servers
dont do this directly */
@@ -362,7 +339,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
if (u && !is_oper(u))
{
const char *newav[2];
- newav[0] = source;
+ newav[0] = source.c_str();
newav[1] = "+o";
return anope_event_mode(source, 2, newav);
}
@@ -370,7 +347,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_fmode(const char *source, int ac, const char **av)
+int anope_event_fmode(const Anope::string &source, int ac, const char **av)
{
const char *newav[128];
int n, o;
@@ -383,10 +360,11 @@ int anope_event_fmode(const char *source, int ac, const char **av)
/* Checking the TS for validity to avoid desyncs */
if ((c = findchan(av[0])))
{
- if (c->creation_time > strtol(av[1], NULL, 10))
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
+ if (c->creation_time > ts)
/* Our TS is bigger, we should lower it */
- c->creation_time = strtol(av[1], NULL, 10);
- else if (c->creation_time < strtol(av[1], NULL, 10))
+ c->creation_time = ts;
+ else if (c->creation_time < ts)
/* The TS we got is bigger, we should ignore this message. */
return MOD_CONT;
}
@@ -410,10 +388,10 @@ int anope_event_fmode(const char *source, int ac, const char **av)
return anope_event_mode(source, ac - 1, newav);
}
-int anope_event_fjoin(const char *source, int ac, const char **av)
+int anope_event_fjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
- time_t ts = atol(av[1]);
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
bool was_created = false;
bool keep_their_modes = true;
@@ -465,11 +443,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
c->SetFlag(CH_SYNCING);
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
std::list<ChannelMode *> Status;
- Status.clear();
char ch;
/* Loop through prefixes */
@@ -538,7 +515,7 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
/* Events */
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -546,7 +523,7 @@ int anope_event_ping(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -555,17 +532,17 @@ int anope_event_436(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
- m_away(source, (ac ? av[0] : NULL));
+ m_away(source, ac ? av[0] : "");
return MOD_CONT;
}
/* Taken from hybrid.c, topic syntax is identical */
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
time_t topic_time = time(NULL);
@@ -579,13 +556,9 @@ int anope_event_topic(const char *source, int ac, const char **av)
if (check_topiclock(c, topic_time))
return MOD_CONT;
- if (c->topic)
- {
- delete [] c->topic;
- c->topic = NULL;
- }
+ c->topic.clear();
if (ac > 1 && *av[1])
- c->topic = sstrdup(av[1]);
+ c->topic = av[1];
c->topic_setter = source;
c->topic_time = topic_time;
@@ -604,7 +577,7 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -612,13 +585,13 @@ int anope_event_squit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_rsquit(const char *source, int ac, const char **av)
+int anope_event_rsquit(const Anope::string &source, int ac, const char **av)
{
if (ac < 1 || ac > 3)
return MOD_CONT;
/* Horrible workaround to an insp bug (#) in how RSQUITs are sent - mark */
- if (ac > 1 && !strcmp(Config.ServerName, av[0]))
+ if (ac > 1 && Config.ServerName.equals_cs(av[0]))
do_squit(source, ac - 1, av + 1);
else
do_squit(source, ac, av);
@@ -626,7 +599,7 @@ int anope_event_rsquit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
return MOD_CONT;
@@ -634,7 +607,7 @@ int anope_event_quit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -643,7 +616,7 @@ int anope_event_kill(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
if (ac != 3)
return MOD_CONT;
@@ -651,7 +624,7 @@ int anope_event_kick(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -659,16 +632,16 @@ int anope_event_join(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
m_motd(source);
return MOD_CONT;
}
-int anope_event_setname(const char *source, int ac, const char **av)
+int anope_event_setname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -686,7 +659,7 @@ int anope_event_setname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgname(const char *source, int ac, const char **av)
+int anope_event_chgname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -704,7 +677,7 @@ int anope_event_chgname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_setident(const char *source, int ac, const char **av)
+int anope_event_setident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -722,7 +695,7 @@ int anope_event_setident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgident(const char *source, int ac, const char **av)
+int anope_event_chgident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -740,7 +713,7 @@ int anope_event_chgident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_sethost(const char *source, int ac, const char **av)
+int anope_event_sethost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -759,27 +732,20 @@ int anope_event_sethost(const char *source, int ac, const char **av)
}
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
User *user;
- struct in_addr addy;
- uint32 *ad = reinterpret_cast<uint32 *>(&addy);
if (ac != 1)
{
if (ac == 8)
{
- int ts = strtoul(av[0], NULL, 10);
-
- inet_aton(av[6], &addy);
- user = do_nick("", av[1], /* nick */
- av[4], /* username */
- av[2], /* realhost */
- source, /* server */
- av[7], /* realname */
- ts, htonl(*ad), av[3], NULL);
+ time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0;
+
+ user = do_nick("", av[1], av[4], av[2], source, av[7], ts, 0, av[3], "");
if (user)
{
+ user->hostip = av[6];
/* InspIRCd1.1 has no user mode +d so we
* use nick timestamp to check for auth - Adam
*/
@@ -791,12 +757,12 @@ int anope_event_nick(const char *source, int ac, const char **av)
}
}
else
- do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", 0, 0, "", "");
return MOD_CONT;
}
-int anope_event_chghost(const char *source, int ac, const char **av)
+int anope_event_chghost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -815,13 +781,13 @@ int anope_event_chghost(const char *source, int ac, const char **av)
}
/* EVENT: SERVER */
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
- do_server(source, av[0], atoi(av[1]), av[2], "");
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], "");
return MOD_CONT;
}
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -829,7 +795,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
if (ac < 1 || ac > 2)
return MOD_CONT;
@@ -837,14 +803,14 @@ int anope_event_part(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
- if (source && ac >= 1)
+ if (!source.empty() && ac >= 1)
m_whois(source, av[0]);
return MOD_CONT;
}
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
if (!strcasecmp(av[0], "START"))
{
@@ -874,17 +840,17 @@ int anope_event_capab(const char *source, int ac, const char **av)
else if (!strcasecmp(av[0], "CAPABILITIES"))
{
spacesepstream ssep(av[1]);
- std::string capab;
+ Anope::string capab;
while (ssep.GetToken(capab))
{
- if (capab.find("CHANMODES") != std::string::npos)
+ if (capab.find("CHANMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -903,7 +869,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -912,12 +878,11 @@ int anope_event_capab(const char *source, int ac, const char **av)
continue;
default:
ModeManager::AddChannelMode(new ChannelModeParam(CMODE_END, "", modebuf[t]));
-
}
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -936,7 +901,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -1005,12 +970,12 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
}
}
- else if (capab.find("PREIX=(") != std::string::npos)
+ else if (capab.find("PREIX=(") != Anope::string::npos)
{
- std::string modes(capab.begin() + 8, capab.begin() + capab.find(")"));
- std::string chars(capab.begin() + capab.find(")") + 1, capab.end());
+ Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')'));
+ Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end());
- for (size_t t = 0, end = modes.size(); t < end; ++t)
+ for (size_t t = 0, end = modes.length(); t < end; ++t)
{
switch (modes[t])
{
@@ -1034,8 +999,8 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
else if (capab.find("MAXMODES=") != std::string::npos)
{
- std::string maxmodes(capab.begin() + 9, capab.end());
- ircd->maxmodes = atoi(maxmodes.c_str());
+ Anope::string maxmodes(capab.begin() + 9, capab.end());
+ ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3;
}
}
}
@@ -1043,21 +1008,21 @@ int anope_event_capab(const char *source, int ac, const char **av)
{
if (!has_globopsmod)
{
- send_cmd(NULL, "ERROR :m_globops is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_globops module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
}
if (!has_servicesmod)
{
- send_cmd(NULL, "ERROR :m_services is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_services is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_services module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
}
if (!has_hidechansmod)
{
- send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server deos not have the m_hidechans module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
@@ -1075,7 +1040,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_endburst(const char *source, int ac, const char **av)
+int anope_event_endburst(const Anope::string &source, int ac, const char **av)
{
Me->GetUplink()->Sync(true);
return MOD_CONT;
@@ -1092,7 +1057,7 @@ void moduleAddIRCDMsgs()
Anope::AddMessage("MODE", anope_event_mode);
Anope::AddMessage("MOTD", anope_event_motd);
Anope::AddMessage("NICK", anope_event_nick);
- Anope::AddMessage("CAPAB",anope_event_capab);
+ Anope::AddMessage("CAPAB", anope_event_capab);
Anope::AddMessage("PART", anope_event_part);
Anope::AddMessage("PING", anope_event_ping);
Anope::AddMessage("PRIVMSG", anope_event_privmsg);
@@ -1116,11 +1081,10 @@ void moduleAddIRCDMsgs()
Anope::AddMessage("IDLE", anope_event_idle);
}
-bool ChannelModeFlood::IsValid(const std::string &value)
+bool ChannelModeFlood::IsValid(const Anope::string &value)
{
- char *dp, *end;
-
- if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end)
+ Anope::string rest;
+ if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
return true;
return false;
@@ -1140,7 +1104,7 @@ static void AddModes()
class ProtoInspIRCd : public Module
{
public:
- ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
@@ -1161,11 +1125,10 @@ class ProtoInspIRCd : public Module
ModuleManager::Attach(I_OnUserNickChange, this);
}
- void OnUserNickChange(User *u, const std::string &)
+ void OnUserNickChange(User *u, const Anope::string &)
{
u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED));
}
-
};
MODULE_INIT(ProtoInspIRCd)
diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp
index 465f0ffff..416a91c96 100644
--- a/modules/protocol/inspircd12.cpp
+++ b/modules/protocol/inspircd12.cpp
@@ -15,22 +15,6 @@
#include "modules.h"
#include "hashcomp.h"
-#ifndef _WIN32
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <arpa/inet.h>
-#endif
-
-#ifdef _WIN32
-# include <winsock.h>
-int inet_aton(const char *name, struct in_addr *addr)
-{
- uint32 a = inet_addr(name);
- addr->s_addr = a;
- return a != (uint32) - 1;
-}
-#endif
-
IRCDVar myIrcd[] = {
{"InspIRCd 1.2", /* ircd name */
"+I", /* Modes used by pseudoclients */
@@ -60,7 +44,6 @@ IRCDVar myIrcd[] = {
0, /* Change RealName */
1, /* No Knock requires +i */
0, /* We support inspircd TOKENS */
- 0, /* TIME STAMPS are BASE64 */
0, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
1, /* ts6 */
@@ -84,7 +67,7 @@ static bool has_hidechansmod = false;
static User *prev_u_intro = NULL;
/* CHGHOST */
-void inspircd_cmd_chghost(const char *nick, const char *vhost)
+void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
if (!has_chghostmod)
{
@@ -92,50 +75,48 @@ void inspircd_cmd_chghost(const char *nick, const char *vhost)
return;
}
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "CHGHOST %s %s", nick, vhost);
+ send_cmd(OperServ->GetUID(), "CHGHOST %s %s", nick.c_str(), vhost.c_str());
}
-int anope_event_idle(const char *source, int ac, const char **av)
+int anope_event_idle(const Anope::string &source, int ac, const char **av)
{
BotInfo *bi = findbot(av[0]);
if (!bi)
return MOD_CONT;
- send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source, static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg));
+ send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg));
return MOD_CONT;
}
-static char currentpass[1024];
+static Anope::string currentpass;
/* PASS */
-void inspircd_cmd_pass(const char *pass)
+void inspircd_cmd_pass(const Anope::string &pass)
{
- strlcpy(currentpass, pass, sizeof(currentpass));
+ currentpass = pass;
}
class InspIRCdProto : public IRCDProto
{
void SendAkillDel(XLine *x)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "GLINE %s", x->Mask.c_str());
+ send_cmd(OperServ->GetUID(), "GLINE %s", x->Mask.c_str());
}
- void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic)
{
- send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic);
+ send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str());
}
void SendVhostDel(User *u)
{
if (u->HasMode(UMODE_CLOAK))
- inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str());
+ inspircd_cmd_chghost(u->nick, u->chost);
else
- inspircd_cmd_chghost(u->nick.c_str(), u->host);
+ inspircd_cmd_chghost(u->nick, u->host);
if (has_chgidentmod && u->GetIdent() != u->GetVIdent())
- inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str());
+ inspircd_cmd_chgident(u->nick, u->GetIdent());
}
void SendAkill(XLine *x)
@@ -144,13 +125,12 @@ class InspIRCdProto : public IRCDProto
time_t timeleft = x->Expires - time(NULL);
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str());
+ send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str());
}
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str());
}
void SendSVSMode(User *u, int ac, const char **av)
@@ -158,56 +138,51 @@ class InspIRCdProto : public IRCDProto
this->SendModeInternal(NULL, u, merge_args(ac, av));
}
- void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf)
- {
- send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf);
- }
-
- void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes)
+ void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf)
{
- send_cmd(TS6SID, "UID %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real);
+ send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf);
+ send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf.c_str());
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid)
{
- send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes, real.c_str());
+ send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes.c_str(), real.c_str());
}
- void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf);
+ if (!buf.empty())
+ send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str());
else
send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), user->nick.c_str());
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf);
+ send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str());
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(Server *server)
{
- send_cmd(NULL, "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str());
+ send_cmd("", "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str());
}
/* JOIN */
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel, static_cast<long>(chantime), user->GetUID().c_str());
+ send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel.c_str(), static_cast<long>(chantime), user->GetUID().c_str());
}
/* UNSQLINE */
@@ -219,23 +194,23 @@ class InspIRCdProto : public IRCDProto
/* SQLINE */
void SendSQLine(XLine *x)
{
- send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/* SQUIT */
- void SendSquit(const char *servname, const char *message)
+ void SendSquit(const Anope::string &servname, const Anope::string &message)
{
- send_cmd(TS6SID, "SQUIT %s :%s", servname, message);
+ send_cmd(TS6SID, "SQUIT %s :%s", servname.c_str(), message.c_str());
}
/* Functions that use serval cmd functions */
- void SendVhost(User *u, const std::string &vIdent, const std::string &vhost)
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost)
{
if (!vIdent.empty())
- inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str());
+ inspircd_cmd_chgident(u->nick, vIdent);
if (!vhost.empty())
- inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str());
+ inspircd_cmd_chghost(u->nick, vhost);
}
void SendConnect()
@@ -243,33 +218,28 @@ class InspIRCdProto : public IRCDProto
inspircd_cmd_pass(uplink_server->password);
SendServer(Me);
send_cmd(TS6SID, "BURST");
- send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
+ send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
}
/* CHGIDENT */
- void inspircd_cmd_chgident(const char *nick, const char *vIdent)
+ void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent)
{
if (!has_chgidentmod)
ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!");
else
- {
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "CHGIDENT %s %s", nick, vIdent);
- }
+ send_cmd(OperServ->GetUID(), "CHGIDENT %s %s", nick.c_str(), vIdent.c_str());
}
/* SVSHOLD - set */
- void SendSVSHold(const char *nick)
+ void SendSVSHold(const Anope::string &nick)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user");
+ send_cmd(OperServ->GetUID(), "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout));
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const char *nick)
+ void SendSVSHoldDel(const Anope::string &nick)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "SVSHOLD %s", nick);
+ send_cmd(OperServ->GetUID(), "SVSHOLD %s", nick.c_str());
}
/* UNSZLINE */
@@ -290,25 +260,25 @@ class InspIRCdProto : public IRCDProto
u->RemoveMode(NickServ, UMODE_REGISTERED);
}
- void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param)
+ void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &)
{
User *u = finduser(nick);
BotInfo *bi = findbot(source);
- send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan);
+ send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan.c_str());
}
- void SendSVSPart(const char *source, const char *nick, const char *chan)
+ void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan)
{
User *u = finduser(nick);
BotInfo *bi = findbot(source);
- send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan);
+ send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan.c_str());
}
- void SendSWhois(const char *source, const char *who, const char *mask)
+ void SendSWhois(const Anope::string &, const Anope::string &who, const Anope::string &mask)
{
User *u = finduser(who);
- send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask);
+ send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask.c_str());
}
void SendEOB()
@@ -316,30 +286,31 @@ class InspIRCdProto : public IRCDProto
send_cmd(TS6SID, "ENDBURST");
}
- void SendGlobopsInternal(BotInfo *source, const char *buf)
+ void SendGlobopsInternal(BotInfo *source, const Anope::string &buf)
{
if (has_globopsmod)
- send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf.c_str());
else
- send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE A :%s", buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE A :%s", buf.c_str());
}
- void SendAccountLogin(User *u, NickCore *account)
+ void SendAccountLogin(User *u, const NickCore *account)
{
- send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display);
+ send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display.c_str());
}
- void SendAccountLogout(User *u, NickCore *account)
+ void SendAccountLogout(User *u, const NickCore *account)
{
send_cmd(TS6SID, "METADATA %s accountname :", u->GetUID().c_str());
}
- int IsNickValid(const char *nick)
+ bool IsNickValid(const Anope::string &nick)
{
/* InspIRCd, like TS6, uses UIDs on collision, so... */
- if (isdigit(*nick))
- return 0;
- return 1;
+ if (isdigit(nick[0]))
+ return false;
+
+ return true;
}
void SetAutoIdentificationToken(User *u)
@@ -351,7 +322,7 @@ class InspIRCdProto : public IRCDProto
}
} ircd_proto;
-int anope_event_ftopic(const char *source, int ac, const char **av)
+int anope_event_ftopic(const Anope::string &source, int ac, const char **av)
{
/* :source FTOPIC channel ts setby :topic */
const char *temp;
@@ -364,7 +335,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
if (*av[0] == '#' || *av[0] == '&')
do_cmode(source, ac, av);
@@ -383,16 +354,16 @@ int anope_event_mode(const char *source, int ac, const char **av)
// if it's still null, drop it like fire.
// most likely situation was that server introduced a nick which we subsequently akilled
- if (u == NULL)
+ if (!u)
return MOD_CONT;
av[0] = u2->nick.c_str();
- do_umode(u->nick.c_str(), ac, av);
+ do_umode(u->nick, ac, av);
}
return MOD_CONT;
}
-int anope_event_opertype(const char *source, int ac, const char **av)
+int anope_event_opertype(const Anope::string &source, int ac, const char **av)
{
/* opertype is equivalent to mode +o because servers
dont do this directly */
@@ -401,7 +372,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
if (u && !is_oper(u))
{
const char *newav[2];
- newav[0] = source;
+ newav[0] = source.c_str();
newav[1] = "+o";
return anope_event_mode(source, 2, newav);
}
@@ -409,7 +380,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_fmode(const char *source, int ac, const char **av)
+int anope_event_fmode(const Anope::string &source, int ac, const char **av)
{
const char *newav[128];
int n, o;
@@ -422,10 +393,11 @@ int anope_event_fmode(const char *source, int ac, const char **av)
/* Checking the TS for validity to avoid desyncs */
if ((c = findchan(av[0])))
{
- if (c->creation_time > strtol(av[1], NULL, 10))
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
+ if (c->creation_time > ts)
/* Our TS is bigger, we should lower it */
- c->creation_time = strtol(av[1], NULL, 10);
- else if (c->creation_time < strtol(av[1], NULL, 10))
+ c->creation_time = ts;
+ else if (c->creation_time < ts)
/* The TS we got is bigger, we should ignore this message. */
return MOD_CONT;
}
@@ -457,10 +429,10 @@ int anope_event_fmode(const char *source, int ac, const char **av)
* 2: channel modes + params (NOTE: this may definitely be more than one param!)
* last: users
*/
-int anope_event_fjoin(const char *source, int ac, const char **av)
+int anope_event_fjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
- time_t ts = atol(av[1]);
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
bool was_created = false;
bool keep_their_modes = true;
@@ -519,11 +491,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
std::list<ChannelMode *> Status;
- Status.clear();
/* Loop through prefixes and find modes for them */
while (buf[0] != ',')
@@ -591,10 +562,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
/* Events */
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac == 1)
- ircdproto->SendPong(NULL, av[0]);
+ ircdproto->SendPong("", av[0]);
if (ac == 2)
ircdproto->SendPong(av[1], av[0]);
@@ -602,32 +573,32 @@ int anope_event_ping(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_time(const char *source, int ac, const char **av)
+int anope_event_time(const Anope::string &source, int ac, const char **av)
{
if (ac !=2)
return MOD_CONT;
- send_cmd(TS6SID, "TIME %s %s %ld", source, av[1], static_cast<long>(time(NULL)));
+ send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL)));
/* We handled it, don't pass it on to the core..
* The core doesn't understand our syntax anyways.. ~ Viper */
return MOD_STOP;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
m_nickcoll(av[0]);
return MOD_CONT;
}
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
- m_away(source, (ac ? av[0] : NULL));
+ m_away(source, ac ? av[0] : "");
return MOD_CONT;
}
/* Taken from hybrid.c, topic syntax is identical */
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
time_t topic_time = time(NULL);
@@ -642,13 +613,9 @@ int anope_event_topic(const char *source, int ac, const char **av)
if (check_topiclock(c, topic_time))
return MOD_CONT;
- if (c->topic)
- {
- delete [] c->topic;
- c->topic = NULL;
- }
+ c->topic.clear();
if (ac > 1 && *av[1])
- c->topic = sstrdup(av[1]);
+ c->topic = av[1];
c->topic_setter = u ? u->nick : source;
c->topic_time = topic_time;
@@ -667,13 +634,13 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
do_squit(source, ac, av);
return MOD_CONT;
}
-int anope_event_rsquit(const char *source, int ac, const char **av)
+int anope_event_rsquit(const Anope::string &source, int ac, const char **av)
{
/* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */
Server *s = Server::Find(av[0]);
@@ -685,39 +652,39 @@ int anope_event_rsquit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
do_quit(source, ac, av);
return MOD_CONT;
}
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
User *u = finduser(av[0]);
BotInfo *bi = findbot(av[0]);
- m_kill(u ? u->nick.c_str() : (bi ? bi->nick : av[0]), av[1]);
+ m_kill(u ? u->nick : (bi ? bi->nick : av[0]), av[1]);
return MOD_CONT;
}
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
do_kick(source, ac, av);
return MOD_CONT;
}
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
do_join(source, ac, av);
return MOD_CONT;
}
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
m_motd(source);
return MOD_CONT;
}
-int anope_event_setname(const char *source, int ac, const char **av)
+int anope_event_setname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -732,7 +699,7 @@ int anope_event_setname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgname(const char *source, int ac, const char **av)
+int anope_event_chgname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -747,7 +714,7 @@ int anope_event_chgname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_setident(const char *source, int ac, const char **av)
+int anope_event_setident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -762,7 +729,7 @@ int anope_event_setident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgident(const char *source, int ac, const char **av)
+int anope_event_chgident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -777,7 +744,7 @@ int anope_event_chgident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_sethost(const char *source, int ac, const char **av)
+int anope_event_sethost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -792,9 +759,9 @@ int anope_event_sethost(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
- do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", 0, 0, "", "");
return MOD_CONT;
}
@@ -812,20 +779,19 @@ int anope_event_nick(const char *source, int ac, const char **av)
* last: realname
*/
-int anope_event_uid(const char *source, int ac, const char **av)
+int anope_event_uid(const Anope::string &source, int ac, const char **av)
{
User *user;
NickAlias *na;
- struct in_addr addy;
- Server *s = Server::Find(source ? source : "");
- uint32 *ad = reinterpret_cast<uint32 *>(&addy);
+ Server *s = Server::Find(source);
int ts = strtoul(av[1], NULL, 10);
/* Check if the previously introduced user was Id'd for the nickgroup of the nick he s currently using.
* If not, validate the user. ~ Viper*/
user = prev_u_intro;
prev_u_intro = NULL;
- if (user) na = findnick(user->nick);
+ if (user)
+ na = findnick(user->nick);
if (user && !user->server->IsSynced() && (!na || na->nc != user->Account()))
{
validate_user(user);
@@ -834,15 +800,10 @@ int anope_event_uid(const char *source, int ac, const char **av)
}
user = NULL;
- inet_aton(av[6], &addy);
- user = do_nick("", av[2], /* nick */
- av[5], /* username */
- av[3], /* realhost */
- s->GetName().c_str(), /* server */
- av[ac - 1], /* realname */
- ts, htonl(*ad), av[4], av[0]);
+ user = do_nick("", av[2], av[5], av[3], s->GetName(), av[ac - 1], ts, 0, av[4], av[0]);
if (user)
{
+ user->host = av[6];
UserSetInternalModes(user, 1, &av[8]);
user->SetCloakedHost(av[4]);
if (!user->server->IsSynced())
@@ -854,7 +815,7 @@ int anope_event_uid(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chghost(const char *source, int ac, const char **av)
+int anope_event_chghost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -877,13 +838,13 @@ int anope_event_chghost(const char *source, int ac, const char **av)
* 3: numeric
* 4: desc
*/
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
- do_server(source, av[0], atoi(av[2]), av[4], av[3]);
+ do_server(source, av[0], Anope::string(av[2]).is_number_only() ? convertTo<unsigned>(av[2]) : 0, av[4], av[3]);
return MOD_CONT;
}
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
if (!finduser(source))
return MOD_CONT; // likely a message from a server, which can happen.
@@ -892,19 +853,19 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
do_part(source, ac, av);
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
m_whois(source, av[0]);
return MOD_CONT;
}
-int anope_event_metadata(const char *source, int ac, const char **av)
+int anope_event_metadata(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -913,16 +874,14 @@ int anope_event_metadata(const char *source, int ac, const char **av)
else if (!strcmp(av[1], "accountname"))
{
if ((u = finduser(av[0])))
- {
/* Identify the user for this account - Adam */
u->AutoID(av[2]);
- }
}
return MOD_CONT;
}
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
if (!strcasecmp(av[0], "START"))
{
@@ -954,17 +913,17 @@ int anope_event_capab(const char *source, int ac, const char **av)
else if (!strcasecmp(av[0], "CAPABILITIES"))
{
spacesepstream ssep(av[1]);
- std::string capab;
+ Anope::string capab;
while (ssep.GetToken(capab))
{
- if (capab.find("CHANMODES") != std::string::npos)
+ if (capab.find("CHANMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -982,7 +941,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '@'));
continue;
case 'a':
- ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT , "CMODE_PROTECT", 'a', '@'));
+ ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT , "CMODE_PROTECT", 'a', '@'));
continue;
// XXX list modes needs a bit of a rewrite, we need to be able to support +g here
default:
@@ -991,7 +950,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -1004,7 +963,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -1032,7 +991,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -1113,15 +1072,15 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
}
}
- else if (capab.find("USERMODES") != std::string::npos)
+ else if (capab.find("USERMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
while (sep.GetToken(modebuf))
{
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -1185,12 +1144,12 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
}
}
- else if (capab.find("PREFIX=(") != std::string::npos)
+ else if (capab.find("PREFIX=(") != Anope::string::npos)
{
- std::string modes(capab.begin() + 8, capab.begin() + capab.find(")"));
- std::string chars(capab.begin() + capab.find(")") + 1, capab.end());
+ Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')'));
+ Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end());
- for (size_t t = 0, end = modes.size(); t < end; ++t)
+ for (size_t t = 0, end = modes.length(); t < end; ++t)
{
switch (modes[t])
{
@@ -1212,10 +1171,10 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
}
}
- else if (capab.find("MAXMODES=") != std::string::npos)
+ else if (capab.find("MAXMODES=") != Anope::string::npos)
{
- std::string maxmodes(capab.begin() + 9, capab.end());
- ircd->maxmodes = atoi(maxmodes.c_str());
+ Anope::string maxmodes(capab.begin() + 9, capab.end());
+ ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3;
}
}
}
@@ -1223,21 +1182,21 @@ int anope_event_capab(const char *source, int ac, const char **av)
{
if (!has_globopsmod)
{
- send_cmd(NULL, "ERROR :m_globops is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope");
quitmsg = "Remote server does not have the m_globops module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
}
if (!has_servicesmod)
{
- send_cmd(NULL, "ERROR :m_services_account.so is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
}
if (!has_hidechansmod)
{
- send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
@@ -1256,11 +1215,11 @@ int anope_event_capab(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_endburst(const char *source, int ac, const char **av)
+int anope_event_endburst(const Anope::string &source, int ac, const char **av)
{
NickAlias *na;
User *u = prev_u_intro;
- Server *s = Server::Find(source ? source : "");
+ Server *s = Server::Find(source);
if (!s)
throw new CoreException("Got ENDBURST without a source");
@@ -1321,30 +1280,31 @@ void moduleAddIRCDMsgs()
Anope::AddMessage("METADATA", anope_event_metadata);
}
-bool ChannelModeFlood::IsValid(const std::string &value)
+bool ChannelModeFlood::IsValid(const Anope::string &value)
{
- char *dp, *end;
- if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end)
- return 1;
- else return 0;
+ Anope::string rest;
+ if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
+ return true;
+ else
+ return false;
}
class ProtoInspIRCd : public Module
{
public:
- ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
- if (Config.Numeric)
- TS6SID = sstrdup(Config.Numeric);
+ if (!Config.Numeric.empty())
+ TS6SID = Config.Numeric;
pmodule_ircd_version("InspIRCd 1.2");
pmodule_ircd_var(myIrcd);
pmodule_ircd_useTSMode(0);
- CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT };
+ CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT };
for (unsigned i = 0; i < 5; ++i)
Capab.SetFlag(c[i]);
@@ -1354,12 +1314,7 @@ class ProtoInspIRCd : public Module
ModuleManager::Attach(I_OnUserNickChange, this);
}
- ~ProtoInspIRCd()
- {
- delete [] TS6SID;
- }
-
- void OnUserNickChange(User *u, const std::string &)
+ void OnUserNickChange(User *u, const Anope::string &)
{
/* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later
* this will cancel out this -r, resulting in no mode changes.
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index f8ef3ee5c..8c3f14e67 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -15,22 +15,6 @@
#include "modules.h"
#include "hashcomp.h"
-#ifndef _WIN32
-# include <sys/socket.h>
-# include <netinet/in.h>
-# include <arpa/inet.h>
-#endif
-
-#ifdef _WIN32
-# include <winsock.h>
-int inet_aton(const char *name, struct in_addr *addr)
-{
- uint32 a = inet_addr(name);
- addr->s_addr = a;
- return a != (uint32) - 1;
-}
-#endif
-
IRCDVar myIrcd[] = {
{"InspIRCd 2.0", /* ircd name */
"+I", /* Modes used by pseudoclients */
@@ -60,7 +44,6 @@ IRCDVar myIrcd[] = {
0, /* Change RealName */
1, /* No Knock requires +i */
0, /* We support inspircd TOKENS */
- 0, /* TIME STAMPS are BASE64 */
0, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
1, /* ts6 */
@@ -82,7 +65,7 @@ static bool has_chgidentmod = false;
static User *prev_u_intro = NULL;
/* CHGHOST */
-void inspircd_cmd_chghost(const char *nick, const char *vhost)
+void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
if (!has_chghostmod)
{
@@ -90,50 +73,48 @@ void inspircd_cmd_chghost(const char *nick, const char *vhost)
return;
}
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "CHGHOST %s %s", nick, vhost);
+ send_cmd(OperServ->GetUID(), "CHGHOST %s %s", nick.c_str(), vhost.c_str());
}
-int anope_event_idle(const char *source, int ac, const char **av)
+int anope_event_idle(const Anope::string &source, int ac, const char **av)
{
BotInfo *bi = findbot(av[0]);
if (!bi)
return MOD_CONT;
- send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source, static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg));
+ send_cmd(bi->GetUID(), "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), static_cast<long>(time(NULL) - bi->lastmsg));
return MOD_CONT;
}
-static char currentpass[1024];
+static Anope::string currentpass;
/* PASS */
-void inspircd_cmd_pass(const char *pass)
+void inspircd_cmd_pass(const Anope::string &pass)
{
- strlcpy(currentpass, pass, sizeof(currentpass));
+ currentpass = pass;
}
class InspIRCdProto : public IRCDProto
{
void SendAkillDel(XLine *x)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "GLINE %s", x->Mask.c_str());
+ send_cmd(OperServ->GetUID(), "GLINE %s", x->Mask.c_str());
}
- void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic)
{
- send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit, topic);
+ send_cmd(whosets->GetUID(), "FTOPIC %s %lu %s :%s", c->name.c_str(), static_cast<unsigned long>(c->topic_time), whosetit.c_str(), topic.c_str());
}
void SendVhostDel(User *u)
{
if (u->HasMode(UMODE_CLOAK))
- inspircd_cmd_chghost(u->nick.c_str(), u->chost.c_str());
+ inspircd_cmd_chghost(u->nick, u->chost);
else
- inspircd_cmd_chghost(u->nick.c_str(), u->host);
+ inspircd_cmd_chghost(u->nick, u->host);
if (has_chgidentmod && u->GetIdent() != u->GetVIdent())
- inspircd_cmd_chgident(u->nick.c_str(), u->GetIdent().c_str());
+ inspircd_cmd_chgident(u->nick, u->GetIdent());
}
void SendAkill(XLine *x)
@@ -142,13 +123,12 @@ class InspIRCdProto : public IRCDProto
time_t timeleft = x->Expires - time(NULL);
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str());
+ send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str());
}
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str());
}
void SendSVSMode(User *u, int ac, const char **av)
@@ -156,56 +136,51 @@ class InspIRCdProto : public IRCDProto
this->SendModeInternal(NULL, u, merge_args(ac, av));
}
- void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf)
- {
- send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest, source, numeric, dest, buf);
- }
-
- void SendGuestNick(const char *nick, const char *user, const char *host, const char *real, const char *modes)
+ void SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf)
{
- send_cmd(TS6SID, "UID %ld %s %s %s %s +%s 0.0.0.0 :%s", static_cast<long>(time(NULL)), nick, host, host, user, modes, real);
+ send_cmd(TS6SID, "PUSH %s ::%s %03d %s %s", dest.c_str(), source.c_str(), numeric, dest.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "FMODE %s %u %s", dest->name.c_str(), static_cast<unsigned>(dest->creation_time), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf);
+ send_cmd(bi ? bi->GetUID() : TS6SID, "MODE %s %s", u->GetUID().c_str(), buf.c_str());
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid)
{
- send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes, real.c_str());
+ send_cmd(TS6SID, "UID %s %ld %s %s %s %s 0.0.0.0 %ld %s :%s", uid.c_str(), static_cast<long>(time(NULL)), nick.c_str(), host.c_str(), host.c_str(), user.c_str(), static_cast<long>(time(NULL)), modes.c_str(), real.c_str());
}
- void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf);
+ if (!buf.empty())
+ send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str());
else
send_cmd(source->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), user->nick.c_str());
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf);
+ send_cmd(TS6SID, "NOTICE @%s :%s", dest->name.c_str(), buf.c_str());
}
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(Server *server)
{
- send_cmd(NULL, "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass, server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str());
+ send_cmd("", "SERVER %s %s %d %s :%s", server->GetName().c_str(), currentpass.c_str(), server->GetHops(), server->GetSID().c_str(), server->GetDescription().c_str());
}
/* JOIN */
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel, static_cast<long>(chantime), user->GetUID().c_str());
+ send_cmd(TS6SID, "FJOIN %s %ld + :,%s", channel.c_str(), static_cast<long>(chantime), user->GetUID().c_str());
}
/* UNSQLINE */
@@ -217,60 +192,55 @@ class InspIRCdProto : public IRCDProto
/* SQLINE */
void SendSQLine(XLine *x)
{
- send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ, static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config.s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/* SQUIT */
- void SendSquit(const char *servname, const char *message)
+ void SendSquit(const Anope::string &servname, const Anope::string &message)
{
- send_cmd(TS6SID, "SQUIT %s :%s", servname, message);
+ send_cmd(TS6SID, "SQUIT %s :%s", servname.c_str(), message.c_str());
}
/* Functions that use serval cmd functions */
- void SendVhost(User *u, const std::string &vIdent, const std::string &vhost)
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost)
{
if (!vIdent.empty())
- inspircd_cmd_chgident(u->nick.c_str(), vIdent.c_str());
+ inspircd_cmd_chgident(u->nick, vIdent);
if (!vhost.empty())
- inspircd_cmd_chghost(u->nick.c_str(), vhost.c_str());
+ inspircd_cmd_chghost(u->nick, vhost);
}
void SendConnect()
{
- send_cmd(NULL, "CAPAB START 1202");
- send_cmd(NULL, "CAPAB CAPABILITIES :PROTOCOL=1202");
- send_cmd(NULL, "CAPAB END");
+ send_cmd("", "CAPAB START 1202");
+ send_cmd("", "CAPAB CAPABILITIES :PROTOCOL=1202");
+ send_cmd("", "CAPAB END");
inspircd_cmd_pass(uplink_server->password);
SendServer(Me);
send_cmd(TS6SID, "BURST");
- send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName, ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
+ send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config.ServerName.c_str(), ircd->name, Config.EncModuleList.begin()->c_str(), Anope::Build().c_str());
}
/* CHGIDENT */
- void inspircd_cmd_chgident(const char *nick, const char *vIdent)
+ void inspircd_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent)
{
if (!has_chgidentmod)
ircdproto->SendGlobops(OperServ, "CHGIDENT not loaded!");
else
- {
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "CHGIDENT %s %s", nick, vIdent);
- }
+ send_cmd(OperServ->GetUID(), "CHGIDENT %s %s", nick.c_str(), vIdent.c_str());
}
/* SVSHOLD - set */
- void SendSVSHold(const char *nick)
+ void SendSVSHold(const Anope::string &nick)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "SVSHOLD %s %u :%s", nick, static_cast<unsigned>(Config.NSReleaseTimeout), "Being held for registered user");
+ send_cmd(OperServ->GetUID(), "SVSHOLD %s %u :Being held for registered user", nick.c_str(), static_cast<unsigned>(Config.NSReleaseTimeout));
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const char *nick)
+ void SendSVSHoldDel(const Anope::string &nick)
{
- BotInfo *bi = OperServ;
- send_cmd(bi->GetUID(), "SVSHOLD %s", nick);
+ send_cmd(OperServ->GetUID(), "SVSHOLD %s", nick.c_str());
}
/* UNSZLINE */
@@ -291,25 +261,25 @@ class InspIRCdProto : public IRCDProto
u->RemoveMode(NickServ, UMODE_REGISTERED);
}
- void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param)
+ void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &)
{
User *u = finduser(nick);
BotInfo *bi = findbot(source);
- send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan);
+ send_cmd(bi->GetUID(), "SVSJOIN %s %s", u->GetUID().c_str(), chan.c_str());
}
- void SendSVSPart(const char *source, const char *nick, const char *chan)
+ void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan)
{
User *u = finduser(nick);
BotInfo *bi = findbot(source);
- send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan);
+ send_cmd(bi->GetUID(), "SVSPART %s %s", u->GetUID().c_str(), chan.c_str());
}
- void SendSWhois(const char *source, const char *who, const char *mask)
+ void SendSWhois(const Anope::string &, const Anope::string &who, const Anope::string &mask)
{
User *u = finduser(who);
- send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask);
+ send_cmd(TS6SID, "METADATA %s swhois :%s", u->GetUID().c_str(), mask.c_str());
}
void SendEOB()
@@ -317,27 +287,28 @@ class InspIRCdProto : public IRCDProto
send_cmd(TS6SID, "ENDBURST");
}
- void SendGlobopsInternal(BotInfo *source, const char *buf)
+ void SendGlobopsInternal(BotInfo *source, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "SNONOTICE g :%s", buf.c_str());
}
- void SendAccountLogin(User *u, NickCore *account)
+ void SendAccountLogin(User *u, const NickCore *account)
{
- send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display);
+ send_cmd(TS6SID, "METADATA %s accountname :%s", u->GetUID().c_str(), account->display.c_str());
}
- void SendAccountLogout(User *u, NickCore *account)
+ void SendAccountLogout(User *u, const NickCore *account)
{
send_cmd(TS6SID, "METADATA %s accountname :", u->GetUID().c_str());
}
- int IsNickValid(const char *nick)
+ bool IsNickValid(const Anope::string &nick)
{
/* InspIRCd, like TS6, uses UIDs on collision, so... */
- if (isdigit(*nick))
- return 0;
- return 1;
+ if (isdigit(nick[0]))
+ return false;
+
+ return true;
}
void SetAutoIdentificationToken(User *u)
@@ -349,7 +320,7 @@ class InspIRCdProto : public IRCDProto
}
} ircd_proto;
-int anope_event_ftopic(const char *source, int ac, const char **av)
+int anope_event_ftopic(const Anope::string &source, int ac, const char **av)
{
/* :source FTOPIC channel ts setby :topic */
const char *temp;
@@ -362,7 +333,7 @@ int anope_event_ftopic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
if (*av[0] == '#' || *av[0] == '&')
do_cmode(source, ac, av);
@@ -381,16 +352,16 @@ int anope_event_mode(const char *source, int ac, const char **av)
// if it's still null, drop it like fire.
// most likely situation was that server introduced a nick which we subsequently akilled
- if (u == NULL)
+ if (!u)
return MOD_CONT;
av[0] = u2->nick.c_str();
- do_umode(u->nick.c_str(), ac, av);
+ do_umode(u->nick, ac, av);
}
return MOD_CONT;
}
-int anope_event_opertype(const char *source, int ac, const char **av)
+int anope_event_opertype(const Anope::string &source, int ac, const char **av)
{
/* opertype is equivalent to mode +o because servers
dont do this directly */
@@ -399,7 +370,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
if (u && !is_oper(u))
{
const char *newav[2];
- newav[0] = source;
+ newav[0] = source.c_str();
newav[1] = "+o";
return anope_event_mode(source, 2, newav);
}
@@ -407,7 +378,7 @@ int anope_event_opertype(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_fmode(const char *source, int ac, const char **av)
+int anope_event_fmode(const Anope::string &source, int ac, const char **av)
{
const char *newav[128];
int n, o;
@@ -420,10 +391,11 @@ int anope_event_fmode(const char *source, int ac, const char **av)
/* Checking the TS for validity to avoid desyncs */
if ((c = findchan(av[0])))
{
- if (c->creation_time > strtol(av[1], NULL, 10))
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
+ if (c->creation_time > ts)
/* Our TS is bigger, we should lower it */
- c->creation_time = strtol(av[1], NULL, 10);
- else if (c->creation_time < strtol(av[1], NULL, 10))
+ c->creation_time = ts;
+ else if (c->creation_time < ts)
/* The TS we got is bigger, we should ignore this message. */
return MOD_CONT;
}
@@ -455,10 +427,10 @@ int anope_event_fmode(const char *source, int ac, const char **av)
* 2: channel modes + params (NOTE: this may definitely be more than one param!)
* last: users
*/
-int anope_event_fjoin(const char *source, int ac, const char **av)
+int anope_event_fjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
- time_t ts = atol(av[1]);
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
bool was_created = false;
bool keep_their_modes = true;
@@ -517,11 +489,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
std::list<ChannelMode *> Status;
- Status.clear();
/* Loop through prefixes and find modes for them */
while (buf[0] != ',')
@@ -589,10 +560,10 @@ int anope_event_fjoin(const char *source, int ac, const char **av)
}
/* Events */
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac == 1)
- ircdproto->SendPong(NULL, av[0]);
+ ircdproto->SendPong("", av[0]);
if (ac == 2)
ircdproto->SendPong(av[1], av[0]);
@@ -600,32 +571,32 @@ int anope_event_ping(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_time(const char *source, int ac, const char **av)
+int anope_event_time(const Anope::string &source, int ac, const char **av)
{
if (ac !=2)
return MOD_CONT;
- send_cmd(TS6SID, "TIME %s %s %ld", source, av[1], static_cast<long>(time(NULL)));
+ send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL)));
/* We handled it, don't pass it on to the core..
* The core doesn't understand our syntax anyways.. ~ Viper */
return MOD_STOP;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
m_nickcoll(av[0]);
return MOD_CONT;
}
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
- m_away(source, (ac ? av[0] : NULL));
+ m_away(source, ac ? av[0] : "");
return MOD_CONT;
}
/* Taken from hybrid.c, topic syntax is identical */
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[0]);
time_t topic_time = time(NULL);
@@ -640,13 +611,9 @@ int anope_event_topic(const char *source, int ac, const char **av)
if (check_topiclock(c, topic_time))
return MOD_CONT;
- if (c->topic)
- {
- delete [] c->topic;
- c->topic = NULL;
- }
+ c->topic.clear();
if (ac > 1 && *av[1])
- c->topic = sstrdup(av[1]);
+ c->topic = av[1];
c->topic_setter = u ? u->nick : source;
c->topic_time = topic_time;
@@ -665,13 +632,13 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
do_squit(source, ac, av);
return MOD_CONT;
}
-int anope_event_rsquit(const char *source, int ac, const char **av)
+int anope_event_rsquit(const Anope::string &source, int ac, const char **av)
{
/* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */
Server *s = Server::Find(av[0]);
@@ -683,39 +650,39 @@ int anope_event_rsquit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
do_quit(source, ac, av);
return MOD_CONT;
}
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
User *u = finduser(av[0]);
BotInfo *bi = findbot(av[0]);
- m_kill(u ? u->nick.c_str() : (bi ? bi->nick : av[0]), av[1]);
+ m_kill(u ? u->nick : (bi ? bi->nick : av[0]), av[1]);
return MOD_CONT;
}
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
do_kick(source, ac, av);
return MOD_CONT;
}
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
do_join(source, ac, av);
return MOD_CONT;
}
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
m_motd(source);
return MOD_CONT;
}
-int anope_event_setname(const char *source, int ac, const char **av)
+int anope_event_setname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -730,7 +697,7 @@ int anope_event_setname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgname(const char *source, int ac, const char **av)
+int anope_event_chgname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -745,7 +712,7 @@ int anope_event_chgname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_setident(const char *source, int ac, const char **av)
+int anope_event_setident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -760,7 +727,7 @@ int anope_event_setident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgident(const char *source, int ac, const char **av)
+int anope_event_chgident(const Anope::string &source, int ac, const char **av)
{
User *u = finduser(source);
@@ -774,7 +741,7 @@ int anope_event_chgident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_sethost(const char *source, int ac, const char **av)
+int anope_event_sethost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -789,9 +756,9 @@ int anope_event_sethost(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
- do_nick(source, av[0], NULL, NULL, NULL, NULL, 0, 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", 0, 0, "", "");
return MOD_CONT;
}
@@ -809,14 +776,12 @@ int anope_event_nick(const char *source, int ac, const char **av)
* last: realname
*/
-int anope_event_uid(const char *source, int ac, const char **av)
+int anope_event_uid(const Anope::string &source, int ac, const char **av)
{
User *user;
NickAlias *na;
- struct in_addr addy;
- Server *s = Server::Find(source ? source : "");
- uint32 *ad = reinterpret_cast<uint32 *>(&addy);
- int ts = strtoul(av[1], NULL, 10);
+ Server *s = Server::Find(source);
+ time_t ts = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
/* Check if the previously introduced user was Id'd for the nickgroup of the nick he s currently using.
* If not, validate the user. ~ Viper*/
@@ -832,15 +797,10 @@ int anope_event_uid(const char *source, int ac, const char **av)
}
user = NULL;
- inet_aton(av[6], &addy);
- user = do_nick("", av[2], /* nick */
- av[5], /* username */
- av[3], /* realhost */
- s->GetName().c_str(), /* server */
- av[ac - 1], /* realname */
- ts, htonl(*ad), av[4], av[0]);
+ user = do_nick("", av[2], av[5], av[3], s->GetName(), av[ac - 1], ts, 0, av[4], av[0]);
if (user)
{
+ user->hostip = av[6];
UserSetInternalModes(user, 1, &av[8]);
user->SetCloakedHost(av[4]);
if (!user->server->IsSynced())
@@ -852,7 +812,7 @@ int anope_event_uid(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chghost(const char *source, int ac, const char **av)
+int anope_event_chghost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -875,13 +835,13 @@ int anope_event_chghost(const char *source, int ac, const char **av)
* 3: numeric
* 4: desc
*/
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
- do_server(source, av[0], atoi(av[2]), av[4], av[3]);
+ do_server(source, av[0], Anope::string(av[2]).is_number_only() ? convertTo<unsigned>(av[2]) : 0, av[4], av[3]);
return MOD_CONT;
}
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
if (!finduser(source))
return MOD_CONT; // likely a message from a server, which can happen.
@@ -890,19 +850,19 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
do_part(source, ac, av);
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
m_whois(source, av[0]);
return MOD_CONT;
}
-int anope_event_metadata(const char *source, int ac, const char **av)
+int anope_event_metadata(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -911,22 +871,20 @@ int anope_event_metadata(const char *source, int ac, const char **av)
else if (!strcmp(av[1], "accountname"))
{
if ((u = finduser(av[0])))
- {
/* Identify the user for this account - Adam */
u->AutoID(av[2]);
- }
}
return MOD_CONT;
}
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
if (!strcasecmp(av[0], "START"))
{
- if (ac < 2 || atoi(av[1]) < 1202)
+ if (ac < 2 || (Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]): 0) < 1202)
{
- send_cmd(NULL, "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START");
+ send_cmd("", "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START");
quitmsg = "Protocol mismatch, no or invalid protocol version given in CAPAB START";
quitting = 1;
return MOD_STOP;
@@ -941,103 +899,103 @@ int anope_event_capab(const char *source, int ac, const char **av)
else if (!strcasecmp(av[0], "CHANMODES"))
{
spacesepstream ssep(av[1]);
- std::string capab;
+ Anope::string capab;
while (ssep.GetToken(capab))
{
- std::string modename = capab.substr(0, capab.find('='));
- std::string modechar = capab.substr(capab.find('=') + 1);
+ Anope::string modename = capab.substr(0, capab.find('='));
+ Anope::string modechar = capab.substr(capab.find('=') + 1);
ChannelMode *cm = NULL;
- if (modename == "admin")
+ if (modename.equals_cs("admin"))
cm = new ChannelModeStatus(CMODE_PROTECT, "CMODE_PROTECT", modechar[1], modechar[0]);
- else if (modename == "allowinvite")
+ else if (modename.equals_cs("allowinvite"))
cm = new ChannelMode(CMODE_ALLINVITE, "CMODE_ALLINVITE", modechar[0]);
- else if (modename == "auditorium")
+ else if (modename.equals_cs("auditorium"))
cm = new ChannelMode(CMODE_AUDITORIUM, "CMODE_AUDITORIUM", modechar[0]);
- else if (modename == "autoop")
+ else if (modename.equals_cs("autoop"))
continue; // XXX Not currently tracked
- else if (modename == "ban")
+ else if (modename.equals_cs("ban"))
cm = new ChannelModeBan(modechar[0]);
- else if (modename == "banexception")
+ else if (modename.equals_cs("banexception"))
cm = new ChannelModeExcept(modechar[0]);
- else if (modename == "blockcaps")
+ else if (modename.equals_cs("blockcaps"))
cm = new ChannelMode(CMODE_BLOCKCAPS, "CMODE_BLOCKCAPS", modechar[0]);
- else if (modename == "blockcolor")
+ else if (modename.equals_cs("blockcolor"))
cm = new ChannelMode(CMODE_BLOCKCOLOR, "CMODE_BLOCKCOLOR", modechar[0]);
- else if (modename == "c_registered")
+ else if (modename.equals_cs("c_registered"))
cm = new ChannelModeRegistered(modechar[0]);
- else if (modename == "censor")
+ else if (modename.equals_cs("censor"))
cm = new ChannelMode(CMODE_FILTER, "CMODE_FILTER", modechar[0]);
- else if (modename == "delayjoin")
+ else if (modename.equals_cs("delayjoin"))
cm = new ChannelMode(CMODE_DELAYEDJOIN, "CMODE_DELAYEDJOIN", modechar[0]);
- else if (modename == "delaymsg")
+ else if (modename.equals_cs("delaymsg"))
continue;
- else if (modename == "exemptchanops")
+ else if (modename.equals_cs("exemptchanops"))
continue; // XXX
- else if (modename == "filter")
+ else if (modename.equals_cs("filter"))
continue; // XXX
- else if (modename == "flood")
+ else if (modename.equals_cs("flood"))
cm = new ChannelModeFlood(modechar[0], true);
- else if (modename == "founder")
+ else if (modename.equals_cs("founder"))
cm = new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", modechar[1], modechar[0]);
- else if (modename == "halfop")
+ else if (modename.equals_cs("halfop"))
cm = new ChannelModeStatus(CMODE_HALFOP, "CMODE_HALFOP", modechar[1], modechar[0]);
- else if (modename == "history")
+ else if (modename.equals_cs("history"))
continue; // XXX
- else if (modename == "invex")
+ else if (modename.equals_cs("invex"))
cm = new ChannelModeInvex(modechar[0]);
- else if (modename == "inviteonly")
+ else if (modename.equals_cs("inviteonly"))
cm = new ChannelMode(CMODE_INVITE, "CMODE_INVITE", modechar[0]);
- else if (modename == "joinflood")
+ else if (modename.equals_cs("joinflood"))
cm = new ChannelModeParam(CMODE_JOINFLOOD, "CMODE_JOINFLOOD", modechar[0], true);
- else if (modename == "key")
+ else if (modename.equals_cs("key"))
cm = new ChannelModeKey(modechar[0]);
- else if (modename == "kicknorejoin")
+ else if (modename.equals_cs("kicknorejoin"))
cm = new ChannelModeParam(CMODE_NOREJOIN, "CMODE_NOREJOIN", modechar[0], true);
- else if (modename == "limit")
+ else if (modename.equals_cs("limit"))
cm = new ChannelModeParam(CMODE_LIMIT, "CMODE_LIMIT", modechar[0], true);
- else if (modename == "moderated")
+ else if (modename.equals_cs("moderated"))
cm = new ChannelMode(CMODE_MODERATED, "CMODE_MODERATED", modechar[0]);
- else if (modename == "namebase")
+ else if (modename.equals_cs("namebase"))
continue; // XXX
- else if (modename == "nickflood")
+ else if (modename.equals_cs("nickflood"))
cm = new ChannelModeParam(CMODE_NICKFLOOD, "CMODE_NICKFLOOD", modechar[0], true);
- else if (modename == "noctcp")
+ else if (modename.equals_cs("noctcp"))
cm = new ChannelMode(CMODE_NOCTCP, "CMODE_NOCTCP", modechar[0]);
- else if (modename == "noextmsg")
+ else if (modename.equals_cs("noextmsg"))
cm = new ChannelMode(CMODE_NOEXTERNAL, "CMODE_NOEXTERNAL", modechar[0]);
- else if (modename == "nokick")
+ else if (modename.equals_cs("nokick"))
cm = new ChannelMode(CMODE_NOKICK, "CMODE_NOKICK", modechar[0]);
- else if (modename == "noknock")
+ else if (modename.equals_cs("noknock"))
cm = new ChannelMode(CMODE_NOKNOCK, "CMODE_NOKNOCK", modechar[0]);
- else if (modename == "nonick")
+ else if (modename.equals_cs("nonick"))
cm = new ChannelMode(CMODE_NONICK, "CMODE_NONICK", modechar[0]);
- else if (modename == "nonotice")
+ else if (modename.equals_cs("nonotice"))
cm = new ChannelMode(CMODE_NONOTICE, "CMODE_NONOTICE", modechar[0]);
- else if (modename == "op")
+ else if (modename.equals_cs("op"))
cm = new ChannelModeStatus(CMODE_OP, "CMODE_OP", modechar[1], modechar[0]);
- else if (modename == "operonly")
+ else if (modename.equals_cs("operonly"))
cm = new ChannelModeOper(modechar[0]);
- else if (modename == "permanent")
+ else if (modename.equals_cs("permanent"))
cm = new ChannelMode(CMODE_PERM, "CMODE_PERM", modechar[0]);
- else if (modename == "private")
+ else if (modename.equals_cs("private"))
cm = new ChannelMode(CMODE_PRIVATE, "CMODE_PRIVATE", modechar[0]);
- else if (modename == "redirect")
+ else if (modename.equals_cs("redirect"))
cm = new ChannelModeParam(CMODE_REDIRECT, "CMODE_REDIRECT", modechar[0], true);
- else if (modename == "reginvite")
+ else if (modename.equals_cs("reginvite"))
cm = new ChannelMode(CMODE_REGISTEREDONLY, "CMODE_REGISTEREDONLY", modechar[0]);
- else if (modename == "regmoderated")
+ else if (modename.equals_cs("regmoderated"))
cm = new ChannelMode(CMODE_REGMODERATED, "CMODE_REGMODERATED", modechar[0]);
- else if (modename == "secret")
+ else if (modename.equals_cs("secret"))
cm = new ChannelMode(CMODE_SECRET, "CMODE_SECRET", modechar[0]);
- else if (modename == "sslonly")
+ else if (modename.equals_cs("sslonly"))
cm = new ChannelMode(CMODE_SSL, "CMODE_SSL", modechar[0]);
- else if (modename == "stripcolor")
+ else if (modename.equals_cs("stripcolor"))
cm = new ChannelMode(CMODE_STRIPCOLOR, "CMODE_STRIPCOLOR", modechar[0]);
- else if (modename == "topiclock")
+ else if (modename.equals_cs("topiclock"))
cm = new ChannelMode(CMODE_TOPIC, "CMODE_TOPIC", modechar[0]);
- else if (modename == "voice")
+ else if (modename.equals_cs("voice"))
cm = new ChannelModeStatus(CMODE_VOICE, "CMODE_VOICE", modechar[1], modechar[0]);
/* Unknown status mode, (customprefix) - add it */
else if (modechar.length() == 2)
@@ -1052,49 +1010,49 @@ int anope_event_capab(const char *source, int ac, const char **av)
else if (!strcasecmp(av[0], "USERMODES"))
{
spacesepstream ssep(av[1]);
- std::string capab;
+ Anope::string capab;
while (ssep.GetToken(capab))
{
- std::string modename = capab.substr(0, capab.find('='));
- std::string modechar = capab.substr(capab.find('=') + 1);
+ Anope::string modename = capab.substr(0, capab.find('='));
+ Anope::string modechar = capab.substr(capab.find('=') + 1);
UserMode *um = NULL;
- if (modename == "bot")
+ if (modename.equals_cs("bot"))
um = new UserMode(UMODE_BOT, "UMODE_BOT", modechar[0]);
- else if (modename == "callerid")
+ else if (modename.equals_cs("callerid"))
um = new UserMode(UMODE_CALLERID, "UMODE_CALLERID", modechar[0]);
- else if (modename == "cloak")
+ else if (modename.equals_cs("cloak"))
um = new UserMode(UMODE_CLOAK, "UMODE_CLOAK", modechar[0]);
- else if (modename == "deaf")
+ else if (modename.equals_cs("deaf"))
um = new UserMode(UMODE_DEAF, "UMODE_DEAF", modechar[0]);
- else if (modename == "deaf_commonchan")
+ else if (modename.equals_cs("deaf_commonchan"))
um = new UserMode(UMODE_COMMONCHANS, "UMODE_COMMONCHANS", modechar[0]);
- else if (modename == "helpop")
+ else if (modename.equals_cs("helpop"))
um = new UserMode(UMODE_HELPOP, "UMODE_HELPOP", modechar[0]);
- else if (modename == "hidechans")
+ else if (modename.equals_cs("hidechans"))
um = new UserMode(UMODE_PRIV, "UMODE_PRIV", modechar[0]);
- else if (modename == "hideoper")
+ else if (modename.equals_cs("hideoper"))
um = new UserMode(UMODE_HIDEOPER, "UMODE_HIDEOPER", modechar[0]);
- else if (modename == "invisible")
+ else if (modename.equals_cs("invisible"))
um = new UserMode(UMODE_INVIS, "UMODE_INVIS", modechar[0]);
- else if (modename == "oper")
+ else if (modename.equals_cs("oper"))
um = new UserMode(UMODE_OPER, "UMODE_OPER", modechar[0]);
- else if (modename == "regdeaf")
+ else if (modename.equals_cs("regdeaf"))
um = new UserMode(UMODE_REGPRIV, "UMODE_REGPRIV", modechar[0]);
- else if (modename == "servprotect")
+ else if (modename.equals_cs("servprotect"))
um = new UserMode(UMODE_PROTECTED, "UMODE_PROTECTED", modechar[0]);
- else if (modename == "showwhois")
+ else if (modename.equals_cs("showwhois"))
um = new UserMode(UMODE_WHOIS, "UMODE_WHOIS", modechar[0]);
- else if (modename == "snomask")
+ else if (modename.equals_cs("snomask"))
continue; // XXX
- else if (modename == "u_censor")
+ else if (modename.equals_cs("u_censor"))
um = new UserMode(UMODE_FILTER, "UMODE_FILTER", modechar[0]);
- else if (modename == "u_registered")
+ else if (modename.equals_cs("u_registered"))
um = new UserMode(UMODE_REGISTERED, "UMODE_REGISTERED", modechar[0]);
- else if (modename == "u_stripcolor")
+ else if (modename.equals_cs("u_stripcolor"))
um = new UserMode(UMODE_STRIPCOLOR, "UMODE_STRIPCOLOR", modechar[0]);
- else if (modename == "wallops")
+ else if (modename.equals_cs("wallops"))
um = new UserMode(UMODE_WALLOPS, "UMODE_WALLOPS", modechar[0]);
if (um)
@@ -1106,43 +1064,43 @@ int anope_event_capab(const char *source, int ac, const char **av)
else if (!strcasecmp(av[0], "MODULES"))
{
spacesepstream ssep(av[1]);
- std::string module;
+ Anope::string module;
while (ssep.GetToken(module))
- if (module == "m_svshold.so")
+ if (module.equals_cs("m_svshold.so"))
has_svsholdmod = true;
}
else if (!strcasecmp(av[0], "MODSUPPORT"))
{
spacesepstream ssep(av[1]);
- std::string module;
+ Anope::string module;
while (ssep.GetToken(module))
{
- if (module == "m_services_account.so")
+ if (module.equals_cs("m_services_account.so"))
has_servicesmod = true;
- else if (module == "m_chghost.so")
+ else if (module.equals_cs("m_chghost.so"))
has_chghostmod = true;
- else if (module == "m_chgident.so")
+ else if (module.equals_cs("m_chgident.so"))
has_chgidentmod = true;
- else if (module == "m_servprotect.so")
+ else if (module.equals_cs("m_servprotect.so"))
ircd->pseudoclient_mode = "+Ik";
}
}
else if (!strcasecmp(av[0], "CAPABILITIES"))
{
spacesepstream ssep(av[1]);
- std::string capab;
+ Anope::string capab;
while (ssep.GetToken(capab))
{
- if (capab.find("CHANMODES") != std::string::npos)
+ if (capab.find("CHANMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
@@ -1151,7 +1109,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
@@ -1159,7 +1117,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
@@ -1167,42 +1125,34 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
- if (ModeManager::FindChannelModeByChar(modebuf[t]));
+ if (ModeManager::FindChannelModeByChar(modebuf[t]))
continue;
ModeManager::AddChannelMode(new ChannelMode(CMODE_END, "", modebuf[t]));
}
}
- else if (capab.find("USERMODES") != std::string::npos)
+ else if (capab.find("USERMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
sep.GetToken(modebuf);
sep.GetToken(modebuf);
if (sep.GetToken(modebuf))
- {
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
- {
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
ModeManager::AddUserMode(new UserModeParam(UMODE_END, "", modebuf[t]));
- }
- }
if (sep.GetToken(modebuf))
- {
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
- {
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
ModeManager::AddUserMode(new UserMode(UMODE_END, "", modebuf[t]));
- }
- }
}
- else if (capab.find("MAXMODES=") != std::string::npos)
+ else if (capab.find("MAXMODES=") != Anope::string::npos)
{
- std::string maxmodes(capab.begin() + 9, capab.end());
- ircd->maxmodes = atoi(maxmodes.c_str());
+ Anope::string maxmodes(capab.begin() + 9, capab.end());
+ ircd->maxmodes = maxmodes.is_number_only() ? convertTo<unsigned>(maxmodes) : 3;
}
}
}
@@ -1210,14 +1160,14 @@ int anope_event_capab(const char *source, int ac, const char **av)
{
if (!has_servicesmod)
{
- send_cmd(NULL, "ERROR :m_services_account.so is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
}
if (!ModeManager::FindUserModeByName(UMODE_PRIV))
{
- send_cmd(NULL, "ERROR :m_hidechans.so is not loaded. This is required by Anope");
+ send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope");
quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
quitting = 1;
return MOD_STOP;
@@ -1236,11 +1186,11 @@ int anope_event_capab(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_endburst(const char *source, int ac, const char **av)
+int anope_event_endburst(const Anope::string &source, int ac, const char **av)
{
NickAlias *na;
User *u = prev_u_intro;
- Server *s = Server::Find(source ? source : "");
+ Server *s = Server::Find(source);
if (!s)
throw new CoreException("Got ENDBURST without a source");
@@ -1301,30 +1251,32 @@ void moduleAddIRCDMsgs()
Anope::AddMessage("METADATA", anope_event_metadata);
}
-bool ChannelModeFlood::IsValid(const std::string &value)
+bool ChannelModeFlood::IsValid(const Anope::string &value)
{
- char *dp, *end;
- if (!value.empty() && value[0] != ':' && strtoul((value[0] == '*' ? value.c_str() + 1 : value.c_str()), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end)
- return 1;
- else return 0;
+ //char *dp, *end;
+ Anope::string rest;
+ if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
+ return true;
+ else
+ return false;
}
class ProtoInspIRCd : public Module
{
public:
- ProtoInspIRCd(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
- if (Config.Numeric)
- TS6SID = sstrdup(Config.Numeric);
+ if (!Config.Numeric.empty())
+ TS6SID = Config.Numeric;
pmodule_ircd_version("InspIRCd 2.0");
pmodule_ircd_var(myIrcd);
pmodule_ircd_useTSMode(0);
- CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT };
+ CapabType c[] = { CAPAB_NOQUIT, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT };
for (unsigned i = 0; i < 5; ++i)
Capab.SetFlag(c[i]);
@@ -1334,12 +1286,7 @@ class ProtoInspIRCd : public Module
ModuleManager::Attach(I_OnUserNickChange, this);
}
- ~ProtoInspIRCd()
- {
- delete [] TS6SID;
- }
-
- void OnUserNickChange(User *u, const std::string &)
+ void OnUserNickChange(User *u, const Anope::string &)
{
u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED));
}
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index 80065222d..a01207a5d 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -12,7 +12,7 @@
#include "services.h"
#include "modules.h"
-static char *TS6UPLINK = NULL; // XXX is this needed?
+static Anope::string TS6UPLINK; // XXX is this needed?
IRCDVar myIrcd[] = {
{"Ratbox 2.0+", /* ircd name */
@@ -43,7 +43,6 @@ IRCDVar myIrcd[] = {
0, /* Change RealName */
0, /* No Knock requires +i */
0, /* We support TOKENS */
- 0, /* TIME STAMPS are BASE64 */
0, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
1, /* ts6 */
@@ -66,70 +65,51 @@ IRCDVar myIrcd[] = {
*/
void ratbox_cmd_svinfo()
{
- send_cmd(NULL, "SVINFO 6 3 0 :%ld", static_cast<long>(time(NULL)));
+ send_cmd("", "SVINFO 6 3 0 :%ld", static_cast<long>(time(NULL)));
}
void ratbox_cmd_svsinfo()
{
}
-void ratbox_cmd_tmode(const char *source, const char *dest, const char *fmt, ...)
-{
- va_list args;
- char buf[BUFSIZE];
- *buf = '\0';
-
- if (fmt)
- {
- va_start(args, fmt);
- vsnprintf(buf, BUFSIZE - 1, fmt, args);
- va_end(args);
- }
- if (!*buf)
- return;
-
- send_cmd(NULL, "MODE %s %s", dest, buf);
-}
-
-
/* CAPAB */
/*
- QS - Can handle quit storm removal
- EX - Can do channel +e exemptions
- CHW - Can do channel wall @#
- LL - Can do lazy links
- IE - Can do invite exceptions
- EOB - Can do EOB message
- KLN - Can do KLINE message
- GLN - Can do GLINE message
- HUB - This server is a HUB
- UID - Can do UIDs
- ZIP - Can do ZIPlinks
- ENC - Can do ENCrypted links
+ QS - Can handle quit storm removal
+ EX - Can do channel +e exemptions
+ CHW - Can do channel wall @#
+ LL - Can do lazy links
+ IE - Can do invite exceptions
+ EOB - Can do EOB message
+ KLN - Can do KLINE message
+ GLN - Can do GLINE message
+ HUB - This server is a HUB
+ UID - Can do UIDs
+ ZIP - Can do ZIPlinks
+ ENC - Can do ENCrypted links
KNOCK - supports KNOCK
TBURST - supports TBURST
- PARA - supports invite broadcasting for +p
- ENCAP - ?
+ PARA - supports invite broadcasting for +p
+ ENCAP - ?
*/
void ratbox_cmd_capab()
{
- send_cmd(NULL, "CAPAB :QS EX CHW IE KLN GLN KNOCK TB UNKLN CLUSTER ENCAP");
+ send_cmd("", "CAPAB :QS EX CHW IE KLN GLN KNOCK TB UNKLN CLUSTER ENCAP");
}
/* PASS */
-void ratbox_cmd_pass(const char *pass)
+void ratbox_cmd_pass(const Anope::string &pass)
{
- send_cmd(NULL, "PASS %s TS 6 :%s", pass, TS6SID);
+ send_cmd("", "PASS %s TS 6 :%s", pass.c_str(), TS6SID.c_str());
}
class RatboxProto : public IRCDTS6Proto
{
- void SendGlobopsInternal(BotInfo *source, const char *buf)
+ void SendGlobopsInternal(BotInfo *source, const Anope::string &buf)
{
if (source)
- send_cmd(source->GetUID(), "OPERWALL :%s", buf);
+ send_cmd(source->GetUID(), "OPERWALL :%s", buf.c_str());
else
- send_cmd(TS6SID, "OPERWALL :%s", buf);
+ send_cmd(TS6SID, "OPERWALL :%s", buf.c_str());
}
void SendSQLine(XLine *x)
@@ -160,9 +140,9 @@ class RatboxProto : public IRCDTS6Proto
send_cmd(TS6SID, "UNRESV * %s", x->Mask.c_str());
}
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(NULL, "SJOIN %ld %s + :%s", static_cast<long>(chantime), channel, user->GetUID().c_str());
+ send_cmd("", "SJOIN %ld %s + :%s", static_cast<long>(chantime), channel.c_str(), user->GetUID().c_str());
}
void SendAkill(XLine *x)
@@ -171,9 +151,9 @@ class RatboxProto : public IRCDTS6Proto
send_cmd(bi ? bi->GetUID() : Config.s_OperServ, "KLINE * %ld %s %s :%s", static_cast<long>(x->Expires - time(NULL)), x->GetUser().c_str(), x->GetHost().c_str(), x->Reason.c_str());
}
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf);
+ send_cmd(source ? source->GetUID() : TS6SID, "KILL %s :%s", user->GetUID().c_str(), buf.c_str());
}
void SendSVSMode(User *u, int ac, const char **av)
@@ -184,7 +164,7 @@ class RatboxProto : public IRCDTS6Proto
/* SERVER name hop descript */
void SendServer(Server *server)
{
- send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
+ send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
}
void SendConnect()
@@ -196,110 +176,111 @@ class RatboxProto : public IRCDTS6Proto
ratbox_cmd_svinfo();
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &uid)
{
- EnforceQlinedNick(nick, NULL);
- send_cmd(TS6SID, "UID %s 1 %ld %s %s %s 0 %s :%s", nick.c_str(), static_cast<long>(time(NULL)), modes, user.c_str(), host.c_str(), uid.c_str(), real.c_str());
+ EnforceQlinedNick(nick, "");
+ send_cmd(TS6SID, "UID %s 1 %ld %s %s %s 0 %s :%s", nick.c_str(), static_cast<long>(time(NULL)), modes.c_str(), user.c_str(), host.c_str(), uid.c_str(), real.c_str());
}
- void SendPartInternal(BotInfo *bi, const char *chan, const char *buf)
+ void SendPartInternal(BotInfo *bi, Channel *chan, const Anope::string &buf)
{
- if (buf)
- send_cmd(bi->GetUID(), "PART %s :%s", chan, buf);
+ if (!buf.empty())
+ send_cmd(bi->GetUID(), "PART %s :%s", chan->name.c_str(), buf.c_str());
else
- send_cmd(bi->GetUID(), "PART %s", chan);
+ send_cmd(bi->GetUID(), "PART %s", chan->name.c_str());
}
- void SendNumericInternal(const char *source, int numeric, const char *dest, const char *buf)
+ void SendNumericInternal(const Anope::string &, int numeric, const Anope::string &dest, const Anope::string &buf)
{
// This might need to be set in the call to SendNumeric instead of here, will review later -- CyberBotX
- send_cmd(TS6SID, "%03d %s %s", numeric, dest, buf);
+ send_cmd(TS6SID, "%03d %s %s", numeric, dest.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *bi, Channel *dest, const Anope::string &buf)
{
if (bi)
- send_cmd(bi->GetUID(), "MODE %s %s", dest->name.c_str(), buf);
- else send_cmd(TS6SID, "MODE %s %s", dest->name.c_str(), buf);
+ send_cmd(bi->GetUID(), "MODE %s %s", dest->name.c_str(), buf.c_str());
+ else
+ send_cmd(TS6SID, "MODE %s %s", dest->name.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->GetUID() : TS6SID, "SVSMODE %s %s", u->nick.c_str(), buf);
+ send_cmd(bi ? bi->GetUID() : TS6SID, "SVSMODE %s %s", u->nick.c_str(), buf.c_str());
}
- void SendKickInternal(BotInfo *bi, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *bi, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(bi->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf);
+ if (!buf.empty())
+ send_cmd(bi->GetUID(), "KICK %s %s :%s", chan->name.c_str(), user->GetUID().c_str(), buf.c_str());
else
send_cmd(bi->GetUID(), "KICK %s %s", chan->name.c_str(), user->GetUID().c_str());
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- send_cmd(NULL, "NOTICE @%s :%s", dest->name.c_str(), buf);
+ send_cmd("", "NOTICE @%s :%s", dest->name.c_str(), buf.c_str());
}
/* QUIT */
- void SendQuitInternal(BotInfo *bi, const char *buf)
+ void SendQuitInternal(BotInfo *bi, const Anope::string &buf)
{
- if (buf)
- send_cmd(bi->GetUID(), "QUIT :%s", buf);
+ if (!buf.empty())
+ send_cmd(bi->GetUID(), "QUIT :%s", buf.c_str());
else
send_cmd(bi->GetUID(), "QUIT");
}
/* INVITE */
- void SendInvite(BotInfo *source, const char *chan, const char *nick)
+ void SendInvite(BotInfo *source, const Anope::string &chan, const Anope::string &nick)
{
User *u = finduser(nick);
- send_cmd(source->GetUID(), "INVITE %s %s", u ? u->GetUID().c_str(): nick, chan);
+ send_cmd(source->GetUID(), "INVITE %s %s", u ? u->GetUID().c_str() : nick.c_str(), chan.c_str());
}
- void SendAccountLogin(User *u, NickCore *account)
+ void SendAccountLogin(User *u, const NickCore *account)
{
- send_cmd(TS6SID, "ENCAP * SU %s %s", u->GetUID().c_str(), account->display);
+ send_cmd(TS6SID, "ENCAP * SU %s %s", u->GetUID().c_str(), account->display.c_str());
}
- void SendAccountLogout(User *u, NickCore *account)
+ void SendAccountLogout(User *u, const NickCore *account)
{
send_cmd(TS6SID, "ENCAP * SU %s", u->GetUID().c_str());
}
- int IsNickValid(const char *nick)
+ bool IsNickValid(const Anope::string &nick)
{
/* TS6 Save extension -Certus */
- if (isdigit(*nick))
- return 0;
- return 1;
+ if (isdigit(nick[0]))
+ return false;
+
+ return true;
}
- void SendTopic(BotInfo *bi, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *bi, Channel *c, const Anope::string &, const Anope::string &topic)
{
- send_cmd(bi->GetUID(), "TOPIC %s :%s", c->name.c_str(), topic);
+ send_cmd(bi->GetUID(), "TOPIC %s :%s", c->name.c_str(), topic.c_str());
}
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15];
if (!u->Account())
return;
- snprintf(svidbuf, sizeof(svidbuf), "%ld", static_cast<long>(u->timestamp));
+ Anope::string svidbuf = stringify(u->timestamp);
u->Account()->Shrink("authenticationtoken");
- u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
+ u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf));
}
} ircd_proto;
-int anope_event_sjoin(const char *source, int ac, const char **av)
+int anope_event_sjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[1]);
- time_t ts = atol(av[0]);
+ time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0;
bool was_created = false;
bool keep_their_modes = true;
@@ -358,11 +339,10 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
}
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
std::list<ChannelMode *> Status;
- Status.clear();
char ch;
/* Get prefixes from the nick */
@@ -452,15 +432,15 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
av[8] = info
*/
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
User *user;
if (ac == 9)
{
- Server *s = Server::Find(source ? source : "");
+ Server *s = Server::Find(source);
/* Source is always the server */
- user = do_nick("", av[0], av[4], av[5], s->GetName().c_str(), av[8], strtoul(av[2], NULL, 10), 0, "*", av[7]);
+ user = do_nick("", av[0], av[4], av[5], s->GetName(), av[8], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, "*", av[7]);
if (user)
{
/* No usermode +d on ratbox so we use
@@ -472,11 +452,11 @@ int anope_event_nick(const char *source, int ac, const char **av)
}
}
else if (ac == 2)
- do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", "");
return MOD_CONT;
}
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -496,13 +476,9 @@ int anope_event_topic(const char *source, int ac, const char **av)
if (check_topiclock(c, topic_time))
return MOD_CONT;
- if (c->topic)
- {
- delete [] c->topic;
- c->topic = NULL;
- }
+ c->topic.clear();
if (ac > 1 && *av[1])
- c->topic = sstrdup(av[1]);
+ c->topic = av[1];
u = finduser(source);
c->topic_setter = u ? u->nick : source;
@@ -522,53 +498,40 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_tburst(const char *source, int ac, const char **av)
+int anope_event_tburst(const Anope::string &source, int ac, const char **av)
{
- char *setter;
Channel *c;
time_t topic_time;
if (ac != 4)
return MOD_CONT;
- setter = myStrGetToken(av[2], '!', 0);
+ Anope::string setter = myStrGetToken(av[2], '!', 0);
c = findchan(av[0]);
- topic_time = strtol(av[1], NULL, 10);
+ topic_time = Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0;
if (!c)
{
Alog(LOG_DEBUG) << "debug: TOPIC " << merge_args(ac - 1, av + 1) << " for nonexistent channel " << av[0];
- if (setter)
- delete [] setter;
return MOD_CONT;
}
if (check_topiclock(c, topic_time))
- {
- if (setter)
- delete [] setter;
return MOD_CONT;
- }
- if (c->topic)
- {
- delete [] c->topic;
- c->topic = NULL;
- }
+ c->topic.clear();
if (ac > 1 && *av[3])
- c->topic = sstrdup(av[3]);
+ c->topic = av[3];
c->topic_setter = setter;
c->topic_time = topic_time;
record_topic(av[0]);
- if (setter)
- delete [] setter;
return MOD_CONT;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -577,7 +540,7 @@ int anope_event_436(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -585,16 +548,16 @@ int anope_event_ping(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
User *u = NULL;
u = finduser(source);
- m_away(u ? u->nick.c_str() : source, (ac ? av[0] : NULL));
+ m_away(u ? u->nick : source, ac ? av[0] : "");
return MOD_CONT;
}
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -603,7 +566,7 @@ int anope_event_kill(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
if (ac != 3)
return MOD_CONT;
@@ -611,7 +574,7 @@ int anope_event_kick(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
{
@@ -623,31 +586,26 @@ int anope_event_join(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
m_motd(source);
return MOD_CONT;
}
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
- User *u;
- BotInfo *bi;
-
if (ac != 2)
return MOD_CONT;
- u = finduser(source);
- bi = findbot(av[0]);
// XXX: this is really the same as charybdis
m_privmsg(source, av[0], av[1]);
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -655,57 +613,50 @@ int anope_event_part(const char *source, int ac, const char **av)
return MOD_CONT;
u = finduser(source);
- do_part(u ? u->nick.c_str() : source, ac, av);
+ do_part(u ? u->nick : source, ac, av);
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
- BotInfo *bi;
-
- if (source && ac >= 1)
+ if (!source.empty() && ac >= 1)
{
- bi = findbot(av[0]);
- m_whois(source, bi->GetUID().c_str());
+ BotInfo *bi = findbot(av[0]);
+ m_whois(source, bi->GetUID());
}
return MOD_CONT;
}
/* EVENT: SERVER */
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
if (!stricmp(av[1], "1"))
- {
- if (TS6UPLINK)
- do_server(source, av[0], atoi(av[1]), av[2], TS6UPLINK);
- else
- do_server(source, av[0], atoi(av[1]), av[2], "");
- }
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], TS6UPLINK);
else
- do_server(source, av[0], atoi(av[1]), av[2], "");
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], "");
return MOD_CONT;
}
-int anope_event_sid(const char *source, int ac, const char **av)
+int anope_event_sid(const Anope::string &source, int ac, const char **av)
{
/* :42X SID trystan.nomadirc.net 2 43X :ircd-ratbox test server */
-
Server *s = Server::Find(source);
- do_server(s->GetName(), av[0], atoi(av[1]), av[3], av[2]);
+ do_server(s->GetName(), av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[3], av[2]);
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
+
do_squit(source, ac, av);
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -714,11 +665,11 @@ int anope_event_quit(const char *source, int ac, const char **av)
u = finduser(source);
- do_quit(u ? u->nick.c_str() : source, ac, av);
+ do_quit(u ? u->nick : source, ac, av);
return MOD_CONT;
}
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
User *u, *u2;
@@ -732,12 +683,12 @@ int anope_event_mode(const char *source, int ac, const char **av)
u = finduser(source);
u2 = finduser(av[0]);
av[0] = u2->nick.c_str();
- do_umode(u->nick.c_str(), ac, av);
+ do_umode(u->nick, ac, av);
}
return MOD_CONT;
}
-int anope_event_tmode(const char *source, int ac, const char **av)
+int anope_event_tmode(const Anope::string &source, int ac, const char **av)
{
if (*av[1] == '#' || *av[1] == '&')
do_cmode(source, ac, av);
@@ -745,37 +696,34 @@ int anope_event_tmode(const char *source, int ac, const char **av)
}
/* Event: PROTOCTL */
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
CapabParse(ac, av);
return MOD_CONT;
}
-int anope_event_pass(const char *source, int ac, const char **av)
+int anope_event_pass(const Anope::string &source, int ac, const char **av)
{
- TS6UPLINK = sstrdup(av[3]);
+ TS6UPLINK = av[3];
return MOD_CONT;
}
-int anope_event_bmask(const char *source, int ac, const char **av)
+int anope_event_bmask(const Anope::string &source, int ac, const char **av)
{
Channel *c;
- char *bans;
- char *b;
- int count, i;
ChannelModeList *cms;
/* :42X BMASK 1106409026 #ircops b :*!*@*.aol.com */
- /* 0 1 2 3 */
+ /* 0 1 2 3 */
c = findchan(av[1]);
if (c)
{
- bans = sstrdup(av[3]);
- count = myNumToken(bans, ' ');
+ Anope::string bans = av[3];
+ int count = myNumToken(bans, ' '), i;
for (i = 0; i <= count - 1; ++i)
{
- b = myStrGetToken(bans, ' ', i);
+ Anope::string b = myStrGetToken(bans, ' ', i);
if (!stricmp(av[2], "b"))
{
cms = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByChar('b'));
@@ -791,15 +739,12 @@ int anope_event_bmask(const char *source, int ac, const char **av)
cms = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByChar('I'));
cms->AddMask(c, b);
}
- if (b)
- delete [] b;
}
- delete [] bans;
}
return MOD_CONT;
}
-int anope_event_error(const char *source, int ac, const char **av)
+int anope_event_error(const Anope::string &source, int ac, const char **av)
{
if (ac >= 1)
Alog(LOG_DEBUG) << av[0];
@@ -867,13 +812,13 @@ static void AddModes()
class ProtoRatbox : public Module
{
public:
- ProtoRatbox(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
- if (Config.Numeric)
- TS6SID = sstrdup(Config.Numeric);
+ if (!Config.Numeric.empty())
+ TS6SID = Config.Numeric;
UseTSMODE = 1; /* TMODE */
pmodule_ircd_version("Ratbox IRCD 2.0+");
@@ -889,11 +834,6 @@ class ProtoRatbox : public Module
pmodule_ircd_proto(&ircd_proto);
moduleAddIRCDMsgs();
}
-
- ~ProtoRatbox()
- {
- delete [] TS6SID;
- }
};
MODULE_INIT(ProtoRatbox)
diff --git a/modules/protocol/unreal32.cpp b/modules/protocol/unreal32.cpp
index 0cfb0512e..f94e5bcbe 100644
--- a/modules/protocol/unreal32.cpp
+++ b/modules/protocol/unreal32.cpp
@@ -43,7 +43,6 @@ IRCDVar myIrcd[] = {
1, /* Change RealName */
1, /* No Knock requires +i */
1, /* We support Unreal TOKENS */
- 1, /* TIME STAMPS are BASE64 */
1, /* Can remove User Channel Modes with SVSMODE */
0, /* Sglines are not enforced until user reconnects */
0, /* ts6 */
@@ -56,19 +55,9 @@ IRCDVar myIrcd[] = {
{NULL}
};
-/* svswatch
- * parv[0] - sender
- * parv[1] - target nick
- * parv[2] - parameters
- */
-void unreal_cmd_svswatch(const char *sender, const char *nick, const char *parm)
-{
- send_cmd(sender, "Bw %s :%s", nick, parm);
-}
-
void unreal_cmd_netinfo(int ac, const char **av)
{
- send_cmd(NULL, "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(time(NULL)), atoi(av[2]), av[3], av[7]);
+ send_cmd("", "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(time(NULL)), Anope::string(av[2]).is_number_only() ? convertTo<int>(av[2]) : 0, av[3], av[7]);
}
/* PROTOCTL */
@@ -88,50 +77,50 @@ void unreal_cmd_netinfo(int ac, const char **av)
*/
void unreal_cmd_capab()
{
- if (Config.Numeric)
- send_cmd(NULL, "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT SJB64 VL");
+ if (!Config.Numeric.empty())
+ send_cmd("", "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT VL");
else
- send_cmd(NULL, "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT SJB64");
+ send_cmd("", "PROTOCTL NICKv2 VHP UMODE2 NICKIP TOKEN SJOIN SJOIN2 SJ3 NOQUIT TKLEXT");
}
/* PASS */
-void unreal_cmd_pass(const char *pass)
+void unreal_cmd_pass(const Anope::string &pass)
{
- send_cmd(NULL, "PASS :%s", pass);
+ send_cmd("", "PASS :%s", pass.c_str());
}
/* CHGHOST */
-void unreal_cmd_chghost(const char *nick, const char *vhost)
+void unreal_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
- if (!nick || !vhost)
+ if (nick.empty() || vhost.empty())
return;
- send_cmd(Config.ServerName, "AL %s %s", nick, vhost);
+ send_cmd(Config.ServerName, "AL %s %s", nick.c_str(), vhost.c_str());
}
/* CHGIDENT */
-void unreal_cmd_chgident(const char *nick, const char *vIdent)
+void unreal_cmd_chgident(const Anope::string &nick, const Anope::string &vIdent)
{
- if (!nick || !vIdent)
+ if (nick.empty() || vIdent.empty())
return;
- send_cmd(Config.ServerName, "AZ %s %s", nick, vIdent);
+ send_cmd(Config.ServerName, "AZ %s %s", nick.c_str(), vIdent.c_str());
}
class UnrealIRCdProto : public IRCDProto
{
/* SVSNOOP */
- void SendSVSNOOP(const char *server, int set)
+ void SendSVSNOOP(const Anope::string &server, int set)
{
- send_cmd(NULL, "f %s %s", server, set ? "+" : "-");
+ send_cmd("", "f %s %s", server.c_str(), set ? "+" : "-");
}
void SendAkillDel(XLine *x)
{
- send_cmd(NULL, "BD - G %s %s %s", x->GetUser().c_str(), x->GetHost().c_str(), Config.s_OperServ);
+ send_cmd("", "BD - G %s %s %s", x->GetUser().c_str(), x->GetHost().c_str(), Config.s_OperServ.c_str());
}
- void SendTopic(BotInfo *whosets, Channel *c, const char *whosetit, const char *topic)
+ void SendTopic(BotInfo *whosets, Channel *c, const Anope::string &whosetit, const Anope::string &topic)
{
- send_cmd(whosets->nick, ") %s %s %lu :%s", c->name.c_str(), whosetit, static_cast<unsigned long>(c->topic_time), topic);
+ send_cmd(whosets->nick, ") %s %s %lu :%s", c->name.c_str(), whosetit.c_str(), static_cast<unsigned long>(c->topic_time), topic.c_str());
}
void SendVhostDel(User *u)
@@ -150,12 +139,12 @@ class UnrealIRCdProto : public IRCDProto
time_t timeleft = x->Expires - time(NULL);
if (timeleft > 172800)
timeleft = 172800;
- send_cmd(NULL, "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL) + timeleft), static_cast<long>(x->Expires), x->Reason.c_str());
+ send_cmd("", "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL) + timeleft), static_cast<long>(x->Expires), x->Reason.c_str());
}
- void SendSVSKillInternal(BotInfo *source, User *user, const char *buf)
+ void SendSVSKillInternal(BotInfo *source, User *user, const Anope::string &buf)
{
- send_cmd(source ? source->nick : Config.ServerName, "h %s :%s", user->nick.c_str(), buf);
+ send_cmd(source ? source->nick : Config.ServerName, "h %s :%s", user->nick.c_str(), buf.c_str());
}
/*
@@ -175,62 +164,62 @@ class UnrealIRCdProto : public IRCDProto
}
}
- void SendModeInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendModeInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(source->nick, "G %s %s", dest->name.c_str(), buf);
+ send_cmd(source->nick, "G %s %s", dest->name.c_str(), buf.c_str());
}
- void SendModeInternal(BotInfo *bi, User *u, const char *buf)
+ void SendModeInternal(BotInfo *bi, User *u, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(bi ? bi->nick : Config.ServerName, "v %s %s", u->nick.c_str(), buf);
+ send_cmd(bi ? bi->nick : Config.ServerName, "v %s %s", u->nick.c_str(), buf.c_str());
}
- void SendClientIntroduction(const std::string &nick, const std::string &user, const std::string &host, const std::string &real, const char *modes, const std::string &uid)
+ void SendClientIntroduction(const Anope::string &nick, const Anope::string &user, const Anope::string &host, const Anope::string &real, const Anope::string &modes, const Anope::string &)
{
EnforceQlinedNick(nick, Config.ServerName);
- send_cmd(NULL, "& %s 1 %ld %s %s %s 0 %s %s%s :%s", nick.c_str(), static_cast<long>(time(NULL)), user.c_str(), host.c_str(), Config.ServerName, modes, host.c_str(), myIrcd->nickip ? " *" : " ", real.c_str());
+ send_cmd("", "& %s 1 %ld %s %s %s 0 %s %s%s :%s", nick.c_str(), static_cast<long>(time(NULL)), user.c_str(), host.c_str(), Config.ServerName.c_str(), modes.c_str(), host.c_str(), myIrcd->nickip ? " *" : "", real.c_str());
}
- void SendKickInternal(BotInfo *source, Channel *chan, User *user, const char *buf)
+ void SendKickInternal(BotInfo *source, Channel *chan, User *user, const Anope::string &buf)
{
- if (buf)
- send_cmd(source->nick, "H %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf);
+ if (!buf.empty())
+ send_cmd(source->nick, "H %s %s :%s", chan->name.c_str(), user->nick.c_str(), buf.c_str());
else
send_cmd(source->nick, "H %s %s", chan->name.c_str(), user->nick.c_str());
}
- void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const char *buf)
+ void SendNoticeChanopsInternal(BotInfo *source, Channel *dest, const Anope::string &buf)
{
- if (!buf)
+ if (buf.empty())
return;
- send_cmd(source->nick, "B @%s :%s", dest->name.c_str(), buf);
+ send_cmd(source->nick, "B @%s :%s", dest->name.c_str(), buf.c_str());
}
/* SERVER name hop descript */
/* Unreal 3.2 actually sends some info about itself in the descript area */
void SendServer(Server *server)
{
- if (Config.Numeric)
- send_cmd(NULL, "SERVER %s %d :U0-*-%s %s", server->GetName().c_str(), server->GetHops(), Config.Numeric, server->GetDescription().c_str());
+ if (!Config.Numeric.empty())
+ send_cmd("", "SERVER %s %d :U0-*-%s %s", server->GetName().c_str(), server->GetHops(), Config.Numeric.c_str(), server->GetDescription().c_str());
else
- send_cmd(NULL, "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
+ send_cmd("", "SERVER %s %d :%s", server->GetName().c_str(), server->GetHops(), server->GetDescription().c_str());
}
/* JOIN */
- void SendJoin(BotInfo *user, const char *channel, time_t chantime)
+ void SendJoin(BotInfo *user, const Anope::string &channel, time_t chantime)
{
- send_cmd(Config.ServerName, "~ !%s %s :%s", base64enc(static_cast<long>(chantime)), channel, user->nick.c_str());
+ send_cmd(Config.ServerName, "~ %ld %s :%s", static_cast<long>(chantime), channel.c_str(), user->nick.c_str());
}
/* unsqline
*/
void SendSQLineDel(XLine *x)
{
- send_cmd(NULL, "d %s", x->Mask.c_str());
+ send_cmd("", "d %s", x->Mask.c_str());
}
/* SQLINE */
@@ -240,7 +229,7 @@ class UnrealIRCdProto : public IRCDProto
*/
void SendSQLine(XLine *x)
{
- send_cmd(NULL, "c %s :%s", x->Mask.c_str(), x->Reason.c_str());
+ send_cmd("", "c %s :%s", x->Mask.c_str(), x->Reason.c_str());
}
/*
@@ -249,29 +238,29 @@ class UnrealIRCdProto : public IRCDProto
** parv[1] = nick
** parv[2] = options
*/
- void SendSVSO(const char *source, const char *nick, const char *flag)
+ void SendSVSO(const Anope::string &source, const Anope::string &nick, const Anope::string &flag)
{
- if (!source || !nick || !flag)
+ if (source.empty() || nick.empty() || flag.empty())
return;
- send_cmd(source, "BB %s %s", nick, flag);
+ send_cmd(source, "BB %s %s", nick.c_str(), flag.c_str());
}
/* NICK <newnick> */
- void SendChangeBotNick(BotInfo *oldnick, const char *newnick)
+ void SendChangeBotNick(BotInfo *oldnick, const Anope::string &newnick)
{
- if (!oldnick || !newnick)
+ if (!oldnick || newnick.empty())
return;
- send_cmd(oldnick->nick, "& %s %ld", newnick, static_cast<long>(time(NULL)));
+ send_cmd(oldnick->nick, "& %s %ld", newnick.c_str(), static_cast<long>(time(NULL)));
}
/* Functions that use serval cmd functions */
- void SendVhost(User *u, const std::string &vIdent, const std::string &vhost)
+ void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost)
{
if (!vIdent.empty())
- unreal_cmd_chgident(u->nick.c_str(), vIdent.c_str());
+ unreal_cmd_chgident(u->nick, vIdent);
if (!vhost.empty())
- unreal_cmd_chghost(u->nick.c_str(), vhost.c_str());
+ unreal_cmd_chghost(u->nick, vhost);
}
void SendConnect()
@@ -282,15 +271,15 @@ class UnrealIRCdProto : public IRCDProto
}
/* SVSHOLD - set */
- void SendSVSHold(const char *nick)
+ void SendSVSHold(const Anope::string &nick)
{
- send_cmd(NULL, "BD + Q H %s %s %ld %ld :%s", nick, Config.ServerName, static_cast<long>(time(NULL) + Config.NSReleaseTimeout), static_cast<long>(time(NULL)), "Being held for registered user");
+ send_cmd("", "BD + Q H %s %s %ld %ld :Being held for registered user", nick.c_str(), Config.ServerName.c_str(), static_cast<long>(time(NULL) + Config.NSReleaseTimeout), static_cast<long>(time(NULL)));
}
/* SVSHOLD - release */
- void SendSVSHoldDel(const char *nick)
+ void SendSVSHoldDel(const Anope::string &nick)
{
- send_cmd(NULL, "BD - Q * %s %s", nick, Config.ServerName);
+ send_cmd("", "BD - Q * %s %s", nick.c_str(), Config.ServerName.c_str());
}
/* UNSGLINE */
@@ -299,19 +288,19 @@ class UnrealIRCdProto : public IRCDProto
*/
void SendSGLineDel(XLine *x)
{
- send_cmd(NULL, "BR - :%s", x->Mask.c_str());
+ send_cmd("", "BR - :%s", x->Mask.c_str());
}
/* UNSZLINE */
void SendSZLineDel(XLine *x)
{
- send_cmd(NULL, "BD - Z * %s %s", x->Mask.c_str(), Config.s_OperServ);
+ send_cmd("", "BD - Z * %s %s", x->Mask.c_str(), Config.s_OperServ.c_str());
}
/* SZLINE */
void SendSZLine(XLine *x)
{
- send_cmd(NULL, "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL) + 172800), static_cast<long>(time(NULL)), x->Reason.c_str());
+ send_cmd("", "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL) + 172800), static_cast<long>(time(NULL)), x->Reason.c_str());
}
/* SGLINE */
@@ -320,26 +309,25 @@ class UnrealIRCdProto : public IRCDProto
*/
void SendSGLine(XLine *x)
{
- char edited_reason[BUFSIZE];
- strlcpy(edited_reason, x->Reason.c_str(), BUFSIZE);
- strnrepl(edited_reason, BUFSIZE, " ", "_");
- send_cmd(NULL, "BR + %s :%s", edited_reason, x->Mask.c_str());
+ Anope::string edited_reason = x->Reason;
+ edited_reason = edited_reason.replace_all_cs(" ", "_");
+ send_cmd("", "BR + %s :%s", edited_reason.c_str(), x->Mask.c_str());
}
/* SVSMODE -b */
- void SendBanDel(Channel *c, const std::string &nick)
+ void SendBanDel(Channel *c, const Anope::string &nick)
{
- SendSVSModeChan(c, "-b", nick.empty() ? NULL : nick.c_str());
+ SendSVSModeChan(c, "-b", nick);
}
/* SVSMODE channel modes */
- void SendSVSModeChan(Channel *c, const char *mode, const char *nick)
+ void SendSVSModeChan(Channel *c, const Anope::string &mode, const Anope::string &nick)
{
- if (nick)
- send_cmd(Config.ServerName, "n %s %s %s", c->name.c_str(), mode, nick);
+ if (!nick.empty())
+ send_cmd(Config.ServerName, "n %s %s %s", c->name.c_str(), mode.c_str(), nick.c_str());
else
- send_cmd(Config.ServerName, "n %s %s", c->name.c_str(), mode);
+ send_cmd(Config.ServerName, "n %s %s", c->name.c_str(), mode.c_str());
}
/* svsjoin
@@ -351,12 +339,12 @@ class UnrealIRCdProto : public IRCDProto
/* In older Unreal SVSJOIN and SVSNLINE tokens were mixed so SVSJOIN and SVSNLINE are broken
when coming from a none TOKEN'd server
*/
- void SendSVSJoin(const char *source, const char *nick, const char *chan, const char *param)
+ void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &param)
{
- if (param)
- send_cmd(source, "BX %s %s :%s", nick, chan, param);
+ if (!param.empty())
+ send_cmd(source, "BX %s %s :%s", nick.c_str(), chan.c_str(), param.c_str());
else
- send_cmd(source, "BX %s :%s", nick, chan);
+ send_cmd(source, "BX %s :%s", nick.c_str(), chan.c_str());
}
/* svspart
@@ -364,14 +352,14 @@ class UnrealIRCdProto : public IRCDProto
parv[1] - nick to make part
parv[2] - channel(s) to part
*/
- void SendSVSPart(const char *source, const char *nick, const char *chan)
+ void SendSVSPart(const Anope::string &source, const Anope::string &nick, const Anope::string &chan)
{
- send_cmd(source, "BT %s :%s", nick, chan);
+ send_cmd(source, "BT %s :%s", nick.c_str(), chan.c_str());
}
- void SendSWhois(const char *source, const char *who, const char *mask)
+ void SendSWhois(const Anope::string &source, const Anope::string &who, const Anope::string &mask)
{
- send_cmd(source, "BA %s :%s", who, mask);
+ send_cmd(source, "BA %s :%s", who.c_str(), mask.c_str());
}
void SendEOB()
@@ -379,40 +367,37 @@ class UnrealIRCdProto : public IRCDProto
send_cmd(Config.ServerName, "ES");
}
- /*
- 1 = valid nick
- 0 = nick is in valid
- */
- int IsNickValid(const char *nick)
+ bool IsNickValid(const Anope::string &nick)
{
- if (!stricmp("ircd", nick) || !stricmp("irc", nick))
- return 0;
- return 1;
+ if (nick.equals_ci("ircd") || nick.equals_ci("irc"))
+ return false;
+
+ return true;
}
- int IsChannelValid(const char *chan)
+ bool IsChannelValid(const Anope::string &chan)
{
- if (strchr(chan, ':') || *chan != '#')
- return 0;
- return 1;
+ if (chan.find(':') != Anope::string::npos || chan[0] != '#')
+ return false;
+
+ return true;
}
void SetAutoIdentificationToken(User *u)
{
- char svidbuf[15];
if (!u->Account())
return;
srand(time(NULL));
- snprintf(svidbuf, sizeof(svidbuf), "%d", rand());
+ Anope::string svidbuf = stringify(rand());
u->Account()->Shrink("authenticationtoken");
- u->Account()->Extend("authenticationtoken", new ExtensibleItemPointerArray<char>(sstrdup(svidbuf)));
+ u->Account()->Extend("authenticationtoken", new ExtensibleItemRegular<Anope::string>(svidbuf));
BotInfo *bi = NickServ;
u->SetMode(bi, UMODE_REGISTERED);
- ircdproto->SendMode(bi, u, "+d %s", svidbuf);
+ ircdproto->SendMode(bi, u, "+d %s", svidbuf.c_str());
}
void SendUnregisteredNick(User *u)
@@ -424,20 +409,20 @@ class UnrealIRCdProto : public IRCDProto
} ircd_proto;
/* Event: PROTOCTL */
-int anope_event_capab(const char *source, int ac, const char **av)
+int anope_event_capab(const Anope::string &source, int ac, const char **av)
{
for (int i = 0; i < ac; ++i)
{
- std::string capab = av[i];
+ Anope::string capab = av[i];
- if (capab.find("CHANMODES") != std::string::npos)
+ if (capab.find("CHANMODES") != Anope::string::npos)
{
- std::string modes(capab.begin() + 10, capab.end());
+ Anope::string modes(capab.begin() + 10, capab.end());
commasepstream sep(modes);
- std::string modebuf;
+ Anope::string modebuf;
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -456,7 +441,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -475,7 +460,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -491,7 +476,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
sep.GetToken(modebuf);
- for (size_t t = 0, end = modebuf.size(); t < end; ++t)
+ for (size_t t = 0, end = modebuf.length(); t < end; ++t)
{
switch (modebuf[t])
{
@@ -574,7 +559,7 @@ int anope_event_capab(const char *source, int ac, const char **av)
}
/* Events */
-int anope_event_ping(const char *source, int ac, const char **av)
+int anope_event_ping(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -591,7 +576,7 @@ int anope_event_ping(const char *source, int ac, const char **av)
* with their server "not syncing". We now send a PING immediatly when receiving a new server
* and then finish sync once we get a pong back from that server
*/
-int anope_event_pong(const char *source, int ac, const char **av)
+int anope_event_pong(const Anope::string &source, int ac, const char **av)
{
Server *s = Server::Find(source);
if (s && !s->IsSynced())
@@ -609,13 +594,13 @@ int anope_event_pong(const char *source, int ac, const char **av)
* argv[6] = free(**)
* argv[7] = ircnet
*/
-int anope_event_netinfo(const char *source, int ac, const char **av)
+int anope_event_netinfo(const Anope::string &source, int ac, const char **av)
{
unreal_cmd_netinfo(ac, av);
return MOD_CONT;
}
-int anope_event_436(const char *source, int ac, const char **av)
+int anope_event_436(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
@@ -629,11 +614,11 @@ int anope_event_436(const char *source, int ac, const char **av)
** parv[0] = sender prefix
** parv[1] = away message
*/
-int anope_event_away(const char *source, int ac, const char **av)
+int anope_event_away(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
- m_away(source, (ac ? av[0] : NULL));
+ m_away(source, ac ? av[0] : "");
return MOD_CONT;
}
@@ -649,7 +634,7 @@ int anope_event_away(const char *source, int ac, const char **av)
** parv[3] = topic time
** parv[4] = topic text
*/
-int anope_event_topic(const char *source, int ac, const char **av)
+int anope_event_topic(const Anope::string &source, int ac, const char **av)
{
if (ac != 4)
return MOD_CONT;
@@ -657,7 +642,7 @@ int anope_event_topic(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_squit(const char *source, int ac, const char **av)
+int anope_event_squit(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -665,7 +650,7 @@ int anope_event_squit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_quit(const char *source, int ac, const char **av)
+int anope_event_quit(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
return MOD_CONT;
@@ -673,7 +658,7 @@ int anope_event_quit(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_mode(const char *source, int ac, const char **av)
+int anope_event_mode(const Anope::string &source, int ac, const char **av)
{
if (ac < 2)
return MOD_CONT;
@@ -686,7 +671,7 @@ int anope_event_mode(const char *source, int ac, const char **av)
}
/* This is used to strip the TS from the end of the mode stirng */
-int anope_event_gmode(const char *source, int ac, const char **av)
+int anope_event_gmode(const Anope::string &source, int ac, const char **av)
{
if (Server::Find(source))
--ac;
@@ -699,19 +684,19 @@ int anope_event_gmode(const char *source, int ac, const char **av)
parv[0] - sender
parv[1] - modes to change
*/
-int anope_event_umode2(const char *source, int ac, const char **av)
+int anope_event_umode2(const Anope::string &source, int ac, const char **av)
{
if (ac < 1)
return MOD_CONT;
const char *newav[4];
- newav[0] = source;
+ newav[0] = source.c_str();
newav[1] = av[0];
do_umode(source, ac, newav);
return MOD_CONT;
}
-int anope_event_kill(const char *source, int ac, const char **av)
+int anope_event_kill(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -720,7 +705,7 @@ int anope_event_kill(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_kick(const char *source, int ac, const char **av)
+int anope_event_kick(const Anope::string &source, int ac, const char **av)
{
if (ac != 3)
return MOD_CONT;
@@ -728,7 +713,7 @@ int anope_event_kick(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_join(const char *source, int ac, const char **av)
+int anope_event_join(const Anope::string &source, int ac, const char **av)
{
if (ac != 1)
return MOD_CONT;
@@ -736,16 +721,16 @@ int anope_event_join(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_motd(const char *source, int ac, const char **av)
+int anope_event_motd(const Anope::string &source, int ac, const char **av)
{
- if (!source)
+ if (source.empty())
return MOD_CONT;
m_motd(source);
return MOD_CONT;
}
-int anope_event_setname(const char *source, int ac, const char **av)
+int anope_event_setname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -763,7 +748,7 @@ int anope_event_setname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_chgname(const char *source, int ac, const char **av)
+int anope_event_chgname(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -781,7 +766,7 @@ int anope_event_chgname(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_setident(const char *source, int ac, const char **av)
+int anope_event_setident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -798,7 +783,8 @@ int anope_event_setident(const char *source, int ac, const char **av)
u->SetVIdent(av[0]);
return MOD_CONT;
}
-int anope_event_chgident(const char *source, int ac, const char **av)
+
+int anope_event_chgident(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -816,7 +802,7 @@ int anope_event_chgident(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_sethost(const char *source, int ac, const char **av)
+int anope_event_sethost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -870,7 +856,7 @@ int anope_event_sethost(const char *source, int ac, const char **av)
char *server, char *realname, time_t ts,
uint32 ip, char *vhost, char *uid)
*/
-int anope_event_nick(const char *source, int ac, const char **av)
+int anope_event_nick(const Anope::string &source, int ac, const char **av)
{
User *user;
@@ -884,11 +870,11 @@ int anope_event_nick(const char *source, int ac, const char **av)
<codemastr> it's sent when a nick collision occurs
- so we have to leave it around for now -TSL
*/
- do_nick(source, av[0], av[3], av[4], av[5], av[6], strtoul(av[2], NULL, 10), 0, "*", NULL);
+ do_nick(source, av[0], av[3], av[4], av[5], av[6], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, "*", "");
}
else if (ac == 11)
{
- user = do_nick(source, av[0], av[3], av[4], av[5], av[10], strtoul(av[2], NULL, 10), ntohl(decode_ip(av[9])), av[8], NULL);
+ user = do_nick(source, av[0], av[3], av[4], av[5], av[10], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, ntohl(decode_ip(av[9])), av[8], "");
if (user)
{
/* Check to see if the user should be identified because their
@@ -902,7 +888,7 @@ int anope_event_nick(const char *source, int ac, const char **av)
else
{
/* NON NICKIP */
- user = do_nick(source, av[0], av[3], av[4], av[5], av[9], strtoul(av[2], NULL, 10), 0, av[8], NULL);
+ user = do_nick(source, av[0], av[3], av[4], av[5], av[9], Anope::string(av[2]).is_number_only() ? convertTo<time_t>(av[2]) : 0, 0, av[8], "");
if (user)
{
/* Check to see if the user should be identified because their
@@ -915,11 +901,11 @@ int anope_event_nick(const char *source, int ac, const char **av)
}
}
else
- do_nick(source, av[0], NULL, NULL, NULL, NULL, strtoul(av[1], NULL, 10), 0, NULL, NULL);
+ do_nick(source, av[0], "", "", "", "", Anope::string(av[1]).is_number_only() ? convertTo<time_t>(av[1]) : 0, 0, "", "");
return MOD_CONT;
}
-int anope_event_chghost(const char *source, int ac, const char **av)
+int anope_event_chghost(const Anope::string &source, int ac, const char **av)
{
User *u;
@@ -938,30 +924,23 @@ int anope_event_chghost(const char *source, int ac, const char **av)
}
/* EVENT: SERVER */
-int anope_event_server(const char *source, int ac, const char **av)
+int anope_event_server(const Anope::string &source, int ac, const char **av)
{
- char *desc;
- char *vl;
- char *upnumeric;
-
if (!stricmp(av[1], "1"))
{
- vl = myStrGetToken(av[2], ' ', 0);
- upnumeric = myStrGetToken(vl, '-', 2);
- desc = myStrGetTokenRemainder(av[2], ' ', 1);
- do_server(source, av[0], atoi(av[1]), desc, upnumeric);
- delete [] vl;
- delete [] desc;
- delete [] upnumeric;
+ Anope::string vl = myStrGetToken(av[2], ' ', 0);
+ Anope::string upnumeric = myStrGetToken(vl, '-', 2);
+ Anope::string desc = myStrGetTokenRemainder(av[2], ' ', 1);
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, desc, upnumeric);
}
else
- do_server(source, av[0], atoi(av[1]), av[2], "");
+ do_server(source, av[0], Anope::string(av[1]).is_number_only() ? convertTo<unsigned>(av[1]) : 0, av[2], "");
ircdproto->SendPing(Config.ServerName, av[0]);
return MOD_CONT;
}
-int anope_event_privmsg(const char *source, int ac, const char **av)
+int anope_event_privmsg(const Anope::string &source, int ac, const char **av)
{
if (ac != 2)
return MOD_CONT;
@@ -969,7 +948,7 @@ int anope_event_privmsg(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_part(const char *source, int ac, const char **av)
+int anope_event_part(const Anope::string &source, int ac, const char **av)
{
if (ac < 1 || ac > 2)
return MOD_CONT;
@@ -977,14 +956,14 @@ int anope_event_part(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_whois(const char *source, int ac, const char **av)
+int anope_event_whois(const Anope::string &source, int ac, const char **av)
{
- if (source && ac >= 1)
+ if (!source.empty() && ac >= 1)
m_whois(source, av[0]);
return MOD_CONT;
}
-int anope_event_error(const char *source, int ac, const char **av)
+int anope_event_error(const Anope::string &source, int ac, const char **av)
{
if (av[0])
{
@@ -993,12 +972,11 @@ int anope_event_error(const char *source, int ac, const char **av)
Alog() << "Error: Your IRCD's link block may not be setup correctly, please check unrealircd.conf";
}
return MOD_CONT;
-
}
-int anope_event_sdesc(const char *source, int ac, const char **av)
+int anope_event_sdesc(const Anope::string &source, int ac, const char **av)
{
- Server *s = Server::Find(source ? source : "");
+ Server *s = Server::Find(source);
if (s)
s->SetDescription(av[0]);
@@ -1006,10 +984,10 @@ int anope_event_sdesc(const char *source, int ac, const char **av)
return MOD_CONT;
}
-int anope_event_sjoin(const char *source, int ac, const char **av)
+int anope_event_sjoin(const Anope::string &source, int ac, const char **av)
{
Channel *c = findchan(av[1]);
- time_t ts = base64dects(av[0]);
+ time_t ts = Anope::string(av[0]).is_number_only() ? convertTo<time_t>(av[0]) : 0;
bool keep_their_modes = true;
bool was_created = false;
@@ -1067,7 +1045,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
}
spacesepstream sep(av[ac - 1]);
- std::string buf;
+ Anope::string buf;
while (sep.GetToken(buf))
{
/* Ban */
@@ -1075,8 +1053,9 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
{
buf.erase(buf.begin());
ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_BAN));
+
if (cml->IsValid(buf))
- cml->AddMask(c, buf.c_str());
+ cml->AddMask(c, buf);
}
/* Except */
else if (keep_their_modes && buf[0] == '"')
@@ -1085,7 +1064,7 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_EXCEPT));
if (cml->IsValid(buf))
- cml->AddMask(c, buf.c_str());
+ cml->AddMask(c, buf);
}
/* Invex */
else if (keep_their_modes && buf[0] == '\'')
@@ -1094,12 +1073,11 @@ int anope_event_sjoin(const char *source, int ac, const char **av)
ChannelModeList *cml = dynamic_cast<ChannelModeList *>(ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE));
if (cml->IsValid(buf))
- cml->AddMask(c, buf.c_str());
+ cml->AddMask(c, buf);
}
else
{
std::list<ChannelMode *> Status;
- Status.clear();
char ch;
/* Get prefixes from the nick */
@@ -1192,7 +1170,7 @@ void moduleAddIRCDMsgs()
Anope::AddMessage("PRIVMSG", anope_event_privmsg);
Anope::AddMessage("!", anope_event_privmsg);
Anope::AddMessage("QUIT", anope_event_quit);
- Anope::AddMessage(",", anope_event_quit);
+ Anope::AddMessage("),", anope_event_quit);
Anope::AddMessage("SERVER", anope_event_server);
Anope::AddMessage("'", anope_event_server);
Anope::AddMessage("SQUIT", anope_event_squit);
@@ -1237,41 +1215,37 @@ void moduleAddIRCDMsgs()
}
/* Borrowed part of this check from UnrealIRCd */
-bool ChannelModeFlood::IsValid(const std::string &value2)
+bool ChannelModeFlood::IsValid(const Anope::string &value)
{
- const char *value = value2.c_str();
- char *dp, *end;
- /* NEW +F */
- char xbuf[256], *p, *p2, *x = xbuf + 1;
- int v;
- if (!value)
- return 0;
- if (*value != ':' && strtoul((*value == '*' ? value + 1 : value), &dp, 10) > 0 && *dp == ':' && *(++dp) && strtoul(dp, &end, 10) > 0 && !*end)
- return 1;
+ if (value.empty())
+ return false;
+ Anope::string rest;
+ if (value[0] != ':' && convertTo<unsigned>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<unsigned>(rest.substr(1), rest, false) > 0 && rest.empty())
+ return true;
else
{
/* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */
- strlcpy(xbuf, value, sizeof(xbuf));
- p2 = strchr(xbuf + 1, ']');
- if (!p2) return 0;
- *p2 = '\0';
- if (*(p2 + 1) != ':')
- return 0;
- for (x = strtok(xbuf + 1, ","); x; x = strtok(NULL, ","))
+ size_t end_bracket = value.find(']', 1);
+ if (end_bracket == Anope::string::npos)
+ return false;
+ Anope::string xbuf = value.substr(0, end_bracket);
+ if (value[end_bracket + 1] != ':')
+ return false;
+ commasepstream args(xbuf.substr(1));
+ Anope::string arg;
+ while (args.GetToken(arg))
{
/* <number><1 letter>[optional: '#'+1 letter] */
- p = x;
- while (isdigit(*p))
+ size_t p = 0;
+ while (p < arg.length() && isdigit(arg[p]))
++p;
- if (!*p || !(*p == 'c' || *p == 'j' || *p == 'k' || *p == 'm' || *p == 'n' || *p == 't'))
+ if (p == arg.length() || !(arg[p] == 'c' || arg[p] == 'j' || arg[p] == 'k' || arg[p] == 'm' || arg[p] == 'n' || arg[p] == 't'))
continue; /* continue instead of break for forward compatability. */
- *p = '\0';
- v = atoi(x);
+ int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0;
if (v < 1 || v > 999)
- return 0;
- ++p;
+ return false;
}
- return 1;
+ return true;
}
}
@@ -1282,7 +1256,7 @@ static void AddModes()
ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, "CMODE_OP", 'o', '@'));
/* Unreal sends +q as * and +a as ~ */
ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT, "CMODE_PROTECT", 'a', '~'));
- ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '*')); /* Unreal sends +q as * */
+ ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, "CMODE_OWNER", 'q', '*'));
/* Add user modes */
ModeManager::AddUserMode(new UserMode(UMODE_SERV_ADMIN, "UMODE_SERV_ADMIN", 'A'));
@@ -1315,7 +1289,7 @@ static void AddModes()
class ProtoUnreal : public Module
{
public:
- ProtoUnreal(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
{
this->SetAuthor("Anope");
this->SetType(PROTOCOL);
@@ -1324,7 +1298,7 @@ class ProtoUnreal : public Module
pmodule_ircd_var(myIrcd);
pmodule_ircd_useTSMode(0);
- CapabType c[] = { CAPAB_NOQUIT, CAPAB_NICKIP, CAPAB_ZIP, CAPAB_TOKEN, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT, CAPAB_CHANMODE, CAPAB_SJB64, CAPAB_NICKCHARS };
+ CapabType c[] = { CAPAB_NOQUIT, CAPAB_NICKIP, CAPAB_ZIP, CAPAB_TOKEN, CAPAB_SSJ3, CAPAB_NICK2, CAPAB_VL, CAPAB_TLKEXT, CAPAB_CHANMODE, CAPAB_NICKCHARS };
for (unsigned i = 0; i < 11; ++i)
Capab.SetFlag(c[i]);
@@ -1336,7 +1310,7 @@ class ProtoUnreal : public Module
ModuleManager::Attach(I_OnUserNickChange, this);
}
- void OnUserNickChange(User *u, const std::string &)
+ void OnUserNickChange(User *u, const Anope::string &)
{
u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED));
}