diff options
Diffstat (limited to 'modules/protocol/inspircd11.cpp')
| -rw-r--r-- | modules/protocol/inspircd11.cpp | 297 |
1 files changed, 130 insertions, 167 deletions
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) |
