From d87c8659876d59ac478128a263544060e85f1a40 Mon Sep 17 00:00:00 2001 From: w00t Date: Sun, 6 Apr 2008 17:53:15 +0000 Subject: Remote /MAP: caution, this doesn't compile git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9381 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree/main.h | 2 +- src/modules/m_spanningtree/override_map.cpp | 67 +++++++++++++++++++++++++---- src/modules/m_spanningtree/precommand.cpp | 3 +- src/modules/m_spanningtree/treesocket2.cpp | 4 ++ 4 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index cfdec9131..216cb6193 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -94,7 +94,7 @@ class ModuleSpanningTree : public Module /** Handle MAP command */ - void HandleMap(const char* const* parameters, int pcnt, User* user); + int HandleMap(const char* const* parameters, int pcnt, User* user); /** Handle SQUIT */ diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 7103b23de..2fc6755dd 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -109,8 +109,41 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, cha // 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. -void ModuleSpanningTree::HandleMap(const char* const* parameters, int pcnt, User* user) +int ModuleSpanningTree::HandleMap(const char* const* parameters, int pcnt, User* user) { + if (pcnt > 0) + { + ServerInstance->Logs->Log("remotemap", DEBUG, "remote map request for %s", parameters[0]); + + /* Remote MAP, the server is within the 1st parameter */ + TreeServer* s = Utils->FindServerMask(parameters[0]); + bool ret = false; + if (!s) + { + ServerInstance->Logs->Log("remotemap", DEBUG, "lolnoserver %s", parameters[0]); + user->WriteServ( "402 %s %s :No such server", user->nick, parameters[0]); + ret = true; + } + else if (s && s != Utils->TreeRoot) + { + ServerInstance->Logs->Log("remotemap", DEBUG, "lol routing to %s", parameters[0]); + std::deque params; + params.push_back(parameters[0]); + + params[0] = s->GetName(); + Utils->DoOneToOne(user->uuid, "MAP", params, s->GetName()); + ret = true; + } + else + { + ServerInstance->Logs->Log("remotemap", DEBUG, "lol it's me"); + } + + // Don't return if s == Utils->TreeRoot (us) + if (ret) + return 1; + } + // This array represents a virtual screen which we will // "scratch" draw to, as the console device of an irc // client does not provide for a proper terminal. @@ -164,14 +197,32 @@ void ModuleSpanningTree::HandleMap(const char* const* parameters, int pcnt, User } } - // dump the whole lot to the user. This is the easy bit, honest. - for (int t = 0; t < line; t++) + float avg_users = totusers / totservers; + + // dump the whole lot to the user. + if (IS_LOCAL(user)) { - user->WriteNumeric(6, "%s :%s",user->nick,&matrix[t][0]); + for (int t = 0; t < line; t++) + { + user->WriteNumeric(6, "%s :%s",user->nick,&matrix[t][0]); + } + user->WriteNumeric(270, "%s :%.0f server%s and %.0f user%s, average %.2f users per server",user->nick,totservers,(totservers > 1 ? "s" : ""),totusers,(totusers > 1 ? "s" : ""),avg_users); + user->WriteNumeric(7, "%s :End of /MAP",user->nick); } - float avg_users = totusers / totservers; - user->WriteNumeric(270, "%s :%.0f server%s and %.0f user%s, average %.2f users per server",user->nick,totservers,(totservers > 1 ? "s" : ""),totusers,(totusers > 1 ? "s" : ""),avg_users); - user->WriteNumeric(7, "%s :End of /MAP",user->nick); - return; + else + { + + //void SpanningTreeProtocolInterface::PushToClient(User* target, const std::string &rawline) + + for (int t = 0; t < line; t++) + { + ServerInstance->PI->PushToClient(user, std::string("6 ") + user->nick + " :" + &matrix[t][0]); + } + + ServerInstance->PI->PushToClient(user, std::string("270 ") + user->nick + " :" + ConvToStr(totservers) + (totservers > 1 ? "s" : "") + " and " + ConvToStr(totusers) + (totusers > 1 ? "s" : "") + ", average " + ConvToStr(avg_users) + " users per server"); + ServerInstance->PI->PushToClient(user, std::string("7 ") + user->nick + " :End of /MAP"); + } + + return 1; } diff --git a/src/modules/m_spanningtree/precommand.cpp b/src/modules/m_spanningtree/precommand.cpp index 324aa3e14..64e9a90dd 100644 --- a/src/modules/m_spanningtree/precommand.cpp +++ b/src/modules/m_spanningtree/precommand.cpp @@ -61,8 +61,7 @@ int ModuleSpanningTree::OnPreCommand(const std::string &command, const char* con } else if (command == "MAP") { - this->HandleMap(parameters,pcnt,user); - return 1; + return this->HandleMap(parameters,pcnt,user); } else if ((command == "TIME") && (pcnt > 0)) { diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 40cee5854..b2aa8d475 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -361,6 +361,10 @@ bool TreeSocket::ProcessLine(std::string &line) { return this->Admin(prefix, params); } + else if (command == "MAP") + { + return Utils->Creator->HandleMap(prefix, params); + } else if (command == "SERVER") { return this->RemoteServer(prefix,params); -- cgit v1.2.3