Remote /MAP: caution, this doesn't compile

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9381 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
w00t 2008-04-06 17:53:15 +00:00
parent 53fbf0cf7f
commit d87c865987
4 changed files with 66 additions and 12 deletions

View File

@ -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
*/

View File

@ -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<std::string> 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++)
{
user->WriteNumeric(6, "%s :%s",user->nick,&matrix[t][0]);
}
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;
// dump the whole lot to the user.
if (IS_LOCAL(user))
{
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);
}
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;
}

View File

@ -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))
{

View File

@ -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);