diff options
author | Adam <Adam@anope.org> | 2016-09-25 20:10:33 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-09-25 20:10:33 -0400 |
commit | f3bfaa814ac9e12bb151620ad807b1f9e57ae323 (patch) | |
tree | a9e8a11be22687193b417fe3c97a40de43c9a6b0 /modules/protocol | |
parent | aee628f6bb7d2a510802a70b635a4c1b4a4fe7c4 (diff) |
Get rid of service alias stuff, make proto mods link to each other
Diffstat (limited to 'modules/protocol')
-rw-r--r-- | modules/protocol/CMakeLists.txt | 1 | ||||
-rw-r--r-- | modules/protocol/charybdis.cpp | 209 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 350 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 224 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 170 |
5 files changed, 403 insertions, 551 deletions
diff --git a/modules/protocol/CMakeLists.txt b/modules/protocol/CMakeLists.txt index cd225a94d..9a236d6d0 100644 --- a/modules/protocol/CMakeLists.txt +++ b/modules/protocol/CMakeLists.txt @@ -1 +1,2 @@ build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 121915924..f6cb2f29a 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -17,9 +17,14 @@ * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.ratbox */ + #include "module.h" -#include "modules/chanserv/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; @@ -164,115 +169,79 @@ class CharybdisProto : public IRCDProto }; -struct IRCDMessageEncap : IRCDMessage +void charybdis::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - ServiceReference<SASL::Service> sasl; + User *u = source.GetUser(); - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT);} - - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) 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") - { - 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); - } - /* - * 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 && 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->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 + * + * 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). * - * 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. + * Charybdis only accepts messages from SASL agents; these must have umode +S */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override + if (params[1] == "SASL" && sasl && params.size() >= 6) { - NickServ::Nick *na = NULL; - if (params[9] != "*") - na = NickServ::FindNick(params[9]); - - User::OnIntroduce(params[0], params[4], params[8], 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); + 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) 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[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) 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; @@ -298,15 +267,20 @@ 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; + hybrid::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; @@ -335,38 +309,20 @@ class ProtoCharybdis : public Module , 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_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) { - - - 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"); -#warning "" -// if (!ratbox) -// throw ModuleException("No protocol interface for ratbox"); - } - - ~ProtoCharybdis() - { - m_ratbox = ModuleManager::FindModule("ratbox"); - ModuleManager::UnloadModule(m_ratbox, NULL); } void OnReload(Configuration::Conf *conf) override @@ -417,4 +373,9 @@ class ProtoCharybdis : public Module } }; +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 ccf4cd05b..8345b18d3 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -19,6 +19,7 @@ */ #include "module.h" +#include "modules/protocol/hybrid.h" static Anope::string UplinkSID; @@ -339,64 +340,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) 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); } + source.GetServer()->Sync(true); +} - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) override - { - 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) 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) override - { - source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1])); - } -}; + source.GetUser()->ChangeNick(params[0], convertTo<time_t>(params[1])); +} struct IRCDMessagePass : IRCDMessage { @@ -410,196 +391,149 @@ struct IRCDMessagePass : IRCDMessage } }; -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) 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) 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); } + 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]); - /* 0 1 2 3 */ - /* :0MC SID hades.arpa 2 4XY :ircd-hybrid test server */ - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) 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]); - - 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); } + 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()); - 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; - 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 + 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 hybrid::SVSMode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - IRCDMessageSVSMode(Module *creator) : IRCDMessage(creator, "SVSMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - /* - * 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) override - { - User *u = User::Find(params[0]); - if (!u) - return; + 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) 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) 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); } + Anope::string ip = params[6]; - /* 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) override - { - 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(); - NickServ::Nick *na = NULL; - if (params[8] != "0" && params[8] != "*") - na = NickServ::FindNick(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->GetAccount() : 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) override - { - User *u = source.GetUser(); - - u->fingerprint = params[0]; - EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); - } -}; + u->fingerprint = params[0]; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); +} class ProtoHybrid : public Module , public EventHook<Event::UserNickChange> @@ -628,20 +562,20 @@ 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; + 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) diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index df9853340..02d2a4d6e 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -17,7 +17,11 @@ * 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; @@ -180,48 +184,43 @@ class PlexusProto : public IRCDProto } }; -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) 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]); - NickServ::Account *nc = NickServ::FindAccount(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]; - EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); - } + u->fingerprint = params[3]; + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } - return; } -}; + return; +} struct IRCDMessagePass : IRCDMessage { @@ -233,70 +232,60 @@ struct IRCDMessagePass : IRCDMessage } }; -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); } + /* 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) 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); - } -}; - -struct IRCDMessageUID : IRCDMessage +/* + 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) 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; - } - - 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]); + 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->GetAccount() : 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 { @@ -325,15 +314,19 @@ class ProtoPlexus : public Module 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; + 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) @@ -358,36 +351,25 @@ class ProtoPlexus : public Module , 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_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"); -#warning "" -// if (!hybrid) -// throw ModuleException("No protocol interface for hybrid"); - } - - ~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 f1a7c85da..5511bcedf 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -17,7 +17,11 @@ * 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; @@ -125,30 +129,25 @@ 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) override + if (params[1] == "LOGIN" || params[1] == "SU") { - if (params[1] == "LOGIN" || params[1] == "SU") - { - 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()); - } + 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 IRCDMessagePass : IRCDMessage { @@ -160,62 +159,45 @@ struct IRCDMessagePass : IRCDMessage } }; -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); } + // 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]); +} - // SERVER hades.arpa 1 :ircd-ratbox test server - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) 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 +/* + * 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) 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) 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 */ @@ -239,16 +221,19 @@ class ProtoRatbox : public Module Message::Version message_version; Message::Whois message_whois; - /* Hybrid message handlers */ - ServiceAlias message_bmask, message_join, message_nick, message_pong, message_sid, - message_sjoin, message_tmode; - /* Our message handlers */ - IRCDMessageEncap message_encap; + hybrid::BMask message_bmask; + ratbox::Encap message_encap; + hybrid::Join message_join; + hybrid::Nick message_nick; IRCDMessagePass message_pass; - IRCDMessageServer message_server; - IRCDMessageTBurst message_tburst; - IRCDMessageUID message_uid; + 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) @@ -273,36 +258,25 @@ class ProtoRatbox : public Module , message_version(this) , message_whois(this) - , message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask") - , message_join("IRCDMessage", "ratbox/join", "hybrid/join") - , 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_bmask(this) , message_encap(this) + , message_join(this) + , message_nick(this) , message_pass(this) + , message_pong(this) , message_server(this) - , message_tburst(this) + , message_sid(this) + , message_sjoin(this) + , message_tb(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"); -#warning "" -// if (!hybrid) -// throw ModuleException("No protocol interface for hybrid"); - } - - ~ProtoRatbox() - { - m_hybrid = ModuleManager::FindModule("hybrid"); - ModuleManager::UnloadModule(m_hybrid, NULL); } }; +template<> void ModuleInfo<ProtoRatbox>(ModuleDef *def) +{ + def->Depends("hybrid"); +} + MODULE_INIT(ProtoRatbox) |