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:
lotodore
2014-03-29 16:13:53 +01:00
parent 8a1e3a4371
commit 757f12f35b
17 changed files with 137 additions and 78 deletions
+19 -13
View File
@@ -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<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));
@@ -589,7 +595,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));
@@ -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<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));
@@ -925,7 +931,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));
@@ -1002,7 +1008,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));
@@ -1010,7 +1016,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));
@@ -1038,7 +1044,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));
@@ -1049,7 +1055,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));
@@ -1117,7 +1123,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()));
@@ -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<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));
@@ -1641,7 +1647,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(