diff options
author | Sadie Powell <sadie@witchery.services> | 2024-03-12 21:57:06 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-03-12 21:57:06 +0000 |
commit | 11edba04feea242a320b06cb45fb892fb500bd1e (patch) | |
tree | 45fc9371d11bacc03d4af0abe3304daa988b14b4 | |
parent | 22ba54b00dbeef1a7ab14c5d22a7360b47c29a40 (diff) |
Add command handlers for encap commands on InspIRCd.
-rw-r--r-- | include/anope.h | 14 | ||||
-rw-r--r-- | modules/protocol/inspircd.cpp | 145 | ||||
-rw-r--r-- | src/process.cpp | 17 |
3 files changed, 123 insertions, 53 deletions
diff --git a/include/anope.h b/include/anope.h index 9145b7337..819de40ee 100644 --- a/include/anope.h +++ b/include/anope.h @@ -535,10 +535,18 @@ namespace Anope */ extern CoreExport Anope::string NormalizeBuffer(const Anope::string &); - /** Main processing routine. Parses the message and takes the appropriate action. - * @param Raw message from the uplink + /** Parses a raw message from the uplink and calls its command handler. + * @param message Raw message from the uplink */ - extern void Process(const Anope::string &); + extern void Process(const Anope::string &message); + + /** Calls the command handler for an already parsed message. + * @param source Source of the message. + * @param command Command name. + * @param params Any extra parameters. + * @param tags IRCv3 message tags. + */ + extern CoreExport void ProcessInternal(MessageSource &src, const Anope::string &command, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> & tags); /** Does a blocking dns query and returns the first IP. * @param host host to look up diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index 8f0404aa1..cd2ad2296 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -1597,60 +1597,87 @@ struct IRCDMessageCapab final } }; -struct IRCDMessageEncap final +struct IRCDMessageChgHost final : IRCDMessage { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(FLAG_SOFT_LIMIT); } + IRCDMessageChgHost(Module *creator) + : IRCDMessage(creator, "CHGHOST", 2) + { + SetFlag(FLAG_REQUIRE_USER); + } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { - if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0])) + auto *u = User::Find(params[0]); + if (!u || u->server != Me) return; - if (params[1] == "CHGIDENT") - { - User *u = User::Find(params[2]); - if (!u || u->server != Me) - return; + u->SetDisplayedHost(params[1]); + if (spanningtree_proto_ver >= 1206) + Uplink::Send(u, "FHOST", u->GetDisplayedHost(), '*'); + else + Uplink::Send(u, "FHOST", u->GetDisplayedHost()); + } +}; - u->SetIdent(params[3]); - if (spanningtree_proto_ver >= 1206) - Uplink::Send(u, "FIDENT", params[3], '*'); - else - Uplink::Send(u, "FIDENT", params[3]); - } - else if (params[1] == "CHGHOST") - { - User *u = User::Find(params[2]); - if (!u || u->server != Me) - return; +struct IRCDMessageChgIdent final + : IRCDMessage +{ + IRCDMessageChgIdent(Module *creator) + : IRCDMessage(creator, "CHGIDENT", 2) + { + SetFlag(FLAG_REQUIRE_USER); + } - u->SetDisplayedHost(params[3]); - if (spanningtree_proto_ver >= 1206) - Uplink::Send(u, "FHOST", params[3], '*'); - else - Uplink::Send(u, "FHOST", params[3]); - } - else if (params[1] == "CHGNAME") - { - User *u = User::Find(params[2]); - if (!u || u->server != Me) - return; + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override + { + auto *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - u->SetRealname(params[3]); - Uplink::Send(u, "FNAME", params[3]); - } - else 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] : ""; + u->SetIdent(params[1]); + if (spanningtree_proto_ver >= 1206) + Uplink::Send(u, "FIDENT", u->GetIdent(), '*'); + else + Uplink::Send(u, "FIDENT", u->GetIdent()); + } +}; - SASL::sasl->ProcessMessage(m); - } +struct IRCDMessageChgName final + : IRCDMessage +{ + IRCDMessageChgName(Module *creator) + : IRCDMessage(creator, "CHGNAME", 2) + { + SetFlag(FLAG_REQUIRE_USER); + } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override + { + auto *u = User::Find(params[0]); + if (!u || u->server != Me) + return; + + u->SetRealname(params[1]); + Uplink::Send(u, "FNAME", u->realname); + } +}; + +struct IRCDMessageEncap final + : IRCDMessage +{ + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 2) + { + SetFlag(FLAG_SOFT_LIMIT); + } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override + { + if (!Anope::Match(Me->GetSID(), params[0]) && !Anope::Match(Me->GetName(), params[0])) + return; + + std::vector<Anope::string> newparams(params.begin() + 2, params.end()); + Anope::ProcessInternal(source, params[1], newparams, tags); } }; @@ -1715,6 +1742,30 @@ struct IRCDMessageKick final } }; +struct IRCDMessageSASL final + : IRCDMessage +{ + IRCDMessageSASL(Module *creator) + : IRCDMessage(creator, "SASL", 4) + { + SetFlag(FLAG_SOFT_LIMIT); + } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override + { + if (!SASL::sasl) + return; + + SASL::Message m; + m.source = params[0]; + m.target = params[1]; + m.type = params[2]; + m.data = params[3]; + m.ext = params.size() > 4 ? params[4] : ""; + SASL::sasl->ProcessMessage(m); + } +}; + struct IRCDMessageSave final : IRCDMessage { @@ -2357,6 +2408,9 @@ class ProtoInspIRCd final /* Our message handlers */ IRCDMessageAway message_away; IRCDMessageCapab message_capab; + IRCDMessageChgHost message_chghost; + IRCDMessageChgIdent message_chgident; + IRCDMessageChgName message_chgname; IRCDMessageEncap message_encap; IRCDMessageEndburst message_endburst; IRCDMessageFHost message_fhost; @@ -2374,6 +2428,7 @@ class ProtoInspIRCd final IRCDMessageOperType message_opertype; IRCDMessagePing message_ping; IRCDMessageRSQuit message_rsquit; + IRCDMessageSASL message_sasl; IRCDMessageSave message_save; IRCDMessageServer message_server; IRCDMessageSQuit message_squit; @@ -2403,6 +2458,9 @@ public: , message_time(this) , message_away(this) , message_capab(this) + , message_chghost(this) + , message_chgident(this) + , message_chgname(this) , message_encap(this) , message_endburst(this) , message_fhost(this) @@ -2420,6 +2478,7 @@ public: , message_opertype(this) , message_ping(this) , message_rsquit(this) + , message_sasl(this) , message_save(this) , message_server(this) , message_squit(this) diff --git a/src/process.cpp b/src/process.cpp index f045bc970..bb31358c8 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -54,28 +54,31 @@ void Anope::Process(const Anope::string &buffer) } } - static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : ""; - MessageSource src(source); - EventReturn MOD_RESULT; FOREACH_RESULT(OnMessage, MOD_RESULT, (src, command, params, tags)); if (MOD_RESULT == EVENT_STOP) return; + ProcessInternal(src, command, params, tags); +} + +void Anope::ProcessInternal(MessageSource &src, const Anope::string &command, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> & tags) +{ + static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : ""; ServiceReference<IRCDMessage> m("IRCDMessage", proto_name + "/" + command.lower()); if (!m) { - Log(LOG_DEBUG) << "unknown message from server (" << buffer << ")"; + Log(LOG_DEBUG) << "unknown message from server: " << command; return; } if (m->HasFlag(IRCDMessage::FLAG_SOFT_LIMIT) ? (params.size() < m->GetParamCount()) : (params.size() != m->GetParamCount())) Log(LOG_DEBUG) << "invalid parameters for " << command << ": " << params.size() << " != " << m->GetParamCount(); else if (m->HasFlag(IRCDMessage::FLAG_REQUIRE_USER) && !src.GetUser()) - Log(LOG_DEBUG) << "unexpected non-user source " << source << " for " << command; - else if (m->HasFlag(IRCDMessage::FLAG_REQUIRE_SERVER) && !source.empty() && !src.GetServer()) - Log(LOG_DEBUG) << "unexpected non-server source " << source << " for " << command; + Log(LOG_DEBUG) << "unexpected non-user source " << src.GetSource() << " for " << command; + else if (m->HasFlag(IRCDMessage::FLAG_REQUIRE_SERVER) && !src.GetSource().empty() && !src.GetServer()) + Log(LOG_DEBUG) << "unexpected non-server source " << src.GetSource() << " for " << command; else { try |