diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-07-01 19:14:14 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-08-19 20:08:41 +0200 |
commit | 0cec1856ccd0cfbf7bd5d6f82be1d02f9bdeed4e (patch) | |
tree | 8035f9ff0f1e14f3cfc45a0b95aa47c0c491ccbd /src/modules/m_spanningtree | |
parent | 5dcd385b772f2ce822cf0700912ced93bd06c914 (diff) |
Remove cmd_map from the core
Diffstat (limited to 'src/modules/m_spanningtree')
-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 |
5 files changed, 46 insertions, 36 deletions
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); |