diff options
Diffstat (limited to 'modules/protocol/inspircd12.cpp')
| -rw-r--r-- | modules/protocol/inspircd12.cpp | 349 |
1 files changed, 152 insertions, 197 deletions
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. |
