]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/override_map.cpp
Add a subclass of IOHookProvider for SSL modules.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / override_map.cpp
index 68551e84f5ba22359cdd4e3a0235c181a4ae40ba..0592eeaf1dcb3aa8bac4b153c41576fd70aa68ea 100644 (file)
@@ -1,10 +1,17 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
+ *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
+ *   Copyright (C) 2016, 2018-2020 Sadie Powell <sadie@witchery.services>
  *   Copyright (C) 2014 Adam <Adam@anope.org>
+ *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
  *
  * 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
@@ -30,6 +37,7 @@
 CommandMap::CommandMap(Module* Creator)
        : Command(Creator, "MAP", 0, 1)
 {
+       allow_empty_last_param = false;
        Penalty = 2;
 }
 
@@ -47,22 +55,26 @@ static inline bool IsHidden(User* user, TreeServer* server)
 }
 
 // Calculate the map depth the servers go, and the longest server name
-static void GetDepthAndLen(TreeServer* current, unsigned int depth, unsigned int& max_depth, unsigned int& max_len)
+static void GetDepthAndLen(TreeServer* current, unsigned int depth, unsigned int& max_depth, unsigned int& max_len, unsigned int& max_version)
 {
        if (depth > max_depth)
                max_depth = depth;
+
        if (current->GetName().length() > max_len)
                max_len = current->GetName().length();
 
+       if (current->GetRawVersion().length() > max_version)
+               max_version = current->GetRawVersion().length();
+
        const TreeServer::ChildServers& servers = current->GetChildren();
        for (TreeServer::ChildServers::const_iterator i = servers.begin(); i != servers.end(); ++i)
        {
                TreeServer* child = *i;
-               GetDepthAndLen(child, depth + 1, max_depth, max_len);
+               GetDepthAndLen(child, depth + 1, max_depth, max_len, max_version);
        }
 }
 
-static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned int max_len, unsigned int depth)
+static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned int max_len, unsigned int max_version_len, unsigned int depth)
 {
        float percent = 0;
 
@@ -76,20 +88,26 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned
        std::string buffer = current->GetName();
        if (user->IsOper())
        {
-               buffer += " (" + current->GetID() + ")";
+               buffer += " (" + current->GetId();
+
+               const std::string& cur_vers = current->GetRawVersion();
+               if (!cur_vers.empty())
+                       buffer += " " + cur_vers;
+
+               buffer += ")";
+
+               buffer.append(max_version_len - current->GetRawVersion().length(), ' ');
        }
 
        // Pad with spaces until its at max len, max_len must always be >= my names length
        buffer.append(max_len - current->GetName().length(), ' ');
 
-       char buf[16];
-       snprintf(buf, sizeof(buf), "%5d [%5.2f%%]", current->UserCount, percent);
-       buffer += buf;
+       buffer += InspIRCd::Format("%5d [%5.2f%%]", current->UserCount, percent);
 
        if (user->IsOper())
        {
                time_t secs_up = ServerInstance->Time() - current->age;
-               buffer += " [Up: " + ModuleSpanningTree::TimeToStr(secs_up) + (current->rtt == 0 ? "]" : " Lag: " + ConvToStr(current->rtt) + "ms]");
+               buffer += " [Up: " + InspIRCd::DurationString(secs_up) + (current->rtt == 0 ? "]" : " Lag: " + ConvToStr(current->rtt) + "ms]");
        }
 
        std::vector<std::string> map;
@@ -122,7 +140,7 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned
                }
 
                // Build the map for this child
