summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-04 18:25:09 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-04 18:25:09 +0000
commit52bb4498765cf649639de308637c8f19d75aa3cc (patch)
tree10747e5da88eb4de81472d537620ef5adf68936f /src/modules
parent4c0a10e109bbbc64e74579c6b0d382ae6ee1acdf (diff)
Added autoconnect
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2158 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_spanningtree.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 34f3e617e..237cf14dd 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -200,6 +200,8 @@ class Link
int Port;
std::string SendPass;
std::string RecvPass;
+ unsigned long AutoConnect;
+ time_t NextConnectTime;
};
/* $ModDesc: Povides a spanning tree server link protocol */
@@ -1423,12 +1425,14 @@ void ReadConfiguration(bool rebind)
L.Port = Conf->ReadInteger("link","port",j,true);
L.SendPass = Conf->ReadValue("link","sendpass",j);
L.RecvPass = Conf->ReadValue("link","recvpass",j);
+ L.AutoConnect = Conf->ReadInteger("link","autoconnect",j,true);
+ L.NextConnectTime = time(NULL) + L.AutoConnect;
LinkBlocks.push_back(L);
log(DEBUG,"m_spanningtree: Read server %s with host %s:%d",L.Name.c_str(),L.IPAddr.c_str(),L.Port);
}
}
-
+
class ModuleSpanningTree : public Module
{
std::vector<TreeSocket*> Bindings;
@@ -1605,6 +1609,28 @@ class ModuleSpanningTree : public Module
return 1;
}
+ void AutoConnectServers(time_t curtime)
+ {
+ for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
+ {
+ if (x->AutoConnect)
+ {
+ TreeServer* CheckDupe = FindServer(x->Name);
+ if (!CheckDupe)
+ {
+ // an autoconnected server is not connected. Check if its time to connect it
+ if (curtime >= x->NextConnectTime)
+ {
+ x->NextConnectTime = curtime + x->AutoConnect;
+ WriteOpers("*** AUTOCONNECT: Auto-connecting server \002%s\002 (%lu seconds until next attempt)",x->Name.c_str(),x->AutoConnect);
+ TreeSocket* newsocket = new TreeSocket(x->IPAddr,x->Port,false,10,x->Name);
+ Srv->AddSocket(newsocket);
+ }
+ }
+ }
+ }
+ }
+
int HandleConnect(char** parameters, int pcnt, userrec* user)
{
for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
@@ -1780,6 +1806,11 @@ class ModuleSpanningTree : public Module
}
}
+ virtual void OnBackgroundTimer(time_t curtime)
+ {
+ AutoConnectServers(curtime);
+ }
+
virtual void OnUserJoin(userrec* user, chanrec* channel)
{
// Only do this for local users