diff options
Diffstat (limited to 'modules/protocol')
-rw-r--r-- | modules/protocol/CMakeLists.txt | 2 | ||||
-rw-r--r-- | modules/protocol/bahamut.cpp | 272 | ||||
-rw-r--r-- | modules/protocol/charybdis.cpp | 439 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 662 | ||||
-rw-r--r-- | modules/protocol/inspircd12.cpp | 1383 | ||||
-rw-r--r-- | modules/protocol/inspircd20.cpp | 1581 | ||||
-rw-r--r-- | modules/protocol/ngircd.cpp | 239 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 432 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 364 | ||||
-rw-r--r-- | modules/protocol/unreal.cpp | 824 | ||||
-rw-r--r-- | modules/protocol/unreal4.cpp | 1468 |
11 files changed, 2559 insertions, 5107 deletions
diff --git a/modules/protocol/CMakeLists.txt b/modules/protocol/CMakeLists.txt new file mode 100644 index 000000000..9a236d6d0 --- /dev/null +++ b/modules/protocol/CMakeLists.txt @@ -0,0 +1,2 @@ +build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 16d593fab..a32a7606d 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -1,12 +1,20 @@ -/* Bahamut functions +/* + * Anope IRC Services + * + * Copyright (C) 2003-2016 Anope Team <team@anope.org> * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Please read COPYING and README for further details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" @@ -16,7 +24,7 @@ class ChannelModeFlood : public ChannelModeParam public: ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { } - bool IsValid(Anope::string &value) const anope_override + bool IsValid(Anope::string &value) const override { try { @@ -45,91 +53,97 @@ class BahamutIRCdProto : public IRCDProto MaxModes = 60; } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { if (Servers::Capab.count("TSMODE") > 0) { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf; + IRCMessage message(source, "MODE", dest->name, dest->creation_time); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } else + { IRCDProto::SendModeInternal(source, dest, buf); + } } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSMODE " << u->nick << " " << u->timestamp << " " << buf; + IRCMessage message(source, "SVSMODE", u->nick, u->timestamp); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick, time_t time) anope_override + void SendSVSHold(const Anope::string &nick, time_t time) override { - UplinkSocket::Message(Me) << "SVSHOLD " << nick << " " << time << " :Being held for registered user"; + Uplink::Send(Me, "SVSHOLD", nick, time, "Being held for registered user"); } /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override + void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message(Me) << "SVSHOLD " << nick << " 0"; + Uplink::Send(Me, "SVSHOLD", nick, 0); } /* SQLINE */ - void SendSQLine(User *, const XLine *x) anope_override + void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason(); + Uplink::Send(Me, "SQLINE", x->GetMask(), x->GetReason()); } /* UNSLINE */ - void SendSGLineDel(const XLine *x) anope_override + void SendSGLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSGLINE 0 :" << x->mask; + Uplink::Send("UNSGLINE", 0, x->GetMask()); } /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override + void SendSZLineDel(XLine *x) override { /* this will likely fail so its only here for legacy */ - UplinkSocket::Message() << "UNSZLINE 0 " << x->GetHost(); + Uplink::Send("UNSZLINE", 0, x->GetHost()); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "RAKILL " << x->GetHost() << " *"; + Uplink::Send("RAKILL", x->GetHost(), "*"); } /* SZLINE */ - void SendSZLine(User *, const XLine *x) anope_override + void SendSZLine(User *, XLine *x) override { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; /* this will likely fail so its only here for legacy */ - UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send("SZLINE", x->GetHost(), x->GetReason()); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason(); + Uplink::Send("AKILL", x->GetHost(), "*", timeleft, x->GetBy(), Anope::CurTime, x->GetReason()); } /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) anope_override + void SendSVSNOOP(const Server *server, bool set) override { - UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-"); + Uplink::Send("SVSNOOP", server->GetName(), set ? "+" : "-"); } /* SGLINE */ - void SendSGLine(User *, const XLine *x) anope_override + void SendSGLine(User *, XLine *x) override { - UplinkSocket::Message() << "SGLINE " << x->mask.length() << " :" << x->mask << ":" << x->GetReason(); + Uplink::Send("SGLINE", x->GetMask().length(), x->GetMask() + ":" + x->GetReason()); } /* RAKILL */ - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) return; @@ -145,25 +159,26 @@ class BahamutIRCdProto : public IRCDProto } } - UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser(); + Uplink::Send("RAKKILL", x->GetHost(), x->GetUser()); } /* TOPIC */ - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } /* UNSQLINE */ - void SendSQLineDel(const XLine *x) anope_override + void SendSQLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSQLINE " << x->mask; + Uplink::Send("UNSQLINE", x->GetMask()); } /* JOIN - SJOIN */ - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name; + Uplink::Send(user, "SJOIN", c->creation_time, c->name); + if (status) { /* First save the channel status incase uc->Status == status */ @@ -175,7 +190,7 @@ class BahamutIRCdProto : public IRCDProto if (uc != NULL) uc->status.Clear(); - BotInfo *setter = BotInfo::Find(user->GetUID()); + ServiceBot *setter = ServiceBot::Find(user->GetUID()); for (size_t i = 0; i < cs.Modes().length(); ++i) c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); @@ -184,7 +199,7 @@ class BahamutIRCdProto : public IRCDProto } } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) { @@ -192,21 +207,26 @@ class BahamutIRCdProto : public IRCDProto { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } - const XLine *old = x; + XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - old->manager->AddXLine(x); - - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; + x = Serialize::New<XLine *>(); + x->SetMask("*@" + u->host); + x->SetBy(old->GetBy()); + x->SetExpires(old->GetExpires()); + x->SetReason(old->GetReason()); + x->SetID(old->GetID()); + old->GetManager()->AddXLine(x); + + Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); } /* ZLine if we can instead */ @@ -221,46 +241,47 @@ class BahamutIRCdProto : public IRCDProto } // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; + time_t timeleft = x->GetExpires() - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason(); + + Uplink::Send("AKILL", x->GetHost(), x->GetUser(), timeleft, x->GetBy(), Anope::CurTime, x->GetReason()); } /* Note: if the stamp is null 0, the below usage is correct of Bahamut */ - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf; + Uplink::Send(source, "SVSKILL", user->nick, buf); } - void SendBOB() anope_override + void SendBOB() override { - UplinkSocket::Message() << "BURST"; + Uplink::Send("BURST"); } - void SendEOB() anope_override + void SendEOB() override { - UplinkSocket::Message() << "BURST 0"; + Uplink::Send("BURST", 0); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 0 :" << u->realname; + Uplink::Send("NICK", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, u->server->GetName(), 0, 0, u->realname); } /* SERVER */ - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " :TS"; - UplinkSocket::Message() << "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS"); + Uplink::Send("CAPAB", "SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"); SendServer(Me); /* * SVINFO @@ -270,24 +291,24 @@ class BahamutIRCdProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 3 1 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 3, 1, 0, Anope::CurTime); this->SendBOB(); } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { Anope::string modes = c->GetModes(true, true); if (modes.empty()) modes = "+"; - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; + Uplink::Send("SJOIN", c->creation_time, c->name, modes, ""); } - void SendLogin(User *u, NickAlias *) anope_override + void SendLogin(User *u, NickServ::Nick *) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 1"); } @@ -297,7 +318,7 @@ struct IRCDMessageBurst : IRCDMessage { IRCDMessageBurst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { /* If we found a server with the given source, that one just * finished bursting. If there was no source, then our uplink @@ -315,7 +336,7 @@ struct IRCDMessageMode : IRCDMessage { IRCDMessageMode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() > 2 && IRCD->IsChannelValid(params[0])) { @@ -366,7 +387,7 @@ struct IRCDMessageNick : IRCDMessage { IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 10) { @@ -377,13 +398,13 @@ struct IRCDMessageNick : IRCDMessage return; } - NickAlias *na = NULL; + NickServ::Nick *na = NULL; time_t signon = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, stamp = params[7].is_pos_number_only() ? convertTo<time_t>(params[7]) : 0; - if (signon && signon == stamp) - na = NickAlias::Find(params[0]); + if (signon && signon == stamp && NickServ::service) + na = NickServ::service->FindNick(params[0]); - User::OnIntroduce(params[0], params[4], params[5], "", params[8], s, params[9], signon, params[3], "", na ? *na->nc : NULL); + User::OnIntroduce(params[0], params[4], params[5], "", params[8], s, params[9], signon, params[3], "", na ? na->GetAccount() : NULL); } else source.GetUser()->ChangeNick(params[0]); @@ -394,7 +415,7 @@ struct IRCDMessageServer : IRCDMessage { IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[2]); @@ -405,7 +426,7 @@ struct IRCDMessageSJoin : IRCDMessage { IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Anope::string modes; if (params.size() >= 4) @@ -461,7 +482,7 @@ struct IRCDMessageTopic : IRCDMessage { IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Channel *c = Channel::Find(params[0]); if (c) @@ -470,6 +491,7 @@ struct IRCDMessageTopic : IRCDMessage }; class ProtoBahamut : public Module + , public EventHook<Event::UserNickChange> { BahamutIRCdProto ircd_proto; @@ -501,60 +523,40 @@ class ProtoBahamut : public Module IRCDMessageSJoin message_sjoin; IRCDMessageTopic message_topic; - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("SERV_ADMIN", 'A')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeOperOnly("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("DEAF", 'd')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - - /* v/h/o/a/q */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 1)); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelModeFlood('f', false)); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - } - public: - ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), - message_join(this), message_kick(this), message_kill(this), message_motd(this), message_notice(this), - message_part(this), message_ping(this), message_privmsg(this), message_quit(this), - message_squit(this), message_stats(this), message_time(this), message_version(this), message_whois(this), - - message_burst(this), message_mode(this, "MODE"), message_svsmode(this, "SVSMODE"), - message_nick(this), message_server(this), message_sjoin(this), message_topic(this) - { - - this->AddModes(); - - } - - void OnUserNickChange(User *u, const Anope::string &) anope_override + ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_burst(this) + , message_mode(this, "MODE") + , message_svsmode(this, "SVSMODE") + , message_nick(this) + , message_server(this) + , message_sjoin(this) + , message_topic(this) + { + } + + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); IRCD->SendLogout(u); diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index c381ef124..c69fbaf5f 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -1,28 +1,39 @@ -/* Charybdis IRCD functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2006-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.ratbox */ + #include "module.h" -#include "modules/cs_mode.h" #include "modules/sasl.h" +#include "modules/protocol/hybrid.h" +#include "modules/protocol/charybdis.h" +#include "modules/protocol/ratbox.h" +#include "modules/chanserv/mode.h" static Anope::string UplinkSID; -static ServiceReference<IRCDProto> ratbox("IRCDProto", "ratbox"); - class ChannelModeLargeBan : public ChannelMode { public: ChannelModeLargeBan(const Anope::string &mname, char modeChar) : ChannelMode(mname, modeChar) { } - bool CanSet(User *u) const anope_override + bool CanSet(User *u) const override { return u && u->HasMode("OPER"); } @@ -31,8 +42,10 @@ class ChannelModeLargeBan : public ChannelMode class CharybdisProto : public IRCDProto { + ServiceReference<IRCDProto> ratbox; // XXX public: CharybdisProto(Module *creator) : IRCDProto(creator, "Charybdis 3.4+") + , ratbox("ratbox") { DefaultPseudoclientModes = "+oiS"; CanCertFP = true; @@ -46,43 +59,32 @@ class CharybdisProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { ratbox->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { ratbox->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { ratbox->SendGlobalPrivmsg(bi, dest, msg); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override { ratbox->SendGlobopsInternal(source, buf); } - void SendSGLine(User *u, const XLine *x) anope_override { ratbox->SendSGLine(u, x); } - void SendSGLineDel(const XLine *x) anope_override { ratbox->SendSGLineDel(x); } - void SendAkill(User *u, XLine *x) anope_override { ratbox->SendAkill(u, x); } - void SendAkillDel(const XLine *x) anope_override { ratbox->SendAkillDel(x); } - void SendSQLineDel(const XLine *x) anope_override { ratbox->SendSQLineDel(x); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { ratbox->SendJoin(user, c, status); } - void SendServer(const Server *server) anope_override { ratbox->SendServer(server); } - void SendChannel(Channel *c) anope_override { ratbox->SendChannel(c); } - void SendTopic(const MessageSource &source, Channel *c) anope_override { ratbox->SendTopic(source, c); } - bool IsIdentValid(const Anope::string &ident) anope_override { return ratbox->IsIdentValid(ident); } - void SendLogin(User *u, NickAlias *na) anope_override { ratbox->SendLogin(u, na); } - void SendLogout(User *u) anope_override { ratbox->SendLogout(u); } - - void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override + void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { ratbox->SendSVSKillInternal(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalPrivmsg(bi, dest, msg); } + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { ratbox->SendGlobopsInternal(source, buf); } + void SendSGLine(User *u, XLine *x) override { ratbox->SendSGLine(u, x); } + void SendSGLineDel(XLine *x) override { ratbox->SendSGLineDel(x); } + void SendAkill(User *u, XLine *x) override { ratbox->SendAkill(u, x); } + void SendAkillDel(XLine *x) override { ratbox->SendAkillDel(x); } + void SendSQLineDel(XLine *x) override { ratbox->SendSQLineDel(x); } + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { ratbox->SendJoin(user, c, status); } + void SendServer(const Server *server) override { ratbox->SendServer(server); } + void SendChannel(Channel *c) override { ratbox->SendChannel(c); } + void SendTopic(const MessageSource &source, Channel *c) override { ratbox->SendTopic(source, c); } + bool IsIdentValid(const Anope::string &ident) override { return ratbox->IsIdentValid(ident); } + void SendLogin(User *u, NickServ::Nick *na) override { ratbox->SendLogin(u, na); } + void SendLogout(User *u) override { ratbox->SendLogout(u); } + + void SendSQLine(User *, XLine *x) override { - Anope::string mechlist; - - for (unsigned i = 0; i < mechanisms.size(); ++i) - { - mechlist += "," + mechanisms[i]; - } - - UplinkSocket::Message(Me) << "ENCAP * MECHLIST :" << (mechanisms.empty() ? "" : mechlist.substr(1)); + Uplink::Send(Me, "RESV", "*", x->GetMask(), x->GetReason()); } - void SendSQLine(User *, const XLine *x) anope_override + void SendConnect() override { - UplinkSocket::Message(Me) << "RESV * " << x->mask << " :" << x->GetReason(); - } + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); - void SendConnect() anope_override - { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); /* * Received: CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN * KNOCK MLOCK QS RSFNC SAVE SERVICES TB UNKLN @@ -106,7 +108,7 @@ class CharybdisProto : public IRCDProto * UNKLN - Can do UNKLINE (encap only) * QS - Can handle quit storm removal */ - UplinkSocket::Message() << "CAPAB :BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN"; + Uplink::Send("CAPAB", "BAN CHW CLUSTER ENCAP EOPMOD EUID EX IE KLN KNOCK MLOCK QS RSFNC SERVICES TB UNKLN"); /* Make myself known to myself in the serverlist */ SendServer(Me); @@ -118,160 +120,141 @@ class CharybdisProto : public IRCDProto * arg[2] = '0' * arg[3] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 6 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, Anope::CurTime); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "EUID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " * * :" << u->realname; + Uplink::Send(Me, "EUID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, 0, u->GetUID(), "*", "*", u->realname); } - void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override + void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " RSFNC " << u->GetUID() - << " " << newnick << " " << when << " " << u->timestamp; + Uplink::Send(Me, "ENCAP", u->server->GetName(), "RSFNC", u->GetUID(), + newnick, when, u->timestamp); } - void SendSVSHold(const Anope::string &nick, time_t delay) anope_override + void SendSVSHold(const Anope::string &nick, time_t delay) override { - UplinkSocket::Message(Me) << "ENCAP * NICKDELAY " << delay << " " << nick; + Uplink::Send(Me, "ENCAP", "*", "NICKDELAY", delay, nick); } - void SendSVSHoldDel(const Anope::string &nick) anope_override + void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message(Me) << "ENCAP * NICKDELAY 0 " << nick; + Uplink::Send(Me, "ENCAP", "*", "NICKDELAY", 0, nick); } - void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override + void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { - UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " :" << host; + Uplink::Send(Me, "ENCAP", "*", "CHGHOST", u->GetUID(), host); } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { this->SendVhost(u, "", u->host); } - void SendSASLMessage(const SASL::Message &message) anope_override + void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override + { + Anope::string mechlist; + + for (unsigned i = 0; i < mechanisms.size(); ++i) + { + mechlist += "," + mechanisms[i]; + } + + Uplink::Send(Me, "ENCAP", "*", "MECHLIST", mechlist.empty() ? "" : mechlist.substr(1)); + } + + void SendSASLMessage(const SASL::Message &message) override { Server *s = Server::Find(message.target.substr(0, 3)); - UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : message.target.substr(0, 3)) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext)); + Uplink::Send(Me, "ENCAP", s ? s->GetName() : message.target.substr(0, 3), "SASL", message.source, message.target, message.type, message.data, message.ext.empty() ? "" : message.ext); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override + void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) override { Server *s = Server::Find(uid.substr(0, 3)); - UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * " << (!vident.empty() ? vident : '*') << " " << (!vhost.empty() ? vhost : '*') << " " << acc; + Uplink::Send(Me, "ENCAP", s ? s->GetName() : uid.substr(0, 3), "SVSLOGIN", uid, "*", vident.empty() ? "*" : vident, vhost.empty() ? "*" : vhost, acc); } }; -struct IRCDMessageEncap : IRCDMessage +void charybdis::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT);} + User *u = source.GetUser(); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + // In a burst, states that the source user is logged in as the account. + if (params[1] == "LOGIN" || params[1] == "SU") { - User *u = source.GetUser(); - - // In a burst, states that the source user is logged in as the account. - if (params[1] == "LOGIN" || params[1] == "SU") - { - NickCore *nc = NickCore::Find(params[2]); - if (!nc) - return; - u->Login(nc); - } - // Received: :42XAAAAAE ENCAP * CERTFP :3f122a9cc7811dbad3566bf2cec3009007c0868f - if (params[1] == "CERTFP") - { - u->fingerprint = params[2]; - FOREACH_MOD(OnFingerprint, (u)); - } - /* - * Received: :42X ENCAP * SASL 42XAAAAAH * S PLAIN - * Received: :42X ENCAP * SASL 42XAAAAAC * D A - * - * Part of a SASL authentication exchange. The mode is 'C' to send some data - * (base64 encoded), or 'S' to end the exchange (data indicates type of - * termination: 'A' for abort, 'F' for authentication failure, 'S' for - * authentication success). - * - * Charybdis only accepts messages from SASL agents; these must have umode +S - */ - if (params[1] == "SASL" && SASL::sasl && params.size() >= 6) - { - SASL::Message m; - m.source = params[2]; - m.target = params[3]; - m.type = params[4]; - m.data = params[5]; - m.ext = params.size() > 6 ? params[6] : ""; - - SASL::sasl->ProcessMessage(m); - } + NickServ::Account *nc = NickServ::FindAccount(params[2]); + if (!nc) + return; + u->Login(nc); + } + // Received: :42XAAAAAE ENCAP * CERTFP :3f122a9cc7811dbad3566bf2cec3009007c0868f + if (params[1] == "CERTFP") + { + u->fingerprint = params[2]; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } -}; - -struct IRCDMessageEUID : IRCDMessage -{ - IRCDMessageEUID(Module *creator) : IRCDMessage(creator, "EUID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - /* - * :42X EUID DukePyrolator 1 1353240577 +Zi ~jens erft-5d80b00b.pool.mediaWays.net 93.128.176.11 42XAAAAAD * * :jens - * :<SID> EUID <NICK> <HOPS> <TS> +<UMODE> <USERNAME> <VHOST> <IP> <UID> <REALHOST> <ACCOUNT> :<GECOS> - * 0 1 2 3 4 5 6 7 8 9 10 + * Received: :42X ENCAP * SASL 42XAAAAAH * S PLAIN + * Received: :42X ENCAP * SASL 42XAAAAAC * D A * - * Introduces a user. The hostname field is now always the visible host. - * The realhost field is * if the real host is equal to the visible host. - * The account field is * if the login is not set. - * Note that even if both new fields are *, an EUID command still carries more - * information than a UID command (namely that real host is visible host and the - * user is not logged in with services). Hence a NICK or UID command received - * from a remote server should not be sent in EUID form to other servers. + * Part of a SASL authentication exchange. The mode is 'C' to send some data + * (base64 encoded), or 'S' to end the exchange (data indicates type of + * termination: 'A' for abort, 'F' for authentication failure, 'S' for + * authentication success). + * + * Charybdis only accepts messages from SASL agents; these must have umode +S */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (params[1] == "SASL" && sasl && params.size() >= 6) { - NickAlias *na = NULL; - if (params[9] != "*") - na = NickAlias::Find(params[9]); - - User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(), params[10], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime, params[3], params[7], na ? *na->nc : NULL); + SASL::Message m; + m.source = params[2]; + m.target = params[3]; + m.type = params[4]; + m.data = params[5]; + m.ext = params.size() > 6 ? params[6] : ""; + + sasl->ProcessMessage(m); } -}; +} -// we can't use this function from ratbox because we set a local variable here -struct IRCDMessageServer : IRCDMessage +void charybdis::EUID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + NickServ::Nick *na = NULL; + if (params[9] != "*") + na = NickServ::FindNick(params[9]); - // SERVER dev.anope.de 1 :charybdis test server - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - // Servers other then our immediate uplink are introduced via SID - if (params[1] != "1") - return; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - IRCD->SendPing(Me->GetName(), params[0]); - } -}; + User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(), params[10], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime, params[3], params[7], na ? na->GetAccount() : NULL); +} // we can't use this function from ratbox because we set a local variable here -struct IRCDMessagePass : IRCDMessage +// SERVER dev.anope.de 1 :charybdis test server +void charybdis::Server::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + // Servers other then our immediate uplink are introduced via SID + if (params[1] != "1") + return; + new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); + IRCD->SendPing(Me->GetName(), params[0]); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - // UplinkSID is used in IRCDMessageServer - UplinkSID = params[3]; - } -}; +// we can't use this function from ratbox because we set a local variable here +void charybdis::Pass::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + // UplinkSID is used in server handler + UplinkSID = params[3]; +} class ProtoCharybdis : public Module + , public EventHook<Event::ChannelSync> + , public EventHook<Event::MLockEvents> { - Module *m_ratbox; + ServiceReference<ModeLocks> mlocks; CharybdisProto ircd_proto; @@ -296,125 +279,115 @@ class ProtoCharybdis : public Module Message::Version message_version; Message::Whois message_whois; - /* Ratbox Message Handlers */ - ServiceAlias message_bmask, message_join, message_nick, message_pong, message_sid, message_sjoin, - message_tb, message_tmode, message_uid; - /* Our message handlers */ - IRCDMessageEncap message_encap; - IRCDMessageEUID message_euid; - IRCDMessagePass message_pass; - IRCDMessageServer message_server; + hybrid::BMask message_bmask; + charybdis::Encap message_encap; + charybdis::EUID message_euid; + ratbox::Join message_join; + hybrid::Nick message_nick; + charybdis::Pass message_pass; + hybrid::Pong message_pong; + charybdis::Server message_server; + hybrid::SID message_sid; + hybrid::SJoin message_sjoin; + ratbox::TB message_tb; + hybrid::TMode message_tmode; + ratbox::UID message_uid; bool use_server_side_mlock; - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserMode("NOFORWARD", 'Q')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'Z')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("QUIET", 'q')); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'f')); - ModeManager::AddChannelMode(new ChannelMode("ALLOWFORWARD", 'F')); - ModeManager::AddChannelMode(new ChannelMode("ALLINVITE", 'g')); - ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j')); - ModeManager::AddChannelMode(new ChannelModeLargeBan("LBAN", 'L')); - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - ModeManager::AddChannelMode(new ChannelMode("NOFORWARD", 'Q')); - ModeManager::AddChannelMode(new ChannelMode("OPMODERATED", 'z')); - } - public: - ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - - message_bmask("IRCDMessage", "charybdis/bmask", "ratbox/bmask"), - message_join("IRCDMessage", "charybdis/join", "ratbox/join"), - message_nick("IRCDMessage", "charybdis/nick", "ratbox/nick"), - message_pong("IRCDMessage", "charybdis/pong", "ratbox/pong"), - message_sid("IRCDMessage", "charybdis/sid", "ratbox/sid"), - message_sjoin("IRCDMessage", "charybdis/sjoin", "ratbox/sjoin"), - message_tb("IRCDMessage", "charybdis/tb", "ratbox/tb"), - message_tmode("IRCDMessage", "charybdis/tmode", "ratbox/tmode"), - message_uid("IRCDMessage", "charybdis/uid", "ratbox/uid"), - - message_encap(this), message_euid(this), message_pass(this), message_server(this) - - { - - - if (ModuleManager::LoadModule("ratbox", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load ratbox"); - m_ratbox = ModuleManager::FindModule("ratbox"); - if (!m_ratbox) - throw ModuleException("Unable to find ratbox"); - if (!ratbox) - throw ModuleException("No protocol interface for ratbox"); - - this->AddModes(); - } - - ~ProtoCharybdis() + ProtoCharybdis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::MLockEvents>(this) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask(this) + , message_encap(this) + , message_euid(this) + , message_join(this) + , message_nick(this) + , message_pass(this) + , message_pong(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_tb(this) + , message_tmode(this) + , message_uid(this) { - m_ratbox = ModuleManager::FindModule("ratbox"); - ModuleManager::UnloadModule(m_ratbox, NULL); } - void OnReload(Configuration::Conf *conf) anope_override + void OnReload(Configuration::Conf *conf) override { use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { - if (!c->ci) + if (!c->ci || !mlocks) return; - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && modelocks && Servers::Capab.count("MLOCK") > 0) + if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); } } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (!mlocks) + return EVENT_CONTINUE; + + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + if (!mlocks) + return EVENT_CONTINUE; + + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; } }; +template<> void ModuleInfo<ProtoCharybdis>(ModuleDef *def) +{ + def->Depends("ratbox"); +} + MODULE_INIT(ProtoCharybdis) diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 2db72717e..c1d85bcf8 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -1,35 +1,51 @@ -/* ircd-hybrid-8 protocol module +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team <team@anope.org> - * (C) 2012-2016 ircd-hybrid development team + * Copyright (C) 2003-2016 Anope Team <team@anope.org> + * Copyright (C) 2012-2016 ircd-hybrid development team * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" +#include "modules/protocol/hybrid.h" static Anope::string UplinkSID; class HybridProto : public IRCDProto { - BotInfo *FindIntroduced() + ServiceBot *FindIntroduced() { - BotInfo *bi = Config->GetClient("OperServ"); - + ServiceBot *bi = Config->GetClient("OperServ"); if (bi && bi->introduced) return bi; - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - if (it->second->introduced) - return it->second; + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + { + User *u = it->second; + if (u->type == UserType::BOT) + { + bi = anope_dynamic_static_cast<ServiceBot *>(u); + if (bi->introduced) + return bi; + } + } return NULL; } - void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) override { IRCDProto::SendSVSKillInternal(source, u, buf); u->KillInternal(source, buf); @@ -52,73 +68,72 @@ class HybridProto : public IRCDProto MaxModes = 6; } - void SendInvite(const MessageSource &source, const Channel *c, User *u) anope_override + void SendInvite(const MessageSource &source, const Channel *c, User *u) override { - UplinkSocket::Message(source) << "INVITE " << u->GetUID() << " " << c->name << " " << c->creation_time; + Uplink::Send(source, "INVITE", u->GetUID(), c->name, c->creation_time); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$$" + dest->GetName(), msg); } - void SendSQLine(User *, const XLine *x) anope_override + void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message(FindIntroduced()) << "RESV * " << (x->expires ? x->expires - Anope::CurTime : 0) << " " << x->mask << " :" << x->reason; + Uplink::Send(FindIntroduced(), "RESV", "*", x->GetExpires() ? x->GetExpires() - Anope::CurTime : 0, x->GetMask(), x->GetReason()); } - void SendSGLineDel(const XLine *x) anope_override + void SendSGLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNXLINE * " << x->mask; + Uplink::Send(Config->GetClient("OperServ"), "UNXLINE", "*", x->GetMask()); } - void SendSGLine(User *, const XLine *x) anope_override + void SendSGLine(User *, XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "XLINE * " << x->mask << " " << (x->expires ? x->expires - Anope::CurTime : 0) << " :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "XLINE", "*", x->GetMask(), x->GetExpires() ? x->GetExpires() - Anope::CurTime : 0, x->GetReason()); } - void SendSZLineDel(const XLine *x) anope_override + void SendSZLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNDLINE * " << x->GetHost(); + Uplink::Send(Config->GetClient("OperServ"), "UNDLINE", "*", x->GetHost()); } - void SendSZLine(User *, const XLine *x) anope_override + void SendSZLine(User *, XLine *x) override { /* Calculate the time left before this would expire, capping it at 2 days */ - time_t timeleft = x->expires - Anope::CurTime; + time_t timeleft = x->GetExpires() - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Config->GetClient("OperServ")) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "DLINE", "*", timeleft, x->GetHost(), x->GetReason()); } - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) return; - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); + Uplink::Send(Config->GetClient("OperServ"), "UNKLINE", "*", x->GetUser(), x->GetHost()); } - void SendSQLineDel(const XLine *x) anope_override + void SendSQLineDel(XLine *x) override { - UplinkSocket::Message(Config->GetClient("OperServ")) << "UNRESV * " << x->mask; + Uplink::Send(Config->GetClient("OperServ"), "UNRESV", "*", x->GetMask()); } - void SendJoin(User *u, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *u, Channel *c, const ChannelStatus *status) override { /* * Note that we must send our modes with the SJOIN and can not add them to the * mode stacker because ircd-hybrid does not allow *any* client to op itself */ - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" - << (status != NULL ? status->BuildModePrefixList() : "") << u->GetUID(); + Uplink::Send("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), (status != NULL ? status->BuildModePrefixList() : "") + u->GetUID()); /* And update our internal status for this user since this is not going through our mode handling system */ if (status) @@ -130,7 +145,7 @@ class HybridProto : public IRCDProto } } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) { @@ -141,50 +156,55 @@ class HybridProto : public IRCDProto * Find users that match and ban them. */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } - const XLine *old = x; + XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - - old->manager->AddXLine(xline); - x = xline; - - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" - << u->realname << " matches " << old->mask; + XLine *xl = Serialize::New<XLine *>(); + xl->SetMask("*@" + u->host); + xl->SetBy(old->GetBy()); + xl->SetExpires(old->GetExpires()); + xl->SetReason(old->GetReason()); + xl->SetID(old->GetID()); + + old->GetManager()->AddXLine(xl); + x = xl; + + Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" + << u->realname << " matches " << old->GetMask(); } /* Calculate the time left before this would expire, capping it at 2 days */ - time_t timeleft = x->expires - Anope::CurTime; + time_t timeleft = x->GetExpires() - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Config->GetClient("OperServ")) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); + Uplink::Send(Config->GetClient("OperServ"), "KLINE", timeleft, x->GetUser(), x->GetHost(), x->GetReason()); } - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { if (server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription()); else - UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " :" << server->GetDescription(); + Uplink::Send(Me, "SID", server->GetName(), server->GetHops() + 1, server->GetSID(), server->GetDescription()); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); /* - * As of January 13, 2016, ircd-hybrid-8 does support the following capabilities + * As of January 13, 2016, ircd-hybrid-8 supports the following capabilities * which are required to work with IRC-services: * * QS - Can handle quit storm removal @@ -197,97 +217,103 @@ class HybridProto : public IRCDProto * SVS - Supports services * EOB - Supports End Of Burst message */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE ENCAP TBURST SVS HOPS EOB"; + Uplink::Send("CAPAB", "QS EX CHW IE ENCAP TBURST SVS HOPS EOB"); SendServer(Me); - UplinkSocket::Message() << "SVINFO 6 6 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " - << u->GetIdent() << " " << u->host << " 0.0.0.0 " << u->GetUID() << " * :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, "0.0.0.0", u->GetUID(), "*", u->realname); } - void SendEOB() anope_override + void SendEOB() override { - UplinkSocket::Message(Me) << "EOB"; + Uplink::Send(Me, "EOB"); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + IRCMessage message(source, "SVSMODE", u->GetUID(), u->timestamp); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->GetAccount()->GetDisplay().c_str()); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d *"); } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { Anope::string modes = c->GetModes(true, true); if (modes.empty()) modes = "+"; - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; + Uplink::Send("SJOIN", c->creation_time, c->name, modes, ""); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TBURST " << c->creation_time << " " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; + Uplink::Send(source, "TBURST", c->creation_time, c->name, c->topic_ts, c->topic_setter, c->topic); } - void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override + void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "SVSNICK " << u->GetUID() << " " << newnick << " " << when; + Uplink::Send(Me, "SVSNICK", u->GetUID(), newnick, when); } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override + void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override { - UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSPART", u->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; + Uplink::Send(source, "SVSPART", u->GetUID(), chan); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override + void SendSVSHold(const Anope::string &nick, time_t t) override { +#if 0 XLine x(nick, Me->GetName(), Anope::CurTime + t, "Being held for registered user"); this->SendSQLine(NULL, &x); +#endif } +#warning "xline on stack" - void SendSVSHoldDel(const Anope::string &nick) anope_override + void SendSVSHoldDel(const Anope::string &nick) override { +#if 0 XLine x(nick); this->SendSQLineDel(&x); +#endif } - void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override + void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { u->SetMode(Config->GetClient("HostServ"), "CLOAK", host); } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { u->RemoveMode(Config->GetClient("HostServ"), "CLOAK", u->host); } - bool IsIdentValid(const Anope::string &ident) anope_override + bool IsIdentValid(const Anope::string &ident) override { if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; @@ -311,65 +337,44 @@ class HybridProto : public IRCDProto } }; -struct IRCDMessageBMask : IRCDMessage +/* 0 1 2 3 */ +/* :0MC BMASK 1350157102 #channel b :*!*@*.test.com */ +void hybrid::BMask::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageBMask(Module *creator) : IRCDMessage(creator, "BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + Channel *c = Channel::Find(params[1]); + ChannelMode *mode = ModeManager::FindChannelModeByChar(params[2][0]); - /* 0 1 2 3 */ - /* :0MC BMASK 1350157102 #channel b :*!*@*.test.com */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (c && mode) { - Channel *c = Channel::Find(params[1]); - ChannelMode *mode = ModeManager::FindChannelModeByChar(params[2][0]); - - if (c && mode) - { - spacesepstream bans(params[3]); - Anope::string token; - - while (bans.GetToken(token)) - c->SetModeInternal(source, mode, token); - } + spacesepstream bans(params[3]); + Anope::string token; + while (bans.GetToken(token)) + c->SetModeInternal(source, mode, token); } -}; +} -struct IRCDMessageEOB : IRCDMessage +void hybrid::EOB::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageEOB(Module *craetor) : IRCDMessage(craetor, "EOB", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->Sync(true); - } -}; + source.GetServer()->Sync(true); +} -struct IRCDMessageJoin : Message::Join +void hybrid::Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { } + if (params.size() < 2) + return; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params.size() < 2) - return; + std::vector<Anope::string> p = params; + p.erase(p.begin()); - std::vector<Anope::string> p = params; - p.erase(p.begin()); - - return Message::Join::Run(source, p); - } -}; + return Message::Join::Run(source, p); +} -struct IRCDMessageNick : IRCDMessage +/* 0 1 */ +/* :0MCAAAAAB NICK newnick 1350157102 */ +void hybrid::Nick::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - /* 0 1 */ - /* :0MCAAAAAB NICK newnick 1350157102 */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1])); - } -}; + source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1])); +} struct IRCDMessagePass : IRCDMessage { @@ -377,207 +382,158 @@ struct IRCDMessagePass : IRCDMessage /* 0 1 2 3 */ /* PASS password TS 6 0MC */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { UplinkSID = params[3]; } }; -struct IRCDMessagePong : IRCDMessage +void hybrid::Pong::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + source.GetServer()->Sync(false); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->Sync(false); - } -}; - -struct IRCDMessageServer : IRCDMessage +/* 0 1 2 */ +/* SERVER hades.arpa 1 :ircd-hybrid test server */ +void hybrid::Server::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + /* Servers other than our immediate uplink are introduced via SID */ + if (params[1] != "1") + return; - /* 0 1 2 */ - /* SERVER hades.arpa 1 :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* Servers other than our immediate uplink are introduced via SID */ - if (params[1] != "1") - return; + new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); + IRCD->SendPing(Me->GetName(), params[0]); +} - IRCD->SendPing(Me->GetName(), params[0]); - } -}; - -struct IRCDMessageSID : IRCDMessage +void hybrid::SID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - /* 0 1 2 3 */ - /* :0MC SID hades.arpa 2 4XY :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); + unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; + new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); - IRCD->SendPing(Me->GetName(), params[0]); - } -}; + IRCD->SendPing(Me->GetName(), params[0]); +} -struct IRCDMessageSJoin : IRCDMessage +void hybrid::SJoin::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string modes; - - if (params.size() >= 3) - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; + Anope::string modes; + if (params.size() >= 3) + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); - if (!modes.empty()) - modes.erase(modes.begin()); + std::list<Message::Join::SJoinUser> users; - std::list<Message::Join::SJoinUser> users; + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; + while (sep.GetToken(buf)) + { + Message::Join::SJoinUser sju; - while (sep.GetToken(buf)) + /* Get prefixes from the nick */ + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { - Message::Join::SJoinUser sju; - - /* Get prefixes from the nick */ - for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) - { - buf.erase(buf.begin()); - sju.first.AddMode(ch); - } - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; - continue; - } + buf.erase(buf.begin()); + sju.first.AddMode(ch); + } - users.push_back(sju); + sju.second = User::Find(buf); + if (!sju.second) + { + Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; + continue; } - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; - Message::Join::SJoin(source, params[1], ts, modes, users); + users.push_back(sju); } -}; -struct IRCDMessageSVSMode : IRCDMessage -{ - IRCDMessageSVSMode(Module *creator) : IRCDMessage(creator, "SVSMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; + Message::Join::SJoin(source, params[1], ts, modes, users); +} - /* - * parv[0] = nickname - * parv[1] = TS - * parv[2] = mode - * parv[3] = optional argument (services id) - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - - if (!u) - return; +/* + * parv[0] = nickname + * parv[1] = TS + * parv[2] = mode + * parv[3] = optional argument (services id) + */ +void hybrid::SVSMode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = User::Find(params[0]); + if (!u) + return; - if (!params[1].is_pos_number_only() || convertTo<time_t>(params[1]) != u->timestamp) - return; + if (!params[1].is_pos_number_only() || convertTo<time_t>(params[1]) != u->timestamp) + return; - u->SetModesInternal(source, "%s", params[2].c_str()); - } -}; + u->SetModesInternal(source, "%s", params[2].c_str()); +} -struct IRCDMessageTBurst : IRCDMessage +void hybrid::TBurst::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TBURST", 5) { } + Anope::string setter; + sepstream(params[3], '!').GetToken(setter, 0); + time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; + Channel *c = Channel::Find(params[1]); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string setter; - sepstream(params[3], '!').GetToken(setter, 0); - time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; - Channel *c = Channel::Find(params[1]); + if (c) + c->ChangeTopicInternal(NULL, setter, params[4], topic_time); +} - if (c) - c->ChangeTopicInternal(NULL, setter, params[4], topic_time); - } -}; - -struct IRCDMessageTMode : IRCDMessage +void hybrid::TMode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageTMode(Module *creator) : IRCDMessage(creator, "TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + time_t ts = 0; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + try { - time_t ts = 0; - - try - { - ts = convertTo<time_t>(params[0]); - } - catch (const ConvertException &) { } + ts = convertTo<time_t>(params[0]); + } + catch (const ConvertException &) { } - Channel *c = Channel::Find(params[1]); - Anope::string modes = params[2]; + Channel *c = Channel::Find(params[1]); + Anope::string modes = params[2]; - for (unsigned i = 3; i < params.size(); ++i) - modes += " " + params[i]; + for (unsigned i = 3; i < params.size(); ++i) + modes += " " + params[i]; - if (c) - c->SetModesInternal(source, modes, ts); - } -}; + if (c) + c->SetModesInternal(source, modes, ts); +} -struct IRCDMessageUID : IRCDMessage +/* 0 1 2 3 4 5 6 7 8 9 */ +/* :0MC UID Steve 1 1350157102 +oi ~steve resolved.host 10.0.0.1 0MCAAAAAB Steve :Mining all the time */ +void hybrid::UID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 10) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - /* 0 1 2 3 4 5 6 7 8 9 */ - /* :0MC UID Steve 1 1350157102 +oi ~steve resolved.host 10.0.0.1 0MCAAAAAB Steve :Mining all the time */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string ip = params[6]; + Anope::string ip = params[6]; - if (ip == "0") /* Can be 0 for spoofed clients */ - ip.clear(); + if (ip == "0") /* Can be 0 for spoofed clients */ + ip.clear(); - NickAlias *na = NULL; - if (params[8] != "0" && params[8] != "*") - na = NickAlias::Find(params[8]); + NickServ::Nick *na = NULL; + if (params[8] != "0" && params[8] != "*") + na = NickServ::FindNick(params[8]); - /* Source is always the server */ - User::OnIntroduce(params[0], params[4], params[5], "", - ip, source.GetServer(), - params[9], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, - params[3], params[7], na ? *na->nc : NULL); - } -}; + /* Source is always the server */ + User::OnIntroduce(params[0], params[4], params[5], "", + ip, source.GetServer(), + params[9], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, + params[3], params[7], na ? na->GetAccount() : NULL); +} -struct IRCDMessageCertFP: IRCDMessage +/* 0 */ +/* :0MCAAAAAB CERTFP 4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */ +void hybrid::CertFP::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageCertFP(Module *creator) : IRCDMessage(creator, "CERTFP", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + User *u = source.GetUser(); - /* 0 */ - /* :0MCAAAAAB CERTFP 4C62287BA6776A89CD4F8FF10A62FFB35E79319F51AF6C62C674984974FCCB1D */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = source.GetUser(); - - u->fingerprint = params[0]; - FOREACH_MOD(OnFingerprint, (u)); - } -}; + u->fingerprint = params[0]; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); +} class ProtoHybrid : public Module + , public EventHook<Event::UserNickChange> { HybridProto ircd_proto; @@ -603,90 +559,62 @@ class ProtoHybrid : public Module Message::Whois message_whois; /* Our message handlers */ - IRCDMessageBMask message_bmask; - IRCDMessageEOB message_eob; - IRCDMessageJoin message_join; - IRCDMessageNick message_nick; + hybrid::CertFP message_certfp; + hybrid::BMask message_bmask; + hybrid::EOB message_eob; + hybrid::Join message_join; + hybrid::Nick message_nick; IRCDMessagePass message_pass; - IRCDMessagePong message_pong; - IRCDMessageServer message_server; - IRCDMessageSID message_sid; - IRCDMessageSJoin message_sjoin; - IRCDMessageSVSMode message_svsmode; - IRCDMessageTBurst message_tburst; - IRCDMessageTMode message_tmode; - IRCDMessageUID message_uid; - IRCDMessageCertFP message_certfp; - - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserModeOperOnly("CALLERID", 'g')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("LOCOPS", 'l')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserMode("HIDECHANS", 'p')); - ModeManager::AddUserMode(new UserMode("HIDEIDLE", 'q')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - ModeManager::AddUserMode(new UserMode("DEAF", 'D')); - ModeManager::AddUserMode(new UserMode("SOFTCALLERID", 'G')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'S')); - ModeManager::AddUserMode(new UserModeNoone("WEBIRC", 'W')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - - /* v/h/o */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - - /* l/k */ - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - ModeManager::AddChannelMode(new ChannelMode("SSL", 'S')); - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T')); - } + hybrid::Pong message_pong; + hybrid::Server message_server; + hybrid::SID message_sid; + hybrid::SJoin message_sjoin; + hybrid::SVSMode message_svsmode; + hybrid::TBurst message_tburst; + hybrid::TMode message_tmode; + hybrid::UID message_uid; public: - ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - message_bmask(this), message_eob(this), message_join(this), - message_nick(this), message_pass(this), message_pong(this), message_server(this), message_sid(this), - message_sjoin(this), message_svsmode(this), message_tburst(this), message_tmode(this), message_uid(this), - message_certfp(this) - { - if (Config->GetModule(this)) - this->AddModes(); - } - - void OnUserNickChange(User *u, const Anope::string &) anope_override + ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + , message_bmask(this) + , message_eob(this) + , message_join(this) + , message_nick(this) + , message_pass(this) + , message_pong(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_svsmode(this) + , message_tburst(this) + , message_tmode(this) + , message_uid(this) + , message_certfp(this) + { + } + + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); } diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp deleted file mode 100644 index b8d846d5f..000000000 --- a/modules/protocol/inspircd12.cpp +++ /dev/null @@ -1,1383 +0,0 @@ -/* inspircd 1.2 functions - * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -#include "module.h" -#include "modules/sasl.h" - -struct SASLUser -{ - Anope::string uid; - Anope::string acc; - time_t created; -}; - -static std::list<SASLUser> saslusers; - -static Anope::string rsquit_server, rsquit_id; - -class ChannelModeFlood : public ChannelModeParam -{ - public: - ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { } - - bool IsValid(Anope::string &value) const anope_override - { - try - { - 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; - } - catch (const ConvertException &) { } - - return false; - } -}; - -class InspIRCd12Proto : public IRCDProto -{ - private: - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override - { - IRCDProto::SendSVSKillInternal(source, user, buf); - user->KillInternal(source, buf); - } - - void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) - { - if (!Servers::Capab.count("CHGIDENT")) - Log() << "CHGIDENT not loaded!"; - else - UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent; - } - - void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) - { - if (!Servers::Capab.count("CHGHOST")) - Log() << "CHGHOST not loaded!"; - else - UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost; - } - - void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) - { - UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason; - } - - void SendDelLine(const Anope::string &xtype, const Anope::string &mask) - { - UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask; - } - - public: - InspIRCd12Proto(Module *creator) : IRCDProto(creator, "InspIRCd 1.2") - { - DefaultPseudoclientModes = "+I"; - CanSVSNick = true; - CanSVSJoin = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanCertFP = true; - RequiresID = true; - MaxModes = 20; - } - - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; - } - - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; - } - - void SendAkillDel(const XLine *x) anope_override - { - /* InspIRCd may support regex bans */ - if (x->IsRegex() && Servers::Capab.count("RLINE")) - { - Anope::string mask = x->mask; - size_t h = x->mask.find('#'); - if (h != Anope::string::npos) - mask = mask.replace(h, 1, ' '); - SendDelLine("R", mask); - return; - } - else if (x->IsRegex() || x->HasNickOrReal()) - return; - - /* ZLine if we can instead */ - if (x->GetUser() == "*") - { - cidr addr(x->GetHost()); - if (addr.valid()) - { - IRCD->SendSZLineDel(x); - return; - } - } - - SendDelLine("G", x->GetUser() + "@" + x->GetHost()); - } - - void SendTopic(const MessageSource &source, Channel *c) anope_override - { - if (Servers::Capab.count("SVSTOPIC")) - { - UplinkSocket::Message(c->ci->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; - } - else - { - /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */ - time_t ts = c->topic_ts; - if (c->topic_time > ts) - ts = Anope::CurTime; - /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ - UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic; - } - } - - void SendVhostDel(User *u) anope_override - { - if (u->HasMode("CLOAK")) - this->SendChgHostInternal(u->nick, u->chost); - else - this->SendChgHostInternal(u->nick, u->host); - - if (Servers::Capab.count("CHGIDENT") && u->GetIdent() != u->GetVIdent()) - this->SendChgIdentInternal(u->nick, u->GetIdent()); - } - - void SendAkill(User *u, XLine *x) anope_override - { - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - - /* InspIRCd may support regex bans, if they do we can send this and forget about it */ - if (x->IsRegex() && Servers::Capab.count("RLINE")) - { - Anope::string mask = x->mask; - size_t h = x->mask.find('#'); - if (h != Anope::string::npos) - mask = mask.replace(h, 1, ' '); - SendAddLine("R", mask, timeleft, x->by, x->GetReason()); - return; - } - else if (x->IsRegex() || x->HasNickOrReal()) - { - if (!u) - { - /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); - return; - } - - const XLine *old = x; - - if (old->manager->HasEntry("*@" + u->host)) - return; - - /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - old->manager->AddXLine(x); - - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; - } - - /* ZLine if we can instead */ - if (x->GetUser() == "*") - { - cidr addr(x->GetHost()); - if (addr.valid()) - { - IRCD->SendSZLine(u, x); - return; - } - } - - SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason()); - } - - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override - { - User *u = User::Find(dest); - UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << (u ? u->nick : dest) << " " << buf; - } - - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; - } - - void SendClientIntroduction(User *u) anope_override - { - Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname; - if (modes.find('o') != Anope::string::npos) - UplinkSocket::Message(u) << "OPERTYPE :services"; - } - - /* SERVER services-dev.chatspike.net password 0 :Description here */ - void SendServer(const Server *server) anope_override - { - /* if rsquit is set then we are waiting on a squit */ - if (rsquit_id.empty() && rsquit_server.empty()) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); - } - - void SendSquit(Server *s, const Anope::string &message) anope_override - { - if (s != Me) - { - rsquit_id = s->GetSID(); - rsquit_server = s->GetName(); - UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message; - } - else - UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message; - } - - /* JOIN */ - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override - { - UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID(); - /* Note that we can send this with the FJOIN but choose not to - * because the mode stacker will handle this and probably will - * merge these modes with +nrt and other mlocked modes - */ - if (status) - { - /* First save the channel status incase uc->Status == status */ - ChannelStatus cs = *status; - /* If the user is internally on the channel with flags, kill them so that - * the stacker will allow this. - */ - ChanUserContainer *uc = c->FindUser(user); - if (uc != NULL) - uc->status.Clear(); - - BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); - - if (uc != NULL) - uc->status = cs; - } - } - - /* UNSQLINE */ - void SendSQLineDel(const XLine *x) anope_override - { - SendDelLine("Q", x->mask); - } - - /* SQLINE */ - void SendSQLine(User *, const XLine *x) anope_override - { - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - SendAddLine("Q", x->mask, timeleft, x->by, x->GetReason()); - } - - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override - { - if (!vIdent.empty()) - this->SendChgIdentInternal(u->nick, vIdent); - if (!vhost.empty()) - this->SendChgHostInternal(u->nick, vhost); - } - - void SendConnect() anope_override - { - SendServer(Me); - } - - /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick, time_t t) anope_override - { - UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user"; - } - - /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override - { - UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick; - } - - /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override - { - SendDelLine("Z", x->GetHost()); - } - - /* SZLINE */ - void SendSZLine(User *, const XLine *x) anope_override - { - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - SendAddLine("Z", x->GetHost(), timeleft, x->by, x->GetReason()); - } - - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) anope_override - { - UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; - } - - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override - { - if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; - else - UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; - } - - void SendSWhois(const MessageSource &, const Anope::string &who, const Anope::string &mask) anope_override - { - User *u = User::Find(who); - - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask; - } - - void SendBOB() anope_override - { - UplinkSocket::Message(Me) << "BURST " << Anope::CurTime; - Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString(); - } - - void SendEOB() anope_override - { - UplinkSocket::Message(Me) << "ENDBURST"; - } - - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override - { - if (Servers::Capab.count("GLOBOPS")) - UplinkSocket::Message(source) << "SNONOTICE g :" << buf; - else - UplinkSocket::Message(source) << "SNONOTICE A :" << buf; - } - - void SendLogin(User *u, NickAlias *na) anope_override - { - /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ - if (na->nc->HasExt("UNCONFIRMED")) - return; - - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display; - } - - void SendLogout(User *u) anope_override - { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; - } - - void SendChannel(Channel *c) anope_override - { - UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :"; - } - - void SendOper(User *u) anope_override - { - } - - void SendSASLMessage(const SASL::Message &message) anope_override - { - UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext)); - } - - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override - { - UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc; - - SASLUser su; - su.uid = uid; - su.acc = acc; - su.created = Anope::CurTime; - - for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) - { - SASLUser &u = *it; - - if (u.created + 30 < Anope::CurTime || u.uid == uid) - it = saslusers.erase(it); - else - ++it; - } - - saslusers.push_back(su); - } - - bool IsExtbanValid(const Anope::string &mask) anope_override - { - return mask.length() >= 3 && mask[1] == ':'; - } - - bool IsIdentValid(const Anope::string &ident) anope_override - { - if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) - return false; - - for (unsigned i = 0; i < ident.length(); ++i) - { - const char &c = ident[i]; - - if (c >= 'A' && c <= '}') - continue; - - if ((c >= '0' && c <= '9') || c == '-' || c == '.') - continue; - - return false; - } - - return true; - } -}; - -class InspIRCdExtBan : public ChannelModeList -{ - public: - InspIRCdExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - - if (mask.find("m:") == 0 || mask.find("N:") == 0) - { - Anope::string real_mask = mask.substr(2); - - Entry en(this->name, real_mask); - if (en.Matches(u)) - return true; - } - else if (mask.find("j:") == 0) - { - Anope::string real_mask = mask.substr(2); - - Channel *c = Channel::Find(real_mask); - if (c != NULL && c->FindUser(u) != NULL) - return true; - } - else if (mask.find("M:") == 0 || mask.find("R:") == 0) - { - Anope::string real_mask = mask.substr(2); - - if (u->IsIdentified() && real_mask.equals_ci(u->Account()->display)) - return true; - } - else if (mask.find("r:") == 0) - { - Anope::string real_mask = mask.substr(2); - - if (Anope::Match(u->realname, real_mask)) - return true; - } - else if (mask.find("s:") == 0) - { - Anope::string real_mask = mask.substr(2); - - if (Anope::Match(u->server->GetName(), real_mask)) - return true; - } - - return false; - } -}; - -struct IRCDMessageCapab : Message::Capab -{ - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params[0].equals_cs("START")) - { - /* reset CAPAB */ - Servers::Capab.clear(); - Servers::Capab.insert("NOQUIT"); - IRCD->CanSVSHold = false; - } - else if (params[0].equals_cs("MODULES") && params.size() > 1) - { - if (params[1].find("m_globops.so") != Anope::string::npos) - Servers::Capab.insert("GLOBOPS"); - if (params[1].find("m_services_account.so") != Anope::string::npos) - Servers::Capab.insert("SERVICES"); - if (params[1].find("m_svshold.so") != Anope::string::npos) - IRCD->CanSVSHold = true; - if (params[1].find("m_chghost.so") != Anope::string::npos) - Servers::Capab.insert("CHGHOST"); - if (params[1].find("m_chgident.so") != Anope::string::npos) - Servers::Capab.insert("CHGIDENT"); - if (params[1].find("m_hidechans.so") != Anope::string::npos) - Servers::Capab.insert("HIDECHANS"); - if (params[1].find("m_servprotect.so") != Anope::string::npos) - IRCD->DefaultPseudoclientModes = "+Ik"; - if (params[1].find("m_rline.so") != Anope::string::npos) - Servers::Capab.insert("RLINE"); - } - else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string capab; - while (ssep.GetToken(capab)) - { - if (capab.find("CHANMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'b': - ModeManager::AddChannelMode(new InspIRCdExtBan("BAN", 'b')); - continue; - case 'e': - ModeManager::AddChannelMode(new InspIRCdExtBan("EXCEPT", 'e')); - continue; - case 'I': - ModeManager::AddChannelMode(new InspIRCdExtBan("INVITEOVERRIDE", 'I')); - continue; - /* InspIRCd sends q and a here if they have no prefixes */ - case 'q': - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '@', 4)); - continue; - case 'a': - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT" , 'a', '@', 3)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'k': - ModeManager::AddChannelMode(new ChannelModeKey('k')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'F': - ModeManager::AddChannelMode(new ChannelModeParam("NICKFLOOD", 'F', true)); - continue; - case 'J': - ModeManager::AddChannelMode(new ChannelModeParam("NOREJOIN", 'J', true)); - continue; - case 'L': - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L', true)); - continue; - case 'f': - ModeManager::AddChannelMode(new ChannelModeFlood('f', true)); - continue; - case 'j': - ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true)); - continue; - case 'l': - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true)); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'A': - ModeManager::AddChannelMode(new ChannelMode("ALLINVITE", 'A')); - continue; - case 'B': - ModeManager::AddChannelMode(new ChannelMode("BLOCKCAPS", 'B')); - continue; - case 'C': - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - continue; - case 'D': - ModeManager::AddChannelMode(new ChannelMode("DELAYEDJOIN", 'D')); - continue; - case 'G': - ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G')); - continue; - case 'K': - ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K')); - continue; - case 'M': - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - continue; - case 'N': - ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N')); - continue; - case 'O': - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - continue; - case 'P': - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - continue; - case 'Q': - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - continue; - case 'R': - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - continue; - case 'S': - ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S')); - continue; - case 'T': - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T')); - continue; - case 'c': - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - continue; - case 'i': - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - continue; - case 'm': - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - continue; - case 'n': - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - continue; - case 'p': - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - continue; - case 'r': - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - continue; - case 's': - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - continue; - case 't': - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - continue; - case 'u': - ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u')); - continue; - case 'z': - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - continue; - default: - ModeManager::AddChannelMode(new ChannelMode("", modebuf[t])); - } - } - } - else if (capab.find("USERMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - while (sep.GetToken(modebuf)) - { - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'h': - ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h')); - continue; - case 'B': - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - continue; - case 'G': - ModeManager::AddUserMode(new UserMode("CENSOR", 'G')); - continue; - case 'H': - ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H')); - continue; - case 'I': - ModeManager::AddUserMode(new UserMode("PRIV", 'I')); - continue; - case 'Q': - ModeManager::AddUserMode(new UserModeOperOnly("HIDDEN", 'Q')); - continue; - case 'R': - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - continue; - case 'S': - ModeManager::AddUserMode(new UserMode("STRIPCOLOR", 'S')); - continue; - case 'W': - ModeManager::AddUserMode(new UserMode("WHOIS", 'W')); - continue; - case 'c': - ModeManager::AddUserMode(new UserMode("COMMONCHANS", 'c')); - continue; - case 'g': - ModeManager::AddUserMode(new UserMode("CALLERID", 'g')); - continue; - case 'i': - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - continue; - case 'k': - ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'k')); - continue; - case 'o': - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - continue; - case 'r': - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - continue; - case 'w': - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - continue; - case 'x': - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - continue; - case 'd': - ModeManager::AddUserMode(new UserMode("DEAF", 'd')); - continue; - default: - ModeManager::AddUserMode(new UserMode("", modebuf[t])); - } - } - } - } - else if (capab.find("PREFIX=(") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')')); - Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end()); - unsigned short level = modes.length() - 1; - - for (size_t t = 0, end = modes.length(); t < end; ++t) - { - switch (modes[t]) - { - case 'q': - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', chars[t], level--)); - continue; - case 'a': - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', chars[t], level--)); - continue; - case 'o': - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', chars[t], level--)); - continue; - case 'h': - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', chars[t], level--)); - continue; - case 'v': - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', chars[t], level--)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeStatus("", modes[t], chars[t], level--)); - } - } - - ModeManager::RebuildStatusModes(); - } - else if (capab.find("MAXMODES=") != Anope::string::npos) - { - Anope::string maxmodes(capab.begin() + 9, capab.end()); - IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; - } - } - } - else if (params[0].equals_cs("END")) - { - if (!Servers::Capab.count("GLOBOPS")) - { - UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope"; - Anope::QuitReason = "Remote server does not have the m_globops module loaded, and this is required."; - Anope::Quitting = true; - return; - } - if (!Servers::Capab.count("SERVICES")) - { - UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; - Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; - Anope::Quitting = true; - return; - } - if (!Servers::Capab.count("HIDECHANS")) - { - UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; - Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; - Anope::Quitting = true; - return; - } - if (!IRCD->CanSVSHold) - Log() << "SVSHOLD missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGHOST")) - Log() << "CHGHOST missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGIDENT")) - Log() << "CHGIDENT missing, Usage disabled until module is loaded."; - } - - Message::Capab::Run(source, params); - } -}; - -struct IRCDMessageChgIdent : IRCDMessage -{ - IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetIdent(params[1]); - } -}; - -struct IRCDMessageChgName : IRCDMessage -{ - IRCDMessageChgName(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetRealname(params[0]); - } -}; - -struct IRCDMessageEncap : IRCDMessage -{ - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (Anope::Match(Me->GetSID(), params[0]) == false) - return; - - if (SASL::sasl && params[1] == "SASL" && params.size() >= 6) - { - SASL::Message m; - m.source = params[2]; - m.target = params[3]; - m.type = params[4]; - m.data = params[5]; - m.ext = params.size() > 6 ? params[6] : ""; - - SASL::sasl->ProcessMessage(m); - } - } -}; - -struct IRCDMessageEndburst : IRCDMessage -{ - IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Server *s = source.GetServer(); - - Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName(); - - s->Sync(true); - } -}; - -struct IRCDMessageFHost : IRCDMessage -{ - IRCDMessageFHost(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetDisplayedHost(params[0]); - } -}; - -struct IRCDMessageFJoin : IRCDMessage -{ - IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string modes; - if (params.size() >= 3) - { - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - } - - std::list<Message::Join::SJoinUser> users; - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) - { - Message::Join::SJoinUser sju; - - /* Loop through prefixes and find modes for them */ - for (char c; (c = buf[0]) != ',' && c;) - { - buf.erase(buf.begin()); - sju.first.AddMode(c); - } - /* Erase the , */ - if (!buf.empty()) - buf.erase(buf.begin()); - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "FJOIN for non-existent user " << buf << " on " << params[0]; - continue; - } - - users.push_back(sju); - } - - time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; - Message::Join::SJoin(source, params[0], ts, modes, users); - } -}; - -struct IRCDMessageFMode : IRCDMessage -{ - IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :source FMODE #test 12345678 +nto foo */ - - Anope::string modes = params[2]; - for (unsigned n = 3; n < params.size(); ++n) - modes += " " + params[n]; - - Channel *c = Channel::Find(params[0]); - time_t ts; - - try - { - ts = convertTo<time_t>(params[1]); - } - catch (const ConvertException &) - { - ts = 0; - } - - if (c) - c->SetModesInternal(source, modes, ts); - } -}; - -struct IRCDMessageFTopic : IRCDMessage -{ - IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :source FTOPIC channel topicts setby :topic */ - - Channel *c = Channel::Find(params[0]); - if (c) - c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); - } -}; - -struct IRCDMessageIdle : IRCDMessage -{ - IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - BotInfo *bi = BotInfo::Find(params[0]); - if (bi) - UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg); - else - { - User *u = User::Find(params[0]); - if (u && u->server == Me) - UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0"; - } - } -}; - -/* - * source = numeric of the sending server - * params[0] = uuid - * params[1] = metadata name - * params[2] = data - */ -struct IRCDMessageMetadata : IRCDMessage -{ - IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (isdigit(params[0][0])) - { - if (params[1].equals_cs("accountname")) - { - User *u = User::Find(params[0]); - NickCore *nc = NickCore::Find(params[2]); - if (u && nc) - u->Login(nc); - } - - /* - * possible incoming ssl_cert messages: - * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> - * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) - */ - else if (params[1].equals_cs("ssl_cert")) - { - User *u = User::Find(params[0]); - if (!u) - return; - u->Extend<bool>("ssl"); - Anope::string data = params[2].c_str(); - size_t pos1 = data.find(' ') + 1; - size_t pos2 = data.find(' ', pos1); - if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. - { - u->fingerprint = data.substr(pos1, pos2 - pos1); - } - FOREACH_MOD(OnFingerprint, (u)); - } - } - else if (params[0][0] == '#') - { - } - else if (params[0] == "*") - { - // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so - - if (params[1].equals_cs("modules") && !params[2].empty()) - { - // only interested when it comes from our uplink - Server* server = source.GetServer(); - if (!server || server->GetUplink() != Me) - return; - - bool plus = (params[2][0] == '+'); - if (!plus && params[2][0] != '-') - return; - - bool required = false; - Anope::string capab, module = params[2].substr(1); - - if (module.equals_cs("m_services_account.so")) - required = true; - else if (module.equals_cs("m_hidechans.so")) - required = true; - else if (module.equals_cs("m_chghost.so")) - capab = "CHGHOST"; - else if (module.equals_cs("m_chgident.so")) - capab = "CHGIDENT"; - else if (module.equals_cs("m_svshold.so")) - capab = "SVSHOLD"; - else if (module.equals_cs("m_rline.so")) - capab = "RLINE"; - else if (module.equals_cs("m_topiclock.so")) - capab = "TOPICLOCK"; - else - return; - - if (required) - { - if (!plus) - Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it"; - } - else - { - if (plus) - Servers::Capab.insert(capab); - else - Servers::Capab.erase(capab); - - Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality"; - } - - } - } - } -}; - -struct IRCDMessageMode : IRCDMessage -{ - IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (IRCD->IsChannelValid(params[0])) - { - Channel *c = Channel::Find(params[0]); - - Anope::string modes = params[1]; - for (unsigned n = 2; n < params.size(); ++n) - modes += " " + params[n]; - - if (c) - c->SetModesInternal(source, modes); - } - else - { - /* InspIRCd lets opers change another - users modes, we have to kludge this - as it slightly breaks RFC1459 - */ - User *u = source.GetUser(); - // This can happen with server-origin modes. - if (!u) - u = User::Find(params[0]); - // if it's still null, drop it like fire. - // most likely situation was that server introduced a nick which we subsequently akilled - if (u) - u->SetModesInternal(source, "%s", params[1].c_str()); - } - } -}; - -struct IRCDMessageNick : IRCDMessage -{ - IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->ChangeNick(params[0]); - } -}; - -struct IRCDMessageOperType : IRCDMessage -{ - IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* opertype is equivalent to mode +o because servers - don't do this directly */ - User *u = source.GetUser(); - if (!u->HasMode("OPER")) - u->SetModesInternal(source, "+o"); - } -}; - -struct IRCDMessageRSQuit : IRCDMessage -{ - IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Server *s = Server::Find(params[0]); - const Anope::string &reason = params.size() > 1 ? params[1] : ""; - if (!s) - return; - - UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason; - s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); - } -}; - -struct IRCDMessageSetIdent : IRCDMessage -{ - IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetIdent(params[0]); - } -}; - -struct IRCDMessageServer : IRCDMessage -{ - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - /* - * [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central! - * 0: name - * 1: pass - * 2: hops - * 3: numeric - * 4: desc - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]); - } -}; - -struct IRCDMessageSQuit : Message::SQuit -{ - IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params[0] == rsquit_id || params[0] == rsquit_server) - { - /* squit for a recently squit server, introduce the juped server now */ - Server *s = Server::Find(rsquit_server); - - rsquit_id.clear(); - rsquit_server.clear(); - - if (s && s->IsJuped()) - IRCD->SendServer(s); - } - else - Message::SQuit::Run(source, params); - } -}; - -struct IRCDMessageTime : IRCDMessage -{ - IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; - } -}; - -struct IRCDMessageUID : IRCDMessage -{ - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - /* - * [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org> - * 0: uid - * 1: ts - * 2: nick - * 3: host - * 4: dhost - * 5: ident - * 6: ip - * 7: signon - * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname! - * last: realname - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - time_t ts = convertTo<time_t>(params[1]); - - Anope::string modes = params[8]; - for (unsigned i = 9; i < params.size() - 1; ++i) - modes += " " + params[i]; - - NickAlias *na = NULL; - if (SASL::sasl) - for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) - { - SASLUser &u = *it; - - if (u.created + 30 < Anope::CurTime) - it = saslusers.erase(it); - else if (u.uid == params[0]) - { - na = NickAlias::Find(u.acc); - it = saslusers.erase(it); - } - else - ++it; - } - - User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL); - if (u) - u->signon = convertTo<time_t>(params[7]); - } -}; - -class ProtoInspIRCd12 : public Module -{ - InspIRCd12Proto ircd_proto; - ExtensibleItem<bool> ssl; - - /* Core message handlers */ - Message::Away message_away; - Message::Error message_error; - Message::Invite message_invite; - Message::Join message_join; - Message::Kick message_kick; - Message::Kill message_kill; - Message::MOTD message_motd; - Message::Notice message_notice; - Message::Part message_part; - Message::Ping message_ping; - Message::Privmsg message_privmsg; - Message::Quit message_quit; - Message::Stats message_stats; - Message::Topic message_topic; - - /* Our message handlers */ - IRCDMessageChgIdent message_chgident; - IRCDMessageChgName message_setname, message_chgname; - IRCDMessageCapab message_capab; - IRCDMessageEncap message_encap; - IRCDMessageEndburst message_endburst; - IRCDMessageFHost message_fhost, message_sethost; - IRCDMessageFJoin message_fjoin; - IRCDMessageFMode message_fmode; - IRCDMessageFTopic message_ftopic; - IRCDMessageIdle message_idle; - IRCDMessageMetadata message_metadata; - IRCDMessageMode message_mode; - IRCDMessageNick message_nick; - IRCDMessageOperType message_opertype; - IRCDMessageRSQuit message_rsquit; - IRCDMessageSetIdent message_setident; - IRCDMessageServer message_server; - IRCDMessageSQuit message_squit; - IRCDMessageTime message_time; - IRCDMessageUID message_uid; - - public: - ProtoInspIRCd12(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), ssl(this, "ssl"), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), message_kill(this), - message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), - message_stats(this), message_topic(this), - - message_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_encap(this), - message_endburst(this), - message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), message_fjoin(this), message_fmode(this), message_ftopic(this), - message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this), - message_setident(this), message_server(this), message_squit(this), message_time(this), message_uid(this) - { - Servers::Capab.insert("NOQUIT"); - } - - void OnUserNickChange(User *u, const Anope::string &) anope_override - { - /* 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. - * - * Do not set -r if we don't have a NickServ loaded - DP - */ - BotInfo *NickServ = Config->GetClient("NickServ"); - if (NickServ) - u->RemoveMode(NickServ, "REGISTERED"); - } -}; - -MODULE_INIT(ProtoInspIRCd12) diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 859bc667f..f8bf9b30e 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -1,23 +1,73 @@ -/* Inspircd 2.0 functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2005-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" -#include "modules/cs_mode.h" +#include "modules/sasl.h" +#include "modules/chanserv/mode.h" +#include "modules/chanserv/set.h" -static unsigned int spanningtree_proto_ver = 0; +struct SASLUser +{ + Anope::string uid; + Anope::string acc; + time_t created; +}; -static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12"); +static std::list<SASLUser> saslusers; +static Anope::string rsquit_server, rsquit_id; +static unsigned int spanningtree_proto_ver = 0; class InspIRCd20Proto : public IRCDProto { + private: + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override + { + IRCDProto::SendSVSKillInternal(source, user, buf); + user->KillInternal(source, buf); + } + + void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) + { + if (!Servers::Capab.count("CHGIDENT")) + Log() << "CHGIDENT not loaded!"; + else + Uplink::Send(Me, "CHGIDENT", nick, vIdent); + } + + void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) + { + if (!Servers::Capab.count("CHGHOST")) + Log() << "CHGHOST not loaded!"; + else + Uplink::Send(Me, "CHGHOST", nick, vhost); + } + + void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) + { + Uplink::Send(Me, "ADDLINE", xtype, mask, addedby, Anope::CurTime, duration, reason); + } + + void SendDelLine(const Anope::string &xtype, const Anope::string &mask) + { + Uplink::Send(Me, "DELLINE", xtype, mask); + } + public: InspIRCd20Proto(Module *creator) : IRCDProto(creator, "InspIRCd 2.0") { @@ -34,70 +84,390 @@ class InspIRCd20Proto : public IRCDProto MaxModes = 20; } - void SendConnect() anope_override + void SendConnect() override + { + Uplink::Send("CAPAB START 1202"); + Uplink::Send("CAPAB CAPABILITIES :PROTOCOL=1202"); + Uplink::Send("CAPAB END"); + SendServer(Me); + } + + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + { + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); + } + + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message() << "CAPAB START 1202"; - UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202"; - UplinkSocket::Message() << "CAPAB END"; - insp12->SendConnect(); + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } - void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override + void SendAkillDel(XLine *x) override + { + /* InspIRCd may support regex bans */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + SendDelLine("R", mask); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + return; + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->SendSZLineDel(x); + return; + } + } + + SendDelLine("G", x->GetUser() + "@" + x->GetHost()); + } + + void SendTopic(const MessageSource &source, Channel *c) override + { + if (Servers::Capab.count("SVSTOPIC")) + { + Uplink::Send(c->ci->WhoSends(), "SVSTOPIC", c->name, c->topic_ts, c->topic_setter, c->topic); + } + else + { + /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */ + time_t ts = c->topic_ts; + if (c->topic_time > ts) + ts = Anope::CurTime; + /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ + Uplink::Send(source, "FTOPIC", c->name, ts, c->topic_setter, c->topic); + } + } + + void SendVhostDel(User *u) override + { + if (u->HasMode("CLOAK")) + this->SendChgHostInternal(u->nick, u->chost); + else + this->SendChgHostInternal(u->nick, u->host); + + if (Servers::Capab.count("CHGIDENT") && u->GetIdent() != u->GetVIdent()) + this->SendChgIdentInternal(u->nick, u->GetIdent()); + } + + void SendAkill(User *u, XLine *x) override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + + /* InspIRCd may support regex bans, if they do we can send this and forget about it */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + SendAddLine("R", mask, timeleft, x->GetBy(), x->GetReason()); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + { + if (!u) + { + /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->GetManager()->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->GetManager()->HasEntry("*@" + u->host)) + return; + + /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ + x = Serialize::New<XLine *>(); + x->SetMask("*@" + u->host); + x->SetBy(old->GetBy()); + x->SetExpires(old->GetExpires()); + x->SetReason(old->GetReason()); + old->GetManager()->AddXLine(x); + + Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); + } + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->SendSZLine(u, x); + return; + } + } + + SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->GetBy(), x->GetReason()); + } + + void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) override + { + User *u = User::Find(dest); + Uplink::Send("PUSH", dest, ":" + Me->GetName() + " " + numeric + " " + (u ? u->nick : dest) + " " + buf); + } + + void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override + { + IRCMessage message(source, "FMODE", dest->name, dest->creation_time); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); + } + + void SendClientIntroduction(User *u) override + { + Anope::string modes = "+" + u->GetModes(); + Uplink::Send(Me, "UID", u->GetUID(), u->timestamp, u->nick, u->host, u->host, u->GetIdent(), "0.0.0.0", u->timestamp, modes, u->realname); + if (modes.find('o') != Anope::string::npos) + Uplink::Send(u, "OPERTYPE", "services"); + } + + /* SERVER services-dev.chatspike.net password 0 :Description here */ + void SendServer(const Server *server) override + { + /* if rsquit is set then we are waiting on a squit */ + if (rsquit_id.empty() && rsquit_server.empty()) + Uplink::Send("SERVER", server->GetName(), Config->Uplinks[Anope::CurrentUplink].password, server->GetHops(), server->GetSID(), server->GetDescription()); + } + + void SendSquit(Server *s, const Anope::string &message) override + { + if (s != Me) + { + rsquit_id = s->GetSID(); + rsquit_server = s->GetName(); + + Uplink::Send("RSQUIT", s->GetName(), message); + } + else + { + Uplink::Send("SQUIT", s->GetName(), message); + } + } + + /* JOIN */ + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override + { + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "," + user->GetUID()); + + /* Note that we can send this with the FJOIN but choose not to + * because the mode stacker will handle this and probably will + * merge these modes with +nrt and other mlocked modes + */ + if (status) + { + /* First save the channel status incase uc->Status == status */ + ChannelStatus cs = *status; + /* If the user is internally on the channel with flags, kill them so that + * the stacker will allow this. + */ + ChanUserContainer *uc = c->FindUser(user); + if (uc != NULL) + uc->status.Clear(); + + ServiceBot *setter = ServiceBot::Find(user->nick); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + + if (uc != NULL) + uc->status = cs; + } + } + + /* UNSQLINE */ + void SendSQLineDel(XLine *x) override + { + SendDelLine("Q", x->GetMask()); + } + + /* SQLINE */ + void SendSQLine(User *, XLine *x) override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + SendAddLine("Q", x->GetMask(), timeleft, x->GetBy(), x->GetReason()); + } + + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override + { + if (!vIdent.empty()) + this->SendChgIdentInternal(u->nick, vIdent); + if (!vhost.empty()) + this->SendChgHostInternal(u->nick, vhost); + } + + /* SVSHOLD - set */ + void SendSVSHold(const Anope::string &nick, time_t t) override + { + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick, t, "Being held for registered user"); + } + + /* SVSHOLD - release */ + void SendSVSHoldDel(const Anope::string &nick) override + { + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick); + } + + /* UNSZLINE */ + void SendSZLineDel(XLine *x) override + { + SendDelLine("Z", x->GetHost()); + } + + /* SZLINE */ + void SendSZLine(User *, XLine *x) override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + SendAddLine("Z", x->GetHost(), timeleft, x->GetBy(), x->GetReason()); + } + + void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &) override + { + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); + } + + void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) override + { + if (!param.empty()) + Uplink::Send(source, "SVSPART", u->GetUID(), chan, param); + else + Uplink::Send(source, "SVSPART", u->GetUID(), chan); + } + + void SendSWhois(const MessageSource &, const Anope::string &who, const Anope::string &mask) override + { + User *u = User::Find(who); + + Uplink::Send(Me, "METADATA", u->GetUID(), "swhois", mask); + } + + void SendBOB() override + { + Uplink::Send(Me, "BURST", Anope::CurTime); + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + Uplink::Send(Me, "VERSION", "Anope-" + Anope::Version() + " " + Me->GetName() + " :" + IRCD->GetProtocolName() + " - (" + (enc ? enc->name : "none") + ") -- " + Anope::VersionBuildString()); + } + + void SendEOB() override + { + Uplink::Send(Me, "ENDBURST"); + } + + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override + { + if (Servers::Capab.count("GLOBOPS")) + Uplink::Send(source, "SNONOTICE", "g", buf); + else + Uplink::Send(source, "SNONOTICE", "A", buf); + } + + void SendLogin(User *u, NickServ::Nick *na) override + { + /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ + if (na->GetAccount()->HasFieldS("UNCONFIRMED")) + return; + + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); + } + + void SendLogout(User *u) override + { + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); + } + + void SendChannel(Channel *c) override + { + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), ""); + } + + void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override { Anope::string mechlist; for (unsigned i = 0; i < mechanisms.size(); ++i) mechlist += "," + mechanisms[i]; - UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); - } - - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); } - void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); } - void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); }; - void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); } - void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); } - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); } - void SendClientIntroduction(User *u) anope_override { insp12->SendClientIntroduction(u); } - void SendServer(const Server *server) anope_override { insp12->SendServer(server); } - void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); } - void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); } - void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); } - void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); } - void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); } - void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); } - void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override { insp12->SendSVSPart(source, u, chan, param); } - void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); } - void SendBOB() anope_override { insp12->SendBOB(); } - void SendEOB() anope_override { insp12->SendEOB(); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); } - void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); } - void SendLogout(User *u) anope_override { insp12->SendLogout(u); } - void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); } - void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendSVSLogin(uid, acc, vident, vhost); } - bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); } - bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); } -}; + Uplink::Send(Me, "METADATA", "*", "saslmechlist", mechlist.empty() ? "" : mechlist.substr(1)); + } -class InspIRCdAutoOpMode : public ChannelModeList -{ - public: - InspIRCdAutoOpMode(char mode) : ChannelModeList("AUTOOP", mode) + void SendSASLMessage(const SASL::Message &message) override { + if (!message.ext.empty()) + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data, message.ext); + else + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data); } - bool IsValid(Anope::string &mask) const anope_override + void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) override { - // We can not validate this because we don't know about the - // privileges of the setter so just reject attempts to set it. - return false; + Uplink::Send(Me, "METADATA", uid, "accountname", acc); + + SASLUser su; + su.uid = uid; + su.acc = acc; + su.created = Anope::CurTime; + + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) + { + SASLUser &u = *it; + + if (u.created + 30 < Anope::CurTime || u.uid == uid) + it = saslusers.erase(it); + else + ++it; + } + + saslusers.push_back(su); + } + + bool IsExtbanValid(const Anope::string &mask) override + { + return mask.length() >= 3 && mask[1] == ':'; + } + + bool IsIdentValid(const Anope::string &ident) override + { + if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) + return false; + + for (unsigned i = 0; i < ident.length(); ++i) + { + const char &c = ident[i]; + + if (c >= 'A' && c <= '}') + continue; + + if ((c >= '0' && c <= '9') || c == '-' || c == '.') + continue; + + return false; + } + + return true; } }; @@ -111,13 +481,13 @@ class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList> { } - ChannelMode *Wrap(Anope::string ¶m) anope_override + ChannelMode *Wrap(Anope::string ¶m) override { param = Anope::string(ext) + ":" + param; return ChannelModeVirtual<ChannelModeList>::Wrap(param); } - ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override + ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) override { if (cm->type != MODE_LIST || param.length() < 3 || param[0] != ext || param[1] != ':') return cm; @@ -136,7 +506,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); @@ -152,7 +522,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); @@ -188,12 +558,12 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); - return u->IsIdentified() && real_mask.equals_ci(u->Account()->display); + return u->IsIdentified() && real_mask.equals_ci(u->Account()->GetDisplay()); } }; @@ -204,7 +574,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -219,7 +589,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -227,14 +597,14 @@ namespace InspIRCdExtban } }; - class FinerprintMatcher : public InspIRCdExtBan + class FingerprintMatcher : public InspIRCdExtBan { public: - FinerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) + FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -249,7 +619,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -258,124 +628,11 @@ namespace InspIRCdExtban }; } -class ColonDelimitedParamMode : public ChannelModeParam -{ - public: - ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } - - bool IsValid(Anope::string &value) const anope_override - { - return IsValid(value, false); - } - - bool IsValid(const Anope::string &value, bool historymode) const - { - if (value.empty()) - return false; // empty param is never valid - - Anope::string::size_type pos = value.find(':'); - if ((pos == Anope::string::npos) || (pos == 0)) - return false; // no ':' or it's the first char, both are invalid - - Anope::string rest; - try - { - if (convertTo<int>(value, rest, false) <= 0) - return false; // negative numbers and zero are invalid - - rest = rest.substr(1); - int n; - if (historymode) - { - // For the history mode, the part after the ':' is a duration and it - // can be in the user friendly "1d3h20m" format, make sure we accept that - n = Anope::DoTime(rest); - } - else - n = convertTo<int>(rest); - - if (n <= 0) - return false; - } - catch (const ConvertException &e) - { - // conversion error, invalid - return false; - } - - return true; - } -}; - -class SimpleNumberParamMode : public ChannelModeParam -{ - public: - SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } - - bool IsValid(Anope::string &value) const anope_override - { - if (value.empty()) - return false; // empty param is never valid - - try - { - if (convertTo<int>(value) <= 0) - return false; - } - catch (const ConvertException &e) - { - // conversion error, invalid - return false; - } - - return true; - } -}; - -class ChannelModeFlood : public ColonDelimitedParamMode -{ - public: - ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { } - - bool IsValid(Anope::string &value) const anope_override - { - // The parameter of this mode is a bit different, it may begin with a '*', - // ignore it if that's the case - Anope::string v = value[0] == '*' ? value.substr(1) : value; - return ((!value.empty()) && (ColonDelimitedParamMode::IsValid(v))); - } -}; - -class ChannelModeHistory : public ColonDelimitedParamMode -{ - public: - ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { } - - bool IsValid(Anope::string &value) const anope_override - { - return (ColonDelimitedParamMode::IsValid(value, true)); - } -}; - -class ChannelModeRedirect : public ChannelModeParam -{ - public: - ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { } - - bool IsValid(Anope::string &value) const anope_override - { - // The parameter of this mode is a channel, and channel names start with '#' - return ((!value.empty()) && (value[0] == '#')); - } -}; - struct IRCDMessageCapab : Message::Capab { - std::map<char, Anope::string> chmodes, umodes; - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params[0].equals_cs("START")) { @@ -384,15 +641,13 @@ struct IRCDMessageCapab : Message::Capab if (spanningtree_proto_ver < 1202) { - UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; Anope::Quitting = true; return; } /* reset CAPAB */ - chmodes.clear(); - umodes.clear(); Servers::Capab.insert("SERVERS"); Servers::Capab.insert("CHGHOST"); Servers::Capab.insert("CHGIDENT"); @@ -406,132 +661,35 @@ struct IRCDMessageCapab : Message::Capab while (ssep.GetToken(capab)) { + if (capab.find('=') == Anope::string::npos) + continue; + Anope::string modename = capab.substr(0, capab.find('=')); Anope::string modechar = capab.substr(capab.find('=') + 1); - ChannelMode *cm = NULL; + char symbol = 0; - if (modename.equals_cs("admin")) - cm = new ChannelModeStatus("PROTECT", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 3); - else if (modename.equals_cs("allowinvite")) - { - cm = new ChannelMode("ALLINVITE", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("INVITEBAN", "BAN", 'A')); - } - else if (modename.equals_cs("auditorium")) - cm = new ChannelMode("AUDITORIUM", modechar[0]); - else if (modename.equals_cs("autoop")) - cm = new InspIRCdAutoOpMode(modechar[0]); - else if (modename.equals_cs("ban")) - cm = new ChannelModeList("BAN", modechar[0]); - else if (modename.equals_cs("banexception")) - cm = new ChannelModeList("EXCEPT", modechar[0]); - else if (modename.equals_cs("blockcaps")) - { - cm = new ChannelMode("BLOCKCAPS", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCAPSBAN", "BAN", 'B')); - } - else if (modename.equals_cs("blockcolor")) - { - cm = new ChannelMode("BLOCKCOLOR", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("BLOCKCOLORBAN", "BAN", 'c')); - } - else if (modename.equals_cs("c_registered")) - cm = new ChannelModeNoone("REGISTERED", modechar[0]); - else if (modename.equals_cs("censor")) - cm = new ChannelMode("CENSOR", modechar[0]); - else if (modename.equals_cs("delayjoin")) - cm = new ChannelMode("DELAYEDJOIN", modechar[0]); - else if (modename.equals_cs("delaymsg")) - cm = new SimpleNumberParamMode("DELAYMSG", modechar[0]); - else if (modename.equals_cs("filter")) - cm = new ChannelModeList("FILTER", modechar[0]); - else if (modename.equals_cs("flood")) - cm = new ChannelModeFlood(modechar[0]); - else if (modename.equals_cs("founder")) - cm = new ChannelModeStatus("OWNER", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 4); - else if (modename.equals_cs("halfop")) - cm = new ChannelModeStatus("HALFOP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 1); - else if (modename.equals_cs("history")) - cm = new ChannelModeHistory(modechar[0]); - else if (modename.equals_cs("invex")) - cm = new ChannelModeList("INVITEOVERRIDE", modechar[0]); - else if (modename.equals_cs("inviteonly")) - cm = new ChannelMode("INVITE", modechar[0]); - else if (modename.equals_cs("joinflood")) - cm = new ColonDelimitedParamMode("JOINFLOOD", modechar[0]); - else if (modename.equals_cs("key")) - cm = new ChannelModeKey(modechar[0]); - else if (modename.equals_cs("kicknorejoin")) - cm = new SimpleNumberParamMode("NOREJOIN", modechar[0]); - else if (modename.equals_cs("limit")) - cm = new ChannelModeParam("LIMIT", modechar[0], true); - else if (modename.equals_cs("moderated")) - cm = new ChannelMode("MODERATED", modechar[0]); - else if (modename.equals_cs("nickflood")) - cm = new ColonDelimitedParamMode("NICKFLOOD", modechar[0]); - else if (modename.equals_cs("noctcp")) - { - cm = new ChannelMode("NOCTCP", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOCTCPBAN", "BAN", 'C')); - } - else if (modename.equals_cs("noextmsg")) - cm = new ChannelMode("NOEXTERNAL", modechar[0]); - else if (modename.equals_cs("nokick")) - { - cm = new ChannelMode("NOKICK", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NOKICKBAN", "BAN", 'Q')); - } - else if (modename.equals_cs("noknock")) - cm = new ChannelMode("NOKNOCK", modechar[0]); - else if (modename.equals_cs("nonick")) - { - cm = new ChannelMode("NONICK", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONICKBAN", "BAN", 'N')); - } - else if (modename.equals_cs("nonotice")) + if (modechar.empty()) + continue; + + if (modechar.length() == 2) { - cm = new ChannelMode("NONOTICE", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("NONOTICEBAN", "BAN", 'T')); + symbol = modechar[0]; + modechar = modechar.substr(1); } - else if (modename.equals_cs("op")) - cm = new ChannelModeStatus("OP", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 2); - else if (modename.equals_cs("operonly")) - cm = new ChannelModeOperOnly("OPERONLY", modechar[0]); - else if (modename.equals_cs("permanent")) - cm = new ChannelMode("PERM", modechar[0]); - else if (modename.equals_cs("private")) - cm = new ChannelMode("PRIVATE", modechar[0]); - else if (modename.equals_cs("redirect")) - cm = new ChannelModeRedirect(modechar[0]); - else if (modename.equals_cs("reginvite")) - cm = new ChannelMode("REGISTEREDONLY", modechar[0]); - else if (modename.equals_cs("regmoderated")) - cm = new ChannelMode("REGMODERATED", modechar[0]); - else if (modename.equals_cs("secret")) - cm = new ChannelMode("SECRET", modechar[0]); - else if (modename.equals_cs("sslonly")) + + ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); + if (cm == nullptr) { - cm = new ChannelMode("SSL", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::FinerprintMatcher("SSLBAN", "BAN", 'z')); + Log(this->GetOwner()) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar; + continue; } - else if (modename.equals_cs("stripcolor")) + + char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast<ChannelModeStatus *>(cm))->symbol : 0; + if (symbol != modesymbol) { - cm = new ChannelMode("STRIPCOLOR", modechar[0]); - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("STRIPCOLORBAN", "BAN", 'S')); + Log(this->GetOwner()) << "Warning: Channel mode " << modename << " has a misconfigured status character"; + continue; } - else if (modename.equals_cs("topiclock")) - cm = new ChannelMode("TOPIC", modechar[0]); - else if (modename.equals_cs("voice")) - cm = new ChannelModeStatus("VOICE", modechar.length() > 1 ? modechar[1] : modechar[0], modechar.length() > 1 ? modechar[0] : 0, 0); - /* Unknown status mode, (customprefix) - add it */ - else if (modechar.length() == 2) - cm = new ChannelModeStatus(modename.upper(), modechar[1], modechar[0], -1); - /* Unknown non status mode, add it to our list for later */ - else - chmodes[modechar[0]] = modename.upper(); - - if (cm) - ModeManager::AddChannelMode(cm); } } if (params[0].equals_cs("USERMODES") && params.size() > 1) @@ -541,54 +699,21 @@ struct IRCDMessageCapab : Message::Capab while (ssep.GetToken(capab)) { + if (capab.find('=') == Anope::string::npos) + continue; + Anope::string modename = capab.substr(0, capab.find('=')); Anope::string modechar = capab.substr(capab.find('=') + 1); - UserMode *um = NULL; - - if (modename.equals_cs("bot")) - um = new UserMode("BOT", modechar[0]); - else if (modename.equals_cs("callerid")) - um = new UserMode("CALLERID", modechar[0]); - else if (modename.equals_cs("cloak")) - um = new UserMode("CLOAK", modechar[0]); - else if (modename.equals_cs("deaf")) - um = new UserMode("DEAF", modechar[0]); - else if (modename.equals_cs("deaf_commonchan")) - um = new UserMode("COMMONCHANS", modechar[0]); - else if (modename.equals_cs("helpop")) - um = new UserModeOperOnly("HELPOP", modechar[0]); - else if (modename.equals_cs("hidechans")) - um = new UserMode("PRIV", modechar[0]); - else if (modename.equals_cs("hideoper")) - um = new UserModeOperOnly("HIDEOPER", modechar[0]); - else if (modename.equals_cs("invisible")) - um = new UserMode("INVIS", modechar[0]); - else if (modename.equals_cs("invis-oper")) - um = new UserModeOperOnly("INVISIBLE_OPER", modechar[0]); - else if (modename.equals_cs("oper")) - um = new UserModeOperOnly("OPER", modechar[0]); - else if (modename.equals_cs("regdeaf")) - um = new UserMode("REGPRIV", modechar[0]); - else if (modename.equals_cs("servprotect")) + + if (modechar.empty()) + continue; + + UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); + if (um == nullptr) { - um = new UserModeNoone("PROTECTED", modechar[0]); - IRCD->DefaultPseudoclientModes += modechar; + Log(this->GetOwner()) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar; + continue; } - else if (modename.equals_cs("showwhois")) - um = new UserMode("WHOIS", modechar[0]); - else if (modename.equals_cs("u_censor")) - um = new UserMode("CENSOR", modechar[0]); - else if (modename.equals_cs("u_registered")) - um = new UserModeNoone("REGISTERED", modechar[0]); - else if (modename.equals_cs("u_stripcolor")) - um = new UserMode("STRIPCOLOR", modechar[0]); - else if (modename.equals_cs("wallops")) - um = new UserMode("WALLOPS", modechar[0]); - else - umodes[modechar[0]] = modename.upper(); - - if (um) - ModeManager::AddUserMode(um); } } else if (params[0].equals_cs("MODULES") && params.size() > 1) @@ -603,7 +728,7 @@ struct IRCDMessageCapab : Message::Capab else if (module.find("m_rline.so") == 0) { Servers::Capab.insert("RLINE"); - const Anope::string ®exengine = Config->GetBlock("options")->Get<const Anope::string>("regexengine"); + const Anope::string ®exengine = Config->GetBlock("options")->Get<Anope::string>("regexengine"); if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies."; } @@ -619,25 +744,11 @@ struct IRCDMessageCapab : Message::Capab while (ssep.GetToken(module)) { if (module.equals_cs("m_services_account.so")) - { Servers::Capab.insert("SERVICES"); - ModeManager::AddChannelMode(new InspIRCdExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'R')); - ModeManager::AddChannelMode(new InspIRCdExtban::UnidentifiedMatcher("UNREGISTEREDBAN", "BAN", 'U')); - } else if (module.equals_cs("m_chghost.so")) Servers::Capab.insert("CHGHOST"); else if (module.equals_cs("m_chgident.so")) Servers::Capab.insert("CHGIDENT"); - else if (module == "m_channelban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::ChannelMatcher("CHANNELBAN", "BAN", 'j')); - else if (module == "m_gecosban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r')); - else if (module == "m_nopartmessage.so") - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("PARTMESSAGEBAN", "BAN", 'p')); - else if (module == "m_serverban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::ServerMatcher("SERVERBAN", "BAN", 's')); - else if (module == "m_muteban.so") - ModeManager::AddChannelMode(new InspIRCdExtban::EntryMatcher("QUIET", "BAN", 'm')); } } else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) @@ -646,89 +757,11 @@ struct IRCDMessageCapab : Message::Capab Anope::string capab; while (ssep.GetToken(capab)) { - if (capab.find("CHANMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeList(chmodes[modebuf[t]], modebuf[t])); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t])); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelModeParam(chmodes[modebuf[t]], modebuf[t], true)); - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - if (ModeManager::FindChannelModeByChar(modebuf[t])) - continue; - ModeManager::AddChannelMode(new ChannelMode(chmodes[modebuf[t]], modebuf[t])); - } - } - else if (capab.find("USERMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - sep.GetToken(modebuf); - - if (sep.GetToken(modebuf)) - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - ModeManager::AddUserMode(new UserModeParam(umodes[modebuf[t]], modebuf[t])); - - if (sep.GetToken(modebuf)) - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - ModeManager::AddUserMode(new UserMode(umodes[modebuf[t]], modebuf[t])); - } - else if (capab.find("MAXMODES=") != Anope::string::npos) + if (capab.find("MAXMODES=") != Anope::string::npos) { Anope::string maxmodes(capab.begin() + 9, capab.end()); IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; } - else if (capab.find("PREFIX=") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 8, capab.begin() + capab.find(')')); - Anope::string chars(capab.begin() + capab.find(')') + 1, capab.end()); - short level = modes.length() - 1; - - for (size_t t = 0, end = modes.length(); t < end; ++t) - { - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[t]); - if (cm == NULL || cm->type != MODE_STATUS) - { - Log() << "CAPAB PREFIX gave unknown channel status mode " << modes[t]; - continue; - } - - ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm); - cms->level = level--; - - Log(LOG_DEBUG) << cms->name << " is now level " << cms->level; - } - - ModeManager::RebuildStatusModes(); - } else if (capab == "GLOBOPS=1") Servers::Capab.insert("GLOBOPS"); } @@ -737,14 +770,14 @@ struct IRCDMessageCapab : Message::Capab { if (!Servers::Capab.count("SERVICES")) { - UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; + Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; Anope::Quitting = true; return; } if (!ModeManager::FindUserModeByName("PRIV")) { - UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; + Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; Anope::Quitting = true; return; @@ -755,9 +788,6 @@ struct IRCDMessageCapab : Message::Capab Log() << "CHGHOST missing, Usage disabled until module is loaded."; if (!Servers::Capab.count("CHGIDENT")) Log() << "CHGIDENT missing, Usage disabled until module is loaded."; - - chmodes.clear(); - umodes.clear(); } Message::Capab::Run(source, params); @@ -766,11 +796,9 @@ struct IRCDMessageCapab : Message::Capab struct IRCDMessageEncap : IRCDMessage { - ServiceReference<IRCDMessage> insp12_encap; - - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4), insp12_encap("IRCDMessage", "inspircd12/encap") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (Anope::Match(Me->GetSID(), params[0]) == false) return; @@ -782,7 +810,7 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetIdent(params[3]); - UplinkSocket::Message(u) << "FIDENT " << params[3]; + Uplink::Send(u, "FIDENT", params[3]); } else if (params[1] == "CHGHOST") { @@ -791,7 +819,7 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetDisplayedHost(params[3]); - UplinkSocket::Message(u) << "FHOST " << params[3]; + Uplink::Send(u, "FHOST", params[3]); } else if (params[1] == "CHGNAME") { @@ -800,11 +828,22 @@ struct IRCDMessageEncap : IRCDMessage return; u->SetRealname(params[3]); - UplinkSocket::Message(u) << "FNAME " << params[3]; + Uplink::Send(u, "FNAME", params[3]); } + } +}; - if (insp12_encap) - insp12_encap->Run(source, params); +struct IRCDMessageEndburst : IRCDMessage +{ + IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + Server *s = source.GetServer(); + + Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName(); + + s->Sync(true); } }; @@ -812,7 +851,7 @@ struct IRCDMessageFHost : IRCDMessage { IRCDMessageFHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); if (u->HasMode("CLOAK")) @@ -825,19 +864,337 @@ struct IRCDMessageFIdent : IRCDMessage { IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { source.GetUser()->SetIdent(params[0]); } }; +struct IRCDMessageFJoin : IRCDMessage +{ + IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + Anope::string modes; + if (params.size() >= 3) + { + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); + } + + std::list<Message::Join::SJoinUser> users; + + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) + { + Message::Join::SJoinUser sju; + + /* Loop through prefixes and find modes for them */ + for (char c; (c = buf[0]) != ',' && c;) + { + buf.erase(buf.begin()); + sju.first.AddMode(c); + } + /* Erase the , */ + if (!buf.empty()) + buf.erase(buf.begin()); + + sju.second = User::Find(buf); + if (!sju.second) + { + Log(LOG_DEBUG) << "FJOIN for non-existent user " << buf << " on " << params[0]; + continue; + } + + users.push_back(sju); + } + + time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + Message::Join::SJoin(source, params[0], ts, modes, users); + } +}; + +struct IRCDMessageFMode : IRCDMessage +{ + IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + /* :source FMODE #test 12345678 +nto foo */ + + Anope::string modes = params[2]; + for (unsigned n = 3; n < params.size(); ++n) + modes += " " + params[n]; + + Channel *c = Channel::Find(params[0]); + time_t ts; + + try + { + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) + { + ts = 0; + } + + if (c) + c->SetModesInternal(source, modes, ts); + } +}; + +struct IRCDMessageFTopic : IRCDMessage +{ + IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + /* :source FTOPIC channel topicts setby :topic */ + + Channel *c = Channel::Find(params[0]); + if (c) + c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); + } +}; + +struct IRCDMessageIdle : IRCDMessage +{ + IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + ServiceBot *bi = ServiceBot::Find(params[0]); + if (bi) + { + Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg); + } + else + { + User *u = User::Find(params[0]); + if (u && u->server == Me) + Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0); + } + } +}; + +/* + * source = numeric of the sending server + * params[0] = uuid + * params[1] = metadata name + * params[2] = data + */ +struct IRCDMessageMetadata : IRCDMessage +{ + const bool &do_topiclock, &do_mlock; + + IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) + : IRCDMessage(creator, "METADATA", 3) + , do_topiclock(handle_topiclock) + , do_mlock(handle_mlock) + { + SetFlag(IRCDMESSAGE_REQUIRE_SERVER); + } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + if (isdigit(params[0][0])) + { + if (params[1].equals_cs("accountname")) + { + User *u = User::Find(params[0]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); + if (u && nc) + u->Login(nc); + } + + /* + * possible incoming ssl_cert messages: + * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> + * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) + */ + else if (params[1].equals_cs("ssl_cert")) + { + User *u = User::Find(params[0]); + if (!u) + return; + u->Extend<bool>("ssl", true); + Anope::string data = params[2].c_str(); + size_t pos1 = data.find(' ') + 1; + size_t pos2 = data.find(' ', pos1); + if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. + { + u->fingerprint = data.substr(pos1, pos2 - pos1); + } + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); + } + } + // We deliberately ignore non-bursting servers to avoid pseudoserver fights + else if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + { + Channel *c = Channel::Find(params[0]); + if (c && c->ci) + { + if ((do_mlock) && (params[1] == "mlock")) + { + ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); + Anope::string modes; + if (modelocks) + modes = modelocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + + // Mode lock string is not what we say it is? + if (modes != params[2]) + Uplink::Send(Me, "METADATA", c->name, "mlock", modes); + } + else if ((do_topiclock) && (params[1] == "topiclock")) + { + bool mystate = c->ci->GetExt<bool>("TOPICLOCK"); + bool serverstate = (params[2] == "1"); + if (mystate != serverstate) + Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); + } + } + } + else if (params[0] == "*") + { + // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so + + if (params[1].equals_cs("modules") && !params[2].empty()) + { + // only interested when it comes from our uplink + Server* server = source.GetServer(); + if (!server || server->GetUplink() != Me) + return; + + bool plus = (params[2][0] == '+'); + if (!plus && params[2][0] != '-') + return; + + bool required = false; + Anope::string capab, module = params[2].substr(1); + + if (module.equals_cs("m_services_account.so")) + required = true; + else if (module.equals_cs("m_hidechans.so")) + required = true; + else if (module.equals_cs("m_chghost.so")) + capab = "CHGHOST"; + else if (module.equals_cs("m_chgident.so")) + capab = "CHGIDENT"; + else if (module.equals_cs("m_svshold.so")) + capab = "SVSHOLD"; + else if (module.equals_cs("m_rline.so")) + capab = "RLINE"; + else if (module.equals_cs("m_topiclock.so")) + capab = "TOPICLOCK"; + else + return; + + if (required) + { + if (!plus) + Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it"; + } + else + { + if (plus) + Servers::Capab.insert(capab); + else + Servers::Capab.erase(capab); + + Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality"; + } + + } + } + } +}; + +struct IRCDMessageMode : IRCDMessage +{ + IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + if (IRCD->IsChannelValid(params[0])) + { + Channel *c = Channel::Find(params[0]); + + Anope::string modes = params[1]; + for (unsigned n = 2; n < params.size(); ++n) + modes += " " + params[n]; + + if (c) + c->SetModesInternal(source, modes); + } + else + { + /* InspIRCd lets opers change another + users modes, we have to kludge this + as it slightly breaks RFC1459 + */ + User *u = source.GetUser(); + // This can happen with server-origin modes. + if (!u) + u = User::Find(params[0]); + // if it's still null, drop it like fire. + // most likely situation was that server introduced a nick which we subsequently akilled + if (u) + u->SetModesInternal(source, "%s", params[1].c_str()); + } + } +}; + +struct IRCDMessageNick : IRCDMessage +{ + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + source.GetUser()->ChangeNick(params[0]); + } +}; + +struct IRCDMessageOperType : IRCDMessage +{ + IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + /* opertype is equivalent to mode +o because servers + dont do this directly */ + User *u = source.GetUser(); + if (!u->HasMode("OPER")) + u->SetModesInternal(source, "+o"); + } +}; + +struct IRCDMessageRSQuit : IRCDMessage +{ + IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + Server *s = Server::Find(params[0]); + const Anope::string &reason = params.size() > 1 ? params[1] : ""; + if (!s) + return; + + Uplink::Send(Me, "SQUIT", s->GetSID(), reason); + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); + } +}; + struct IRCDMessageSave : IRCDMessage { time_t last_collide; IRCDMessageSave(Module *creator) : IRCDMessage(creator, "SAVE", 2), last_collide(0) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *targ = User::Find(params[0]); time_t ts; @@ -873,54 +1230,118 @@ struct IRCDMessageSave : IRCDMessage } }; -class IRCDMessageMetadata : IRCDMessage +struct IRCDMessageServer : IRCDMessage { - ServiceReference<IRCDMessage> insp12_metadata; - const bool &do_topiclock; - const bool &do_mlock; + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + /* + * [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central! + * 0: name + * 1: pass + * 2: hops + * 3: numeric + * 4: desc + */ + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0; + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]); + } +}; - public: - IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) : IRCDMessage(creator, "METADATA", 3), insp12_metadata("IRCDMessage", "inspircd12/metadata"), do_topiclock(handle_topiclock), do_mlock(handle_mlock) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } +struct IRCDMessageSQuit : Message::SQuit +{ + IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { - // We deliberately ignore non-bursting servers to avoid pseudoserver fights - if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + if (params[0] == rsquit_id || params[0] == rsquit_server) { - Channel *c = Channel::Find(params[0]); - if (c && c->ci) + /* squit for a recently squit server, introduce the juped server now */ + Server *s = Server::Find(rsquit_server); + + rsquit_id.clear(); + rsquit_server.clear(); + + if (s && s->IsJuped()) + IRCD->SendServer(s); + } + else + Message::SQuit::Run(source, params); + } +}; + +struct IRCDMessageTime : IRCDMessage +{ + IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + Uplink::Send(Me, "TIME", source.GetSource(), params[1], Anope::CurTime); + } +}; + +struct IRCDMessageUID : IRCDMessage +{ + ServiceReference<SASL::Service> sasl; + + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + /* + * [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org> + * 0: uid + * 1: ts + * 2: nick + * 3: host + * 4: dhost + * 5: ident + * 6: ip + * 7: signon + * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname! + * last: realname + */ + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + time_t ts = convertTo<time_t>(params[1]); + + Anope::string modes = params[8]; + for (unsigned i = 9; i < params.size() - 1; ++i) + modes += " " + params[i]; + + NickServ::Nick *na = NULL; + if (sasl) + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) { - if ((do_mlock) && (params[1] == "mlock")) - { - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - Anope::string modes; - if (modelocks) - modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); + SASLUser &u = *it; - // Mode lock string is not what we say it is? - if (modes != params[2]) - UplinkSocket::Message(Me) << "METADATA " << c->name << " mlock :" << modes; - } - else if ((do_topiclock) && (params[1] == "topiclock")) + if (u.created + 30 < Anope::CurTime) + it = saslusers.erase(it); + else if (u.uid == params[0]) { - bool mystate = c->ci->GetExt<bool>("TOPICLOCK"); - bool serverstate = (params[2] == "1"); - if (mystate != serverstate) - UplinkSocket::Message(Me) << "METADATA " << c->name << " topiclock :" << (mystate ? "1" : ""); + na = NickServ::FindNick(u.acc); + it = saslusers.erase(it); } + else + ++it; } - } - if (insp12_metadata) - insp12_metadata->Run(source, params); + User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? na->GetAccount() : NULL); + if (u) + u->signon = convertTo<time_t>(params[7]); } }; class ProtoInspIRCd20 : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> + , public EventHook<Event::SetChannelOption> { - Module *m_insp12; - InspIRCd20Proto ircd_proto; + ExtensibleItem<bool> ssl; + ServiceReference<ModeLocks> mlocks; /* Core message handlers */ Message::Away message_away; @@ -938,103 +1359,149 @@ class ProtoInspIRCd20 : public Module Message::Stats message_stats; Message::Topic message_topic; - /* InspIRCd 1.2 message handlers */ - ServiceAlias message_endburst, message_fjoin, message_fmode, - message_ftopic, message_idle, message_mode, - message_nick, message_opertype, message_rsquit, message_server, - message_squit, message_time, message_uid; - /* Our message handlers */ IRCDMessageCapab message_capab; IRCDMessageEncap message_encap; + IRCDMessageEndburst message_endburst; IRCDMessageFHost message_fhost; IRCDMessageFIdent message_fident; + IRCDMessageFJoin message_fjoin; + IRCDMessageFMode message_fmode; + IRCDMessageFTopic message_ftopic; + IRCDMessageIdle message_idle; IRCDMessageMetadata message_metadata; + IRCDMessageMode message_mode; + IRCDMessageNick message_nick; + IRCDMessageOperType message_opertype; + IRCDMessageRSQuit message_rsquit; IRCDMessageSave message_save; + IRCDMessageServer message_server; + IRCDMessageSQuit message_squit; + IRCDMessageTime message_time; + IRCDMessageUID message_uid; bool use_server_side_topiclock, use_server_side_mlock; void SendChannelMetadata(Channel *c, const Anope::string &metadataname, const Anope::string &value) { - UplinkSocket::Message(Me) << "METADATA " << c->name << " " << metadataname << " :" << value; + Uplink::Send(Me, "METADATA", c->name, metadataname, value); } public: - ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_stats(this), message_topic(this), - - message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"), - message_fjoin("IRCDMessage", "inspircd20/fjoin", "inspircd12/fjoin"), - message_fmode("IRCDMessage", "inspircd20/fmode", "inspircd12/fmode"), - message_ftopic("IRCDMessage", "inspircd20/ftopic", "inspircd12/ftopic"), - message_idle("IRCDMessage", "inspircd20/idle", "inspircd12/idle"), - message_mode("IRCDMessage", "inspircd20/mode", "inspircd12/mode"), - message_nick("IRCDMessage", "inspircd20/nick", "inspircd12/nick"), - message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"), - message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"), - message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"), - message_squit("IRCDMessage", "inspircd20/squit", "inspircd12/squit"), - message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"), - message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"), - - message_capab(this), message_encap(this), message_fhost(this), message_fident(this), message_metadata(this, use_server_side_topiclock, use_server_side_mlock), - message_save(this) + ProtoInspIRCd20(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::MLockEvents>(this) + , EventHook<Event::SetChannelOption>(this) + + , ircd_proto(this) + , ssl(this, "ssl") + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_stats(this) + , message_topic(this) + + , message_capab(this) + , message_encap(this) + , message_endburst(this) + , message_fhost(this) + , message_fident(this) + , message_fjoin(this) + , message_fmode(this) + , message_ftopic(this) + , message_idle(this) + , message_metadata(this, use_server_side_topiclock, use_server_side_mlock) + , message_mode(this) + , message_nick(this) + , message_opertype(this) + , message_rsquit(this) + , message_save(this) + , message_server(this) + , message_squit(this) + , message_time(this) + , message_uid(this) { - - if (ModuleManager::LoadModule("inspircd12", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load inspircd12"); - m_insp12 = ModuleManager::FindModule("inspircd12"); - if (!m_insp12) - throw ModuleException("Unable to find inspircd12"); - if (!insp12) - throw ModuleException("No protocol interface for insp12"); - ModuleManager::DetachAll(m_insp12); - } - ~ProtoInspIRCd20() - { - m_insp12 = ModuleManager::FindModule("inspircd12"); - ModuleManager::UnloadModule(m_insp12, NULL); - } - - void OnReload(Configuration::Conf *conf) anope_override + void OnReload(Configuration::Conf *conf) override { use_server_side_topiclock = conf->GetModule(this)->Get<bool>("use_server_side_topiclock"); use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); + + for (int i = 0; i < conf->CountBlock("extban"); ++i) + { + Configuration::Block *extban = conf->GetBlock("extban", i); + Anope::string name = extban->Get<Anope::string>("name"), + type = extban->Get<Anope::string>("type"), + base = extban->Get<Anope::string>("base"), + character = extban->Get<Anope::string>("character"); + + ChannelMode *cm; + + if (character.empty()) + continue; + + if (type == "channel") + cm = new InspIRCdExtban::ChannelMatcher(name, base, character[0]); + else if (type == "entry") + cm = new InspIRCdExtban::EntryMatcher(name, base, character[0]); + else if (type == "realname") + cm = new InspIRCdExtban::RealnameMatcher(name, base, character[0]); + else if (type == "account") + cm = new InspIRCdExtban::AccountMatcher(name, base, character[0]); + else if (type == "fingerprint") + cm = new InspIRCdExtban::FingerprintMatcher(name, base, character[0]); + else if (type == "unidentified") + cm = new InspIRCdExtban::UnidentifiedMatcher(name, base, character[0]); + else if (type == "server") + cm = new InspIRCdExtban::ServerMatcher(name, base, character[0]); + else + continue; + + if (!ModeManager::AddChannelMode(cm)) + delete cm; + } } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { if (c->ci) this->OnChanRegistered(c->ci); } - void OnChanRegistered(ChannelInfo *ci) anope_override + void OnChanRegistered(ChanServ::Channel *ci) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && ci->c && modelocks && !modelocks->GetMLockAsString(false).empty()) + if (use_server_side_mlock && ci->c && mlocks && !mlocks->GetMLockAsString(ci, false).empty()) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); SendChannelMetadata(ci->c, "mlock", modes); } if (use_server_side_topiclock && Servers::Capab.count("TOPICLOCK") && ci->c) { - if (ci->HasExt("TOPICLOCK")) + if (ci->HasFieldS("TOPICLOCK")) SendChannelMetadata(ci->c, "topiclock", "1"); } } - void OnDelChan(ChannelInfo *ci) anope_override + void OnDelChan(ChanServ::Channel *ci) override { if (use_server_side_mlock && ci->c) SendChannelMetadata(ci->c, "mlock", ""); @@ -1043,35 +1510,33 @@ class ProtoInspIRCd20 : public Module SendChannelMetadata(ci->c, "topiclock", ""); } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; SendChannelMetadata(ci->c, "mlock", modes); } return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && ci->c && modelocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && ci->c && mlocks && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM)) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); SendChannelMetadata(ci->c, "mlock", modes); } return EVENT_CONTINUE; } - EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChannelInfo *ci, const Anope::string &setting) anope_override + EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) override { - if (cmd->name == "chanserv/topic" && ci->c) + if (cmd->GetName() == "chanserv/topic" && ci->c) { if (setting == "topiclock on") SendChannelMetadata(ci->c, "topiclock", "1"); diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index e7ae31fce..aa2c23a80 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -1,19 +1,28 @@ -/* ngIRCd Protocol module for Anope IRC Services +/* + * Anope IRC Services * - * (C) 2011-2012, 2014 Alexander Barton <alex@barton.de> - * (C) 2011-2016 Anope Team <team@anope.org> + * Copyright (C) 2011-2016 Anope Team <team@anope.org> + * Copyright (C) 2011-2012, 2014 Alexander Barton <alex@barton.de> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" class ngIRCdProto : public IRCDProto { - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { IRCDProto::SendSVSKillInternal(source, user, buf); user->KillInternal(source, buf); @@ -30,64 +39,64 @@ class ngIRCdProto : public IRCDProto MaxModes = 5; } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, XLine *x) override { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message(Me) << "GLINE " << x->mask << " " << timeleft << " :" << x->GetReason() << " (" << x->by << ")"; + Uplink::Send(Me, "GLINE", x->GetMask(), timeleft, x->GetReason() + " (" + x->GetBy() + ")"); } - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(XLine *x) override { - UplinkSocket::Message(Me) << "GLINE " << x->mask; + Uplink::Send(Me, "GLINE", x->GetMask()); } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { - UplinkSocket::Message(Me) << "CHANINFO " << c->name << " +" << c->GetModes(true, true); + Uplink::Send(Me, "CHANINFO", c->name, "+" + c->GetModes(true, true)); } // Received: :dev.anope.de NICK DukeP 1 ~DukePyro p57ABF9C9.dip.t-dialin.net 1 +i :DukePyrolator - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "NICK " << u->nick << " 1 " << u->GetIdent() << " " << u->host << " 1 " << modes << " :" << u->realname; + Uplink::Send(Me, "NICK", u->nick, 1, u->GetIdent(), u->host, 1, modes, u->realname); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P"; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "0210-IRC+", "Anope|" + Anope::VersionShort(), "CLHMSo P"); /* Make myself known to myself in the serverlist */ SendServer(Me); /* finish the enhanced server handshake and register the connection */ this->SendNumeric(376, "*", ":End of MOTD command"); } - void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override + void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "SVSNICK " << u->nick << " " << newnick; + Uplink::Send(Me, "SVSNICK", u->nick, newnick); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "WALLOPS :" << buf; + Uplink::Send(source, "WALLOPS", buf); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(user) << "JOIN " << c->name; + Uplink::Send(user, "JOIN", c->name); if (status) { /* First save the channel status incase uc->Status == status */ @@ -99,7 +108,7 @@ class ngIRCdProto : public IRCDProto if (uc != NULL) uc->status.Clear(); - BotInfo *setter = BotInfo::Find(user->GetUID()); + ServiceBot *setter = ServiceBot::Find(user->GetUID()); for (size_t i = 0; i < cs.Modes().length(); ++i) c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); @@ -108,54 +117,56 @@ class ngIRCdProto : public IRCDProto } } - void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) anope_override + void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick << " :" << buf; + Uplink::Send(source, "KICK", chan->name, user->nick, buf); else - UplinkSocket::Message(source) << "KICK " << chan->name << " " << user->nick; + Uplink::Send(source, "KICK", chan->name, user->nick); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display; + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; - } + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); + } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override { - UplinkSocket::Message(source) << "MODE " << dest->name << " " << buf; + IRCMessage message(source, "MODE", dest->name); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } - void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) anope_override + void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) override { if (!buf.empty()) - UplinkSocket::Message(u) << "PART " << chan->name << " :" << buf; + Uplink::Send(u, "PART", chan->name, buf); else - UplinkSocket::Message(u) << "PART " << chan->name; + Uplink::Send(u, "PART", chan->name); } /* SERVER name hop descript */ - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic); } - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override { if (!vIdent.empty()) - UplinkSocket::Message(Me) << "METADATA " << u->nick << " user :" << vIdent; + Uplink::Send(Me, "METADATA", u->nick, "user", vIdent); - UplinkSocket::Message(Me) << "METADATA " << u->nick << " cloakhost :" << vhost; + Uplink::Send(Me, "METADATA", u->nick, "cloakhost", vhost); if (!u->HasMode("CLOAK")) { u->SetMode(Config->GetClient("HostServ"), "CLOAK"); @@ -163,14 +174,16 @@ class ngIRCdProto : public IRCDProto } } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { this->SendVhost(u, u->GetIdent(), ""); } - Anope::string Format(const Anope::string &source, const Anope::string &message) anope_override + Anope::string Format(IRCMessage &message) { - return IRCDProto::Format(source.empty() ? Me->GetSID() : source, message); + if (message.GetSource().GetSource().empty()) + message.SetSource(Me); + return IRCDProto::Format(message); } }; @@ -179,7 +192,7 @@ struct IRCDMessage005 : IRCDMessage IRCDMessage005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Please see <http://www.irc.org/tech_docs/005.html> for details. - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { size_t pos; Anope::string parameter, data; @@ -220,7 +233,7 @@ struct IRCDMessage376 : IRCDMessage * */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { } }; @@ -246,7 +259,7 @@ struct IRCDMessageChaninfo : IRCDMessage * a channel has no user limit (the parameter <modes> doesn't list the "l" * channel mode). In this case <limit> should be "0". */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { bool created; Channel *c = Channel::FindOrCreate(params[0], created); @@ -288,7 +301,7 @@ struct IRCDMessageJoin : Message::Join * * if a user joins a new channel, the ircd sends <channelname>\7<umode> */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *user = source.GetUser(); size_t pos = params[0].find('\7'); @@ -338,7 +351,7 @@ struct IRCDMessageMetadata : IRCDMessage * - "user": the user name (ident) of a client (can't be empty) */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = User::Find(params[0]); if (!u) @@ -348,14 +361,14 @@ struct IRCDMessageMetadata : IRCDMessage } if (params[1].equals_cs("accountname")) { - NickCore *nc = NickCore::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); if (nc) u->Login(nc); } else if (params[1].equals_cs("certfp")) { u->fingerprint = params[2]; - FOREACH_MOD(OnFingerprint, (u)); + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } else if (params[1].equals_cs("cloakhost")) { @@ -389,7 +402,7 @@ struct IRCDMessageMode : IRCDMessage * params[n] = parameters */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Anope::string modes = params[1]; @@ -436,7 +449,7 @@ struct IRCDMessageNick : IRCDMessage * params[0] = newnick * */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 1) { @@ -477,7 +490,7 @@ struct IRCDMessageNJoin : IRCDMessage * * Received: :dev.anope.de NJOIN #test :DukeP2,@DukeP,%test,+test2 */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { std::list<Message::Join::SJoinUser> users; @@ -502,7 +515,7 @@ struct IRCDMessageNJoin : IRCDMessage continue; } users.push_back(sju); - } + } Message::Join::SJoin(source, params[0], 0, "", users); } @@ -517,7 +530,7 @@ struct IRCDMessagePong : IRCDMessage * when receiving a new server and then finish sync once we * get a pong back from that server. */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (!source.GetServer()->IsSynced()) source.GetServer()->Sync(false); @@ -553,7 +566,7 @@ struct IRCDMessageServer : IRCDMessage * params[3] = server description */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 3) { @@ -580,7 +593,7 @@ struct IRCDMessageTopic : IRCDMessage IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Received: :DukeP TOPIC #anope :test - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Channel *c = Channel::Find(params[0]); if (!c) @@ -595,6 +608,7 @@ struct IRCDMessageTopic : IRCDMessage class ProtongIRCd : public Module + , public EventHook<Event::UserNickChange> { ngIRCdProto ircd_proto; @@ -629,71 +643,46 @@ class ProtongIRCd : public Module IRCDMessageServer message_server; IRCDMessageTopic message_topic; - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserMode("NOCTCP", 'b')); - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - ModeManager::AddUserMode(new UserMode("COMMONCHANS", 'C')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'q')); - ModeManager::AddUserMode(new UserModeOperOnly("RESTRICTED", 'r')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - - /* Add modes for ban, exception, and invite lists */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - - /* Add channel user modes */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '&', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '~', 4)); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("OPERONLY", 'O')); - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V')); - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - } - public: - ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this), - message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_squery(this, "SQUERY"), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_005(this), message_376(this), message_chaninfo(this), message_join(this), message_metadata(this), - message_mode(this), message_nick(this), message_njoin(this), message_pong(this), message_server(this), - message_topic(this) + ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this) + , ircd_proto(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_squery(this, "SQUERY") + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_005(this) + , message_376(this) + , message_chaninfo(this) + , message_join(this) + , message_metadata(this) + , message_mode(this) + , message_nick(this) + , message_njoin(this) + , message_pong(this) + , message_server(this) + , message_topic(this) { Servers::Capab.insert("QS"); - this->AddModes(); - } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveMode(Config->GetClient("NickServ"), "REGISTERED"); } diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index eeb22d4fe..02d2a4d6e 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -1,24 +1,37 @@ -/* Plexus 3+ IRCD functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2005-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.hybrid */ + #include "module.h" +#include "modules/protocol/plexus.h" +#include "modules/protocol/hybrid.h" static Anope::string UplinkSID; -static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); - class PlexusProto : public IRCDProto { + ServiceReference<IRCDProto> hybrid; // XXX use moddeps + inheritance here + public: PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1") + , hybrid("hybrid") { DefaultPseudoclientModes = "+oiU"; CanSVSNick = true; @@ -34,28 +47,28 @@ class PlexusProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { hybrid->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } - void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); } - void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); } - void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); } - void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); } - void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); } - void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); } - void SendServer(const Server *server) anope_override { hybrid->SendServer(server); } - void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override { hybrid->SendSVSHold(nick, t); } - void SendSVSHoldDel(const Anope::string &nick) anope_override { hybrid->SendSVSHoldDel(nick); } - - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKillInternal(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendSQLine(User *u, XLine *x) override { hybrid->SendSQLine(u, x); } + void SendSQLineDel(XLine *x) override { hybrid->SendSQLineDel(x); } + void SendSGLineDel(XLine *x) override { hybrid->SendSGLineDel(x); } + void SendSGLine(User *u, XLine *x) override { hybrid->SendSGLine(u, x); } + void SendAkillDel(XLine *x) override { hybrid->SendAkillDel(x); } + void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); } + void SendServer(const Server *server) override { hybrid->SendServer(server); } + void SendChannel(Channel *c) override { hybrid->SendChannel(c); } + void SendSVSHold(const Anope::string &nick, time_t t) override { hybrid->SendSVSHold(nick, t); } + void SendSVSHoldDel(const Anope::string &nick) override { hybrid->SendSVSHoldDel(nick); } + + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "OPERWALL :" << buf; + Uplink::Send(source, "OPERWALL", buf); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID(); + Uplink::Send(Me, "SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), user->GetUID()); if (status) { /* First save the channel status incase uc->Status == status */ @@ -67,7 +80,7 @@ class PlexusProto : public IRCDProto if (uc != NULL) uc->status.Clear(); - BotInfo *setter = BotInfo::Find(user->GetUID()); + ServiceBot *setter = ServiceBot::Find(user->GetUID()); for (size_t i = 0; i < cs.Modes().length(); ++i) c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); @@ -76,27 +89,28 @@ class PlexusProto : public IRCDProto } } - void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) anope_override + void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override { - UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when; + Uplink::Send(Me, "ENCAP", u->server->GetName(), "SVSNICK", u->GetUID(), u->timestamp, newnick, when); } - void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override + void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) override { if (!ident.empty()) - UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident; - UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host; + Uplink::Send(Me, "ENCAP", "*", "CHGIDENT", u->GetUID(), ident); + Uplink::Send(Me, "ENCAP", "*", "CHGHOST", u->GetUID(), host); u->SetMode(Config->GetClient("HostServ"), "CLOAK"); } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { u->RemoveMode(Config->GetClient("HostServ"), "CLOAK"); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); + /* CAPAB * QS - Can handle quit storm removal * EX - Can do channel +e exemptions @@ -117,9 +131,11 @@ class PlexusProto : public IRCDProto * ENCAP - Supports encapsulization of protocol messages * SVS - Supports services protocol extensions */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS"; + Uplink::Send("CAPAB", "QS EX CHW IE EOB KLN UNKLN GLN HUB KNOCK TBURST PARA ENCAP SVS"); + /* Make myself known to myself in the serverlist */ SendServer(Me); + /* * SVINFO * parv[0] = sender prefix @@ -128,163 +144,148 @@ class PlexusProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 5 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 255.255.255.255 " << u->GetUID() << " 0 " << u->host << " :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, "255.255.255.255", u->GetUID(), 0, u->host, u->realname); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + Uplink::Send(source, "ENCAP", "*", "SVSMODE", u->GetUID(), u->timestamp, buf); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display; + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), na->GetAccount()->GetDisplay()); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), ""); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "ENCAP", "*", "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } - void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { - UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSJOIN " << user->GetUID() << " " << chan; + Uplink::Send(source, "ENCAP", user->server->GetName(), "SVSJOIN", user->GetUID(), chan); } - void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { - UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSPART " << user->GetUID() << " " << chan; + Uplink::Send(source, "ENCAP", user->server->GetName(), "SVSPART", user->GetUID(), chan); } }; -struct IRCDMessageEncap : IRCDMessage +void plexus::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + /* + * Received: :dev.anope.de ENCAP * SU DukePyrolator DukePyrolator + * params[0] = * + * params[1] = SU + * params[2] = nickname + * params[3] = account + */ + if (params[1].equals_cs("SU")) { - /* - * Received: :dev.anope.de ENCAP * SU DukePyrolator DukePyrolator - * params[0] = * - * params[1] = SU - * params[2] = nickname - * params[3] = account - */ - if (params[1].equals_cs("SU")) + User *u = User::Find(params[2]); + NickServ::Account *nc = NickServ::FindAccount(params[3]); + if (u && nc) { - User *u = User::Find(params[2]); - NickCore *nc = NickCore::Find(params[3]); - if (u && nc) - { - u->Login(nc); - } + u->Login(nc); } + } - /* - * Received: :dev.anope.de ENCAP * CERTFP DukePyrolator :3F122A9CC7811DBAD3566BF2CEC3009007C0868F - * params[0] = * - * params[1] = CERTFP - * params[2] = nickname - * params[3] = fingerprint - */ - else if (params[1].equals_cs("CERTFP")) + /* + * Received: :dev.anope.de ENCAP * CERTFP DukePyrolator :3F122A9CC7811DBAD3566BF2CEC3009007C0868F + * params[0] = * + * params[1] = CERTFP + * params[2] = nickname + * params[3] = fingerprint + */ + else if (params[1].equals_cs("CERTFP")) + { + User *u = User::Find(params[2]); + if (u) { - User *u = User::Find(params[2]); - if (u) - { - u->fingerprint = params[3]; - FOREACH_MOD(OnFingerprint, (u)); - } + u->fingerprint = params[3]; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } - return; } -}; + return; +} struct IRCDMessagePass : IRCDMessage { IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { UplinkSID = params[3]; } }; -struct IRCDMessageServer : IRCDMessage +/* 0 1 2 */ +/* SERVER hades.arpa 1 :ircd-hybrid test server */ +void plexus::Server::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - /* 0 1 2 */ - /* SERVER hades.arpa 1 :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* Servers other than our immediate uplink are introduced via SID */ - if (params[1] != "1") - return; - - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - } -}; + /* Servers other than our immediate uplink are introduced via SID */ + if (params[1] != "1") + return; -struct IRCDMessageUID : IRCDMessage + new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); +} + +/* + params[0] = nick + params[1] = hop + params[2] = ts + params[3] = modes + params[4] = user + params[5] = host + params[6] = IP + params[7] = UID + params[8] = services stamp + params[9] = realhost + params[10] = info +*/ +// :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB 0 192.168.0.5 :Adam +void plexus::UID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + /* An IP of 0 means the user is spoofed */ + Anope::string ip = params[6]; + if (ip == "0") + ip.clear(); - /* - params[0] = nick - params[1] = hop - params[2] = ts - params[3] = modes - params[4] = user - params[5] = host - params[6] = IP - params[7] = UID - params[8] = services stamp - params[9] = realhost - params[10] = info - */ - // :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB 0 192.168.0.5 :Adam - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + time_t ts; + try { - /* An IP of 0 means the user is spoofed */ - Anope::string ip = params[6]; - if (ip == "0") - ip.clear(); - - time_t ts; - try - { - ts = convertTo<time_t>(params[2]); - } - catch (const ConvertException &) - { - ts = Anope::CurTime; - } - - NickAlias *na = NULL; - try - { - if (params[8].is_pos_number_only() && convertTo<time_t>(params[8]) == ts) - na = NickAlias::Find(params[0]); - } - catch (const ConvertException &) { } - if (params[8] != "0" && !na) - na = NickAlias::Find(params[8]); + ts = convertTo<time_t>(params[2]); + } + catch (const ConvertException &) + { + ts = Anope::CurTime; + } - User::OnIntroduce(params[0], params[4], params[9], params[5], ip, source.GetServer(), params[10], ts, params[3], params[7], na ? *na->nc : NULL); + NickServ::Nick *na = NULL; + try + { + if (params[8].is_pos_number_only() && convertTo<time_t>(params[8]) == ts) + na = NickServ::FindNick(params[0]); } -}; + catch (const ConvertException &) { } + if (params[8] != "0" && !na) + na = NickServ::FindNick(params[8]); + + User::OnIntroduce(params[0], params[4], params[9], params[5], ip, source.GetServer(), params[10], ts, params[3], params[7], na ? na->GetAccount() : NULL); +} class ProtoPlexus : public Module { @@ -312,108 +313,63 @@ class ProtoPlexus : public Module Message::Topic message_topic; Message::Version message_version; Message::Whois message_whois; - - /* Hybrid message handlers */ - ServiceAlias message_bmask, message_eob, message_join, message_nick, message_sid, message_sjoin, - message_tburst, message_tmode; /* Our message handlers */ - IRCDMessageEncap message_encap; + hybrid::BMask message_bmask; + hybrid::EOB message_eob; + plexus::Encap message_encap; + hybrid::Join message_join; + hybrid::Nick message_nick; IRCDMessagePass message_pass; - IRCDMessageServer message_server; - IRCDMessageUID message_uid; - - void AddModes() - { - /* Add user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserMode("NOCTCP", 'C')); - ModeManager::AddUserMode(new UserMode("DEAF", 'D')); - ModeManager::AddUserMode(new UserMode("SOFTCALLERID", 'G')); - ModeManager::AddUserMode(new UserMode("CALLERID", 'g')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("LOCOPS", 'l')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserModeOperOnly("NETADMIN", 'N')); - ModeManager::AddUserMode(new UserMode("PRIV", 'p')); - ModeManager::AddUserMode(new UserModeOperOnly("ROUTING", 'q')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'S')); - ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'U')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserModeNoone("WEBIRC", 'W')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - - /* v/h/o/a/q */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '&', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '~', 4)); - - /* l/k */ - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode("BANDWIDTH", 'B')); - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'N')); - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - ModeManager::AddChannelMode(new ChannelMode("SSL", 'S')); - ModeManager::AddChannelMode(new ChannelMode("PERM", 'z')); - } + plexus::Server message_server; + hybrid::SID message_sid; + hybrid::SJoin message_sjoin; + hybrid::TBurst message_tburst; + hybrid::TMode message_tmode; + plexus::UID message_uid; public: - ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), message_kill(this), - message_mode(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_quit(this), message_squit(this), message_stats(this), message_time(this), message_topic(this), message_version(this), - message_whois(this), - - message_bmask("IRCDMessage", "plexus/bmask", "hybrid/bmask"), message_eob("IRCDMessage", "plexus/eob", "hybrid/eob"), - message_join("IRCDMessage", "plexus/join", "hybrid/join"), message_nick("IRCDMessage", "plexus/nick", "hybrid/nick"), - message_sid("IRCDMessage", "plexus/sid", "hybrid/sid"), - message_sjoin("IRCDMessage", "plexus/sjoin", "hybrid/sjoin"), message_tburst("IRCDMessage", "plexus/tburst", "hybrid/tburst"), - message_tmode("IRCDMessage", "plexus/tmode", "hybrid/tmode"), - - message_encap(this), message_pass(this), message_server(this), message_uid(this) + ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask(this) + , message_eob(this) + , message_encap(this) + , message_join(this) + , message_nick(this) + , message_pass(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_tburst(this) + , message_tmode(this) + , message_uid(this) { - - if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load hybrid"); - m_hybrid = ModuleManager::FindModule("hybrid"); - if (!m_hybrid) - throw ModuleException("Unable to find hybrid"); - if (!hybrid) - throw ModuleException("No protocol interface for hybrid"); - - this->AddModes(); - } - - ~ProtoPlexus() - { - m_hybrid = ModuleManager::FindModule("hybrid"); - ModuleManager::UnloadModule(m_hybrid, NULL); } }; +template<> void ModuleInfo<ProtoPlexus>(ModuleDef *def) +{ + def->Depends("hybrid"); +} + MODULE_INIT(ProtoPlexus) diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index d89bff602..223902457 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -1,24 +1,36 @@ -/* Ratbox IRCD functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2005-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.hybrid */ + #include "module.h" +#include "modules/protocol/hybrid.h" +#include "modules/protocol/ratbox.h" static Anope::string UplinkSID; -static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); - class RatboxProto : public IRCDProto { + ServiceReference<IRCDProto> hybrid; // XXX public: RatboxProto(Module *creator) : IRCDProto(creator, "Ratbox 3.0+") + , hybrid("hybrid") { DefaultPseudoclientModes = "+oiS"; CanSNLine = true; @@ -28,29 +40,30 @@ class RatboxProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) anope_override { hybrid->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } - void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); } - void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); } - void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); } - void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); } - void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); } - void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); } - void SendServer(const Server *server) anope_override { hybrid->SendServer(server); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override { hybrid->SendModeInternal(source, u, buf); } - void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); } - bool IsIdentValid(const Anope::string &ident) anope_override { return hybrid->IsIdentValid(ident); } - - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKillInternal(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendSQLine(User *u, XLine *x) override { hybrid->SendSQLine(u, x); } + void SendSGLine(User *u, XLine *x) override { hybrid->SendSGLine(u, x); } + void SendSGLineDel(XLine *x) override { hybrid->SendSGLineDel(x); } + void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); } + void SendAkillDel(XLine *x) override { hybrid->SendAkillDel(x); } + void SendSQLineDel(XLine *x) override { hybrid->SendSQLineDel(x); } + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { hybrid->SendJoin(user, c, status); } + void SendServer(const Server *server) override { hybrid->SendServer(server); } + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { hybrid->SendModeInternal(source, u, buf); } + void SendChannel(Channel *c) override { hybrid->SendChannel(c); } + bool IsIdentValid(const Anope::string &ident) override { return hybrid->IsIdentValid(ident); } + + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { - UplinkSocket::Message(source) << "OPERWALL :" << buf; + Uplink::Send(source, "OPERWALL", buf); } - void SendConnect() anope_override + void SendConnect() override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink].password << " TS 6 :" << Me->GetSID(); + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password, "TS", 6, Me->GetSID()); + /* QS - Can handle quit storm removal EX - Can do channel +e exemptions @@ -61,9 +74,11 @@ class RatboxProto : public IRCDProto TB - supports topic burst ENCAP - supports ENCAP */ - UplinkSocket::Message() << "CAPAB :QS EX CHW IE GLN TB ENCAP"; + Uplink::Send("CAPAB", "QS EX CHW IE GLN TB ENCAP"); + /* Make myself known to myself in the serverlist */ SendServer(Me); + /* * SVINFO * parv[0] = sender prefix @@ -72,31 +87,31 @@ class RatboxProto : public IRCDProto * parv[3] = server is standalone or connected to non-TS only * parv[4] = server's idea of UTC time */ - UplinkSocket::Message() << "SVINFO 6 3 0 :" << Anope::CurTime; + Uplink::Send("SVINFO", 6, 6, 0, Anope::CurTime); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname; + Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, 0, u->GetUID(), u->realname); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { - if (na->nc->HasExt("UNCONFIRMED")) + if (na->GetAccount()->HasFieldS("UNCONFIRMED")) return; - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display; + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID(), na->GetAccount()->GetDisplay()); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); + Uplink::Send(Me, "ENCAP", "*", "SU", u->GetUID()); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - BotInfo *bi = source.GetBot(); + ServiceBot *bi = source.GetBot(); bool needjoin = c->FindUser(bi) == NULL; if (needjoin) @@ -114,116 +129,89 @@ class RatboxProto : public IRCDProto } }; -struct IRCDMessageEncap : IRCDMessage +// Debug: Received: :00BAAAAAB ENCAP * LOGIN Adam +void ratbox::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - // Debug: Received: :00BAAAAAB ENCAP * LOGIN Adam - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + if (params[1] == "LOGIN" || params[1] == "SU") { - if (params[1] == "LOGIN" || params[1] == "SU") - { - User *u = source.GetUser(); - - NickCore *nc = NickCore::Find(params[2]); - if (!nc) - return; - u->Login(nc); - - /* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if - * their server isn't syncing) and then we receive this.. so tell them about it. - */ - if (u->server->IsSynced()) - u->SendMessage(Config->GetClient("NickServ"), _("You have been logged in as \002%s\002."), nc->display.c_str()); - } + User *u = source.GetUser(); + + NickServ::Account *nc = NickServ::FindAccount(params[2]); + if (!nc) + return; + u->Login(nc); + + /* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if + * their server isn't syncing) and then we receive this.. so tell them about it. + */ + if (u->server->IsSynced()) + u->SendMessage(Config->GetClient("NickServ"), _("You have been logged in as \002%s\002."), nc->GetDisplay().c_str()); } -}; +} -struct IRCDMessageJoin : Message::Join +void ratbox::Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { } + if (params.size() == 1 && params[0] == "0") + return Message::Join::Run(source, params); - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params.size() == 1 && params[0] == "0") - return Message::Join::Run(source, params); - - if (params.size() < 2) - return; + if (params.size() < 2) + return; - std::vector<Anope::string> p = params; - p.erase(p.begin()); + std::vector<Anope::string> p = params; + p.erase(p.begin()); - return Message::Join::Run(source, p); - } -}; + return Message::Join::Run(source, p); +} struct IRCDMessagePass : IRCDMessage { IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { UplinkSID = params[3]; } }; -struct IRCDMessageServer : IRCDMessage +// SERVER hades.arpa 1 :ircd-ratbox test server +void ratbox::Server::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - // SERVER hades.arpa 1 :ircd-ratbox test server - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - // Servers other then our immediate uplink are introduced via SID - if (params[1] != "1") - return; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - IRCD->SendPing(Me->GetName(), params[0]); - } -}; - -struct IRCDMessageTBurst : IRCDMessage + // Servers other then our immediate uplink are introduced via SID + if (params[1] != "1") + return; + new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); + IRCD->SendPing(Me->GetName(), params[0]); +} + +/* + * params[0] = channel + * params[1] = ts + * params[2] = topic OR who set the topic + * params[3] = topic if params[2] isn't the topic + */ +void ratbox::TB::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TB", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - /* - * params[0] = channel - * params[1] = ts - * params[2] = topic OR who set the topic - * params[3] = topic if params[2] isn't the topic - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - time_t topic_time = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; - Channel *c = Channel::Find(params[0]); + time_t topic_time = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + Channel *c = Channel::Find(params[0]); - if (!c) - return; + if (!c) + return; - const Anope::string &setter = params.size() == 4 ? params[2] : "", - topic = params.size() == 4 ? params[3] : params[2]; + const Anope::string &setter = params.size() == 4 ? params[2] : "", + topic = params.size() == 4 ? params[3] : params[2]; - c->ChangeTopicInternal(NULL, setter, topic, topic_time); - } -}; + c->ChangeTopicInternal(NULL, setter, topic, topic_time); +} -struct IRCDMessageUID : IRCDMessage +// :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB :Adam +void ratbox::UID::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 9) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - // :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB :Adam - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* Source is always the server */ - User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7], NULL); - } -}; + /* Source is always the server */ + User::OnIntroduce(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7], NULL); +} class ProtoRatbox : public Module { - Module *m_hybrid; - RatboxProto ircd_proto; /* Core message handlers */ @@ -247,98 +235,62 @@ class ProtoRatbox : public Module Message::Version message_version; Message::Whois message_whois; - /* Hybrid message handlers */ - ServiceAlias message_bmask, message_nick, message_pong, message_sid, - message_sjoin, message_tmode; - /* Our message handlers */ - IRCDMessageEncap message_encap; - IRCDMessageJoin message_join; + hybrid::BMask message_bmask; + ratbox::Encap message_encap; + ratbox::Join message_join; + hybrid::Nick message_nick; IRCDMessagePass message_pass; - IRCDMessageServer message_server; - IRCDMessageTBurst message_tburst; - IRCDMessageUID message_uid; - - void AddModes() - { - /* user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserModeOperOnly("BOT", 'b')); - // c/C = con - // d = debug? - ModeManager::AddUserMode(new UserMode("DEAF", 'D')); - // f = full? - ModeManager::AddUserMode(new UserMode("CALLERID", 'g')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - // k = skill? - ModeManager::AddUserMode(new UserModeOperOnly("LOCOPS", 'l')); - // n = nchange - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - // r = rej - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeNoone("PROTECTED", 'S')); - // u = unauth? - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - // x = external? - // y = spy? - ModeManager::AddUserMode(new UserModeOperOnly("OPERWALLS", 'z')); - // Z = spy? - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - - /* v/h/o/a/q */ - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 1)); - - /* l/k */ - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - - /* channel modes */ - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'r')); - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - ModeManager::AddChannelMode(new ChannelMode("SSL", 'S')); - } + hybrid::Pong message_pong; + ratbox::Server message_server; + hybrid::SID message_sid; + hybrid::SJoin message_sjoin; + ratbox::TB message_tb; + hybrid::TMode message_tmode; + ratbox::UID message_uid; public: - ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_capab(this), message_error(this), message_invite(this), message_kick(this), - message_kill(this), message_mode(this), message_motd(this), message_notice(this), message_part(this), - message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), - message_time(this), message_topic(this), message_version(this), message_whois(this), - - message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask"), message_nick("IRCDMessage", "ratbox/nick", "hybrid/nick"), - message_pong("IRCDMessage", "ratbox/pong", "hybrid/pong"), message_sid("IRCDMessage", "ratbox/sid", "hybrid/sid"), - message_sjoin("IRCDMessage", "ratbox/sjoin", "hybrid/sjoin"), message_tmode("IRCDMessage", "ratbox/tmode", "hybrid/tmode"), - - message_encap(this), message_join(this), message_pass(this), message_server(this), message_tburst(this), message_uid(this) - { - - if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load hybrid"); - m_hybrid = ModuleManager::FindModule("hybrid"); - if (!m_hybrid) - throw ModuleException("Unable to find hybrid"); - if (!hybrid) - throw ModuleException("No protocol interface for hybrid"); - - this->AddModes(); - } - - ~ProtoRatbox() + ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , ircd_proto(this) + , message_away(this) + , message_capab(this) + , message_error(this) + , message_invite(this) + , message_kick(this) + , message_kill(this) + , message_mode(this) + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_topic(this) + , message_version(this) + , message_whois(this) + + , message_bmask(this) + , message_encap(this) + , message_join(this) + , message_nick(this) + , message_pass(this) + , message_pong(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_tb(this) + , message_tmode(this) + , message_uid(this) { - m_hybrid = ModuleManager::FindModule("hybrid"); - ModuleManager::UnloadModule(m_hybrid, NULL); } }; +template<> void ModuleInfo<ProtoRatbox>(ModuleDef *def) +{ + def->Depends("hybrid"); +} + MODULE_INIT(ProtoRatbox) diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index cff2f440b..d805e60cb 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -1,22 +1,33 @@ -/* Unreal IRCD 3.2.x functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2003-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" -#include "modules/cs_mode.h" +#include "modules/chanserv/mode.h" #include "modules/sasl.h" +#include "modules/operserv/stats.h" + +static Anope::string UplinkSID; class UnrealIRCdProto : public IRCDProto { public: - UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 3.2.x") + UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 4") { DefaultPseudoclientModes = "+Soiq"; CanSVSNick = true; @@ -27,18 +38,19 @@ class UnrealIRCdProto : public IRCDProto CanSQLine = true; CanSZLine = true; CanSVSHold = true; - CanSVSO = true; + CanCertFP = true; + RequiresID = true; MaxModes = 12; } private: /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) anope_override + void SendSVSNOOP(const Server *server, bool set) override { - UplinkSocket::Message() << "SVSNOOP " << server->GetName() << " " << (set ? "+" : "-"); + Uplink::Send("SVSNOOP", server->GetSID(), set ? "+" : "-"); } - void SendAkillDel(const XLine *x) anope_override + void SendAkillDel(XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) return; @@ -54,34 +66,34 @@ class UnrealIRCdProto : public IRCDProto } } - UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by; + Uplink::Send("TKL", "-", "G", x->GetUser(), x->GetHost(), x->GetBy()); } - void SendTopic(const MessageSource &source, Channel *c) anope_override + void SendTopic(const MessageSource &source, Channel *c) override { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; + Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } - void SendVhostDel(User *u) anope_override + void SendVhostDel(User *u) override { - BotInfo *HostServ = Config->GetClient("HostServ"); + ServiceBot *HostServ = Config->GetClient("HostServ"); u->RemoveMode(HostServ, "CLOAK"); u->RemoveMode(HostServ, "VHOST"); ModeManager::ProcessModes(); u->SetMode(HostServ, "CLOAK"); } - void SendAkill(User *u, XLine *x) anope_override + void SendAkill(User *u, XLine *x) override { if (x->IsRegex() || x->HasNickOrReal()) { @@ -89,22 +101,28 @@ class UnrealIRCdProto : public IRCDProto { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) + if (x->GetManager()->Check(it->second, x)) this->SendAkill(it->second, x); return; } - const XLine *old = x; + XLine *old = x; - if (old->manager->HasEntry("*@" + u->host)) + if (old->GetManager()->HasEntry("*@" + u->host)) return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - old->manager->AddXLine(xline); - x = xline; + XLine *xl = Serialize::New<XLine *>(); + xl->SetMask("*@" + u->host); + xl->SetBy(old->GetBy()); + xl->SetExpires(old->GetExpires()); + xl->SetReason(old->GetReason()); + xl->SetID(old->GetID()); + + old->GetManager()->AddXLine(xl); + x = xl; - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; + Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->GetMask() << " because " << u->GetMask() << "#" << u->realname << " matches " << old->GetMask(); } /* ZLine if we can instead */ @@ -119,43 +137,45 @@ class UnrealIRCdProto : public IRCDProto } // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); + Uplink::Send("TKL", "+", "G", x->GetUser(), x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); } - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVSKILL " << user->nick << " :" << buf; + Uplink::Send(source, "SVSKILL", user->GetUID(), buf); user->KillInternal(source, buf); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override + void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { - UplinkSocket::Message(source) << "SVS2MODE " << u->nick <<" " << buf; + IRCMessage message(source, "SVS2MODE", u->GetUID()); + message.TokenizeAndPush(buf); + Uplink::SendMessage(message); } - void SendClientIntroduction(User *u) anope_override + void SendClientIntroduction(User *u) override { Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message() << "NICK " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " " << u->server->GetName() << " 0 " << modes << " " << u->host << " * :" << u->realname; + Uplink::Send("UID", u->nick, 1, u->timestamp, u->GetIdent(), u->host, u->GetUID(), "*", modes, !u->vhost.empty() ? u->vhost : "*", !u->chost.empty() ? u->chost : "*", "*", u->realname); } /* SERVER name hop descript */ /* Unreal 3.2 actually sends some info about itself in the descript area */ - void SendServer(const Server *server) anope_override + void SendServer(const Server *server) override { if (!server->GetSID().empty() && server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :U0-*-" << server->GetSID() << " " << server->GetDescription(); + Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription()); else - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + Uplink::Send("SID", server->GetName(), server->GetHops() + 1, server->GetSID(), server->GetDescription()); } /* JOIN */ - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->nick; + Uplink::Send(Me, "SJOIN", c->creation_time, c->name, user->GetUID()); if (status) { /* First save the channel status incase uc->Status == status */ @@ -167,7 +187,7 @@ class UnrealIRCdProto : public IRCDProto if (uc != NULL) uc->status.Clear(); - BotInfo *setter = BotInfo::Find(user->GetUID()); + ServiceBot *setter = ServiceBot::Find(user->GetUID()); for (size_t i = 0; i < cs.Modes().length(); ++i) c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); @@ -178,9 +198,9 @@ class UnrealIRCdProto : public IRCDProto /* unsqline */ - void SendSQLineDel(const XLine *x) anope_override + void SendSQLineDel(XLine *x) override { - UplinkSocket::Message() << "UNSQLINE " << x->mask; + Uplink::Send("UNSQLINE", x->GetMask()); } /* SQLINE */ @@ -188,103 +208,88 @@ class UnrealIRCdProto : public IRCDProto ** - Unreal will translate this to TKL for us ** */ - void SendSQLine(User *, const XLine *x) anope_override + void SendSQLine(User *, XLine *x) override { - UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason(); - } - - /* - ** svso - ** parv[0] = sender prefix - ** parv[1] = nick - ** parv[2] = options - */ - void SendSVSO(BotInfo *source, const Anope::string &nick, const Anope::string &flag) anope_override - { - UplinkSocket::Message(source) << "SVSO " << nick << " " << flag; + Uplink::Send("SQLINE", x->GetMask(), x->GetReason()); } /* Functions that use serval cmd functions */ - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) override { if (!vIdent.empty()) - UplinkSocket::Message(Me) << "CHGIDENT " << u->nick << " " << vIdent; + Uplink::Send(Me, "CHGIDENT", u->GetUID(), vIdent); if (!vhost.empty()) - UplinkSocket::Message(Me) << "CHGHOST " << u->nick << " " << vhost; + Uplink::Send(Me, "CHGHOST", u->GetUID(), vhost); } - void SendConnect() anope_override + void SendConnect() override { /* NICKv2 = Nick Version 2 VHP = Sends hidden host UMODE2 = sends UMODE2 on user modes NICKIP = Sends IP on NICK - TOKEN = Use tokens to talk SJ3 = Supports SJOIN NOQUIT = No Quit TKLEXT = Extended TKL we don't use it but best to have it - SJB64 = Base64 encoded time stamps - ESVID = Allows storing account names as services stamp MLOCK = Supports the MLOCK server command VL = Version Info - NS = Config->Numeric Server + SID = SID/UID mode */ - Anope::string protoctl = "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK VL"; - if (!Me->GetSID().empty()) - protoctl += " VL"; - UplinkSocket::Message() << "PROTOCTL " << protoctl; - UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password; + Uplink::Send("PASS", Config->Uplinks[Anope::CurrentUplink].password); + Uplink::Send("PROTOCTL", "NICKv2", "VHP", "UMODE2", "NICKIP", "SJOIN", "SJOIN2", "SJ3", "NOQUIT", "TKLEXT", "MLOCK", "SID"); + Uplink::Send("PROTOCTL", "EAUTH=" + Me->GetName() + ",,,Anope-" + Anope::VersionShort()); + Uplink::Send("PROTOCTL", "SID=" + Me->GetSID()); SendServer(Me); } /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick, time_t t) anope_override + void SendSVSHold(const Anope::string &nick, time_t t) override { - UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user"; + Uplink::Send("TKL", "+", "Q", "H", nick, Me->GetName(), Anope::CurTime + t, Anope::CurTime, "Being held for registered user"); } /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override + void SendSVSHoldDel(const Anope::string &nick) override { - UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName(); + Uplink::Send("TKL", "-", "Q", "*", nick, Me->GetName()); } /* UNSGLINE */ /* * SVSNLINE - :realname mask */ - void SendSGLineDel(const XLine *x) anope_override + void SendSGLineDel(XLine *x) override { - UplinkSocket::Message() << "SVSNLINE - :" << x->mask; + Uplink::Send("SVSNLINE", "-", x->GetMask()); } /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override + void SendSZLineDel(XLine *x) override { - UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by; + Uplink::Send("TKL", "-", "Z", "*", x->GetHost(), x->GetBy()); } /* SZLINE */ - void SendSZLine(User *, const XLine *x) anope_override + void SendSZLine(User *, XLine *x) override { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) timeleft = 172800; - UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); + Uplink::Send("TKL", "+", "Z", "*", x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); } /* SGLINE */ /* * SVSNLINE + reason_where_is_space :realname mask with spaces */ - void SendSGLine(User *, const XLine *x) anope_override + void SendSGLine(User *, XLine *x) override { Anope::string edited_reason = x->GetReason(); edited_reason = edited_reason.replace_all_cs(" ", "_"); - UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask; + Uplink::Send("SVSNLINE", "+", edited_reason, x->GetMask()); } /* svsjoin @@ -296,33 +301,33 @@ 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 MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSJoin(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSJOIN " << user->GetUID() << " " << chan; + Uplink::Send(source, "SVSJOIN", user->GetUID(), chan); } - void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override + void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) override { if (!param.empty()) - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan << " :" << param; + Uplink::Send(source, "SVSPART", user->GetUID(), chan, param); else - UplinkSocket::Message(source) << "SVSPART " << user->GetUID() << " " << chan; + Uplink::Send(source, "SVSPART", user->GetUID(), chan); } - void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override + void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) override { - UplinkSocket::Message(source) << "SWHOIS " << who << " :" << mask; + Uplink::Send(source, "SWHOIS", who, mask); } - void SendEOB() anope_override + void SendEOB() override { - UplinkSocket::Message(Me) << "EOS"; + Uplink::Send(Me, "EOS"); } - bool IsNickValid(const Anope::string &nick) anope_override + bool IsNickValid(const Anope::string &nick) override { if (nick.equals_ci("ircd") || nick.equals_ci("irc")) return false; @@ -330,7 +335,7 @@ class UnrealIRCdProto : public IRCDProto return IRCDProto::IsNickValid(nick); } - bool IsChannelValid(const Anope::string &chan) anope_override + bool IsChannelValid(const Anope::string &chan) override { if (chan.find(':') != Anope::string::npos) return false; @@ -338,31 +343,31 @@ class UnrealIRCdProto : public IRCDProto return IRCDProto::IsChannelValid(chan); } - bool IsExtbanValid(const Anope::string &mask) anope_override + bool IsExtbanValid(const Anope::string &mask) override { return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':'; } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickServ::Nick *na) override { /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ - if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED")) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); + if (Servers::Capab.count("ESVID") > 0 && !na->GetAccount()->HasFieldS("UNCONFIRMED")) + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->GetAccount()->GetDisplay().c_str()); else IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0"); } - void SendChannel(Channel *c) anope_override + void SendChannel(Channel *c) override { /* Unreal does not support updating a channels TS without actually joining a user, * so we will join and part us now */ - BotInfo *bi = c->ci->WhoSends(); + ServiceBot *bi = c->ci->WhoSends(); if (!bi) ; else if (c->FindUser(bi) == NULL) @@ -377,24 +382,27 @@ class UnrealIRCdProto : public IRCDProto } } - void SendSASLMessage(const SASL::Message &message) anope_override + void SendSASLMessage(const SASL::Message &message) override { size_t p = message.target.find('!'); if (p == Anope::string::npos) return; - UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext); + if (!message.ext.empty()) + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data, message.ext); + else + Uplink::Send(ServiceBot::Find(message.source), "SASL", message.target.substr(0, p), message.target, message.type, message.data); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override + void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) override { size_t p = uid.find('!'); if (p == Anope::string::npos) return; - UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc; + Uplink::Send(Me, "SVSLOGIN", uid.substr(0, p), uid, acc); } - bool IsIdentValid(const Anope::string &ident) anope_override + bool IsIdentValid(const Anope::string &ident) override { if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; @@ -426,13 +434,13 @@ class UnrealExtBan : public ChannelModeVirtual<ChannelModeList> { } - ChannelMode *Wrap(Anope::string ¶m) anope_override + ChannelMode *Wrap(Anope::string ¶m) override { param = "~" + Anope::string(ext) + ":" + param; return ChannelModeVirtual<ChannelModeList>::Wrap(param); } - ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override + ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) override { if (cm->type != MODE_LIST || param.length() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':') return cm; @@ -451,7 +459,7 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string channel = mask.substr(3); @@ -486,7 +494,7 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); @@ -502,7 +510,7 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); @@ -518,7 +526,7 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); return u->HasMode("REGISTERED") && mask.equals_ci(u->nick); @@ -532,14 +540,29 @@ namespace UnrealExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); - return u->Account() && Anope::Match(u->Account()->display, real_mask); + return u->Account() && Anope::Match(u->Account()->GetDisplay(), real_mask); } }; + + class FingerprintMatcher : public UnrealExtBan + { + public: + FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) + { + } + + bool Matches(User *u, const Entry *e) override + { + const Anope::string &mask = e->GetMask(); + Anope::string real_mask = mask.substr(3); + return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask); + } + }; } class ChannelModeFlood : public ChannelModeParam @@ -548,7 +571,7 @@ class ChannelModeFlood : public ChannelModeParam ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { } /* Borrowed part of this check from UnrealIRCd */ - bool IsValid(Anope::string &value) const anope_override + bool IsValid(Anope::string &value) const override { if (value.empty()) return false; @@ -559,7 +582,7 @@ class ChannelModeFlood : public ChannelModeParam return true; } catch (const ConvertException &) { } - + /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */ size_t end_bracket = value.find(']', 1); if (end_bracket == Anope::string::npos) @@ -600,180 +623,17 @@ class ChannelModeUnrealSSL : public ChannelMode { } - bool CanSet(User *u) const anope_override + bool CanSet(User *u) const override { return false; } }; -struct IRCDMessageCapab : Message::Capab -{ - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - for (unsigned i = 0; i < params.size(); ++i) - { - Anope::string capab = params[i]; - - if (capab.find("CHANMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'b': - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - - ModeManager::AddChannelMode(new UnrealExtban::ChannelMatcher("CHANNELBAN", "BAN", 'c')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("JOINBAN", "BAN", 'j')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("NONICKBAN", "BAN", 'n')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("QUIET", "BAN", 'q')); - ModeManager::AddChannelMode(new UnrealExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r')); - ModeManager::AddChannelMode(new UnrealExtban::RegisteredMatcher("REGISTEREDBAN", "BAN", 'R')); - ModeManager::AddChannelMode(new UnrealExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'a')); - continue; - case 'e': - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - continue; - case 'I': - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'k': - ModeManager::AddChannelMode(new ChannelModeKey('k')); - continue; - case 'f': - ModeManager::AddChannelMode(new ChannelModeFlood('f', false)); - continue; - case 'L': - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'l': - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - continue; - case 'j': - ModeManager::AddChannelMode(new ChannelModeParam("JOINFLOOD", 'j', true)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true)); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'p': - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - continue; - case 's': - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - continue; - case 'm': - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - continue; - case 'n': - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - continue; - case 't': - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - continue; - case 'i': - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - continue; - case 'r': - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - continue; - case 'R': - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - continue; - case 'c': - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - continue; - case 'O': - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - continue; - case 'A': - ModeManager::AddChannelMode(new ChannelModeOperOnly("ADMINONLY", 'A')); - continue; - case 'Q': - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - continue; - case 'K': - ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K')); - continue; - case 'V': - ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V')); - continue; - case 'C': - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - continue; - case 'u': - ModeManager::AddChannelMode(new ChannelMode("AUDITORIUM", 'u')); - continue; - case 'z': - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - continue; - case 'N': - ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N')); - continue; - case 'S': - ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S')); - continue; - case 'M': - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - continue; - case 'T': - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T')); - continue; - case 'G': - ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G')); - continue; - case 'Z': - ModeManager::AddChannelMode(new ChannelModeUnrealSSL("", 'Z')); - continue; - default: - ModeManager::AddChannelMode(new ChannelMode("", modebuf[t])); - } - } - } - } - - Message::Capab::Run(source, params); - } -}; - struct IRCDMessageChgHost : IRCDMessage { IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = User::Find(params[0]); if (u) @@ -785,7 +645,7 @@ struct IRCDMessageChgIdent : IRCDMessage { IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = User::Find(params[0]); if (u) @@ -797,7 +657,7 @@ struct IRCDMessageChgName : IRCDMessage { IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = User::Find(params[0]); if (u) @@ -805,11 +665,39 @@ struct IRCDMessageChgName : IRCDMessage } }; +struct IRCDMessageMD : IRCDMessage +{ + IRCDMessageMD(Module *creator) : IRCDMessage(creator, "MD", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &mdtype = params[0], + &obj = params[1], + &var = params[2], + &value = params.size() > 3 ? params[3] : ""; + + if (mdtype == "client") + { + User *u = User::Find(obj); + + if (u == nullptr) + return; + + if (var == "certfp" && !value.empty()) + { + u->Extend<bool>("ssl", true); + u->fingerprint = value; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); + } + } + } +}; + struct IRCDMessageMode : IRCDMessage { IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { bool server_source = source.GetServer() != NULL; Anope::string modes = params[1]; @@ -854,9 +742,10 @@ struct IRCDMessageNetInfo : IRCDMessage { IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { - UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; + Stats *stats = Serialize::GetObject<Stats *>(); + Uplink::Send("NETINFO", stats ? stats->GetMaxUserCount() : 0, Anope::CurTime, params[2], params[3], "0", "0", "0", params[7]); } }; @@ -884,7 +773,7 @@ struct IRCDMessageNick : IRCDMessage ** parv[0] = new nickname ** parv[1] = hopcount */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (params.size() == 11) { @@ -911,22 +800,22 @@ struct IRCDMessageNick : IRCDMessage Log(LOG_DEBUG) << "User " << params[0] << " introduced from non-existent server " << params[5] << "?"; return; } - - NickAlias *na = NULL; + + NickServ::Nick *na = NULL; if (params[6] == "0") ; else if (params[6].is_pos_number_only()) { if (convertTo<time_t>(params[6]) == user_ts) - na = NickAlias::Find(params[0]); + na = NickServ::FindNick(params[0]); } else { - na = NickAlias::Find(params[6]); + na = NickServ::FindNick(params[6]); } - User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL); + User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? na->GetAccount() : NULL); } else source.GetUser()->ChangeNick(params[0]); @@ -946,21 +835,43 @@ struct IRCDMessagePong : IRCDMessage { IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { if (!source.GetServer()->IsSynced()) source.GetServer()->Sync(false); } }; +struct IRCDMessageProtoctl : Message::Capab +{ + IRCDMessageProtoctl(Module *creator) : Message::Capab(creator, "PROTOCTL") { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + for (unsigned int i = 0; i < params.size(); ++i) + { + Anope::string capab = params[i]; + + if (!capab.find("SID=")) + { + UplinkSID = capab.substr(4); + } + } + + Message::Capab::Run(source, params); + } +}; + struct IRCDMessageSASL : IRCDMessage { + ServiceReference<SASL::Service> sasl; + IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { size_t p = params[1].find('!'); - if (!SASL::sasl || p == Anope::string::npos) + if (!sasl || p == Anope::string::npos) return; SASL::Message m; @@ -970,7 +881,7 @@ struct IRCDMessageSASL : IRCDMessage m.data = params[3]; m.ext = params.size() > 4 ? params[4] : ""; - SASL::sasl->ProcessMessage(m); + sasl->ProcessMessage(m); } }; @@ -978,7 +889,7 @@ struct IRCDMessageSDesc : IRCDMessage { IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { source.GetServer()->SetDescription(params[0]); } @@ -988,7 +899,7 @@ struct IRCDMessageSetHost : IRCDMessage { IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); @@ -1004,7 +915,7 @@ struct IRCDMessageSetIdent : IRCDMessage { IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); u->SetVIdent(params[0]); @@ -1015,7 +926,7 @@ struct IRCDMessageSetName : IRCDMessage { IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { User *u = source.GetUser(); u->SetRealname(params[0]); @@ -1026,7 +937,7 @@ struct IRCDMessageServer : IRCDMessage { IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; @@ -1035,7 +946,7 @@ struct IRCDMessageServer : IRCDMessage Anope::string desc; spacesepstream(params[2]).GetTokenRemainder(desc, 1); - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc); + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc, UplinkSID); } else new Server(source.GetServer(), params[0], hops, params[2]); @@ -1044,11 +955,25 @@ struct IRCDMessageServer : IRCDMessage } }; +struct IRCDMessageSID : IRCDMessage +{ + IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; + + new Server(source.GetServer(), params[0], hops, params[3], params[2]); + + IRCD->SendPing(Me->GetName(), params[0]); + } +}; + struct IRCDMessageSJoin : IRCDMessage { IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Anope::string modes; if (params.size() >= 4) @@ -1103,7 +1028,7 @@ struct IRCDMessageSJoin : IRCDMessage users.push_back(sju); } } - + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; Message::Join::SJoin(source, params[1], ts, modes, users); @@ -1142,7 +1067,7 @@ struct IRCDMessageTopic : IRCDMessage ** parv[2] = topic time ** parv[3] = topic text */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { Channel *c = Channel::Find(params[0]); if (c) @@ -1150,20 +1075,108 @@ struct IRCDMessageTopic : IRCDMessage } }; +/* + * parv[0] = nickname + * parv[1] = hopcount + * parv[2] = timestamp + * parv[3] = username + * parv[4] = hostname + * parv[5] = UID + * parv[6] = servicestamp + * parv[7] = umodes + * parv[8] = virthost, * if none + * parv[9] = cloaked host, * if none + * parv[10] = ip + * parv[11] = info + */ +struct IRCDMessageUID : IRCDMessage +{ + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + { + Anope::string + nickname = params[0], + hopcount = params[1], + timestamp = params[2], + username = params[3], + hostname = params[4], + uid = params[5], + account = params[6], + umodes = params[7], + vhost = params[8], + chost = params[9], + ip = params[10], + info = params[11]; + + if (ip != "*") + { + Anope::string decoded_ip; + Anope::B64Decode(ip, decoded_ip); + + sockaddrs ip_addr; + ip_addr.ntop(ip.length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); + ip = ip_addr.addr(); + } + + if (vhost == "*") + vhost.clear(); + + if (chost == "*") + chost.clear(); + + time_t user_ts; + try + { + user_ts = convertTo<time_t>(timestamp); + } + catch (const ConvertException &) + { + user_ts = Anope::CurTime; + } + + NickServ::Nick *na = NULL; + + if (account == "0") + { + /* nothing */ + } + else if (account.is_pos_number_only()) + { + if (convertTo<time_t>(account) == user_ts) + na = NickServ::FindNick(nickname); + } + else + { + na = NickServ::FindNick(account); + } + + User *u = User::OnIntroduce(nickname, username, hostname, vhost, ip, source.GetServer(), info, user_ts, umodes, uid, na ? na->GetAccount() : NULL); + + if (u && !chost.empty() && chost != u->GetCloakedHost()) + u->SetCloakedHost(chost); + } +}; struct IRCDMessageUmode2 : IRCDMessage { IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override { source.GetUser()->SetModesInternal(source, "%s", params[0].c_str()); } }; class ProtoUnreal : public Module + , public EventHook<Event::UserNickChange> + , public EventHook<Event::ChannelSync> + , public EventHook<Event::ChanRegistered> + , public EventHook<Event::DelChan> + , public EventHook<Event::MLockEvents> { UnrealIRCdProto ircd_proto; + ServiceReference<ModeLocks> mlocks; /* Core message handlers */ Message::Away message_away; @@ -1185,148 +1198,171 @@ class ProtoUnreal : public Module Message::Whois message_whois; /* Our message handlers */ - IRCDMessageCapab message_capab; IRCDMessageChgHost message_chghost; IRCDMessageChgIdent message_chgident; IRCDMessageChgName message_chgname; + IRCDMessageMD message_md; IRCDMessageMode message_mode, message_svsmode, message_svs2mode; IRCDMessageNetInfo message_netinfo; IRCDMessageNick message_nick; IRCDMessagePong message_pong; + IRCDMessageProtoctl message_protoctl; IRCDMessageSASL message_sasl; IRCDMessageSDesc message_sdesc; IRCDMessageSetHost message_sethost; IRCDMessageSetIdent message_setident; IRCDMessageSetName message_setname; IRCDMessageServer message_server; + IRCDMessageSID message_sid; IRCDMessageSJoin message_sjoin; IRCDMessageTopic message_topic; + IRCDMessageUID message_uid; IRCDMessageUmode2 message_umode2; bool use_server_side_mlock; - void AddModes() - { - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - /* Unreal sends +q as * and +a as ~ */ - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '~', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '*', 4)); - - /* Add user modes */ - ModeManager::AddUserMode(new UserModeOperOnly("SERV_ADMIN", 'A')); - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - ModeManager::AddUserMode(new UserModeOperOnly("CO_ADMIN", 'C')); - ModeManager::AddUserMode(new UserMode("CENSOR", 'G')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEIDLE", 'I')); - ModeManager::AddUserMode(new UserModeOperOnly("NETADMIN", 'N')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'S')); - ModeManager::AddUserMode(new UserMode("NOCTCP", 'T')); - ModeManager::AddUserMode(new UserMode("WEBTV", 'V')); - ModeManager::AddUserMode(new UserModeOperOnly("WHOIS", 'W')); - ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); - ModeManager::AddUserMode(new UserMode("DEAF", 'd')); - ModeManager::AddUserMode(new UserModeOperOnly("GLOBOPS", 'g')); - ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserMode("PRIV", 'p')); - ModeManager::AddUserMode(new UserModeOperOnly("GOD", 'q')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeNoone("VHOST", 't')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'z')); - } - public: - ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_svskill(this, "SVSKILL"), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_mode(this, "MODE"), - message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this), - message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this), - message_sjoin(this), message_topic(this), message_umode2(this) + ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) + , EventHook<Event::UserNickChange>(this, EventHook<Event::UserNickChange>::Priority::FIRST) + , EventHook<Event::ChannelSync>(this, EventHook<Event::ChannelSync>::Priority::FIRST) + , EventHook<Event::ChanRegistered>(this, EventHook<Event::ChanRegistered>::Priority::FIRST) + , EventHook<Event::DelChan>(this, EventHook<Event::DelChan>::Priority::FIRST) + , EventHook<Event::MLockEvents>(this, EventHook<Event::MLockEvents>::Priority::FIRST) + , ircd_proto(this) + , message_away(this) + , message_error(this) + , message_invite(this) + , message_join(this) + , message_kick(this) + , message_kill(this) + , message_svskill(this, "SVSKILL") + , message_motd(this) + , message_notice(this) + , message_part(this) + , message_ping(this) + , message_privmsg(this) + , message_quit(this) + , message_squit(this) + , message_stats(this) + , message_time(this) + , message_version(this) + , message_whois(this) + + , message_chghost(this) + , message_chgident(this) + , message_chgname(this) + , message_md(this) + , message_mode(this, "MODE") + , message_svsmode(this, "SVSMODE") + , message_svs2mode(this, "SVS2MODE") + , message_netinfo(this) + , message_nick(this) + , message_pong(this) + , message_protoctl(this) + , message_sasl(this) + , message_sdesc(this) + , message_sethost(this) + , message_setident(this) + , message_setname(this) + , message_server(this) + , message_sid(this) + , message_sjoin(this) + , message_topic(this) + , message_uid(this) + , message_umode2(this) + { + } + + void OnReload(Configuration::Conf *conf) override { + use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); - this->AddModes(); - } + for (int i = 0; i < conf->CountBlock("extban"); ++i) + { + Configuration::Block *extban = conf->GetBlock("extban", i); + Anope::string name = extban->Get<Anope::string>("name"), + type = extban->Get<Anope::string>("type"), + base = extban->Get<Anope::string>("base"), + character = extban->Get<Anope::string>("character"); - void Prioritize() anope_override - { - ModuleManager::SetPriority(this, PRIORITY_FIRST); - } + ChannelMode *cm; - void OnReload(Configuration::Conf *conf) anope_override - { - use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); + if (character.empty()) + continue; + + if (type == "channel") + cm = new UnrealExtban::ChannelMatcher(name, base, character[0]); + else if (type == "entry") + cm = new UnrealExtban::EntryMatcher(name, base, character[0]); + else if (type == "realname") + cm = new UnrealExtban::RealnameMatcher(name, base, character[0]); + else if (type == "registered") + cm = new UnrealExtban::RegisteredMatcher(name, base, character[0]); + else if (type == "account") + cm = new UnrealExtban::AccountMatcher(name, base, character[0]); + else if (type == "fingerprint") + cm = new UnrealExtban::FingerprintMatcher(name, base, character[0]); + else + continue; + + if (!ModeManager::AddChannelMode(cm)) + delete cm; + } } - void OnUserNickChange(User *u, const Anope::string &) anope_override + void OnUserNickChange(User *u, const Anope::string &) override { u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); if (Servers::Capab.count("ESVID") == 0) IRCD->SendLogout(u); } - void OnChannelSync(Channel *c) anope_override + void OnChannelSync(Channel *c) override { if (!c->ci) return; - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks) + if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && mlocks) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", c->creation_time, c->ci->GetName(), modes); } } - void OnChanRegistered(ChannelInfo *ci) anope_override + void OnChanRegistered(ChanServ::Channel *ci) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK")) + if (!ci->c || !use_server_side_mlock || !mlocks || !Servers::Capab.count("MLOCK")) return; - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } - void OnDelChan(ChannelInfo *ci) anope_override + void OnDelChan(ChanServ::Channel *ci) override { if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) return; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :"; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), ""); } - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; } - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override + EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) override { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) + ChannelMode *cm = ModeManager::FindChannelModeByName(lock->GetName()); + if (use_server_side_mlock && cm && mlocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; + Anope::string modes = mlocks->GetMLockAsString(ci, false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); + Uplink::Send(Me, "MLOCK", ci->c->creation_time, ci->GetName(), modes); } return EVENT_CONTINUE; diff --git a/modules/protocol/unreal4.cpp b/modules/protocol/unreal4.cpp deleted file mode 100644 index 6e5f6ec55..000000000 --- a/modules/protocol/unreal4.cpp +++ /dev/null @@ -1,1468 +0,0 @@ -/* Unreal IRCD 4 functions - * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -#include "module.h" -#include "modules/cs_mode.h" -#include "modules/sasl.h" - -static Anope::string UplinkSID; - -class UnrealIRCdProto : public IRCDProto -{ - public: - UnrealIRCdProto(Module *creator) : IRCDProto(creator, "UnrealIRCd 4") - { - DefaultPseudoclientModes = "+Soiq"; - CanSVSNick = true; - CanSVSJoin = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSNLine = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanCertFP = true; - RequiresID = true; - MaxModes = 12; - } - - private: - /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) anope_override - { - UplinkSocket::Message() << "SVSNOOP " << server->GetSID() << " " << (set ? "+" : "-"); - } - - void SendAkillDel(const XLine *x) anope_override - { - if (x->IsRegex() || x->HasNickOrReal()) - return; - - /* ZLine if we can instead */ - if (x->GetUser() == "*") - { - cidr a(x->GetHost()); - if (a.valid()) - { - IRCD->SendSZLineDel(x); - return; - } - } - - UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << x->by; - } - - void SendTopic(const MessageSource &source, Channel *c) anope_override - { - UplinkSocket::Message(source) << "TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; - } - - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; - } - - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; - } - - void SendVhostDel(User *u) anope_override - { - BotInfo *HostServ = Config->GetClient("HostServ"); - u->RemoveMode(HostServ, "CLOAK"); - u->RemoveMode(HostServ, "VHOST"); - ModeManager::ProcessModes(); - u->SetMode(HostServ, "CLOAK"); - } - - void SendAkill(User *u, XLine *x) anope_override - { - if (x->IsRegex() || x->HasNickOrReal()) - { - if (!u) - { - /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); - return; - } - - const XLine *old = x; - - if (old->manager->HasEntry("*@" + u->host)) - return; - - /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); - old->manager->AddXLine(xline); - x = xline; - - Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; - } - - /* ZLine if we can instead */ - if (x->GetUser() == "*") - { - cidr a(x->GetHost()); - if (a.valid()) - { - IRCD->SendSZLine(u, x); - return; - } - } - - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - UplinkSocket::Message() << "TKL + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); - } - - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "SVSKILL " << user->GetUID() << " :" << buf; - user->KillInternal(source, buf); - } - - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "SVS2MODE " << u->GetUID() <<" " << buf; - } - - void SendClientIntroduction(User *u) anope_override - { - Anope::string modes = "+" + u->GetModes(); - UplinkSocket::Message(u->server) << "UID " << u->nick << " 1 " << u->timestamp << " " << u->GetIdent() << " " << u->host << " " - << u->GetUID() << " * " << modes << " " << (!u->vhost.empty() ? u->vhost : "*") << " " - << (!u->chost.empty() ? u->chost : "*") << " " << "*" << " :" << u->realname; - } - - void SendServer(const Server *server) anope_override - { - if (server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() + 1 << " :" << server->GetDescription(); - else - UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() + 1 << " " << server->GetSID() << " :" << server->GetDescription(); - } - - /* JOIN */ - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override - { - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->GetUID(); - if (status) - { - /* First save the channel status incase uc->Status == status */ - ChannelStatus cs = *status; - /* If the user is internally on the channel with flags, kill them so that - * the stacker will allow this. - */ - ChanUserContainer *uc = c->FindUser(user); - if (uc != NULL) - uc->status.Clear(); - - BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); - - if (uc != NULL) - uc->status = cs; - } - } - - /* unsqline - */ - void SendSQLineDel(const XLine *x) anope_override - { - UplinkSocket::Message() << "UNSQLINE " << x->mask; - } - - /* SQLINE */ - /* - ** - Unreal will translate this to TKL for us - ** - */ - void SendSQLine(User *, const XLine *x) anope_override - { - UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason(); - } - - /* Functions that use serval cmd functions */ - - void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override - { - if (!vIdent.empty()) - UplinkSocket::Message(Me) << "CHGIDENT " << u->GetUID() << " " << vIdent; - if (!vhost.empty()) - UplinkSocket::Message(Me) << "CHGHOST " << u->GetUID() << " " << vhost; - } - - void SendConnect() anope_override - { - /* - NICKv2 = Nick Version 2 - VHP = Sends hidden host - UMODE2 = sends UMODE2 on user modes - NICKIP = Sends IP on NICK - SJ3 = Supports SJOIN - NOQUIT = No Quit - TKLEXT = Extended TKL we don't use it but best to have it - MLOCK = Supports the MLOCK server command - VL = Version Info - SID = SID/UID mode - */ - UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink].password; - UplinkSocket::Message() << "PROTOCTL " << "NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT MLOCK SID"; - UplinkSocket::Message() << "PROTOCTL " << "EAUTH=" << Me->GetName() << ",,,Anope-" << Anope::VersionShort(); - UplinkSocket::Message() << "PROTOCTL " << "SID=" << Me->GetSID(); - SendServer(Me); - } - - /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick, time_t t) anope_override - { - UplinkSocket::Message() << "TKL + Q H " << nick << " " << Me->GetName() << " " << Anope::CurTime + t << " " << Anope::CurTime << " :Being held for registered user"; - } - - /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override - { - UplinkSocket::Message() << "TKL - Q * " << nick << " " << Me->GetName(); - } - - /* UNSGLINE */ - /* - * SVSNLINE - :realname mask - */ - void SendSGLineDel(const XLine *x) anope_override - { - UplinkSocket::Message() << "SVSNLINE - :" << x->mask; - } - - /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override - { - UplinkSocket::Message() << "TKL - Z * " << x->GetHost() << " " << x->by; - } - - /* SZLINE */ - void SendSZLine(User *, const XLine *x) anope_override - { - // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->expires) - timeleft = 172800; - UplinkSocket::Message() << "TKL + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); - } - - /* SGLINE */ - /* - * SVSNLINE + reason_where_is_space :realname mask with spaces - */ - void SendSGLine(User *, const XLine *x) anope_override - { - Anope::string edited_reason = x->GetReason(); - edited_reason = edited_reason.replace_all_cs(" ", "_"); - UplinkSocket::Message() << "SVSNLINE + " << edited_reason << " :" << x->mask; - } - - /* svsjoin - parv[0] - sender - parv[1] - nick to make join - parv[2] - channel to join - parv[3] - (optional) channel key(s) - */ - /* 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 MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override - { - if (!param.empty()) - UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan << " :" << param; - else - UplinkSocket::Message() << "SVSJOIN " << user->GetUID() << " " << chan; - } - - void SendSVSPart(const MessageSource &source, User *user, const Anope::string &chan, const Anope::string ¶m) anope_override - { - if (!param.empty()) - UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan << " :" << param; - else - UplinkSocket::Message() << "SVSPART " << user->GetUID() << " " << chan; - } - - void SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask) anope_override - { - UplinkSocket::Message(source) << "SWHOIS " << who << " :" << mask; - } - - void SendEOB() anope_override - { - UplinkSocket::Message(Me) << "EOS"; - } - - bool IsNickValid(const Anope::string &nick) anope_override - { - if (nick.equals_ci("ircd") || nick.equals_ci("irc")) - return false; - - return IRCDProto::IsNickValid(nick); - } - - bool IsChannelValid(const Anope::string &chan) anope_override - { - if (chan.find(':') != Anope::string::npos) - return false; - - return IRCDProto::IsChannelValid(chan); - } - - bool IsExtbanValid(const Anope::string &mask) anope_override - { - return mask.length() >= 4 && mask[0] == '~' && mask[2] == ':'; - } - - void SendLogin(User *u, NickAlias *na) anope_override - { - /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ - if (Servers::Capab.count("ESVID") > 0 && !na->nc->HasExt("UNCONFIRMED")) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->nc->display.c_str()); - else - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); - } - - void SendLogout(User *u) anope_override - { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d 0"); - } - - void SendChannel(Channel *c) anope_override - { - /* Unreal does not support updating a channels TS without actually joining a user, - * so we will join and part us now - */ - BotInfo *bi = c->ci->WhoSends(); - if (!bi) - ; - else if (c->FindUser(bi) == NULL) - { - bi->Join(c); - bi->Part(c); - } - else - { - bi->Part(c); - bi->Join(c); - } - } - - void SendSASLMessage(const SASL::Message &message) anope_override - { - size_t p = message.target.find('!'); - if (p == Anope::string::npos) - return; - - UplinkSocket::Message(BotInfo::Find(message.source)) << "SASL " << message.target.substr(0, p) << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : " " + message.ext); - } - - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override - { - size_t p = uid.find('!'); - if (p == Anope::string::npos) - return; - UplinkSocket::Message(Me) << "SVSLOGIN " << uid.substr(0, p) << " " << uid << " " << acc; - } - - bool IsIdentValid(const Anope::string &ident) anope_override - { - if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) - return false; - - for (unsigned i = 0; i < ident.length(); ++i) - { - const char &c = ident[i]; - - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') - continue; - - if (c == '-' || c == '.' || c == '_') - continue; - - return false; - } - - return true; - } -}; - -class UnrealExtBan : public ChannelModeVirtual<ChannelModeList> -{ - char ext; - - public: - UnrealExtBan(const Anope::string &mname, const Anope::string &basename, char extban) : ChannelModeVirtual<ChannelModeList>(mname, basename) - , ext(extban) - { - } - - ChannelMode *Wrap(Anope::string ¶m) anope_override - { - param = "~" + Anope::string(ext) + ":" + param; - return ChannelModeVirtual<ChannelModeList>::Wrap(param); - } - - ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override - { - if (cm->type != MODE_LIST || param.length() < 4 || param[0] != '~' || param[1] != ext || param[2] != ':') - return cm; - - param = param.substr(3); - return this; - } -}; - -namespace UnrealExtban -{ - class ChannelMatcher : public UnrealExtBan - { - public: - ChannelMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - Anope::string channel = mask.substr(3); - - ChannelMode *cm = NULL; - if (channel[0] != '#') - { - char modeChar = ModeManager::GetStatusChar(channel[0]); - channel.erase(channel.begin()); - cm = ModeManager::FindChannelModeByChar(modeChar); - if (cm != NULL && cm->type != MODE_STATUS) - cm = NULL; - } - - Channel *c = Channel::Find(channel); - if (c != NULL) - { - ChanUserContainer *uc = c->FindUser(u); - if (uc != NULL) - if (cm == NULL || uc->status.HasMode(cm->mchar)) - return true; - } - - return false; - } - }; - - class EntryMatcher : public UnrealExtBan - { - public: - EntryMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - return Entry(this->name, real_mask).Matches(u); - } - }; - - class RealnameMatcher : public UnrealExtBan - { - public: - RealnameMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - return Anope::Match(u->realname, real_mask); - } - }; - - class RegisteredMatcher : public UnrealExtBan - { - public: - RegisteredMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - return u->HasMode("REGISTERED") && mask.equals_ci(u->nick); - } - }; - - class AccountMatcher : public UnrealExtBan - { - public: - AccountMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - - return u->Account() && Anope::Match(u->Account()->display, real_mask); - } - }; - - class FingerprintMatcher : public UnrealExtBan - { - public: - FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : UnrealExtBan(mname, mbase, c) - { - } - - bool Matches(User *u, const Entry *e) anope_override - { - const Anope::string &mask = e->GetMask(); - Anope::string real_mask = mask.substr(3); - return !u->fingerprint.empty() && Anope::Match(u->fingerprint, real_mask); - } - }; -} - -class ChannelModeFlood : public ChannelModeParam -{ - public: - ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam("FLOOD", modeChar, minusNoArg) { } - - /* Borrowed part of this check from UnrealIRCd */ - bool IsValid(Anope::string &value) const anope_override - { - if (value.empty()) - return false; - try - { - 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; - } - catch (const ConvertException &) { } - - /* '['<number><1 letter>[optional: '#'+1 letter],[next..]']'':'<number> */ - 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] */ - size_t p = 0; - while (p < arg.length() && isdigit(arg[p])) - ++p; - 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 compatibility. */ - try - { - int v = arg.substr(0, p).is_number_only() ? convertTo<int>(arg.substr(0, p)) : 0; - if (v < 1 || v > 999) - return false; - } - catch (const ConvertException &) - { - return false; - } - } - - return true; - } -}; - -class ChannelModeUnrealSSL : public ChannelMode -{ - public: - ChannelModeUnrealSSL(const Anope::string &n, char c) : ChannelMode(n, c) - { - } - - bool CanSet(User *u) const anope_override - { - return false; - } -}; - -struct IRCDMessageCapab : Message::Capab -{ - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - for (unsigned i = 0; i < params.size(); ++i) - { - Anope::string capab = params[i]; - - if (capab.find("CHANMODES") != Anope::string::npos) - { - Anope::string modes(capab.begin() + 10, capab.end()); - commasepstream sep(modes); - Anope::string modebuf; - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'b': - ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); - - ModeManager::AddChannelMode(new UnrealExtban::ChannelMatcher("CHANNELBAN", "BAN", 'c')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("JOINBAN", "BAN", 'j')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("NONICKBAN", "BAN", 'n')); - ModeManager::AddChannelMode(new UnrealExtban::EntryMatcher("QUIET", "BAN", 'q')); - ModeManager::AddChannelMode(new UnrealExtban::RealnameMatcher("REALNAMEBAN", "BAN", 'r')); - ModeManager::AddChannelMode(new UnrealExtban::RegisteredMatcher("REGISTEREDBAN", "BAN", 'R')); - ModeManager::AddChannelMode(new UnrealExtban::AccountMatcher("ACCOUNTBAN", "BAN", 'a')); - ModeManager::AddChannelMode(new UnrealExtban::FingerprintMatcher("SSLBAN", "BAN", 'S')); - // also has O for opertype extban, but it doesn't send us users opertypes - continue; - case 'e': - ModeManager::AddChannelMode(new ChannelModeList("EXCEPT", 'e')); - continue; - case 'I': - ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'k': - ModeManager::AddChannelMode(new ChannelModeKey('k')); - continue; - case 'f': - ModeManager::AddChannelMode(new ChannelModeFlood('f', false)); - continue; - case 'L': - ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L')); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t])); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'l': - ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); - continue; - default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true)); - } - } - - sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) - { - switch (modebuf[t]) - { - case 'p': - ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); - continue; - case 's': - ModeManager::AddChannelMode(new ChannelMode("SECRET", 's')); - continue; - case 'm': - ModeManager::AddChannelMode(new ChannelMode("MODERATED", 'm')); - continue; - case 'n': - ModeManager::AddChannelMode(new ChannelMode("NOEXTERNAL", 'n')); - continue; - case 't': - ModeManager::AddChannelMode(new ChannelMode("TOPIC", 't')); - continue; - case 'i': - ModeManager::AddChannelMode(new ChannelMode("INVITE", 'i')); - continue; - case 'r': - ModeManager::AddChannelMode(new ChannelModeNoone("REGISTERED", 'r')); - continue; - case 'R': - ModeManager::AddChannelMode(new ChannelMode("REGISTEREDONLY", 'R')); - continue; - case 'c': - ModeManager::AddChannelMode(new ChannelMode("BLOCKCOLOR", 'c')); - continue; - case 'O': - ModeManager::AddChannelMode(new ChannelModeOperOnly("OPERONLY", 'O')); - continue; - case 'Q': - ModeManager::AddChannelMode(new ChannelMode("NOKICK", 'Q')); - continue; - case 'K': - ModeManager::AddChannelMode(new ChannelMode("NOKNOCK", 'K')); - continue; - case 'V': - ModeManager::AddChannelMode(new ChannelMode("NOINVITE", 'V')); - continue; - case 'C': - ModeManager::AddChannelMode(new ChannelMode("NOCTCP", 'C')); - continue; - case 'z': - ModeManager::AddChannelMode(new ChannelMode("SSL", 'z')); - continue; - case 'N': - ModeManager::AddChannelMode(new ChannelMode("NONICK", 'N')); - continue; - case 'S': - ModeManager::AddChannelMode(new ChannelMode("STRIPCOLOR", 'S')); - continue; - case 'M': - ModeManager::AddChannelMode(new ChannelMode("REGMODERATED", 'M')); - continue; - case 'T': - ModeManager::AddChannelMode(new ChannelMode("NONOTICE", 'T')); - continue; - case 'G': - ModeManager::AddChannelMode(new ChannelMode("CENSOR", 'G')); - continue; - case 'Z': - ModeManager::AddChannelMode(new ChannelModeUnrealSSL("", 'Z')); - continue; - case 'd': - // post delayed. means that channel is -D but invisible users still exist. - continue; - case 'D': - ModeManager::AddChannelMode(new ChannelMode("DELAYEDJOIN", 'D')); - continue; - case 'P': - ModeManager::AddChannelMode(new ChannelMode("PERM", 'P')); - continue; - default: - ModeManager::AddChannelMode(new ChannelMode("", modebuf[t])); - } - } - } - else if (!capab.find("SID=")) - { - UplinkSID = capab.substr(4); - } - } - - Message::Capab::Run(source, params); - } -}; - -struct IRCDMessageChgHost : IRCDMessage -{ - IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetDisplayedHost(params[1]); - } -}; - -struct IRCDMessageChgIdent : IRCDMessage -{ - IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetVIdent(params[1]); - } -}; - -struct IRCDMessageChgName : IRCDMessage -{ - IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = User::Find(params[0]); - if (u) - u->SetRealname(params[1]); - } -}; - -struct IRCDMessageMD : IRCDMessage -{ - IRCDMessageMD(Module *creator) : IRCDMessage(creator, "MD", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - const Anope::string &mdtype = params[0], - &obj = params[1], - &var = params[2], - &value = params.size() > 3 ? params[3] : ""; - - if (mdtype == "client") - { - User *u = User::Find(obj); - - if (u == NULL) - return; - - if (var == "certfp" && !value.empty()) - { - u->Extend<bool>("ssl"); - u->fingerprint = value; - FOREACH_MOD(OnFingerprint, (u)); - } - } - } -}; - -struct IRCDMessageMode : IRCDMessage -{ - IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - bool server_source = source.GetServer() != NULL; - Anope::string modes = params[1]; - for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i) - modes += " " + params[i]; - - if (IRCD->IsChannelValid(params[0])) - { - Channel *c = Channel::Find(params[0]); - time_t ts = 0; - - try - { - if (server_source) - ts = convertTo<time_t>(params[params.size() - 1]); - } - catch (const ConvertException &) { } - - if (c) - c->SetModesInternal(source, modes, ts); - } - else - { - User *u = User::Find(params[0]); - if (u) - u->SetModesInternal(source, "%s", params[1].c_str()); - } - } -}; - -/* netinfo - * argv[0] = max global count - * argv[1] = time of end sync - * argv[2] = unreal protocol using (numeric) - * argv[3] = cloak-crc (> u2302) - * argv[4] = free(**) - * argv[5] = free(**) - * argv[6] = free(**) - * argv[7] = ircnet - */ -struct IRCDMessageNetInfo : IRCDMessage -{ - IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - UplinkSocket::Message() << "NETINFO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; - } -}; - -struct IRCDMessageNick : IRCDMessage -{ - IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - /* - ** NICK - new - ** source = NULL - ** parv[0] = nickname - ** parv[1] = hopcount - ** parv[2] = timestamp - ** parv[3] = username - ** parv[4] = hostname - ** parv[5] = servername - ** parv[6] = servicestamp - ** parv[7] = umodes - ** parv[8] = virthost, * if none - ** parv[9] = ip - ** parv[10] = info - ** - ** NICK - change - ** source = oldnick - ** parv[0] = new nickname - ** parv[1] = hopcount - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params.size() == 11) - { - Anope::string ip; - if (params[9] != "*") - { - Anope::string decoded_ip; - Anope::B64Decode(params[9], decoded_ip); - - sockaddrs ip_addr; - ip_addr.ntop(params[9].length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); - ip = ip_addr.addr(); - } - - Anope::string vhost = params[8]; - if (vhost.equals_cs("*")) - vhost.clear(); - - time_t user_ts = params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; - - Server *s = Server::Find(params[5]); - if (s == NULL) - { - Log(LOG_DEBUG) << "User " << params[0] << " introduced from non-existent server " << params[5] << "?"; - return; - } - - NickAlias *na = NULL; - - if (params[6] == "0") - ; - else if (params[6].is_pos_number_only()) - { - if (convertTo<time_t>(params[6]) == user_ts) - na = NickAlias::Find(params[0]); - } - else - { - na = NickAlias::Find(params[6]); - } - - User::OnIntroduce(params[0], params[3], params[4], vhost, ip, s, params[10], user_ts, params[7], "", na ? *na->nc : NULL); - } - else - source.GetUser()->ChangeNick(params[0]); - } -}; - -/** This is here because: - * - * If we had three servers, A, B & C linked like so: A<->B<->C - * If Anope is linked to A and B splits from A and then reconnects - * B introduces itself, introduces C, sends EOS for C, introduces Bs clients - * introduces Cs clients, sends EOS for B. This causes all of Cs clients to be introduced - * with their server "not syncing". We now send a PING immediately when receiving a new server - * and then finish sync once we get a pong back from that server. - */ -struct IRCDMessagePong : IRCDMessage -{ - IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (!source.GetServer()->IsSynced()) - source.GetServer()->Sync(false); - } -}; - -struct IRCDMessageSASL : IRCDMessage -{ - IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - size_t p = params[1].find('!'); - if (!SASL::sasl || p == Anope::string::npos) - return; - - SASL::Message m; - m.source = params[1]; - m.target = params[0]; - m.type = params[2]; - m.data = params[3]; - m.ext = params.size() > 4 ? params[4] : ""; - - SASL::sasl->ProcessMessage(m); - } -}; - -struct IRCDMessageSDesc : IRCDMessage -{ - IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->SetDescription(params[0]); - } -}; - -struct IRCDMessageSetHost : IRCDMessage -{ - IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = source.GetUser(); - - /* When a user sets +x we receive the new host and then the mode change */ - if (u->HasMode("CLOAK")) - u->SetDisplayedHost(params[0]); - else - u->SetCloakedHost(params[0]); - } -}; - -struct IRCDMessageSetIdent : IRCDMessage -{ - IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = source.GetUser(); - u->SetVIdent(params[0]); - } -}; - -struct IRCDMessageSetName : IRCDMessage -{ - IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - User *u = source.GetUser(); - u->SetRealname(params[0]); - } -}; - -struct IRCDMessageServer : IRCDMessage -{ - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; - - if (params[1].equals_cs("1")) - { - Anope::string desc; - spacesepstream(params[2]).GetTokenRemainder(desc, 1); - - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc, UplinkSID); - } - else - new Server(source.GetServer(), params[0], hops, params[2]); - - IRCD->SendPing(Me->GetName(), params[0]); - } -}; - -struct IRCDMessageSID : IRCDMessage -{ - IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; - - new Server(source.GetServer(), params[0], hops, params[3], params[2]); - - IRCD->SendPing(Me->GetName(), params[0]); - } -}; - -struct IRCDMessageSJoin : IRCDMessage -{ - IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string modes; - if (params.size() >= 4) - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - - std::list<Anope::string> bans, excepts, invites; - std::list<Message::Join::SJoinUser> users; - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) - { - /* Ban */ - if (buf[0] == '&') - { - buf.erase(buf.begin()); - bans.push_back(buf); - } - /* Except */ - else if (buf[0] == '"') - { - buf.erase(buf.begin()); - excepts.push_back(buf); - } - /* Invex */ - else if (buf[0] == '\'') - { - buf.erase(buf.begin()); - invites.push_back(buf); - } - else - { - Message::Join::SJoinUser sju; - - /* Get prefixes from the nick */ - for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) - { - sju.first.AddMode(ch); - buf.erase(buf.begin()); - } - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; - continue; - } - - users.push_back(sju); - } - } - - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; - Message::Join::SJoin(source, params[1], ts, modes, users); - - if (!bans.empty() || !excepts.empty() || !invites.empty()) - { - Channel *c = Channel::Find(params[1]); - - if (!c || c->creation_time != ts) - return; - - ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"), - *except = ModeManager::FindChannelModeByName("EXCEPT"), - *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE"); - - if (ban) - for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it) - c->SetModeInternal(source, ban, *it); - if (except) - for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it) - c->SetModeInternal(source, except, *it); - if (invex) - for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it) - c->SetModeInternal(source, invex, *it); - } - } -}; - -struct IRCDMessageTopic : IRCDMessage -{ - IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } - - /* - ** source = sender prefix - ** parv[0] = channel name - ** parv[1] = topic nickname - ** parv[2] = topic time - ** parv[3] = topic text - */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Channel *c = Channel::Find(params[0]); - if (c) - c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime); - } -}; - -/* - * parv[0] = nickname - * parv[1] = hopcount - * parv[2] = timestamp - * parv[3] = username - * parv[4] = hostname - * parv[5] = UID - * parv[6] = servicestamp - * parv[7] = umodes - * parv[8] = virthost, * if none - * parv[9] = cloaked host, * if none - * parv[10] = ip - * parv[11] = info - */ -struct IRCDMessageUID : IRCDMessage -{ - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Anope::string - nickname = params[0], - hopcount = params[1], - timestamp = params[2], - username = params[3], - hostname = params[4], - uid = params[5], - account = params[6], - umodes = params[7], - vhost = params[8], - chost = params[9], - ip = params[10], - info = params[11]; - - if (ip != "*") - { - Anope::string decoded_ip; - Anope::B64Decode(ip, decoded_ip); - - sockaddrs ip_addr; - ip_addr.ntop(ip.length() == 8 ? AF_INET : AF_INET6, decoded_ip.c_str()); - ip = ip_addr.addr(); - } - - if (vhost == "*") - vhost.clear(); - - if (chost == "*") - chost.clear(); - - time_t user_ts; - try - { - user_ts = convertTo<time_t>(timestamp); - } - catch (const ConvertException &) - { - user_ts = Anope::CurTime; - } - - NickAlias *na = NULL; - - if (account == "0") - { - ; - } - else if (account.is_pos_number_only()) - { - if (convertTo<time_t>(account) == user_ts) - na = NickAlias::Find(nickname); - } - else - { - na = NickAlias::Find(account); - } - - User *u = User::OnIntroduce(nickname, username, hostname, vhost, ip, source.GetServer(), info, user_ts, umodes, uid, na ? *na->nc : NULL); - - if (u && !chost.empty() && chost != u->GetCloakedHost()) - u->SetCloakedHost(chost); - } -}; - -struct IRCDMessageUmode2 : IRCDMessage -{ - IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetModesInternal(source, "%s", params[0].c_str()); - } -}; - -class ProtoUnreal : public Module -{ - UnrealIRCdProto ircd_proto; - - /* Core message handlers */ - Message::Away message_away; - Message::Error message_error; - Message::Invite message_invite; - Message::Join message_join; - Message::Kick message_kick; - Message::Kill message_kill, message_svskill; - Message::MOTD message_motd; - Message::Notice message_notice; - Message::Part message_part; - Message::Ping message_ping; - Message::Privmsg message_privmsg; - Message::Quit message_quit; - Message::SQuit message_squit; - Message::Stats message_stats; - Message::Time message_time; - Message::Version message_version; - Message::Whois message_whois; - - /* Our message handlers */ - IRCDMessageCapab message_capab; - IRCDMessageChgHost message_chghost; - IRCDMessageChgIdent message_chgident; - IRCDMessageChgName message_chgname; - IRCDMessageMD message_md; - IRCDMessageMode message_mode, message_svsmode, message_svs2mode; - IRCDMessageNetInfo message_netinfo; - IRCDMessageNick message_nick; - IRCDMessagePong message_pong; - IRCDMessageSASL message_sasl; - IRCDMessageSDesc message_sdesc; - IRCDMessageSetHost message_sethost; - IRCDMessageSetIdent message_setident; - IRCDMessageSetName message_setname; - IRCDMessageServer message_server; - IRCDMessageSID message_sid; - IRCDMessageSJoin message_sjoin; - IRCDMessageTopic message_topic; - IRCDMessageUID message_uid; - IRCDMessageUmode2 message_umode2; - - bool use_server_side_mlock; - - void AddModes() - { - ModeManager::AddChannelMode(new ChannelModeStatus("VOICE", 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus("HALFOP", 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus("OP", 'o', '@', 2)); - /* Unreal sends +q as * and +a as ~ */ - ModeManager::AddChannelMode(new ChannelModeStatus("PROTECT", 'a', '~', 3)); - ModeManager::AddChannelMode(new ChannelModeStatus("OWNER", 'q', '*', 4)); - - /* Add user modes */ - ModeManager::AddUserMode(new UserMode("BOT", 'B')); - ModeManager::AddUserMode(new UserMode("CENSOR", 'G')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEOPER", 'H')); - ModeManager::AddUserMode(new UserModeOperOnly("HIDEIDLE", 'I')); - ModeManager::AddUserMode(new UserMode("REGPRIV", 'R')); - ModeManager::AddUserMode(new UserModeOperOnly("PROTECTED", 'S')); - ModeManager::AddUserMode(new UserMode("NOCTCP", 'T')); - ModeManager::AddUserMode(new UserMode("WEBTV", 'V')); - ModeManager::AddUserMode(new UserModeOperOnly("WHOIS", 'W')); - ModeManager::AddUserMode(new UserMode("DEAF", 'd')); - ModeManager::AddUserMode(new UserModeOperOnly("GLOBOPS", 'g')); - ModeManager::AddUserMode(new UserModeOperOnly("HELPOP", 'h')); - ModeManager::AddUserMode(new UserMode("INVIS", 'i')); - ModeManager::AddUserMode(new UserModeOperOnly("OPER", 'o')); - ModeManager::AddUserMode(new UserMode("PRIV", 'p')); - ModeManager::AddUserMode(new UserModeOperOnly("GOD", 'q')); - ModeManager::AddUserMode(new UserModeNoone("REGISTERED", 'r')); - ModeManager::AddUserMode(new UserModeOperOnly("SNOMASK", 's')); - ModeManager::AddUserMode(new UserModeNoone("VHOST", 't')); - ModeManager::AddUserMode(new UserMode("WALLOPS", 'w')); - ModeManager::AddUserMode(new UserMode("CLOAK", 'x')); - ModeManager::AddUserMode(new UserModeNoone("SSL", 'z')); - } - - public: - ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR), - ircd_proto(this), - message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), - message_kill(this), message_svskill(this, "SVSKILL"), message_motd(this), message_notice(this), message_part(this), message_ping(this), - message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_time(this), - message_version(this), message_whois(this), - - message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_md(this), message_mode(this, "MODE"), - message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this), - message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this), - message_sid(this), message_sjoin(this), message_topic(this), message_uid(this), message_umode2(this) - { - - this->AddModes(); - } - - void Prioritize() anope_override - { - ModuleManager::SetPriority(this, PRIORITY_FIRST); - } - - void OnReload(Configuration::Conf *conf) anope_override - { - use_server_side_mlock = conf->GetModule(this)->Get<bool>("use_server_side_mlock"); - } - - void OnUserNickChange(User *u, const Anope::string &) anope_override - { - u->RemoveModeInternal(Me, ModeManager::FindUserModeByName("REGISTERED")); - if (Servers::Capab.count("ESVID") == 0) - IRCD->SendLogout(u); - } - - void OnChannelSync(Channel *c) anope_override - { - if (!c->ci) - return; - - ModeLocks *modelocks = c->ci->GetExt<ModeLocks>("modelocks"); - if (use_server_side_mlock && Servers::Capab.count("MLOCK") > 0 && modelocks) - { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes; - } - } - - void OnChanRegistered(ChannelInfo *ci) anope_override - { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - if (!ci->c || !use_server_side_mlock || !modelocks || !Servers::Capab.count("MLOCK")) - return; - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; - } - - void OnDelChan(ChannelInfo *ci) anope_override - { - if (!ci->c || !use_server_side_mlock || !Servers::Capab.count("MLOCK")) - return; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " :"; - } - - EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override - { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) - { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; - } - - return EVENT_CONTINUE; - } - - EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override - { - ModeLocks *modelocks = ci->GetExt<ModeLocks>("modelocks"); - ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (use_server_side_mlock && cm && modelocks && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0) - { - Anope::string modes = modelocks->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); - UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; - } - - return EVENT_CONTINUE; - } -}; - -MODULE_INIT(ProtoUnreal) |