]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
Document ModuleSpanningTree::RemoteMessage. Maybe useful for other stuff.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index 97941cb5d70dcaf558e6a78bc8b24394f2fe1070..5613251b08ddcb94f7d5dcf48fd45daea7064e1b 100644 (file)
@@ -137,13 +137,20 @@ void ModuleSpanningTree::HandleLusers(const char** parameters, int pcnt, userrec
                        }
                }
        }
-       user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,n_users-ServerInstance->InvisibleUserCount(),ServerInstance->InvisibleUserCount(),ulined_count ? this->CountServs() - ulined_count : this->CountServs());
+       user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,
+                       n_users-ServerInstance->InvisibleUserCount(),
+                       ServerInstance->InvisibleUserCount(),
+                       ulined_count ? this->CountServs() - ulined_count : this->CountServs());
+
        if (ServerInstance->OperCount())
                user->WriteServ("252 %s %d :operator(s) online",user->nick,ServerInstance->OperCount());
+
        if (ServerInstance->UnregisteredUserCount())
                user->WriteServ("253 %s %d :unknown connections",user->nick,ServerInstance->UnregisteredUserCount());
+       
        if (ServerInstance->ChannelCount())
                user->WriteServ("254 %s %d :channels formed",user->nick,ServerInstance->ChannelCount());
+       
        user->WriteServ("255 %s :I have %d clients and %d servers",user->nick,ServerInstance->LocalUserCount(),ulined_local_count ? this->CountLocalServs() - ulined_local_count : this->CountLocalServs());
        user->WriteServ("265 %s :Current Local Users: %d  Max: %d",user->nick,ServerInstance->LocalUserCount(),max_local);
        user->WriteServ("266 %s :Current Global Users: %d  Max: %d",user->nick,n_users,max_global);
@@ -167,7 +174,7 @@ std::string ModuleSpanningTree::TimeToStr(time_t secs)
 const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
 {
        time_t secs_up = ServerInstance->Time() - Current->age;
-       return (" [Up: " + TimeToStr(secs_up) + " Lag: "+ConvToStr(Current->rtt)+"s]");
+       return (" [Up: " + TimeToStr(secs_up) + " Lag: "+ConvToStr(Current->rtt)+"ms]");
 }
 
 // WARNING: NOT THREAD SAFE - DONT GET ANY SMART IDEAS.
@@ -405,7 +412,6 @@ int ModuleSpanningTree::HandleSquit(const char** parameters, int pcnt, userrec*
                        sock->Squit(s,std::string("Server quit by ") + user->GetFullRealHost());
                        ServerInstance->SE->DelFd(sock);
                        sock->Close();
-                       delete sock;
                }
                else
                {
@@ -479,8 +485,12 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                                if (serv->AnsweredLastPing())
                                {
                                        sock->WriteLine(std::string(":")+ServerInstance->Config->ServerName+" PING "+serv->GetName());
-                                       serv->SetNextPingTime(curtime + 60);
+                                       serv->SetNextPingTime(curtime + Utils->PingFreq);
                                        serv->LastPing = curtime;
+                                       timeval t;
+                                       gettimeofday(&t, NULL);
+                                       long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
+                                       serv->LastPingMsec = ts;
                                        serv->Warned = false;
                                }
                                else
@@ -490,11 +500,10 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                                        sock->Squit(serv,"Ping timeout");
                                        ServerInstance->SE->DelFd(sock);
                                        sock->Close();
-                                       delete sock;
                                        return;
                                }
                        }
-                       else if ((Utils->PingWarnTime) && (!serv->Warned) && (curtime >= serv->NextPingTime() - (60 - Utils->PingWarnTime)) && (!serv->AnsweredLastPing()))
+                       else if ((Utils->PingWarnTime) && (!serv->Warned) && (curtime >= serv->NextPingTime() - (Utils->PingFreq - 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);
@@ -543,8 +552,9 @@ void ModuleSpanningTree::ConnectServer(Link* x)
                }
                else
                {
-                       ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
-                       delete newsocket;
+                       RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
+                       if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end())
+                               ServerInstance->SocketCull[newsocket] = newsocket;
                        Utils->DoFailOver(x);
                }
        }
@@ -558,7 +568,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
                }
                catch (ModuleException& e)
                {
-                       ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
+                       RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
                        Utils->DoFailOver(x);
                }
        }
