diff options
-rw-r--r-- | src/commands/cmd_map.cpp | 58 | ||||
-rw-r--r-- | src/modules/m_spanningtree/commands.h | 17 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.h | 13 | ||||
-rw-r--r-- | src/modules/m_spanningtree/override_map.cpp | 40 | ||||
-rw-r--r-- | src/modules/m_spanningtree/precommand.cpp | 4 | ||||
-rw-r--r-- | src/server.cpp | 2 |
7 files changed, 47 insertions, 95 deletions
diff --git a/src/commands/cmd_map.cpp b/src/commands/cmd_map.cpp deleted file mode 100644 index 0698134b5..000000000 --- a/src/commands/cmd_map.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * InspIRCd -- Internet Relay Chat Daemon - * - * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org> - * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net> - * - * 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 <http://www.gnu.org/licenses/>. - */ - - -#include "inspircd.h" - -class CommandMap : public Command -{ - public: - /** Constructor for map. - */ - CommandMap ( Module* parent) : Command(parent,"MAP",0,0) { Penalty=2; } - /** Handle command. - * @param parameters The parameters to the comamnd - * @param pcnt The number of parameters passed to teh command - * @param user The user issuing the command - * @return A value from CmdResult to indicate command success or failure. - */ - CmdResult Handle(const std::vector<std::string>& parameters, User *user); -}; - -/** Handle /MAP - */ -CmdResult CommandMap::Handle (const std::vector<std::string>&, User *user) -{ - // as with /LUSERS this does nothing without a linking - // module to override its behaviour and display something - // better. - - if (user->IsOper()) - { - user->WriteNumeric(006, "%s :%s [%s]", user->nick.c_str(), ServerInstance->Config->ServerName.c_str(), ServerInstance->Config->GetSID().c_str()); - user->WriteNumeric(007, "%s :End of /MAP", user->nick.c_str()); - return CMD_SUCCESS; - } - user->WriteNumeric(006, "%s :%s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str()); - user->WriteNumeric(007, "%s :End of /MAP",user->nick.c_str()); - - return CMD_SUCCESS; -} - -COMMAND_INIT(CommandMap) diff --git a/src/modules/m_spanningtree/commands.h b/src/modules/m_spanningtree/commands.h index a895c569b..e467cdc8b 100644 --- a/src/modules/m_spanningtree/commands.h +++ b/src/modules/m_spanningtree/commands.h @@ -39,6 +39,22 @@ class CommandRSQuit : public Command RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters); }; +class CommandMap : public Command +{ + /** Show MAP output to a user (recursive) + */ + void ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats); + + /** Returns oper-specific MAP information + */ + std::string MapOperInfo(TreeServer* Current); + + public: + CommandMap(Module* Creator); + CmdResult Handle(const std::vector<std::string>& parameters, User* user); + RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters); +}; + class CommandSVSJoin : public ServerCommand { public: @@ -269,6 +285,7 @@ class SpanningTreeCommands public: CommandRConnect rconnect; CommandRSQuit rsquit; + CommandMap map; CommandSVSJoin svsjoin; CommandSVSPart svspart; CommandSVSNick svsnick; diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 060dc01df..d9a3afbd4 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -41,7 +41,7 @@ ModuleSpanningTree::ModuleSpanningTree() } SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module) - : rconnect(module), rsquit(module), + : rconnect(module), rsquit(module), map(module), svsjoin(module), svspart(module), svsnick(module), metadata(module), uid(module), opertype(module), fjoin(module), ijoin(module), resync(module), fmode(module), ftopic(module), fhost(module), fident(module), fname(module), @@ -61,6 +61,7 @@ void ModuleSpanningTree::init() commands = new SpanningTreeCommands(this); ServerInstance->Modules->AddService(commands->rconnect); ServerInstance->Modules->AddService(commands->rsquit); + ServerInstance->Modules->AddService(commands->map); delete ServerInstance->PI; ServerInstance->PI = new SpanningTreeProtocolInterface(Utils); @@ -393,6 +394,11 @@ ModResult ModuleSpanningTree::HandleConnect(const std::vector<std::string>& para return MOD_RES_DENY; } +void ModuleSpanningTree::On005Numeric(std::map<std::string, std::string>& tokens) +{ + tokens["MAP"]; +} + void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description) { TreeServer* s = Utils->FindServer(servername); diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index e9be44167..f03a36db2 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -77,14 +77,6 @@ class ModuleSpanningTree : public Module */ void HandleLinks(const std::vector<std::string>& parameters, User* user); - /** Show MAP output to a user (recursive) - */ - void ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats); - - /** Handle MAP command - */ - bool HandleMap(const std::vector<std::string>& parameters, User* user); - /** Handle SQUIT */ ModResult HandleSquit(const std::vector<std::string>& parameters, User* user); @@ -125,10 +117,6 @@ class ModuleSpanningTree : public Module */ void RemoteMessage(User* user, const char* format, ...) CUSTOM_PRINTF(3, 4); - /** Returns oper-specific MAP information - */ - const std::string MapOperInfo(TreeServer* Current); - /** Display a time as a human readable string */ static std::string TimeToStr(time_t secs); @@ -166,6 +154,7 @@ class ModuleSpanningTree : public Module void OnLoadModule(Module* mod) CXX11_OVERRIDE; void OnUnloadModule(Module* mod) CXX11_OVERRIDE; ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE; + void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE; CullResult cull(); ~ModuleSpanningTree(); Version GetVersion() CXX11_OVERRIDE; diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index ae30ae706..2b655097d 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -24,14 +24,21 @@ #include "main.h" #include "utils.h" #include "treeserver.h" +#include "commands.h" -const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current) +CommandMap::CommandMap(Module* Creator) + : Command(Creator, "MAP", 0, 1) +{ + Penalty = 2; +} + +std::string CommandMap::MapOperInfo(TreeServer* Current) { time_t secs_up = ServerInstance->Time() - Current->age; - return " [Up: " + TimeToStr(secs_up) + (Current->rtt == 0 ? "]" : " Lag: " + ConvToStr(Current->rtt) + "ms]"); + return " [Up: " + ModuleSpanningTree::TimeToStr(secs_up) + (Current->rtt == 0 ? "]" : " Lag: " + ConvToStr(Current->rtt) + "ms]"); } -void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats) +void CommandMap::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "ShowMap depth %d on line %d", depth, line); float percent; @@ -92,31 +99,20 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int // and divisons, we instead render the map onto a backplane of characters // (a character matrix), then draw the branches as a series of "L" shapes // from the nodes. This is not only friendlier on CPU it uses less stack. -bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, User* user) +CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* user) { if (parameters.size() > 0) { /* Remote MAP, the server is within the 1st parameter */ TreeServer* s = Utils->FindServerMask(parameters[0]); - bool ret = false; if (!s) { user->WriteNumeric(ERR_NOSUCHSERVER, "%s %s :No such server", user->nick.c_str(), parameters[0].c_str()); - ret = true; - } - else if (s && s != Utils->TreeRoot) - { - parameterlist params; - params.push_back(parameters[0]); - - params[0] = s->GetName(); - Utils->DoOneToOne(user->uuid, "MAP", params, s->GetName()); - ret = true; + return CMD_FAILURE; } - // Don't return if s == Utils->TreeRoot (us) - if (ret) - return true; + if (s != Utils->TreeRoot) + return CMD_SUCCESS; } // These arrays represent a virtual screen which we will @@ -184,6 +180,12 @@ bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, U delete[] names; delete[] stats; - return true; + return CMD_SUCCESS; } +RouteDescriptor CommandMap::GetRouting(User* user, const std::vector<std::string>& parameters) +{ + if (!parameters.empty()) + return ROUTE_UNICAST(parameters[0]); + return ROUTE_LOCALONLY; +} diff --git a/src/modules/m_spanningtree/precommand.cpp b/src/modules/m_spanningtree/precommand.cpp index bc78e96ab..29b6ae642 100644 --- a/src/modules/m_spanningtree/precommand.cpp +++ b/src/modules/m_spanningtree/precommand.cpp @@ -36,10 +36,6 @@ ModResult ModuleSpanningTree::OnPreCommand(std::string &command, std::vector<std { return this->HandleSquit(parameters,user); } - else if (command == "MAP") - { - return this->HandleMap(parameters,user) ? MOD_RES_DENY : MOD_RES_PASSTHRU; - } else if (command == "LINKS") { this->HandleLinks(parameters,user); diff --git a/src/server.cpp b/src/server.cpp index efefa0d37..97b4058c0 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -186,7 +186,7 @@ void ISupportManager::Build() tokens["STATUSMSG"] = ServerInstance->Modes->BuildPrefixes(false); tokens["TOPICLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxTopic); - tokens["FNC"] = tokens["MAP"] = tokens["VBANLIST"] = + tokens["FNC"] = tokens["VBANLIST"] = tokens["WALLCHOPS"] = tokens["WALLVOICES"]; // Modules can add new tokens and also edit or remove existing tokens |