X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Fmain.cpp;h=5613251b08ddcb94f7d5dcf48fd45daea7064e1b;hb=8e14d91fb92768ea4fe838cd4a0ec335b7b735df;hp=2b159fa4e240c3eb837bc3ed31e76558d49d842a;hpb=728a907e887406df109f37e68cafbb3abd2a02e4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 2b159fa4e..5613251b0 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -485,7 +485,7 @@ 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); @@ -503,7 +503,7 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime) 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); @@ -552,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); } } @@ -567,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); } } @@ -622,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 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) { @@ -632,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 ? "" : 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 ? "" : 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; }