From ccc99fa8f4766d60e87bb0ac58be2ce8e77e34ef Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 16:23:39 +0200 Subject: m_spanningtree Add class SpanningTree::RemoteUser --- src/modules/m_spanningtree/remoteuser.cpp | 28 ++++++++++++++++++++++++++++ src/modules/m_spanningtree/remoteuser.h | 31 +++++++++++++++++++++++++++++++ src/modules/m_spanningtree/uid.cpp | 3 ++- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/modules/m_spanningtree/remoteuser.cpp create mode 100644 src/modules/m_spanningtree/remoteuser.h (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/remoteuser.cpp b/src/modules/m_spanningtree/remoteuser.cpp new file mode 100644 index 000000000..cbd1b801e --- /dev/null +++ b/src/modules/m_spanningtree/remoteuser.cpp @@ -0,0 +1,28 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2016 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd 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. + * + * 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 . + */ + + +#include "inspircd.h" + +#include "main.h" +#include "remoteuser.h" + +SpanningTree::RemoteUser::RemoteUser(const std::string& uid, Server* srv) + : ::RemoteUser(uid, srv) +{ +} diff --git a/src/modules/m_spanningtree/remoteuser.h b/src/modules/m_spanningtree/remoteuser.h new file mode 100644 index 000000000..235cbfd78 --- /dev/null +++ b/src/modules/m_spanningtree/remoteuser.h @@ -0,0 +1,31 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2016 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd 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. + * + * 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 . + */ + + +#pragma once + +namespace SpanningTree +{ + class RemoteUser; +} + +class SpanningTree::RemoteUser : public ::RemoteUser +{ + public: + RemoteUser(const std::string& uid, Server* srv); +}; diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 01465670a..eff537119 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -24,6 +24,7 @@ #include "utils.h" #include "treeserver.h" +#include "remoteuser.h" CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector& params) { @@ -73,7 +74,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vectorUsers->clientlist[params[2]] = _new; _new->nick = params[2]; _new->host = params[3]; -- cgit v1.3.1-10-gc9f91 From a7dedb347b7dcd26ce93d4af81e77cfa3cf82d0f Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 16:28:01 +0200 Subject: m_spanningtree Add NUM command handler --- src/modules/m_spanningtree/commands.h | 9 +++++++ src/modules/m_spanningtree/main.cpp | 2 +- src/modules/m_spanningtree/num.cpp | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/modules/m_spanningtree/num.cpp (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h index 1f7456426..a65639434 100644 --- a/src/modules/m_spanningtree/commands.h +++ b/src/modules/m_spanningtree/commands.h @@ -369,6 +369,14 @@ class CommandSInfo : public ServerOnlyServerCommand }; }; +class CommandNum : public ServerOnlyServerCommand +{ + public: + CommandNum(Module* Creator) : ServerOnlyServerCommand(Creator, "NUM", 3) { } + CmdResult HandleServer(TreeServer* server, std::vector& parameters); + RouteDescriptor GetRouting(User* user, const std::vector& parameters); +}; + class SpanningTreeCommands { public: @@ -401,5 +409,6 @@ class SpanningTreeCommands CommandSNONotice snonotice; CommandEndBurst endburst; CommandSInfo sinfo; + CommandNum num; SpanningTreeCommands(ModuleSpanningTree* module); }; diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index d06755c1f..7f88a07f5 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -52,7 +52,7 @@ SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module) away(module), addline(module), delline(module), encap(module), idle(module), nick(module), ping(module), pong(module), push(module), save(module), server(module), squit(module), snonotice(module), - endburst(module), sinfo(module) + endburst(module), sinfo(module), num(module) { } diff --git a/src/modules/m_spanningtree/num.cpp b/src/modules/m_spanningtree/num.cpp new file mode 100644 index 000000000..047dba432 --- /dev/null +++ b/src/modules/m_spanningtree/num.cpp @@ -0,0 +1,47 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2016 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd 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. + * + * 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 . + */ + + +#include "inspircd.h" + +#include "utils.h" +#include "commands.h" + +CmdResult CommandNum::HandleServer(TreeServer* server, std::vector& params) +{ + User* const target = ServerInstance->FindUUID(params[1]); + if (!target) + return CMD_FAILURE; + + LocalUser* const localtarget = IS_LOCAL(target); + if (!localtarget) + return CMD_SUCCESS; + + Numeric::Numeric numeric(ConvToInt(params[2])); + // Passing NULL is ok, in that case the numeric source becomes this server + numeric.SetServer(Utils->FindServerID(params[0])); + numeric.GetParams().insert(numeric.GetParams().end(), params.begin()+3, params.end()); + + localtarget->WriteNumeric(numeric); + return CMD_SUCCESS; +} + +RouteDescriptor CommandNum::GetRouting(User* user, const std::vector& params) +{ + return ROUTE_UNICAST(params[1]); +} -- cgit v1.3.1-10-gc9f91 From ab115e4fe39c8aeb74482462dd6a473341fa7608 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 16:36:22 +0200 Subject: m_spanningtree Translate NUM to PUSH and PUSH to NUM, NOTICE or PRIVMSG for 1202 protocol servers --- src/modules/m_spanningtree/compat.cpp | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 41b5488f0..63fc9cf6c 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -290,6 +290,25 @@ void TreeSocket::WriteLine(const std::string& original_line) line = CmdBuilder(line.substr(spcolon-3, 3), "BURST").push_int(ServerInstance->Time()).str(); } } + else if (command == "NUM") + { + // : NUM <3 digit number> + // Translate to + // : PUSH : <3 digit number> + + TreeServer* const numericsource = Utils->FindServerID(line.substr(9, 3)); + if (!numericsource) + return; + + // The nick of the target is necessary for building the PUSH message + User* const target = ServerInstance->FindUUID(line.substr(13, UIDGenerator::UUID_LENGTH)); + if (!target) + return; + + std::string push = InspIRCd::Format(":%.*s PUSH %s ::%s %.*s %s", 3, line.c_str()+1, target->uuid.c_str(), numericsource->GetName().c_str(), 3, line.c_str()+23, target->nick.c_str()); + push.append(line, 26, std::string::npos); + push.swap(line); + } } WriteLineNoCompat(line); return; @@ -485,6 +504,77 @@ bool TreeSocket::PreProcessOldProtocolMessage(User*& who, std::string& cmd, std: // SVSWATCH was removed because nothing was using it, but better be sure return false; } + else if (cmd == "PUSH") + { + if ((params.size() != 2) || (!this->MyRoot)) + return false; // Huh? + + irc::tokenstream ts(params.back()); + + std::string srcstr; + ts.GetToken(srcstr); + srcstr.erase(0, 1); + + std::string token; + ts.GetToken(token); + + // See if it's a numeric being sent to the target via PUSH + unsigned int numeric_number = 0; + if (token.length() == 3) + numeric_number = ConvToInt(token); + + if ((numeric_number > 0) && (numeric_number < 1000)) + { + // It's a numeric, translate to NUM + + // srcstr must be a valid server name + TreeServer* const numericsource = Utils->FindServer(srcstr); + if (!numericsource) + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Unable to translate PUSH numeric %s to user %s from 1202 protocol server %s: source \"%s\" doesn't exist", token.c_str(), params[0].c_str(), this->MyRoot->GetName().c_str(), srcstr.c_str()); + return false; + } + + cmd = "NUM"; + + // Second parameter becomes the target uuid + params[0].swap(params[1]); + // Replace first param (now the PUSH payload, not needed) with the source sid + params[0] = numericsource->GetID(); + + params.push_back(InspIRCd::Format("%03u", numeric_number)); + + // Ignore the nickname in the numeric in PUSH + ts.GetToken(token); + + // Rest of the tokens are the numeric parameters, add them to NUM + while (ts.GetToken(token)) + params.push_back(token); + } + else if ((token == "PRIVMSG") || (token == "NOTICE")) + { + // Command is a PRIVMSG/NOTICE + cmd.swap(token); + + // Check if the PRIVMSG/NOTICE target is a nickname + ts.GetToken(token); + if (token.c_str()[0] == '#') + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Unable to translate PUSH %s to user %s from 1202 protocol server %s, target \"%s\"", cmd.c_str(), params[0].c_str(), this->MyRoot->GetName().c_str(), token.c_str()); + return false; + } + + // Replace second parameter with the message + ts.GetToken(params[1]); + } + else + { + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Unable to translate PUSH to user %s from 1202 protocol server %s", params[0].c_str(), this->MyRoot->GetName().c_str()); + return false; + } + + return true; + } return true; // Passthru } -- cgit v1.3.1-10-gc9f91 From 484b30f67b1479de72ff99532b7b91e775686e97 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 16:39:06 +0200 Subject: m_spanningtree Add CommandNum::Builder --- src/modules/m_spanningtree/commands.h | 7 +++++++ src/modules/m_spanningtree/num.cpp | 15 +++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src/modules') diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h index a65639434..4810e9d4b 100644 --- a/src/modules/m_spanningtree/commands.h +++ b/src/modules/m_spanningtree/commands.h @@ -21,6 +21,7 @@ #include "servercommand.h" #include "commandbuilder.h" +#include "remoteuser.h" /** Handle /RCONNECT */ @@ -375,6 +376,12 @@ class CommandNum : public ServerOnlyServerCommand CommandNum(Module* Creator) : ServerOnlyServerCommand(Creator, "NUM", 3) { } CmdResult HandleServer(TreeServer* server, std::vector& parameters); RouteDescriptor GetRouting(User* user, const std::vector& parameters); + + class Builder : public CmdBuilder + { + public: + Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric); + }; }; class SpanningTreeCommands diff --git a/src/modules/m_spanningtree/num.cpp b/src/modules/m_spanningtree/num.cpp index 047dba432..2c8697c9a 100644 --- a/src/modules/m_spanningtree/num.cpp +++ b/src/modules/m_spanningtree/num.cpp @@ -21,6 +21,7 @@ #include "utils.h" #include "commands.h" +#include "remoteuser.h" CmdResult CommandNum::HandleServer(TreeServer* server, std::vector& params) { @@ -45,3 +46,17 @@ RouteDescriptor CommandNum::GetRouting(User* user, const std::vector(numeric.GetServer())) : Utils->TreeRoot); + push(server->GetID()).push(target->uuid).push(InspIRCd::Format("%03u", numeric.GetNumeric())); + const std::vector& params = numeric.GetParams(); + if (!params.empty()) + { + for (std::vector::const_iterator i = params.begin(); i != params.end()-1; ++i) + push(*i); + push_last(params.back()); + } +} -- cgit v1.3.1-10-gc9f91 From 5fbb5a0b2c5c08f76f99bd03b51bce2164feade3 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 16:43:30 +0200 Subject: Make User::WriteRemoteNumeric() virtual, implement it in SpanningTree::RemoteUser --- include/users.h | 2 +- src/modules/m_spanningtree/remoteuser.cpp | 5 +++++ src/modules/m_spanningtree/remoteuser.h | 1 + src/users.cpp | 3 +-- 4 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/include/users.h b/include/users.h index c2ad6b9ee..8cbf8a8da 100644 --- a/include/users.h +++ b/include/users.h @@ -524,7 +524,7 @@ class CoreExport User : public Extensible */ virtual void WriteRemoteNotice(const std::string& text); - void WriteRemoteNumeric(const Numeric::Numeric& numeric); + virtual void WriteRemoteNumeric(const Numeric::Numeric& numeric); template void WriteRemoteNumeric(unsigned int numeric, T1 p1) diff --git a/src/modules/m_spanningtree/remoteuser.cpp b/src/modules/m_spanningtree/remoteuser.cpp index cbd1b801e..717a6fd9f 100644 --- a/src/modules/m_spanningtree/remoteuser.cpp +++ b/src/modules/m_spanningtree/remoteuser.cpp @@ -26,3 +26,8 @@ SpanningTree::RemoteUser::RemoteUser(const std::string& uid, Server* srv) : ::RemoteUser(uid, srv) { } + +void SpanningTree::RemoteUser::WriteRemoteNumeric(const Numeric::Numeric& numeric) +{ + CommandNum::Builder(this, numeric).Unicast(this); +} diff --git a/src/modules/m_spanningtree/remoteuser.h b/src/modules/m_spanningtree/remoteuser.h index 235cbfd78..416f2f760 100644 --- a/src/modules/m_spanningtree/remoteuser.h +++ b/src/modules/m_spanningtree/remoteuser.h @@ -28,4 +28,5 @@ class SpanningTree::RemoteUser : public ::RemoteUser { public: RemoteUser(const std::string& uid, Server* srv); + void WriteRemoteNumeric(const Numeric::Numeric& numeric) CXX11_OVERRIDE; }; diff --git a/src/users.cpp b/src/users.cpp index e1bda1ad3..7437e8a20 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -950,8 +950,7 @@ void User::SendText(const char *text, ...) void User::WriteRemoteNumeric(const Numeric::Numeric& numeric) { - const std::string& servername = (numeric.GetServer() ? numeric.GetServer()->GetName() : ServerInstance->Config->ServerName); - SendText(BuildNumeric(servername, this, numeric.GetNumeric(), numeric.GetParams())); + WriteNumeric(numeric); } /* return 0 or 1 depending if users u and u2 share one or more common channels -- cgit v1.3.1-10-gc9f91