Implementing ticket #47 Automatic notifications before server restart.
This commit is contained in:
@@ -34,7 +34,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ServerAdminBot::ServerAdminBot()
|
ServerAdminBot::ServerAdminBot()
|
||||||
: m_ircRestartTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::auto_start)
|
: m_notifyTimeoutMinutes(0), m_notifyIntervalMinutes(0), m_notifyCounter(0),
|
||||||
|
m_ircRestartTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::auto_start),
|
||||||
|
m_notifyTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::manual_start)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +233,30 @@ ServerAdminBot::SignalIrcChatMsg(const std::string &nickName, const std::string
|
|||||||
else
|
else
|
||||||
m_ircAdminThread->SendChatMessage(nickName + ": Invalid message.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid message.");
|
||||||
}
|
}
|
||||||
|
else if (command == "notify-restart")
|
||||||
|
{
|
||||||
|
int timeoutMinutes = 0;
|
||||||
|
int intervalMinutes = 0;
|
||||||
|
msgStream >> timeoutMinutes;
|
||||||
|
msgStream >> intervalMinutes;
|
||||||
|
if (timeoutMinutes && intervalMinutes)
|
||||||
|
{
|
||||||
|
ostringstream ack;
|
||||||
|
ack << nickName << ": Restart planned in " << timeoutMinutes << " minutes, notifying every " << intervalMinutes << " minutes.";
|
||||||
|
m_ircAdminThread->SendChatMessage(ack.str());
|
||||||
|
boost::mutex::scoped_lock lock(m_notifyMutex);
|
||||||
|
m_notifyTimeoutMinutes = timeoutMinutes;
|
||||||
|
m_notifyIntervalMinutes = intervalMinutes;
|
||||||
|
m_notifyCounter = 0;
|
||||||
|
m_notifyTimer.reset();
|
||||||
|
m_notifyTimer.start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid parameters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
else
|
else
|
||||||
m_ircAdminThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
||||||
}
|
}
|
||||||
@@ -278,6 +304,58 @@ ServerAdminBot::Process()
|
|||||||
m_ircRestartTimer.reset();
|
m_ircRestartTimer.reset();
|
||||||
m_ircRestartTimer.start();
|
m_ircRestartTimer.start();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_notifyMutex);
|
||||||
|
|
||||||
|
if (m_notifyTimeoutMinutes && m_notifyTimer.elapsed().total_seconds() >= m_notifyCounter * m_notifyIntervalMinutes * 60)
|
||||||
|
{
|
||||||
|
int remainingMinutes = m_notifyTimeoutMinutes - m_notifyCounter * m_notifyIntervalMinutes;
|
||||||
|
++m_notifyCounter;
|
||||||
|
if (remainingMinutes > 1)
|
||||||
|
{
|
||||||
|
ostringstream notifyStream;
|
||||||
|
notifyStream << "The server will be restarted in " << remainingMinutes << " minutes.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Der Server wird in " << remainingMinutes << " Minuten neu gestartet werden.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Le serveur va être redémarré dans " << remainingMinutes << " minutes.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Il server verrà riavviato in " << remainingMinutes << " minuti.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "El servidor se reiniciará en " << remainingMinutes << " minutos.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
}
|
||||||
|
else if (remainingMinutes == 1)
|
||||||
|
{
|
||||||
|
ostringstream notifyStream;
|
||||||
|
notifyStream << "The server will be restarted in " << remainingMinutes << " minute.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Der Server wird in " << remainingMinutes << " Minute neu gestartet werden.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Le serveur va être redémarré dans " << remainingMinutes << " minute.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "Il server verrà riavviato in " << remainingMinutes << " minuto.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
notifyStream.str("");
|
||||||
|
notifyStream << "El servidor se reiniciará en " << remainingMinutes << " minuto.";
|
||||||
|
GetLobbyThread().SendGlobalChat(notifyStream.str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetLobbyThread().SendGlobalChat("The server will be restarted NOW.");
|
||||||
|
GetLobbyThread().SendGlobalMsgBox("The server will be restarted NOW.");
|
||||||
|
m_notifyTimeoutMinutes = m_notifyCounter = m_notifyIntervalMinutes = 0;
|
||||||
|
m_notifyTimer.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ServerLobbyBot::ServerLobbyBot()
|
ServerLobbyBot::ServerLobbyBot()
|
||||||
: m_ircRestartTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::auto_start)
|
: m_ircRestartTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::auto_start)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ ServerManager::JoinAll(bool wait)
|
|||||||
ServerLobbyThread &
|
ServerLobbyThread &
|
||||||
ServerManager::GetLobbyThread()
|
ServerManager::GetLobbyThread()
|
||||||
{
|
{
|
||||||
assert(m_lobbyThread.get());
|
assert(m_lobbyThread);
|
||||||
return *m_lobbyThread;
|
return *m_lobbyThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define _SERVERADMINBOT_H_
|
#define _SERVERADMINBOT_H_
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
#include <boost/thread.hpp>
|
||||||
#include <third_party/boost/timers.hpp>
|
#include <third_party/boost/timers.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
@@ -69,10 +70,15 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_ircNick;
|
std::string m_ircNick;
|
||||||
|
mutable boost::mutex m_notifyMutex;
|
||||||
|
int m_notifyTimeoutMinutes;
|
||||||
|
int m_notifyIntervalMinutes;
|
||||||
|
int m_notifyCounter;
|
||||||
|
|
||||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
boost::shared_ptr<IrcThread> m_ircAdminThread;
|
boost::shared_ptr<IrcThread> m_ircAdminThread;
|
||||||
boost::timers::portable::microsec_timer m_ircRestartTimer;
|
boost::timers::portable::second_timer m_ircRestartTimer;
|
||||||
|
boost::timers::portable::second_timer m_notifyTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ private:
|
|||||||
|
|
||||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
boost::shared_ptr<IrcThread> m_ircLobbyThread;
|
boost::shared_ptr<IrcThread> m_ircLobbyThread;
|
||||||
boost::timers::portable::microsec_timer m_ircRestartTimer;
|
boost::timers::portable::second_timer m_ircRestartTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user