diff options
Diffstat (limited to 'modules/protocol/plexus.cpp')
-rw-r--r-- | modules/protocol/plexus.cpp | 182 |
1 files changed, 96 insertions, 86 deletions
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 62618ec82..b5d43a91c 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -16,14 +16,16 @@ static Anope::string UplinkSID; static ServiceReference<IRCDProto> hybrid("IRCDProto", "hybrid"); -class PlexusProto : public IRCDProto +class PlexusProto final + : public IRCDProto { - public: +public: PlexusProto(Module *creator) : IRCDProto(creator, "hybrid-7.2.3+plexus-3.0.1") { DefaultPseudoclientModes = "+iU"; CanSVSNick = true; CanSVSJoin = true; + CanSVSNOOP = true; CanSetVHost = true; CanSetVIdent = true; CanSNLine = true; @@ -35,28 +37,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 SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKill(source, targ, reason); } + void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendSQLine(User *u, const XLine *x) override { hybrid->SendSQLine(u, x); } + void SendSQLineDel(const XLine *x) override { hybrid->SendSQLineDel(x); } + void SendSGLineDel(const XLine *x) override { hybrid->SendSGLineDel(x); } + void SendSGLine(User *u, const XLine *x) override { hybrid->SendSGLine(u, x); } + void SendAkillDel(const 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 SendGlobops(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("SJOIN", c->creation_time, c->name, "+" + c->GetModes(true, true), user->GetUID()); if (status) { /* First save the channel status incase uc->Status == status */ @@ -69,35 +71,37 @@ class PlexusProto : public IRCDProto 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); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; } } - 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("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("ENCAP", '*', "CHGIDENT", u->GetUID(), ident); + + Uplink::Send("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 @@ -118,7 +122,8 @@ class PlexusProto : public IRCDProto * ENCAP - Supports encapsulation 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); /* @@ -129,69 +134,82 @@ 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, 5, 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("UID", u->nick, 1, u->timestamp, "+" + u->GetModes(), 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 &modes, const std::vector<Anope::string> &values) override { - UplinkSocket::Message(source) << "ENCAP * SVSMODE " << u->GetUID() << " " << u->timestamp << " " << buf; + auto params = values; + params.insert(params.begin(), { "*", "SVSMODE", u->GetUID(), Anope::ToString(u->timestamp), modes }); + Uplink::SendInternal({}, source, "ENCAP", params); } - void SendLogin(User *u, NickAlias *na) anope_override + void SendLogin(User *u, NickAlias *na) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID() << " " << na->nc->display; + Uplink::Send("ENCAP", '*', "SU", u->GetUID(), na->nc->display); } - void SendLogout(User *u) anope_override + void SendLogout(User *u) override { - UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); + Uplink::Send("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 &key) override { - UplinkSocket::Message(source) << "ENCAP " << user->server->GetName() << " SVSJOIN " << user->GetUID() << " " << chan; + Uplink::Send(source, "ENCAP", '*', "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", '*', "SVSPART", user->GetUID(), chan); } - void SendSASLMessage(const SASL::Message &message) anope_override + 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)); + auto target = s ? s->GetName() : message.target.substr(0, 3); + if (message.ext.empty()) + Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data); + else + Uplink::Send("ENCAP", target, "SASL", message.source, message.target, message.type, message.data, 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, NickAlias *na) override { Server *s = Server::Find(uid.substr(0, 3)); - UplinkSocket::Message(Me) << "ENCAP " << (s ? s->GetName() : uid.substr(0, 3)) << " SVSLOGIN " << uid << " * * " - << (vhost.empty() ? "*" : vhost) << " " << acc; + Anope::string target = s ? s->GetName() : uid.substr(0, 3); + if (na) + { + Uplink::Send("ENCAP", target, "SVSLOGIN", uid, '*', '*', na->GetVHostHost().empty() ? "*" : na->GetVHostHost(), na->nc->display); + } + else + { + Uplink::Send("ENCAP", target, "SU", uid, ""); + } } - void SendSVSNOOP(const Server *server, bool set) anope_override + void SendSVSNOOP(const Server *server, bool set) override { - UplinkSocket::Message() << "ENCAP " << server->GetName() << " SVSNOOP " << (set ? "+" : "-"); + Uplink::Send("ENCAP", '*', "SVSNOOP", set ? '+' : '-'); } }; -struct IRCDMessageEncap : IRCDMessage +struct IRCDMessageEncap final + : IRCDMessage { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(FLAG_REQUIRE_SERVER); SetFlag(FLAG_SOFT_LIMIT); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { /* * Received: :dev.anope.de ENCAP * SU DukePyrolator DukePyrolator @@ -243,23 +261,25 @@ struct IRCDMessageEncap : IRCDMessage } }; -struct IRCDMessagePass : IRCDMessage +struct IRCDMessagePass final + : IRCDMessage { - IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(FLAG_REQUIRE_SERVER); } - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { UplinkSID = params[3]; } }; -struct IRCDMessageServer : IRCDMessage +struct IRCDMessageServer final + : IRCDMessage { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(FLAG_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 + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { /* Servers other than our immediate uplink are introduced via SID */ if (params[1] != "1") @@ -269,9 +289,10 @@ struct IRCDMessageServer : IRCDMessage } }; -struct IRCDMessageUID : IRCDMessage +struct IRCDMessageUID final + : IRCDMessage { - IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(FLAG_REQUIRE_SERVER); } /* params[0] = nick @@ -287,30 +308,18 @@ struct IRCDMessageUID : IRCDMessage 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 + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { /* 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; - } - + auto ts = IRCD->ExtractTimestamp(params[2]); 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 (IRCD->ExtractTimestamp(params[8]) == ts) + na = NickAlias::Find(params[0]); + if (params[8] != "0" && !na) na = NickAlias::Find(params[8]); @@ -318,7 +327,8 @@ struct IRCDMessageUID : IRCDMessage } }; -class ProtoPlexus : public Module +class ProtoPlexus final + : public Module { Module *m_hybrid; @@ -355,7 +365,7 @@ class ProtoPlexus : public Module IRCDMessageServer message_server; IRCDMessageUID message_uid; - void AddModes() + static void AddModes() { /* Add user modes */ ModeManager::AddUserMode(new UserModeOperOnly("ADMIN", 'a')); @@ -413,7 +423,7 @@ class ProtoPlexus : public Module ModeManager::AddChannelMode(new ChannelMode("PERM", 'z')); } - public: +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), @@ -441,7 +451,7 @@ class ProtoPlexus : public Module this->AddModes(); } - ~ProtoPlexus() + ~ProtoPlexus() override { m_hybrid = ModuleManager::FindModule("hybrid"); ModuleManager::UnloadModule(m_hybrid, NULL); |