Let the server irc bot reconnect once every day.
This commit is contained in:
@@ -251,11 +251,30 @@ irc_event_numeric(irc_session_t * session, unsigned irc_event, const char * /*or
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IrcThread::IrcThread(IrcCallback &callback)
|
IrcThread::IrcThread(const IrcThread &other)
|
||||||
|
: m_terminationTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start),
|
||||||
|
m_lastConnectTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
|
||||||
|
{
|
||||||
|
m_callback = other.m_callback;
|
||||||
|
m_context.reset(new IrcContext(*this));
|
||||||
|
|
||||||
|
IrcContext &context = GetContext();
|
||||||
|
const IrcContext &otherContext = other.GetContext();
|
||||||
|
|
||||||
|
context.serverAddress = otherContext.serverAddress;
|
||||||
|
context.serverPort = otherContext.serverPort;
|
||||||
|
context.useIPv6 = otherContext.useIPv6;
|
||||||
|
context.nick = otherContext.nick;
|
||||||
|
context.channel = otherContext.channel;
|
||||||
|
context.channelPassword = otherContext.channelPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
IrcThread::IrcThread(IrcCallback *callback)
|
||||||
: m_callback(callback),
|
: m_callback(callback),
|
||||||
m_terminationTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start),
|
m_terminationTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start),
|
||||||
m_lastConnectTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
|
m_lastConnectTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
|
||||||
{
|
{
|
||||||
|
assert(callback);
|
||||||
m_context.reset(new IrcContext(*this));
|
m_context.reset(new IrcContext(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,6 +488,7 @@ IrcThread::GetContext()
|
|||||||
IrcCallback &
|
IrcCallback &
|
||||||
IrcThread::GetCallback()
|
IrcThread::GetCallback()
|
||||||
{
|
{
|
||||||
return m_callback;
|
assert(m_callback);
|
||||||
|
return *m_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
|
||||||
|
#define SERVER_RESTART_IRC_BOT_INTERVAL_SEC 86400 // 1 day
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ServerManager::ServerManager(GuiInterface &gui, ConfigFile *config, AvatarManager &avatarManager)
|
ServerManager::ServerManager(GuiInterface &gui, ConfigFile *config, AvatarManager &avatarManager)
|
||||||
@@ -172,6 +174,26 @@ ServerManager::RunAll()
|
|||||||
for_each(m_acceptThreadPool.begin(), m_acceptThreadPool.end(), boost::mem_fn(&ServerAcceptThread::Run));
|
for_each(m_acceptThreadPool.begin(), m_acceptThreadPool.end(), boost::mem_fn(&ServerAcceptThread::Run));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerManager::Process()
|
||||||
|
{
|
||||||
|
if (m_ircRestartTimer.elapsed().total_seconds() > SERVER_RESTART_IRC_BOT_INTERVAL_SEC)
|
||||||
|
{
|
||||||
|
if (m_ircThread)
|
||||||
|
{
|
||||||
|
m_ircThread->SignalTermination();
|
||||||
|
if (m_ircThread->Join(NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC))
|
||||||
|
{
|
||||||
|
boost::shared_ptr<IrcThread> tmpIrcThread(new IrcThread(*m_ircThread));
|
||||||
|
tmpIrcThread->Run();
|
||||||
|
m_ircThread = tmpIrcThread;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_ircRestartTimer.reset();
|
||||||
|
m_ircRestartTimer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerManager::SignalTerminationAll()
|
ServerManager::SignalTerminationAll()
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-2
@@ -31,7 +31,8 @@ struct IrcContext;
|
|||||||
class IrcThread : public Thread
|
class IrcThread : public Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IrcThread(IrcCallback &callback);
|
IrcThread(const IrcThread &other);
|
||||||
|
IrcThread(IrcCallback *callback);
|
||||||
virtual ~IrcThread();
|
virtual ~IrcThread();
|
||||||
|
|
||||||
// Set the parameters.
|
// Set the parameters.
|
||||||
@@ -58,7 +59,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
boost::shared_ptr<IrcContext> m_context;
|
boost::shared_ptr<IrcContext> m_context;
|
||||||
IrcCallback &m_callback;
|
IrcCallback *m_callback;
|
||||||
|
|
||||||
boost::timers::portable::microsec_timer m_terminationTimer;
|
boost::timers::portable::microsec_timer m_terminationTimer;
|
||||||
boost::timers::portable::microsec_timer m_lastConnectTimer;
|
boost::timers::portable::microsec_timer m_lastConnectTimer;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <game_defs.h>
|
#include <game_defs.h>
|
||||||
|
|
||||||
#include <gui/guiinterface.h>
|
#include <gui/guiinterface.h>
|
||||||
|
#include <third_party/boost/timers.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -46,6 +47,9 @@ public:
|
|||||||
// Main start function.
|
// Main start function.
|
||||||
void RunAll();
|
void RunAll();
|
||||||
|
|
||||||
|
// Let the server manager perform processing.
|
||||||
|
void Process();
|
||||||
|
|
||||||
void SignalTerminationAll();
|
void SignalTerminationAll();
|
||||||
bool JoinAll(bool wait);
|
bool JoinAll(bool wait);
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ private:
|
|||||||
|
|
||||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
boost::shared_ptr<IrcThread> m_ircThread;
|
boost::shared_ptr<IrcThread> m_ircThread;
|
||||||
|
boost::timers::portable::microsec_timer m_ircRestartTimer;
|
||||||
AcceptThreadList m_acceptThreadPool;
|
AcceptThreadList m_acceptThreadPool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -157,7 +157,7 @@ void Session::startInternetClient()
|
|||||||
|
|
||||||
if (myConfig->readConfigInt("UseIRCLobbyChat"))
|
if (myConfig->readConfigInt("UseIRCLobbyChat"))
|
||||||
{
|
{
|
||||||
myClientIrcThread = new IrcThread(*myGui);
|
myClientIrcThread = new IrcThread(myGui);
|
||||||
myClientIrcThread->Init(
|
myClientIrcThread->Init(
|
||||||
myConfig->readConfigString("IRCServerAddress"),
|
myConfig->readConfigString("IRCServerAddress"),
|
||||||
myConfig->readConfigInt("IRCServerPort"),
|
myConfig->readConfigInt("IRCServerPort"),
|
||||||
@@ -281,7 +281,7 @@ void Session::startNetworkServer()
|
|||||||
boost::shared_ptr<IrcThread> tmpIrcThread;
|
boost::shared_ptr<IrcThread> tmpIrcThread;
|
||||||
if (myConfig->readConfigInt("UseAdminIRC"))
|
if (myConfig->readConfigInt("UseAdminIRC"))
|
||||||
{
|
{
|
||||||
tmpIrcThread = boost::shared_ptr<IrcThread>(new IrcThread(*myNetServer));
|
tmpIrcThread = boost::shared_ptr<IrcThread>(new IrcThread(myNetServer));
|
||||||
|
|
||||||
tmpIrcThread->Init(
|
tmpIrcThread->Init(
|
||||||
myConfig->readConfigString("AdminIRCServerAddress"),
|
myConfig->readConfigString("AdminIRCServerAddress"),
|
||||||
@@ -323,6 +323,7 @@ bool Session::pollNetworkServerTerminated()
|
|||||||
retVal = true; // already terminated
|
retVal = true; // already terminated
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
myNetServer->Process();
|
||||||
if (myNetServer->JoinAll(false))
|
if (myNetServer->JoinAll(false))
|
||||||
retVal = true;
|
retVal = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user