/*
* InspIRCd -- Internet Relay Chat Daemon
*
+ * Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
* Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
- * Copyright (C) 2016, 2018-2019 Sadie Powell <sadie@witchery.services>
+ * 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>
CommandMap::CommandMap(Module* Creator)
: Command(Creator, "MAP", 0, 1)
{
+ allow_empty_last_param = false;
Penalty = 2;
}
}
// 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;
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
}
// 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)
{
// 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)
{
// 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->WriteRemoteNumeric(RPL_MAP, *i);