Switching from asio deadline_timer to asio steady_timer in order to fix #55. This requires the (boost or native) chrono lib.
This commit is contained in:
@@ -11,7 +11,7 @@ Linux:
|
||||
- libgsasl version >= 1.4 --> http://www.gnu.org/software/gsasl/
|
||||
- libboost_thread, libboost_filesystem, libboost_datetime, libboost_program_options,
|
||||
libboost_iostreams, libboost_asio, libboost_regex, libboost_random, libboost_uuid
|
||||
(version >= 1.44, latest always recommended) --> http://www.boost.org/
|
||||
(version >= 1.49, latest always recommended) --> http://www.boost.org/
|
||||
- libSDL_mixer, libSDL --> http://www.libsdl.org/
|
||||
- libSQLite3 --> http://sqlite.org/
|
||||
- libtinyxml > 2.0 --> http://www.sourceforge.net/projects/tinyxml
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
@@ -218,7 +219,7 @@ protected:
|
||||
|
||||
ClientState &GetState();
|
||||
void SetState(ClientState &newState);
|
||||
boost::asio::deadline_timer &GetStateTimer();
|
||||
boost::asio::steady_timer &GetStateTimer();
|
||||
|
||||
SenderHelper &GetSender();
|
||||
|
||||
@@ -341,8 +342,8 @@ private:
|
||||
mutable boost::mutex m_pingDataMutex;
|
||||
PingData m_pingData;
|
||||
|
||||
boost::asio::deadline_timer m_stateTimer;
|
||||
boost::asio::deadline_timer m_avatarTimer;
|
||||
boost::asio::steady_timer m_stateTimer;
|
||||
boost::asio::steady_timer m_avatarTimer;
|
||||
|
||||
friend class AbstractClientStateReceiving;
|
||||
friend class ClientStateInit;
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
using namespace std;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
#define CLIENT_WAIT_TIMEOUT_MSEC 50
|
||||
#define CLIENT_CONNECT_TIMEOUT_SEC 10
|
||||
|
||||
@@ -238,7 +244,7 @@ void
|
||||
ClientStateDownloadingServerList::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -265,7 +271,7 @@ ClientStateDownloadingServerList::TimerLoop(const boost::system::error_code& ec,
|
||||
client->SetState(ClientStateReadingServerList::Instance());
|
||||
} else {
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -409,7 +415,7 @@ void
|
||||
ClientStateWaitChooseServer::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -432,7 +438,7 @@ ClientStateWaitChooseServer::TimerLoop(const boost::system::error_code& ec, boos
|
||||
client->SetState(ClientStateStartResolve::Instance());
|
||||
} else {
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -461,7 +467,7 @@ void
|
||||
ClientStateStartConnect::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::seconds(CLIENT_CONNECT_TIMEOUT_SEC));
|
||||
seconds(CLIENT_CONNECT_TIMEOUT_SEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateStartConnect::TimerTimeout, this, boost::asio::placeholders::error, client));
|
||||
@@ -986,7 +992,7 @@ void
|
||||
ClientStateWaitEnterLogin::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -1065,7 +1071,7 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
|
||||
}
|
||||
} else {
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -1399,7 +1405,7 @@ void
|
||||
ClientStateSynchronizeStart::Enter(boost::shared_ptr<ClientThread> client)
|
||||
{
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
@@ -1429,7 +1435,7 @@ ClientStateSynchronizeStart::TimerLoop(const boost::system::error_code& ec, boos
|
||||
client->SetState(ClientStateWaitStart::Instance());
|
||||
} else {
|
||||
client->GetStateTimer().expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
|
||||
client->GetStateTimer().async_wait(
|
||||
boost::bind(
|
||||
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
|
||||
|
||||
@@ -66,6 +66,12 @@ using namespace std;
|
||||
using namespace boost::filesystem;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager, Log *myLog)
|
||||
: m_ioService(new boost::asio::io_service), m_clientLog(myLog), m_curState(NULL), m_gui(gui),
|
||||
m_avatarManager(avatarManager), m_isServerSelected(false),
|
||||
@@ -586,7 +592,7 @@ void
|
||||
ClientThread::RegisterTimers()
|
||||
{
|
||||
m_avatarTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
||||
milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
||||
m_avatarTimer.async_wait(
|
||||
boost::bind(
|
||||
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -910,7 +916,7 @@ ClientThread::TimerCheckAvatarDownloads(const boost::system::error_code& ec)
|
||||
PassAvatarFileToManager(playerId, tmpAvatar);
|
||||
}
|
||||
m_avatarTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
||||
milliseconds(CLIENT_AVATAR_LOOP_MSEC));
|
||||
m_avatarTimer.async_wait(
|
||||
boost::bind(
|
||||
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -1022,7 +1028,7 @@ ClientThread::SetState(ClientState &newState)
|
||||
m_curState->Enter(shared_from_this());
|
||||
}
|
||||
|
||||
boost::asio::deadline_timer &
|
||||
boost::asio::steady_timer &
|
||||
ClientThread::GetStateTimer()
|
||||
{
|
||||
return m_stateTimer;
|
||||
|
||||
@@ -49,6 +49,12 @@
|
||||
using namespace std;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
ServerAdminBot::ServerAdminBot(boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_notifyTimeoutMinutes(0), m_notifyIntervalMinutes(0), m_notifyCounter(0),
|
||||
m_notifyTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::manual_start),
|
||||
@@ -272,17 +278,17 @@ ServerAdminBot::Run()
|
||||
if (m_ircAdminThread) {
|
||||
// Initialise the timers.
|
||||
m_reconnectTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
m_reconnectTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error));
|
||||
m_notifyLoopTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
|
||||
m_notifyLoopTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error));
|
||||
m_checkFileTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
|
||||
m_checkFileTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -298,7 +304,7 @@ ServerAdminBot::ReconnectHandler(const boost::system::error_code& ec)
|
||||
Reconnect();
|
||||
|
||||
m_reconnectTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
m_reconnectTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -330,7 +336,7 @@ ServerAdminBot::CheckFileHandler(const boost::system::error_code& ec)
|
||||
Reconnect();
|
||||
}
|
||||
m_checkFileTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
|
||||
m_checkFileTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -386,7 +392,7 @@ ServerAdminBot::NotifyLoop(const boost::system::error_code& ec)
|
||||
}
|
||||
}
|
||||
m_notifyLoopTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
|
||||
m_notifyLoopTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error));
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
ServerBanManager::ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_ioService(ioService), m_curBanId(0)
|
||||
@@ -126,7 +131,7 @@ ServerBanManager::GetBanList(list<string> &list) const
|
||||
banText << (*i_nick).first << ": (nickStr) - " << (*i_nick).second.nameStr;
|
||||
|
||||
if ((*i_nick).second.timer)
|
||||
banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h";
|
||||
banText << " duration: " << duration_cast<hours>((*i_nick).second.timer->expires_from_now()).count() << "h";
|
||||
list.push_back(banText.str());
|
||||
++i_nick;
|
||||
}
|
||||
@@ -136,7 +141,7 @@ ServerBanManager::GetBanList(list<string> &list) const
|
||||
ostringstream banText;
|
||||
banText << (*i_ip).first << ": (IP) - " << (*i_ip).second.ipAddress;
|
||||
if ((*i_ip).second.timer)
|
||||
banText << " duration: " << (*i_ip).second.timer->expires_from_now().hours() << "h";
|
||||
banText << " duration: " << duration_cast<hours>((*i_ip).second.timer->expires_from_now()).count() << "h";
|
||||
list.push_back(banText.str());
|
||||
++i_ip;
|
||||
}
|
||||
@@ -235,14 +240,14 @@ ServerBanManager::IsBadGameName(const std::string &name) const
|
||||
return retVal;
|
||||
}
|
||||
|
||||
boost::shared_ptr<boost::asio::deadline_timer>
|
||||
boost::shared_ptr<boost::asio::steady_timer>
|
||||
ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours)
|
||||
{
|
||||
boost::shared_ptr<boost::asio::deadline_timer> tmpTimer;
|
||||
boost::shared_ptr<boost::asio::steady_timer> tmpTimer;
|
||||
if (durationHours) {
|
||||
tmpTimer.reset(new boost::asio::deadline_timer(*m_ioService));
|
||||
tmpTimer.reset(new boost::asio::steady_timer(*m_ioService));
|
||||
tmpTimer->expires_from_now(
|
||||
boost::posix_time::hours(durationHours));
|
||||
hours(durationHours));
|
||||
tmpTimer->async_wait(
|
||||
boost::bind(
|
||||
&ServerBanManager::TimerRemoveBan, shared_from_this(), boost::asio::placeholders::error, timerId, tmpTimer));
|
||||
@@ -251,7 +256,7 @@ ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHo
|
||||
}
|
||||
|
||||
void
|
||||
ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::deadline_timer> timer)
|
||||
ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::steady_timer> timer)
|
||||
{
|
||||
if (!ec && timer)
|
||||
UnBan(banId);
|
||||
|
||||
@@ -53,6 +53,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
static bool LessThanPlayerHandStartMoney(const boost::shared_ptr<PlayerInterface> p1, const boost::shared_ptr<PlayerInterface> p2)
|
||||
{
|
||||
return p1->getMyRoundStartCash() < p2->getMyRoundStartCash();
|
||||
@@ -276,7 +282,7 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
|
||||
m_voteKickData.reset();
|
||||
}
|
||||
m_voteKickTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
||||
m_voteKickTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -515,7 +521,7 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned
|
||||
SendToAllPlayers(packet, SessionData::Game);
|
||||
|
||||
m_voteKickTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
|
||||
m_voteKickTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -1073,13 +1079,13 @@ ServerGame::SetState(ServerGameState &newState)
|
||||
m_curState->Enter(shared_from_this());
|
||||
}
|
||||
|
||||
boost::asio::deadline_timer &
|
||||
boost::asio::steady_timer &
|
||||
ServerGame::GetStateTimer1()
|
||||
{
|
||||
return m_stateTimer1;
|
||||
}
|
||||
|
||||
boost::asio::deadline_timer &
|
||||
boost::asio::steady_timer &
|
||||
ServerGame::GetStateTimer2()
|
||||
{
|
||||
return m_stateTimer2;
|
||||
|
||||
@@ -52,6 +52,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
//#define POKERTH_SERVER_TEST
|
||||
|
||||
#ifdef POKERTH_SERVER_TEST
|
||||
@@ -575,7 +581,7 @@ ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server)
|
||||
// No admin timeout in LAN or ranking games.
|
||||
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetGameData().gameType != GAME_TYPE_RANKING) {
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
|
||||
seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateInit::TimerAdminWarning, this, boost::asio::placeholders::error, server));
|
||||
@@ -594,7 +600,7 @@ ServerGameStateInit::RegisterAutoStartTimer(boost::shared_ptr<ServerGame> server
|
||||
// No autostart in LAN games.
|
||||
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN) {
|
||||
server->GetStateTimer2().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_AUTOSTART_GAME_DELAY_SEC));
|
||||
seconds(SERVER_AUTOSTART_GAME_DELAY_SEC));
|
||||
server->GetStateTimer2().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateInit::TimerAutoStart, this, boost::asio::placeholders::error, server));
|
||||
@@ -632,7 +638,7 @@ ServerGameStateInit::TimerAdminWarning(const boost::system::error_code &ec, boos
|
||||
}
|
||||
// Start timeout timer.
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
|
||||
seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateInit::TimerAdminTimeout, this, boost::asio::placeholders::error, server));
|
||||
@@ -767,7 +773,7 @@ void
|
||||
ServerGameStateStartGame::Enter(boost::shared_ptr<ServerGame> server)
|
||||
{
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_START_GAME_TIMEOUT_SEC));
|
||||
seconds(SERVER_START_GAME_TIMEOUT_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateStartGame::TimerTimeout, this, boost::asio::placeholders::error, server));
|
||||
@@ -930,7 +936,7 @@ void
|
||||
ServerGameStateHand::Enter(boost::shared_ptr<ServerGame> server)
|
||||
{
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
@@ -1007,7 +1013,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
curGame.getCurrentHand()->setCardsShown(true);
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_SHOW_CARDS_DELAY_SEC));
|
||||
seconds(SERVER_SHOW_CARDS_DELAY_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server));
|
||||
@@ -1015,7 +1021,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
SendNewRoundCards(*server, curGame, newRound);
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(GetDealCardsDelaySec(*server)));
|
||||
seconds(GetDealCardsDelaySec(*server)));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
@@ -1043,7 +1049,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
// If the player is computer controlled, let the engine act.
|
||||
if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) {
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
|
||||
seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
|
||||
@@ -1054,7 +1060,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
@@ -1122,7 +1128,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
|
||||
// View a dialog for a new game - delayed.
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_DELAY_NEXT_GAME_SEC));
|
||||
seconds(SERVER_DELAY_NEXT_GAME_SEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server, winnerPlayer->getMyUniqueID()));
|
||||
@@ -1141,7 +1147,7 @@ ServerGameStateHand::TimerShowCards(const boost::system::error_code &ec, boost::
|
||||
SendNewRoundCards(*server, curGame, curGame.getCurrentHand()->getCurrentRound());
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(GetDealCardsDelaySec(*server)));
|
||||
seconds(GetDealCardsDelaySec(*server)));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
@@ -1512,7 +1518,7 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr<ServerGame> server)
|
||||
int timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
|
||||
#endif
|
||||
|
||||
server->GetStateTimer1().expires_from_now(boost::posix_time::seconds(timeoutSec));
|
||||
server->GetStateTimer1().expires_from_now(seconds(timeoutSec));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateWaitPlayerAction::TimerTimeout, this, boost::asio::placeholders::error, server));
|
||||
@@ -1646,7 +1652,7 @@ ServerGameStateWaitNextHand::Enter(boost::shared_ptr<ServerGame> server)
|
||||
#endif
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::seconds(timeoutSec));
|
||||
seconds(timeoutSec));
|
||||
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
|
||||
@@ -45,6 +45,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
ServerLobbyBot::ServerLobbyBot(boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_reconnectTimer(*ioService)
|
||||
{
|
||||
@@ -110,7 +116,7 @@ ServerLobbyBot::Run()
|
||||
if (m_ircLobbyThread) {
|
||||
// Initialise the reconnect timer.
|
||||
m_reconnectTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
m_reconnectTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -132,7 +138,7 @@ ServerLobbyBot::Reconnect(const boost::system::error_code& ec)
|
||||
}
|
||||
}
|
||||
m_reconnectTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
|
||||
m_reconnectTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error));
|
||||
|
||||
@@ -95,6 +95,11 @@
|
||||
using namespace std;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
class InternalServerCallback : public SessionDataCallback, public ChatCleanerCallback, public ServerDBCallback
|
||||
{
|
||||
@@ -860,19 +865,19 @@ ServerLobbyThread::RegisterTimers()
|
||||
{
|
||||
// Remove closed games.
|
||||
m_removeGameTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
||||
m_removeGameTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
|
||||
// Update the statistics file.
|
||||
m_saveStatisticsTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
||||
seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
||||
m_saveStatisticsTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
|
||||
// Update the avatar upload locks.
|
||||
m_loginLockTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
||||
m_loginLockTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -1872,7 +1877,7 @@ ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec)
|
||||
}
|
||||
// Restart timer
|
||||
m_removeGameTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
|
||||
m_removeGameTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -1897,7 +1902,7 @@ ServerLobbyThread::TimerUpdateClientLoginLock(const boost::system::error_code &e
|
||||
}
|
||||
// Restart timer
|
||||
m_loginLockTimer.expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
||||
milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
|
||||
m_loginLockTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -2244,7 +2249,7 @@ ServerLobbyThread::TimerSaveStatisticsFile(const boost::system::error_code &ec)
|
||||
}
|
||||
// Restart timer
|
||||
m_saveStatisticsTimer.expires_from_now(
|
||||
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
||||
seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
|
||||
m_saveStatisticsTimer.async_wait(
|
||||
boost::bind(
|
||||
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
|
||||
|
||||
@@ -41,6 +41,12 @@
|
||||
using namespace std;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
#ifdef BOOST_ASIO_HAS_STD_CHRONO
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
using namespace boost::chrono;
|
||||
#endif
|
||||
|
||||
SessionData::SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService)
|
||||
: m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true),
|
||||
m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService),
|
||||
@@ -236,7 +242,7 @@ SessionData::TimerActivityWarning(const boost::system::error_code &ec)
|
||||
m_callback.SessionTimeoutWarning(shared_from_this(), m_activityWarningRemainingSec);
|
||||
|
||||
m_activityTimeoutTimer.expires_from_now(
|
||||
boost::posix_time::seconds(m_activityWarningRemainingSec));
|
||||
seconds(m_activityWarningRemainingSec));
|
||||
m_activityTimeoutTimer.async_wait(
|
||||
boost::bind(
|
||||
&SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -327,7 +333,7 @@ SessionData::ResetActivityTimer()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
m_activityTimeoutTimer.expires_from_now(
|
||||
boost::posix_time::seconds(m_activityTimeoutSec - m_activityWarningRemainingSec));
|
||||
seconds(m_activityTimeoutSec - m_activityWarningRemainingSec));
|
||||
m_activityTimeoutTimer.async_wait(
|
||||
boost::bind(
|
||||
&SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -338,7 +344,7 @@ SessionData::StartTimerInitTimeout(unsigned timeoutSec)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
m_initTimeoutTimer.expires_from_now(
|
||||
boost::posix_time::seconds(timeoutSec));
|
||||
seconds(timeoutSec));
|
||||
m_initTimeoutTimer.async_wait(
|
||||
boost::bind(
|
||||
&SessionData::TimerInitTimeout, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -349,7 +355,7 @@ SessionData::StartTimerGlobalTimeout(unsigned timeoutSec)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_dataMutex);
|
||||
m_globalTimeoutTimer.expires_from_now(
|
||||
boost::posix_time::seconds(timeoutSec));
|
||||
seconds(timeoutSec));
|
||||
m_globalTimeoutTimer.async_wait(
|
||||
boost::bind(
|
||||
&SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error));
|
||||
@@ -363,7 +369,7 @@ SessionData::StartTimerActivityTimeout(unsigned timeoutSec, unsigned warningRema
|
||||
m_activityWarningRemainingSec = warningRemainingSec;
|
||||
|
||||
m_activityTimeoutTimer.expires_from_now(
|
||||
boost::posix_time::seconds(timeoutSec - warningRemainingSec));
|
||||
seconds(timeoutSec - warningRemainingSec));
|
||||
m_activityTimeoutTimer.async_wait(
|
||||
boost::bind(
|
||||
&SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error));
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#define _SERVERADMINBOT_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <third_party/boost/timers.hpp>
|
||||
@@ -96,9 +97,9 @@ private:
|
||||
boost::shared_ptr<IrcThread> m_ircAdminThread;
|
||||
boost::timers::portable::second_timer m_notifyTimer;
|
||||
|
||||
boost::asio::deadline_timer m_reconnectTimer;
|
||||
boost::asio::deadline_timer m_notifyLoopTimer;
|
||||
boost::asio::deadline_timer m_checkFileTimer;
|
||||
boost::asio::steady_timer m_reconnectTimer;
|
||||
boost::asio::steady_timer m_notifyLoopTimer;
|
||||
boost::asio::steady_timer m_checkFileTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <db/dbdefs.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
@@ -67,12 +68,12 @@ public:
|
||||
protected:
|
||||
|
||||
struct TimedPlayerBan {
|
||||
boost::shared_ptr<boost::asio::deadline_timer> timer;
|
||||
boost::shared_ptr<boost::asio::steady_timer> timer;
|
||||
std::string nameStr;
|
||||
boost::regex nameRegex;
|
||||
};
|
||||
struct TimedIPBan {
|
||||
boost::shared_ptr<boost::asio::deadline_timer> timer;
|
||||
boost::shared_ptr<boost::asio::steady_timer> timer;
|
||||
std::string ipAddress;
|
||||
};
|
||||
|
||||
@@ -81,8 +82,8 @@ protected:
|
||||
typedef std::list<boost::regex> RegexList;
|
||||
typedef std::vector<DB_id> DBPlayerIdList;
|
||||
|
||||
boost::shared_ptr<boost::asio::deadline_timer> InternalRegisterTimedBan(unsigned timerId, unsigned durationHours);
|
||||
void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::deadline_timer> timer);
|
||||
boost::shared_ptr<boost::asio::steady_timer> InternalRegisterTimedBan(unsigned timerId, unsigned durationHours);
|
||||
void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::steady_timer> timer);
|
||||
|
||||
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#define _SERVERGAME_H_
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <third_party/boost/timers.hpp>
|
||||
#include <map>
|
||||
|
||||
@@ -180,8 +181,8 @@ protected:
|
||||
ServerGameState &GetState();
|
||||
void SetState(ServerGameState &newState);
|
||||
|
||||
boost::asio::deadline_timer &GetStateTimer1();
|
||||
boost::asio::deadline_timer &GetStateTimer2();
|
||||
boost::asio::steady_timer &GetStateTimer1();
|
||||
boost::asio::steady_timer &GetStateTimer2();
|
||||
|
||||
const StartData &GetStartData() const;
|
||||
void SetStartData(const StartData &startData);
|
||||
@@ -242,9 +243,9 @@ private:
|
||||
ConfigFile &m_playerConfig;
|
||||
unsigned m_gameNum;
|
||||
unsigned m_curPetitionId;
|
||||
boost::asio::deadline_timer m_voteKickTimer;
|
||||
boost::asio::deadline_timer m_stateTimer1;
|
||||
boost::asio::deadline_timer m_stateTimer2;
|
||||
boost::asio::steady_timer m_voteKickTimer;
|
||||
boost::asio::steady_timer m_stateTimer1;
|
||||
boost::asio::steady_timer m_stateTimer2;
|
||||
bool m_isNameReported;
|
||||
|
||||
friend class ServerLobbyThread;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#define _SERVERLOBBYBOT_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -86,7 +87,7 @@ private:
|
||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||
boost::shared_ptr<IrcThread> m_ircLobbyThread;
|
||||
|
||||
boost::asio::deadline_timer m_reconnectTimer;
|
||||
boost::asio::steady_timer m_reconnectTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#define _SERVERLOBBYTHREAD_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
|
||||
@@ -268,9 +269,9 @@ private:
|
||||
boost::shared_ptr<ChatCleanerManager> m_chatCleanerManager;
|
||||
boost::shared_ptr<ServerDBInterface> m_database;
|
||||
|
||||
boost::asio::deadline_timer m_removeGameTimer;
|
||||
boost::asio::deadline_timer m_saveStatisticsTimer;
|
||||
boost::asio::deadline_timer m_loginLockTimer;
|
||||
boost::asio::steady_timer m_removeGameTimer;
|
||||
boost::asio::steady_timer m_saveStatisticsTimer;
|
||||
boost::asio::steady_timer m_loginLockTimer;
|
||||
|
||||
boost::uuids::random_generator m_sessionIdGenerator;
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
typedef unsigned SessionId;
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <string>
|
||||
@@ -144,9 +145,9 @@ private:
|
||||
bool m_wantsLobbyMsg;
|
||||
unsigned m_activityTimeoutSec;
|
||||
unsigned m_activityWarningRemainingSec;
|
||||
boost::asio::deadline_timer m_initTimeoutTimer;
|
||||
boost::asio::deadline_timer m_globalTimeoutTimer;
|
||||
boost::asio::deadline_timer m_activityTimeoutTimer;
|
||||
boost::asio::steady_timer m_initTimeoutTimer;
|
||||
boost::asio::steady_timer m_globalTimeoutTimer;
|
||||
boost::asio::steady_timer m_activityTimeoutTimer;
|
||||
SessionDataCallback &m_callback;
|
||||
Gsasl_session *m_authSession;
|
||||
int m_curAuthStep;
|
||||
|
||||
Reference in New Issue
Block a user