From 6464700d9476afb1615a047f8740b80322cc9b56 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 5 Sep 2010 14:33:34 +0000 Subject: [PATCH] AFK players are now kicked from ranking games after some timeouts if they do not enable autocheck/fold. --- src/engine/local_engine/localplayer.cpp | 20 +++++++++++++++++++- src/engine/local_engine/localplayer.h | 8 ++++++-- src/engine/network_engine/clientplayer.h | 13 +++++++++---- src/engine/playerinterface.h | 6 +++++- src/net/common/clientstate.cpp | 5 +++++ src/net/common/servergamestate.cpp | 23 ++++++++++++++++++++++- 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 8a6f7940..3e42e4d5 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -850,7 +850,7 @@ static const RoundData FlopValues[] = #define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) - : PlayerInterface(), myConfig(c), currentHand(0), currentBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(0) + : PlayerInterface(), myConfig(c), currentHand(0), currentBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(0), m_actionTimeoutCounter(0) { // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!! @@ -4911,6 +4911,24 @@ boost::shared_ptr LocalPlayer::getNetSessionData() return myNetSessionData; } +unsigned +LocalPlayer::getActionTimeoutCounter() const +{ + return m_actionTimeoutCounter; +} + +void +LocalPlayer::incrementActionTimeoutCounter() +{ + m_actionTimeoutCounter++; +} + +void +LocalPlayer::resetActionTimeoutCounter() +{ + m_actionTimeoutCounter = 0; +} + bool LocalPlayer::checkIfINeedToShowCards() { std::list playerNeedToShowCardsList = currentBoard->getPlayerNeedToShowCards(); diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index b0afde8b..26688686 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -179,8 +179,11 @@ public: void setNetSessionData(boost::shared_ptr session); boost::shared_ptr getNetSessionData(); - bool checkIfINeedToShowCards(); - + unsigned getActionTimeoutCounter() const; + void incrementActionTimeoutCounter(); + void resetActionTimeoutCounter(); + + bool checkIfINeedToShowCards(); private: @@ -227,6 +230,7 @@ private: bool myWinnerState; + unsigned m_actionTimeoutCounter; boost::shared_ptr myNetSessionData; }; diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index 07df969a..4db11832 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -71,8 +71,8 @@ public: void setMyActiveStatus(bool theValue); bool getMyActiveStatus() const; - void setMyStayOnTableStatus(bool theValue); - bool getMyStayOnTableStatus() const; + void setMyStayOnTableStatus(bool theValue); + bool getMyStayOnTableStatus() const; void setMyCards(int* theValue); void getMyCards(int* theValue) const; @@ -134,6 +134,13 @@ public: void setNetSessionData(boost::shared_ptr session); boost::shared_ptr getNetSessionData(); + // unused as client + unsigned getActionTimeoutCounter() const {return 0;} + void incrementActionTimeoutCounter() {} + void resetActionTimeoutCounter() {} + + bool checkIfINeedToShowCards(); + private: mutable boost::recursive_mutex m_syncMutex; @@ -181,8 +188,6 @@ private: bool myWinnerState; boost::shared_ptr myNetSessionData; - - bool checkIfINeedToShowCards(); }; #endif diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index 91dcf6d9..2d000b78 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -116,7 +116,11 @@ public: virtual void setNetSessionData(boost::shared_ptr session) =0; virtual boost::shared_ptr getNetSessionData() =0; - virtual bool checkIfINeedToShowCards() =0; + virtual unsigned getActionTimeoutCounter() const =0; + virtual void incrementActionTimeoutCounter() =0; + virtual void resetActionTimeoutCounter() =0; + + virtual bool checkIfINeedToShowCards() =0; }; #endif diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index af4e6879..abbd2f2a 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -749,6 +749,11 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr clien TimeoutWarningMessage_t *tmpTimeout = &tmpPacket->GetMsg()->choice.timeoutWarningMessage; client->GetCallback().SignalNetClientShowTimeoutDialog((NetTimeoutReason)tmpTimeout->timeoutReason, tmpTimeout->remainingSeconds); } + else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_afkWarningMessage) + { + AfkWarningMessage_t *tmpAfk = &tmpPacket->GetMsg()->choice.afkWarningMessage; + client->GetCallback().SignalNetClientWarningAutoFoldInRankingGame(tmpAfk->remainingTimeouts); + } else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_chatMessage) { // Chat message - display it in the GUI. diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 7318a3d7..ea9288ab 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -68,6 +68,9 @@ using namespace std; #define SERVER_VOTE_KICK_TIMEOUT_SEC 30 #define SERVER_LOOP_DELAY_MSEC 50 +#define SERVER_WARNING_ACTION_TIMEOUT_THRESHOLD 6 +#define SERVER_KICK_ACTION_TIMEOUT_REMAINING 2 + // Helper functions static void SendPlayerAction(ServerGame &server, boost::shared_ptr player) @@ -1345,7 +1348,7 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e Game &curGame = server->GetGame(); // Retrieve current player. boost::shared_ptr curPlayer = curGame.getCurrentPlayer(); - if (!curPlayer.get()) + if (!curPlayer) throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); // Player did not act fast enough. Act for him. @@ -1354,6 +1357,24 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e else PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0); + curPlayer->incrementActionTimeoutCounter(); + + if (server->GetGameData().gameType == GAME_TYPE_RANKING + && server->GetGameData().playerActionTimeoutSec >= 10) + { + if (curPlayer->getActionTimeoutCounter() == SERVER_WARNING_ACTION_TIMEOUT_THRESHOLD) + { + boost::shared_ptr warning(new NetPacket(NetPacket::Alloc)); + warning->GetMsg()->present = PokerTHMessage_PR_afkWarningMessage; + AfkWarningMessage_t *netWarning = &warning->GetMsg()->choice.afkWarningMessage; + netWarning->remainingTimeouts = SERVER_KICK_ACTION_TIMEOUT_REMAINING; + server->GetLobbyThread().GetSender().Send(curPlayer->getNetSessionData(), warning); + } + else if (curPlayer->getActionTimeoutCounter() > SERVER_WARNING_ACTION_TIMEOUT_THRESHOLD + SERVER_KICK_ACTION_TIMEOUT_REMAINING) + { + server->InternalKickPlayer(curPlayer->getMyUniqueID()); + } + } server->SetState(ServerGameStateHand::Instance()); } catch (const PokerTHException &e)