diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 19 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.h | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/override_map.cpp | 19 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treeserver.cpp | 23 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treeserver.h | 20 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket1.cpp | 7 |
6 files changed, 49 insertions, 41 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 6a629b803..34af202fd 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -57,7 +57,7 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me) { I_OnPreCommand, I_OnGetServerDescription, I_OnUserInvite, I_OnPostLocalTopicChange, I_OnWallops, I_OnUserNotice, I_OnUserMessage, I_OnBackgroundTimer, - I_OnUserJoin, I_OnChangeHost, I_OnChangeName, I_OnUserPart, I_OnUserConnect, + I_OnUserJoin, I_OnChangeHost, I_OnChangeName, I_OnUserPart, I_OnPostConnect, I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash, I_OnOper, I_OnAddLine, I_OnDelLine, I_ProtoSendMode, I_OnMode, I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnCancelAway, I_OnPostCommand @@ -619,7 +619,7 @@ void ModuleSpanningTree::OnUserPart(User* user, Channel* channel, const std::str } } -void ModuleSpanningTree::OnUserConnect(User* user) +void ModuleSpanningTree::OnPostConnect(User* user) { if (IS_LOCAL(user)) { @@ -635,12 +635,12 @@ void ModuleSpanningTree::OnUserConnect(User* user) params.push_back(ConvToStr(user->signon)); params.push_back(":"+std::string(user->fullname)); Utils->DoOneToMany(ServerInstance->Config->GetSID(), "UID", params); - // User is Local, change needs to be reflected! - TreeServer* SourceServer = Utils->FindServer(user->server); - if (SourceServer) - { - SourceServer->AddUserCount(); - } + } + + TreeServer* SourceServer = Utils->FindServer(user->server); + if (SourceServer) + { + SourceServer->SetUserCount(1); // increment by 1 } } @@ -659,11 +659,12 @@ void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const params.push_back(":"+reason); Utils->DoOneToMany(user->uuid,"QUIT",params); } + // Regardless, We need to modify the user Counts.. TreeServer* SourceServer = Utils->FindServer(user->server); if (SourceServer) { - SourceServer->DelUserCount(); + SourceServer->SetUserCount(-1); // decrement by 1 } } diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index f9b63d431..bfd48cda4 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -170,7 +170,7 @@ class ModuleSpanningTree : public Module virtual void OnChangeHost(User* user, const std::string &newhost); virtual void OnChangeName(User* user, const std::string &gecos); virtual void OnUserPart(User* user, Channel* channel, const std::string &partmessage, bool &silent); - virtual void OnUserConnect(User* user); + virtual void OnPostConnect(User* user); virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message); virtual void OnUserPostNick(User* user, const std::string &oldnick); virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent); diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index d0940936a..1a97cf8f3 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -47,7 +47,8 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, cha 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]; @@ -59,12 +60,14 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, cha { 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 (ServerInstance->clientlist->size() == 0) + { // If there are no users, WHO THE HELL DID THE /MAP?!?!?! percent = 0; } @@ -72,12 +75,14 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, cha { 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())))) @@ -112,13 +117,17 @@ void ModuleSpanningTree::HandleMap(const char** parameters, int pcnt, User* user float totusers = 0; float totservers = 0; char matrix[128][128]; + for (unsigned int t = 0; t < 128; t++) { matrix[t][0] = '\0'; } + line = 0; + // The only recursive bit is called here. ShowMap(Utils->TreeRoot,user,0,matrix,totusers,totservers); + // Process each line one by one. The algorithm has a limit of // 128 servers (which is far more than a spanning tree should have // anyway, so we're ok). This limit can be raised simply by making @@ -130,17 +139,22 @@ void ModuleSpanningTree::HandleMap(const char** parameters, int pcnt, User* user // the servers at indented positions depending on what they // are related to) int first_nonspace = 0; + while (matrix[l][first_nonspace] == ' ') { first_nonspace++; } + first_nonspace--; + // Draw the `- (corner) section: this may be overwritten by // another L shape passing along the same vertical pane, becoming // a |- (branch) section instead. + matrix[l][first_nonspace] = '-'; matrix[l][first_nonspace-1] = '`'; int l2 = l - 1; + // Draw upwards until we hit the parent server, causing possibly // other corners (`-) to become branches (|-) while ((matrix[l2][first_nonspace-1] == ' ') || (matrix[l2][first_nonspace-1] == '`')) @@ -149,6 +163,7 @@ void ModuleSpanningTree::HandleMap(const char** parameters, int pcnt, User* user l2--; } } + // dump the whole lot to the user. This is the easy bit, honest. for (int t = 0; t < line; t++) { diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 64f01e83c..4215fcd3d 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -30,7 +30,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, const st ServerName.clear(); ServerDesc.clear(); VersionString.clear(); - UserCount = OperCount = 0; + ServerUserCount = ServerOperCount = 0; rtt = LastPing = 0; Warned = Hidden = DupError = false; VersionString = ServerInstance->GetVersionString(); @@ -46,8 +46,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::str { Parent = NULL; VersionString.clear(); - UserCount = ServerInstance->UserCount(); - OperCount = ServerInstance->OperCount(); + ServerUserCount = ServerOperCount = 0; VersionString = ServerInstance->GetVersionString(); Route = NULL; Socket = NULL; /* Fix by brain */ @@ -65,7 +64,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::str : ServerInstance(Instance), Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), Hidden(Hide) { VersionString.clear(); - UserCount = OperCount = 0; + ServerUserCount = ServerOperCount = 0; this->SetNextPingTime(time(NULL) + Utils->PingFreq); this->SetPingFlag(); DupError = false; @@ -241,24 +240,24 @@ void TreeServer::SetPingFlag() LastPingWasGood = true; } -int TreeServer::GetUserCount() +unsigned int TreeServer::GetUserCount() { - return UserCount; + return ServerUserCount; } -void TreeServer::AddUserCount() +void TreeServer::SetUserCount(int diff) { - UserCount++; + ServerUserCount += diff; } -void TreeServer::DelUserCount() +void TreeServer::SetOperCount(int diff) { - UserCount--; + ServerOperCount += diff; } -int TreeServer::GetOperCount() +unsigned int TreeServer::GetOperCount() { - return OperCount; + return ServerOperCount; } TreeSocket* TreeServer::GetSocket() diff --git a/src/modules/m_spanningtree/treeserver.h b/src/modules/m_spanningtree/treeserver.h index d465722aa..28e36252d 100644 --- a/src/modules/m_spanningtree/treeserver.h +++ b/src/modules/m_spanningtree/treeserver.h @@ -37,8 +37,8 @@ class TreeServer : public classbase irc::string ServerName; /* Server's name */ std::string ServerDesc; /* Server's description */ std::string VersionString; /* Version string or empty string */ - int UserCount; /* Not used in this version */ - int OperCount; /* Not used in this version */ + unsigned int ServerUserCount; /* How many users are on this server? [note: doesn't care about +i] */ + unsigned int ServerOperCount; /* How many opers are on this server? */ TreeSocket* Socket; /* For directly connected servers this points at the socket object */ time_t NextPing; /* After this time, the server should be PINGed*/ bool LastPingWasGood; /* True if the server responded to the last PING with a PONG */ @@ -137,21 +137,21 @@ class TreeServer : public classbase */ void SetPingFlag(); - /** Get the number of users on this server for MAP + /** Get the number of users on this server. */ - int GetUserCount(); + unsigned int GetUserCount(); - /** Increment the user counter + /** Increment or decrement the user count by diff. */ - void AddUserCount(); + void SetUserCount(int diff); - /** Decrement the user counter + /** Gets the numbers of opers on this server. */ - void DelUserCount(); + unsigned int GetOperCount(); - /** Get the oper count for this server + /** Increment or decrement the oper count by diff. */ - int GetOperCount(); + void SetOperCount(int diff); /** Get the TreeSocket pointer for local servers. * For remote servers, this returns NULL. diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index 37a93084e..29562e5e8 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -1126,13 +1126,6 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa params[9] = ":" + params[9]; Utils->DoOneToAllButSender(source, "UID", params, source); - // Increment the Source Servers User Count.. - TreeServer* SourceServer = Utils->FindServer(source); - if (SourceServer) - { - SourceServer->AddUserCount(); - } - FOREACH_MOD_I(Instance,I_OnPostConnect,OnPostConnect(_new)); return true; |