}
}
}
- 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);
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.
sock->Squit(s,std::string("Server quit by ") + user->GetFullRealHost());
ServerInstance->SE->DelFd(sock);
sock->Close();
- delete sock;
}
else
{
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
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);
}
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);
}
}
}
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);
}
}
}
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)
{
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;
}