diff --git a/INSTALL b/INSTALL index ff5c6195..db210ced 100644 --- a/INSTALL +++ b/INSTALL @@ -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 diff --git a/src/net/clientthread.h b/src/net/clientthread.h index 03f5fd96..55ec12a9 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 84921ced..2f0de9cd 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -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 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 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 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 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 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)); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index c36e94af..2a338483 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -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; diff --git a/src/net/common/serveradminbot.cpp b/src/net/common/serveradminbot.cpp index a200cc97..36c3a1dc 100644 --- a/src/net/common/serveradminbot.cpp +++ b/src/net/common/serveradminbot.cpp @@ -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 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)); diff --git a/src/net/common/serverbanmanager.cpp b/src/net/common/serverbanmanager.cpp index 99951f21..62a94997 100644 --- a/src/net/common/serverbanmanager.cpp +++ b/src/net/common/serverbanmanager.cpp @@ -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 ioService) : m_ioService(ioService), m_curBanId(0) @@ -126,7 +131,7 @@ ServerBanManager::GetBanList(list &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((*i_nick).second.timer->expires_from_now()).count() << "h"; list.push_back(banText.str()); ++i_nick; } @@ -136,7 +141,7 @@ ServerBanManager::GetBanList(list &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((*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::shared_ptr ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours) { - boost::shared_ptr tmpTimer; + boost::shared_ptr 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 timer) +ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer) { if (!ec && timer) UnBan(banId); diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index bf7102b0..4deb7940 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -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 p1, const boost::shared_ptr 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)); @@ -514,7 +520,7 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr 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)); @@ -1072,13 +1078,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; diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 372e5165..83c91943 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -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 @@ -570,7 +576,7 @@ ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr 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)); @@ -589,7 +595,7 @@ ServerGameStateInit::RegisterAutoStartTimer(boost::shared_ptr 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)); @@ -627,7 +633,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)); @@ -762,7 +768,7 @@ void ServerGameStateStartGame::Enter(boost::shared_ptr 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)); @@ -925,7 +931,7 @@ void ServerGameStateHand::Enter(boost::shared_ptr 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)); @@ -1002,7 +1008,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr 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)); @@ -1010,7 +1016,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr 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)); @@ -1038,7 +1044,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr 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)); @@ -1049,7 +1055,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr 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)); @@ -1117,7 +1123,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr 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())); @@ -1136,7 +1142,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)); @@ -1507,7 +1513,7 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr 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)); @@ -1641,7 +1647,7 @@ ServerGameStateWaitNextHand::Enter(boost::shared_ptr server) #endif server->GetStateTimer1().expires_from_now( - boost::posix_time::seconds(timeoutSec)); + seconds(timeoutSec)); server->GetStateTimer1().async_wait( boost::bind( diff --git a/src/net/common/serverlobbybot.cpp b/src/net/common/serverlobbybot.cpp index 31d3325b..c3fd6afd 100644 --- a/src/net/common/serverlobbybot.cpp +++ b/src/net/common/serverlobbybot.cpp @@ -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 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)); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 4e63dc5e..0c920afa 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -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 { @@ -859,19 +864,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)); @@ -1859,7 +1864,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)); @@ -1884,7 +1889,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)); @@ -2231,7 +2236,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)); diff --git a/src/net/common/sessiondata.cpp b/src/net/common/sessiondata.cpp index fd30cc44..f9cd30b9 100644 --- a/src/net/common/sessiondata.cpp +++ b/src/net/common/sessiondata.cpp @@ -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 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)); @@ -322,7 +328,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)); @@ -333,7 +339,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)); @@ -344,7 +350,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)); @@ -358,7 +364,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)); diff --git a/src/net/serveradminbot.h b/src/net/serveradminbot.h index dea02915..3f0f5df2 100644 --- a/src/net/serveradminbot.h +++ b/src/net/serveradminbot.h @@ -34,6 +34,7 @@ #define _SERVERADMINBOT_H_ #include +#include #include #include #include @@ -96,9 +97,9 @@ private: boost::shared_ptr 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 diff --git a/src/net/serverbanmanager.h b/src/net/serverbanmanager.h index 22336adb..50ca465a 100644 --- a/src/net/serverbanmanager.h +++ b/src/net/serverbanmanager.h @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -67,12 +68,12 @@ public: protected: struct TimedPlayerBan { - boost::shared_ptr timer; + boost::shared_ptr timer; std::string nameStr; boost::regex nameRegex; }; struct TimedIPBan { - boost::shared_ptr timer; + boost::shared_ptr timer; std::string ipAddress; }; @@ -81,8 +82,8 @@ protected: typedef std::list RegexList; typedef std::vector DBPlayerIdList; - boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); - void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); + boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); + void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); boost::shared_ptr m_ioService; diff --git a/src/net/servergame.h b/src/net/servergame.h index 560c54aa..146bbd59 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -34,6 +34,7 @@ #define _SERVERGAME_H_ #include +#include #include #include @@ -177,8 +178,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); @@ -237,9 +238,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; diff --git a/src/net/serverlobbybot.h b/src/net/serverlobbybot.h index 2a6b8746..8ada9ad5 100644 --- a/src/net/serverlobbybot.h +++ b/src/net/serverlobbybot.h @@ -34,6 +34,7 @@ #define _SERVERLOBBYBOT_H_ #include +#include #include #include #include @@ -86,7 +87,7 @@ private: boost::shared_ptr m_lobbyThread; boost::shared_ptr m_ircLobbyThread; - boost::asio::deadline_timer m_reconnectTimer; + boost::asio::steady_timer m_reconnectTimer; }; #endif diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index c26486b7..7886d398 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -34,6 +34,7 @@ #define _SERVERLOBBYTHREAD_H_ #include +#include #include #include @@ -268,9 +269,9 @@ private: boost::shared_ptr m_chatCleanerManager; boost::shared_ptr 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; diff --git a/src/net/sessiondata.h b/src/net/sessiondata.h index 48d94d9b..d9b502ac 100644 --- a/src/net/sessiondata.h +++ b/src/net/sessiondata.h @@ -36,6 +36,7 @@ typedef unsigned SessionId; #include +#include #include #include #include @@ -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;