// WARNING: NOT THREAD SAFE - DONT GET ANY SMART IDEAS. void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth, char matrix[128][128], float &totusers, float &totservers) { if (line < 128) { for (int t = 0; t < depth; t++) { matrix[line][t] = ' '; } // For Aligning, we need to work out exactly how deep this thing is, and produce // a 'Spacer' String to compensate. char spacer[40]; memset(spacer,' ',40); if ((40 - Current->GetName().length() - depth) > 1) { spacer[40 - Current->GetName().length() - depth] = '\0'; } else { spacer[5] = '\0'; } float percent; char text[128]; /* Neat and tidy default values, as we're dealing with a matrix not a simple string */ memset(text, 0, 128); if (ServerInstance->clientlist->size() == 0) { // If there are no users, WHO THE HELL DID THE /MAP?!?!?! percent = 0; } else { percent = ((float)Current->GetUserCount() / (float)ServerInstance->clientlist->size()) * 100; } const std::string operdata = IS_OPER(user) ? MapOperInfo(Current) : ""; snprintf(text, 126, "%s %s%5d [%5.2f%%]%s", Current->GetName().c_str(), spacer, Current->GetUserCount(), percent, operdata.c_str()); totusers += Current->GetUserCount(); totservers++; strlcpy(&matrix[line][depth],text,126); line++; for (unsigned int q = 0; q < Current->ChildCount(); q++) { if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName().c_str())))) { if (*user->oper) { ShowMap(Current->GetChild(q),user,(Utils->FlatLinks && (!*user->oper)) ? depth : depth+2,matrix,totusers,totservers); } } else { ShowMap(Current->GetChild(q),user,(Utils->FlatLinks && (!*user->oper)) ? depth : depth+2,matrix,totusers,totservers); } } } }
void CommandMap::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "ShowMap depth %d on line %d", depth, line); float percent; if (ServerInstance->Users->clientlist->size() == 0) { // If there are no users, WHO THE HELL DID THE /MAP?!?!?! percent = 0; } else { percent = Current->UserCount * 100.0 / ServerInstance->Users->clientlist->size(); } const std::string operdata = user->IsOper() ? MapOperInfo(Current) : ""; char* myname = names + 100 * line; char* mystat = stats + 50 * line; memset(myname, ' ', depth); int w = depth; if (user->IsOper()) { w += snprintf(myname + depth, 99 - depth, "%s (%s)", Current->GetName().c_str(), Current->GetID().c_str()); } else { w += snprintf(myname + depth, 99 - depth, "%s", Current->GetName().c_str()); } memset(myname + w, ' ', 100 - w); if (w > maxnamew) maxnamew = w; snprintf(mystat, 49, "%5d [%5.2f%%]%s", Current->UserCount, percent, operdata.c_str()); line++; if (user->IsOper() || !Utils->FlatLinks) depth = depth + 2; const TreeServer::ChildServers& servers = Current->GetChildren(); for (TreeServer::ChildServers::const_iterator i = servers.begin(); i != servers.end(); ++i) { TreeServer* child = *i; if (!user->IsOper()) { if (child->Hidden) continue; if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName()))) continue; } ShowMap(child, user, depth, line, names, maxnamew, stats); } }
void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats) { ServerInstance->Logs->Log("map",LOG_DEBUG,"ShowMap depth %d on line %d", depth, line); float percent; if (ServerInstance->Users->clientlist->size() == 0) { // If there are no users, WHO THE HELL DID THE /MAP?!?!?! percent = 0; } else { percent = Current->UserCount * 100.0 / ServerInstance->Users->clientlist->size(); } const std::string operdata = user->IsOper() ? MapOperInfo(Current) : ""; char* myname = names + 100 * line; char* mystat = stats + 50 * line; memset(myname, ' ', depth); int w = depth; std::string servername = Current->GetName(); if (user->IsOper()) { w += snprintf(myname + depth, 99 - depth, "%s (%s)", servername.c_str(), Current->GetID().c_str()); } else { w += snprintf(myname + depth, 99 - depth, "%s", servername.c_str()); } memset(myname + w, ' ', 100 - w); if (w > maxnamew) maxnamew = w; snprintf(mystat, 49, "%5d [%5.2f%%]%s", Current->UserCount, percent, operdata.c_str()); line++; if (user->IsOper() || !Utils->FlatLinks) depth = depth + 2; for (unsigned int q = 0; q < Current->ChildCount(); q++) { TreeServer* child = Current->GetChild(q); if (!user->IsOper()) { if (child->Hidden) continue; if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName()))) continue; } ShowMap(child, user, depth, line, names, maxnamew, stats); } }