-               std::vector<std::string> child_map = GetMap(user, child, next_len, depth + 1);
+               std::vector<std::string> child_map = GetMap(user, child, next_len, max_version_len, depth + 1);
 
                for (std::vector<std::string>::const_iterator j = child_map.begin(); j != child_map.end(); ++j)
                {
@@ -134,10 +152,10 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned
                                if (j != child_map.begin())
                                {
                                        // If this child is not my last child, then add |
-                                       // to be able to "link" the next server in my list to me, and to indent this childs servers
+                                       // to be able to "link" the next server in my list to me, and to indent this child's servers
                                        if (!last)
                                                prefix = "| ";
-                                       // Otherwise this is my last child, so just use a space as theres nothing else linked to me below this
+                                       // Otherwise this is my last child, so just use a space as there's nothing else linked to me below this
                                        else
                                                prefix = "  ";
                                }
@@ -164,15 +182,15 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned
        return map;
 }
 
-CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* user)
+CmdResult CommandMap::Handle(User* user, const Params& parameters)
 {
        if (parameters.size() > 0)
        {
-               /* Remote MAP, the server is within the 1st parameter */
+               // Remote MAP, the target server is the 1st parameter
                TreeServer* s = Utils->FindServerMask(parameters[0]);
                if (!s)
                {
-                       user->WriteNumeric(ERR_NOSUCHSERVER, "%s :No such server", parameters[0].c_str());
+                       user->WriteNumeric(ERR_NOSUCHSERVER, parameters[0], "No such server");
                        return CMD_FAILURE;
                }
 
@@ -183,7 +201,8 @@ CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* u
        // Max depth and max server name length
        unsigned int max_depth = 0;
        unsigned int max_len = 0;
-       GetDepthAndLen(Utils->TreeRoot, 0, max_depth, max_len);
+       unsigned int max_version = 0;
+       GetDepthAndLen(Utils->TreeRoot, 0, max_depth, max_len, max_version);
 
        unsigned int max;
        if (user->IsOper() || !Utils->FlatLinks)
@@ -195,26 +214,25 @@ CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* u
        {
                // This user can't see any depth
                max = max_len;
+               if (!user->IsOper())
+                       max_version = 0;
        }
 
-       std::vector<std::string> map = GetMap(user, Utils->TreeRoot, max, 0);
+       std::vector<std::string> map = GetMap(user, Utils->TreeRoot, max, max_version, 0);
        for (std::vector<std::string>::const_iterator i = map.begin(); i != map.end(); ++i)
-               user->SendText(":%s %03d %s :%s", ServerInstance->Config->ServerName.c_str(),
-                       RPL_MAP, user->nick.c_str(), i->c_str());
+               user->WriteRemoteNumeric(RPL_MAP, *i);
 
        size_t totusers = ServerInstance->Users->GetUsers().size();
        float avg_users = (float) totusers / Utils->serverlist.size();
 
-       user->SendText(":%s %03d %s :%u server%s and %u user%s, average %.2f users per server",
-               ServerInstance->Config->ServerName.c_str(), RPL_MAPUSERS, user->nick.c_str(),
-               (unsigned int)Utils->serverlist.size(), (Utils->serverlist.size() > 1 ? "s" : ""), (unsigned int)totusers, (totusers > 1 ? "s" : ""), avg_users);
-       user->SendText(":%s %03d %s :End of /MAP", ServerInstance->Config->ServerName.c_str(),
-               RPL_ENDMAP, user->nick.c_str());
+       user->WriteRemoteNumeric(RPL_MAPUSERS, InspIRCd::Format("%u server%s and %u user%s, average %.2f users per server",
+               (unsigned int)Utils->serverlist.size(), (Utils->serverlist.size() > 1 ? "s" : ""), (unsigned int)totusers, (totusers > 1 ? "s" : ""), avg_users));
+       user->WriteRemoteNumeric(RPL_ENDMAP, "End of /MAP");
 
        return CMD_SUCCESS;
 }
 
-RouteDescriptor CommandMap::GetRouting(User* user, const std::vector<std::string>& parameters)
+RouteDescriptor CommandMap::GetRouting(User* user, const Params& parameters)
 {
        if (!parameters.empty())
                return ROUTE_UNICAST(parameters[0]);