@@ -613,6 +623,45 @@ int ModuleSpanningTree::HandleVersion(const char** parameters, int pcnt, userrec
        }
        return 1;
 }
+
+/* This method will attempt to get a link message out to as many people as is required.
+ * If a user is provided, and that user is local, then the user is sent the message using
+ * WriteServ (they are the local initiator of that message). If the user is remote, they are
+ * sent that message remotely via PUSH.
+ * If the user is NULL, then the notice is sent locally via WriteToSnoMask with snomask 'l',
+ * and remotely via SNONOTICE with mask 'l'.
+ */
+void ModuleSpanningTree::RemoteMessage(userrec* user, const char* format, ...)
+{
+       std::deque<std::string> params;
+       char text[MAXBUF];
+       va_list argsPtr;
+
+       va_start(argsPtr, format);
+       vsnprintf(text, MAXBUF, format, argsPtr);
+       va_end(argsPtr);
+
+       if (!user)
+       {
+               /* No user, target it generically at everyone */
+               ServerInstance->SNO->WriteToSnoMask('l', "%s", text);
+               params.push_back("l");
+               params.push_back(std::string(":") + text);
+               Utils->DoOneToMany(ServerInstance->Config->ServerName, "SNONOTICE", params);
+       }
+       else
+       {
+               if (IS_LOCAL(user))
+                       user->WriteServ("NOTICE %s :%s", user->nick, text);
+               else
+               {
+                       params.push_back(user->nick);
+                       params.push_back(std::string("::") + ServerInstance->Config->ServerName + " NOTICE " + user->nick + " :*** From " +
+                                       ServerInstance->Config->ServerName+ ": " + text);
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName, "PUSH", params);
+               }
+       }
+}
        
 int ModuleSpanningTree::HandleConnect(const char** parameters, int pcnt, userrec* user)
 {
@@ -623,18 +672,18 @@ int ModuleSpanningTree::HandleConnect(const char** parameters, int pcnt, userrec
                        TreeServer* CheckDupe = Utils->FindServer(x->Name.c_str());
                        if (!CheckDupe)
                        {
-                               user->WriteServ("NOTICE %s :*** CONNECT: Connecting to server: \002%s\002 (%s:%d)",user->nick,x->Name.c_str(),(x->HiddenFromStats ? "<hidden>" : x->IPAddr.c_str()),x->Port);
+                               RemoteMessage(user, "*** CONNECT: Connecting to server: \002%s\002 (%s:%d)",user->nick,x->Name.c_str(),(x->HiddenFromStats ? "<hidden>" : x->IPAddr.c_str()),x->Port);
                                ConnectServer(&(*x));
                                return 1;
                        }
                        else
                        {
-                               user->WriteServ("NOTICE %s :*** CONNECT: Server \002%s\002 already exists on the network and is connected via \002%s\002",user->nick,x->Name.c_str(),CheckDupe->GetParent()->GetName().c_str());
+                               RemoteMessage(user, "*** CONNECT: Server \002%s\002 already exists on the network and is connected via \002%s\002",user->nick,x->Name.c_str(),CheckDupe->GetParent()->GetName().c_str());
                                return 1;
                        }
                }
        }
-       user->WriteServ("NOTICE %s :*** CONNECT: No server matching \002%s\002 could be found in the config file.",user->nick,parameters[0]);
+       RemoteMessage(user, "NOTICE %s :*** CONNECT: No server matching \002%s\002 could be found in the config file.",user->nick,parameters[0]);
        return 1;
 }
 
@@ -1058,11 +1107,15 @@ void ModuleSpanningTree::OnUserKick(userrec* source, userrec* user, chanrec* cha
        }
 }
 
-void ModuleSpanningTree::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason)
+void ModuleSpanningTree::OnRemoteKill(userrec* source, userrec* dest, const std::string &reason, const std::string &operreason)
 {
        std::deque<std::string> params;
+       params.push_back(":"+reason);
+       Utils->DoOneToMany(dest->nick,"OPERQUIT",params);
+       params.clear();
        params.push_back(dest->nick);
        params.push_back(":"+reason);
+       dest->SetOperQuit(operreason);
        Utils->DoOneToMany(source->nick,"KILL",params);
 }
 
@@ -1387,5 +1440,5 @@ Priority ModuleSpanningTree::Prioritize()
        return PRIORITY_LAST;
 }
 
-MODULE_INIT(ModuleSpanningTree);
+MODULE_INIT(ModuleSpanningTree)