summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-08-26 16:49:12 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-08-26 16:49:12 +0000
commit5577604494b8a5fdb023e2fa2843a6736fde52b8 (patch)
treed159096d843ca09ad4b015f3d52489ab214cad96
parent5f17af5118115522fa7a6dfc5ac5c4e6890a2267 (diff)
Routing failure messages back where they came from on /rconnect
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7826 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/m_spanningtree/main.cpp44
-rw-r--r--src/modules/m_spanningtree/main.h5
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp4
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp24
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp8
-rw-r--r--src/modules/m_spanningtree/utils.cpp6
6 files changed, 64 insertions, 27 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 0be0007d2..3a338a55a 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -552,7 +552,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
}
else
{
- ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
+ 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);
@@ -568,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);
}
}
@@ -623,6 +623,40 @@ int ModuleSpanningTree::HandleVersion(const char** parameters, int pcnt, userrec
}
return 1;
}
+
+/*
+ */
+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)
{
@@ -633,18 +667,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;
}
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index c184ef076..dd4f70f0f 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -16,6 +16,7 @@
#include "inspircd.h"
#include "modules.h"
+#include <stdarg.h>
/** If you make a change which breaks the protocol, increment this.
* If you completely change the protocol, completely change the number.
@@ -141,6 +142,10 @@ class ModuleSpanningTree : public Module
*/
void BroadcastTimeSync();
+ /** Attempt to send a message to a user
+ */
+ void RemoteMessage(userrec* user, const char* format, ...);
+
/** Returns oper-specific MAP information
*/
const std::string MapOperInfo(TreeServer* Current);
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index 972b36366..16ef1d9d4 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -68,7 +68,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
else
{
/* Something barfed, show the opers */
- ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
+ Utils->Creator->RemoteMessage(NULL, "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);
@@ -86,7 +86,7 @@ void ServernameResolver::OnError(ResolverError e, const std::string &errormessag
ServerInstance->AddResolver(snr, cached);
return;
}
- ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s",MyLink.Name.c_str(),errormessage.c_str());
+ Utils->Creator->RemoteMessage(NULL, "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 2b4b6d301..149bf42ac 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -180,11 +180,12 @@ bool TreeSocket::OnConnected()
{
if (x->Name == this->myhost)
{
- this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] started.");
+ Utils->Creator->RemoteMessage(NULL,"Connection to \2%s\2[%s] started.", myhost.c_str(), (x->HiddenFromStats ? "<hidden>" : this->GetIP().c_str()));
if (Hook)
{
InspSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
- this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+x->Hook+"\2");
+ 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()),
+ x->Hook.c_str());
}
this->OutboundPass = x->SendPass;
sentcapab = false;
@@ -204,7 +205,7 @@ bool TreeSocket::OnConnected()
* If that happens the connection hangs here until it's closed. Unlikely
* and rather harmless.
*/
- this->Instance->SNO->WriteToSnoMask('l',"Connection to \2"+myhost+"\2 lost link tag(!)");
+ this->Utils->Creator->RemoteMessage(NULL,"Connection to \2%s\2 lost link tag(!)", myhost.c_str());
return true;
}
@@ -218,29 +219,26 @@ void TreeSocket::OnError(InspSocketError e)
switch (e)
{
case I_ERR_CONNECT:
- this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Connection to \002"+myhost+"\002 refused");
+ Utils->Creator->RemoteMessage(NULL,"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:
- this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Could not create socket");
+ Utils->Creator->RemoteMessage(NULL,"Connection failed: Could not create socket");
break;
case I_ERR_BIND:
- this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Error binding socket to address or port");
+ Utils->Creator->RemoteMessage(NULL,"Connection failed: Error binding socket to address or port");
break;
case I_ERR_WRITE:
- this->Instance->SNO->WriteToSnoMask('l',"Connection failed: I/O error on connection");
+ Utils->Creator->RemoteMessage(NULL,"Connection failed: I/O error on connection");
break;
case I_ERR_NOMOREFDS:
- this->Instance->SNO->WriteToSnoMask('l',"Connection failed: Operating system is out of file descriptors!");
+ Utils->Creator->RemoteMessage(NULL,"Connection failed: Operating system is out of file descriptors!");
break;
default:
if ((errno) && (errno != EINPROGRESS) && (errno != EAGAIN))
- {
- std::string errstr = strerror(errno);
- this->Instance->SNO->WriteToSnoMask('l',"Connection to \002"+myhost+"\002 failed with OS error: " + errstr);
- }
+ Utils->Creator->RemoteMessage(NULL,"Connection to \002%s\002 failed with OS error: %s", myhost.c_str(), strerror(errno));
break;
}
}
@@ -415,7 +413,7 @@ void TreeSocket::SendError(const std::string &errormessage)
{
/* Display the error locally as well as sending it remotely */
this->WriteLine("ERROR :"+errormessage);
- this->Instance->SNO->WriteToSnoMask('l',"Sent \2ERROR\2 to "+ (this->InboundServerName.empty() ? "<unknown>" : this->InboundServerName) +": "+errormessage);
+ Utils->Creator->RemoteMessage(NULL, "Sent \2ERROR\2 to %s: %s", (this->InboundServerName.empty() ? "<unknown>" : this->InboundServerName.c_str()), errormessage.c_str());
/* One last attempt to make sure the error reaches its target */
this->FlushWriteBuffer();
}
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index da7dcf5ea..48960b89b 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -1495,7 +1495,7 @@ void TreeSocket::OnTimeout()
{
if (this->LinkState == CONNECTING)
{
- this->Instance->SNO->WriteToSnoMask('l',"CONNECT: Connection to \002"+myhost+"\002 timed out.");
+ Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
Link* MyLink = Utils->FindLink(myhost);
if (MyLink)
Utils->DoFailOver(MyLink);
@@ -1523,10 +1523,10 @@ void TreeSocket::OnClose()
if (!quitserver.empty())
{
- this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
+ Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
time_t server_uptime = Instance->Time() - this->age;
if (server_uptime)
- Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+ Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
}
}
@@ -1547,7 +1547,7 @@ int TreeSocket::OnIncomingConnection(int newsock, char* ip)
if (!found)
{
- this->Instance->SNO->WriteToSnoMask('l',"Server connection from %s denied (no link blocks with that IP address)", ip);
+ Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
close(newsock);
return false;
}
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 1c54c5a68..b8a634797 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -621,18 +621,18 @@ void SpanningTreeUtilities::DoFailOver(Link* x)
{
if (x->FailOver == x->Name)
{
- 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());
+ 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());
return;
}
Link* TryThisOne = this->FindLink(x->FailOver.c_str());
if (TryThisOne)
{
- ServerInstance->SNO->WriteToSnoMask('l',"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
+ Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
Creator->ConnectServer(TryThisOne);
}
else
{
- ServerInstance->SNO->WriteToSnoMask('l',"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
+ Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
}
}
}