]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
Poach feature request: If a server does not respond after x seconds to a PING, send...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index 471e7ba4d3c101de9ebadfd9c7db05495170aa75..4dc6eedc0e9d3d4e4cf0cb4a3875b205db6821a7 100644 (file)
@@ -163,7 +163,7 @@ const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
 }
 
 // WARNING: NOT THREAD SAFE - DONT GET ANY SMART IDEAS.
-void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth, char matrix[128][80], float &totusers, float &totservers)
+void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth, char matrix[128][128], float &totusers, float &totservers)
 {
        if (line < 128)
        {
@@ -183,7 +183,10 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth,
                        spacer[5] = '\0';
                }
                float percent;
-               char text[80];
+               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;
@@ -193,10 +196,10 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, userrec* user, int depth,
                        percent = ((float)Current->GetUserCount() / (float)ServerInstance->clientlist->size()) * 100;
                }
                const std::string operdata = IS_OPER(user) ? MapOperInfo(Current) : "";
-               snprintf(text, 80, "%s %s%5d [%5.2f%%]%s", Current->GetName().c_str(), spacer, Current->GetUserCount(), percent, operdata.c_str());
+               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,80);
+               strlcpy(&matrix[line][depth],text,126);
                line++;
                for (unsigned int q = 0; q < Current->ChildCount(); q++)
                {
@@ -315,7 +318,7 @@ void ModuleSpanningTree::HandleMap(const char** parameters, int pcnt, userrec* u
        // client does not provide for a proper terminal.
        float totusers = 0;
        float totservers = 0;
-       char matrix[128][80];
+       char matrix[128][128];
        for (unsigned int t = 0; t < 128; t++)
        {
                matrix[t][0] = '\0';
@@ -460,11 +463,13 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                                        sock->WriteLine(std::string(":")+ServerInstance->Config->ServerName+" PING "+serv->GetName());
                                        serv->SetNextPingTime(curtime + 60);
                                        serv->LastPing = curtime;
+                                       serv->Warned = false;
                                }
                                else
                                {
                                        // they didnt answer, boot them
                                        ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 pinged out",serv->GetName().c_str());
+                                       sock->SendError("Ping timeout");
                                        sock->Squit(serv,"Ping timeout");
                                        ServerInstance->SE->DelFd(sock);
                                        sock->Close();
@@ -472,6 +477,12 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                                        return;
                                }
                        }
+                       else if ((Utils->PingWarnTime) && (!serv->Warned) && (curtime >= serv->NextPingTime() - (60 - Utils->PingWarnTime)) && (!serv->AnsweredLastPing()))
+                       {
+                               /* The server hasnt responded, send a warning to opers */
+                               ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", serv->GetName().c_str(), Utils->PingWarnTime);
+                               serv->Warned = true;
+                       }
                }
        }
 }
@@ -869,7 +880,7 @@ void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
        DoPingChecks(curtime);
 }
 
-void ModuleSpanningTree::OnUserJoin(userrec* user, chanrec* channel)
+void ModuleSpanningTree::OnUserJoin(userrec* user, chanrec* channel, bool &silent)
 {
        // Only do this for local users
        if (IS_LOCAL(user))
@@ -920,7 +931,7 @@ void ModuleSpanningTree::OnChangeName(userrec* user, const std::string &gecos)
        Utils->DoOneToMany(user->nick,"FNAME",params);
 }
 
-void ModuleSpanningTree::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage)
+void ModuleSpanningTree::OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
 {
        if (IS_LOCAL(user))
        {
@@ -990,7 +1001,7 @@ void ModuleSpanningTree::OnUserPostNick(userrec* user, const std::string &oldnic
        }
 }
 
-void ModuleSpanningTree::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason)
+void ModuleSpanningTree::OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent)
 {
        if ((source) && (IS_LOCAL(source)))
        {