summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/main.cpp38
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp4
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp32
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp7
-rw-r--r--src/modules/m_spanningtree/utils.cpp8
5 files changed, 36 insertions, 53 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 42547fbdc..2d9bc3b83 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -247,7 +247,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
if (InspIRCd::Match(ServerInstance->Config->ServerName, assign(x->Name)))
{
- RemoteMessage(NULL, "CONNECT: Not connecting to myself.");
+ this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Not connecting to myself.");
return;
}
@@ -281,7 +281,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
}
else
{
- RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
+ this->ServerInstance->SNO->WriteToSnoMask('l', "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);
@@ -297,7 +297,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
}
catch (ModuleException& e)
{
- RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
Utils->DoFailOver(x);
}
}
@@ -377,24 +377,10 @@ int ModuleSpanningTree::HandleVersion(const std::vector<std::string>& parameters
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'.
+/* This method will attempt to get a message to a remote user.
*/
void ModuleSpanningTree::RemoteMessage(User* user, const char* format, ...)
{
- /* This could cause an infinite loop, because DoOneToMany() will, on error,
- * call TreeSocket::OnError(), which in turn will call this function to
- * notify everyone of the error. So, drop any messages that are generated
- * during the sending of another message. -Special */
- static bool SendingRemoteMessage = false;
- if (SendingRemoteMessage)
- return;
- SendingRemoteMessage = true;
-
char text[MAXBUF];
va_list argsPtr;
@@ -402,20 +388,10 @@ void ModuleSpanningTree::RemoteMessage(User* user, const char* format, ...)
vsnprintf(text, MAXBUF, format, argsPtr);
va_end(argsPtr);
- if (!user)
- {
- /* No user, target it generically at everyone */
- ServerInstance->SNO->WriteToSnoMask('l', "%s", text);
- }
+ if (IS_LOCAL(user))
+ user->WriteServ("NOTICE %s :%s", user->nick.c_str(), text);
else
- {
- if (IS_LOCAL(user))
- user->WriteServ("NOTICE %s :%s", user->nick.c_str(), text);
- else
- ServerInstance->PI->SendUserNotice(user, text);
- }
-
- SendingRemoteMessage = false;
+ ServerInstance->PI->SendUserNotice(user, text);
}
int ModuleSpanningTree::HandleConnect(const std::vector<std::string>& parameters, User* user)
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index 4a33cd216..291a609d6 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -63,7 +63,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
else
{
/* Something barfed, show the opers */
- Utils->Creator->RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
+ ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
if (ServerInstance->SocketCull.find(newsocket) == ServerInstance->SocketCull.end())
ServerInstance->SocketCull[newsocket] = newsocket;
Utils->DoFailOver(&MyLink);
@@ -81,7 +81,7 @@ void ServernameResolver::OnError(ResolverError e, const std::string &errormessag
ServerInstance->AddResolver(snr, cached);
return;
}
- Utils->Creator->RemoteMessage(NULL, "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink.Name.c_str(), errormessage.c_str() );
+ ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink.Name.c_str(), errormessage.c_str() );
Utils->DoFailOver(&MyLink);
}
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 03fd05a34..4de0926d6 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -103,11 +103,11 @@ bool TreeSocket::OnConnected()
{
if (x->Name == this->myhost)
{
- Utils->Creator->RemoteMessage(NULL,"Connection to \2%s\2[%s] started.", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()));
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] started.", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()));
if (Hook)
{
BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
- Utils->Creator->RemoteMessage(NULL,"Connection to \2%s\2[%s] using transport \2%s\2", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()),
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2[%s] using transport \2%s\2", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()),
x->Hook.c_str());
}
this->OutboundPass = x->SendPass;
@@ -128,7 +128,7 @@ bool TreeSocket::OnConnected()
* If that happens the connection hangs here until it's closed. Unlikely
* and rather harmless.
*/
- this->Utils->Creator->RemoteMessage(NULL,"Connection to \2%s\2 lost link tag(!)", myhost.c_str());
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection to \2%s\2 lost link tag(!)", myhost.c_str());
return true;
}
@@ -139,26 +139,26 @@ void TreeSocket::OnError(BufferedSocketError e)
switch (e)
{
case I_ERR_CONNECT:
- Utils->Creator->RemoteMessage(NULL,"Connection failed: Connection to \002%s\002 refused", myhost.c_str());
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Connection to \002%s\002 refused", myhost.c_str());
MyLink = Utils->FindLink(myhost);
if (MyLink)
Utils->DoFailOver(MyLink);
break;
case I_ERR_SOCKET:
- Utils->Creator->RemoteMessage(NULL,"Connection failed: Could not create socket (%s)", strerror(errno));
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Could not create socket (%s)", strerror(errno));
break;
case I_ERR_BIND:
- Utils->Creator->RemoteMessage(NULL,"Connection failed: Error binding socket to address or port (%s)", strerror(errno));
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Error binding socket to address or port (%s)", strerror(errno));
break;
case I_ERR_WRITE:
- Utils->Creator->RemoteMessage(NULL,"Connection failed: I/O error on connection (%s)", errno ? strerror(errno) : "Connection closed unexpectedly");
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: I/O error on connection (%s)", errno ? strerror(errno) : "Connection closed unexpectedly");
break;
case I_ERR_NOMOREFDS:
- Utils->Creator->RemoteMessage(NULL,"Connection failed: Operating system is out of file descriptors!");
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Operating system is out of file descriptors!");
break;
default:
if ((errno) && (errno != EINPROGRESS) && (errno != EAGAIN))
- Utils->Creator->RemoteMessage(NULL,"Connection to \002%s\002 failed with OS error: %s", myhost.c_str(), strerror(errno));
+ ServerInstance->SNO->WriteToSnoMask('l', "Connection to \002%s\002 failed with OS error: %s", myhost.c_str(), strerror(errno));
break;
}
}
@@ -174,7 +174,7 @@ int TreeSocket::OnDisconnect()
void TreeSocket::SendError(const std::string &errormessage)
{
/* Display the error locally as well as sending it remotely */
- Utils->Creator->RemoteMessage(NULL, "Sent \2ERROR\2 to %s: %s", (this->InboundServerName.empty() ? this->GetIP().c_str() : this->InboundServerName.c_str()), errormessage.c_str());
+ ServerInstance->SNO->WriteToSnoMask('l', "Sent \2ERROR\2 to %s: %s", (this->InboundServerName.empty() ? this->GetIP().c_str() : this->InboundServerName.c_str()), errormessage.c_str());
this->WriteLine("ERROR :"+errormessage);
/* One last attempt to make sure the error reaches its target */
this->FlushWriteBuffer();
@@ -208,6 +208,8 @@ void TreeSocket::SquitServer(std::string &from, TreeServer* Current)
*/
void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
{
+ bool LocalSquit = false;
+
if ((Current) && (Current != Utils->TreeRoot))
{
Event rmode((char*)Current->GetName().c_str(), (Module*)Utils->Creator, "lost_server");
@@ -219,11 +221,12 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
Utils->DoOneToAllButSender(Current->GetParent()->GetName(),"SQUIT",params,Current->GetName());
if (Current->GetParent() == Utils->TreeRoot)
{
- this->ServerInstance->SNO->WriteToSnoMask('l',"Server \002"+Current->GetName()+"\002 split: "+reason);
+ this->ServerInstance->SNO->WriteToSnoMask('l', "Server \002"+Current->GetName()+"\002 split: "+reason);
+ LocalSquit = true;
}
else
{
- this->ServerInstance->SNO->WriteToSnoMask('l',"Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason);
+ this->ServerInstance->SNO->WriteToSnoMask('L', "Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason);
}
num_lost_servers = 0;
num_lost_users = 0;
@@ -232,7 +235,10 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
Current->Tidy();
Current->GetParent()->DelChild(Current);
delete Current;
- this->ServerInstance->SNO->WriteToSnoMask('l',"Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers);
+ if (LocalSquit)
+ this->ServerInstance->SNO->WriteToSnoMask('l', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers);
+ else
+ this->ServerInstance->SNO->WriteToSnoMask('L', "Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers);
}
else
ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Squit from unknown server");
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index e27c1d879..b27661481 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -625,7 +625,7 @@ void TreeSocket::OnTimeout()
{
if (this->LinkState == CONNECTING)
{
- Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
Link* MyLink = Utils->FindLink(myhost);
if (MyLink)
Utils->DoFailOver(MyLink);
@@ -654,10 +654,11 @@ void TreeSocket::OnClose()
if (!quitserver.empty())
{
- Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' failed.",quitserver.c_str());
+
time_t server_uptime = ServerInstance->Time() - this->age;
if (server_uptime)
- Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
}
}
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index c6c9ae700..48d829f6f 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -48,7 +48,7 @@ void ServerSocketListener::OnAcceptReady(const std::string &ipconnectedto, int n
if (!found)
{
- Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
+ this->ServerInstance->SNO->WriteToSnoMask('l', "Server connection from %s denied (no link blocks with that IP address)", ip);
ServerInstance->SE->Close(newsock);
return;
}
@@ -628,7 +628,7 @@ void SpanningTreeUtilities::DoFailOver(Link* x)
{
if (x->FailOver == x->Name)
{
- Creator->RemoteMessage(NULL,"FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
return;
}
Link* TryThisOne = this->FindLink(x->FailOver.c_str());
@@ -641,13 +641,13 @@ void SpanningTreeUtilities::DoFailOver(Link* x)
}
else
{
- Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
Creator->ConnectServer(TryThisOne);
}
}
else
{
- Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
+ this->ServerInstance->SNO->WriteToSnoMask('l', "FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
}
}
}