X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Foverride_map.cpp;h=5122fd0edb71edbf81d7e43b7193608c1e8b6a94;hb=b618b194f3166a55ca7e7889c7346b65c174d397;hp=80ff832cbc5703681256d03f0d1acc108fee7871;hpb=4f9abe96a4301a740d4a5fd7932550d88d60a3fc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 80ff832cb..5122fd0ed 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -2,7 +2,7 @@ * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2017 B00mX0r - * Copyright (C) 2016, 2018-2019 Sadie Powell + * Copyright (C) 2016, 2018-2020 Sadie Powell * Copyright (C) 2014 Adam * Copyright (C) 2013-2016 Attila Molnar * Copyright (C) 2012 Robby @@ -53,22 +53,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 GetMap(User* user, TreeServer* current, unsigned int max_len, unsigned int depth) +static std::vector GetMap(User* user, TreeServer* current, unsigned int max_len, unsigned int max_version_len, unsigned int depth) { float percent = 0; @@ -89,6 +93,8 @@ static std::vector GetMap(User* user, TreeServer* current, unsigned 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 @@ -132,7 +138,7 @@ static std::vector GetMap(User* user, TreeServer* current, unsigned } // Build the map for this child - std::vector child_map = GetMap(user, child, next_len, depth + 1); + std::vector child_map = GetMap(user, child, next_len, max_version_len, depth + 1); for (std::vector::const_iterator j = child_map.begin(); j != child_map.end(); ++j) { @@ -144,7 +150,7 @@ static std::vector 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 children 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 there's nothing else linked to me below this @@ -193,7 +199,8 @@ CmdResult CommandMap::Handle(User* user, const Params& parameters) // 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) @@ -205,9 +212,11 @@ CmdResult CommandMap::Handle(User* user, const Params& parameters) { // This user can't see any depth max = max_len; + if (!user->IsOper()) + max_version = 0; } - std::vector map = GetMap(user, Utils->TreeRoot, max, 0); + std::vector map = GetMap(user, Utils->TreeRoot, max, max_version, 0); for (std::vector::const_iterator i = map.begin(); i != map.end(); ++i) user->WriteRemoteNumeric(RPL_MAP, *i);