Implementing automatic kick of players after a certain timeout within a game.

This commit is contained in:
lotodore
2011-12-16 22:39:24 +00:00
parent 91b3307584
commit 0a8cd1cce4
8 changed files with 51 additions and 27 deletions
+10
View File
@@ -5123,3 +5123,13 @@ bool LocalPlayer::checkIfINeedToShowCards()
return false; return false;
} }
void LocalPlayer::markRemoteAction()
{
m_lastRemoteActionTimer.restart();
}
unsigned LocalPlayer::getTimeSecSinceLastRemoteAction() const
{
return m_lastRemoteActionTimer.elapsed().total_seconds();
}
+4 -4
View File
@@ -285,12 +285,11 @@ public:
void setIsKicked(bool kicked); void setIsKicked(bool kicked);
bool isKicked() const; bool isKicked() const;
unsigned getActionTimeoutCounter() const;
void incrementActionTimeoutCounter();
void resetActionTimeoutCounter();
bool checkIfINeedToShowCards(); bool checkIfINeedToShowCards();
void markRemoteAction();
unsigned getTimeSecSinceLastRemoteAction() const;
private: private:
ConfigFile *myConfig; ConfigFile *myConfig;
@@ -336,6 +335,7 @@ private:
unsigned m_actionTimeoutCounter; unsigned m_actionTimeoutCounter;
bool m_isSessionActive; bool m_isSessionActive;
bool m_isKicked; bool m_isKicked;
boost::timers::portable::microsec_timer m_lastRemoteActionTimer;
}; };
#endif #endif
+3
View File
@@ -140,6 +140,9 @@ public:
bool checkIfINeedToShowCards(); bool checkIfINeedToShowCards();
void markRemoteAction() {}
unsigned getTimeSecSinceLastRemoteAction() const {return 0;}
private: private:
mutable boost::recursive_mutex m_syncMutex; mutable boost::recursive_mutex m_syncMutex;
+3
View File
@@ -124,6 +124,9 @@ public:
virtual bool isKicked() const=0; virtual bool isKicked() const=0;
virtual bool checkIfINeedToShowCards() =0; virtual bool checkIfINeedToShowCards() =0;
virtual void markRemoteAction() =0;
virtual unsigned getTimeSecSinceLastRemoteAction() const =0;
}; };
#endif #endif
+2 -2
View File
@@ -220,7 +220,7 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
// Perform kick. // Perform kick.
if (doKick) if (doKick)
InternalKickPlayer(m_voteKickData->kickPlayerId); KickPlayer(m_voteKickData->kickPlayerId);
// This petition has ended. // This petition has ended.
m_voteKickData.reset(); m_voteKickData.reset();
} }
@@ -398,7 +398,7 @@ ServerGame::InternalEndGame()
} }
void void
ServerGame::InternalKickPlayer(unsigned playerId) ServerGame::KickPlayer(unsigned playerId)
{ {
MarkPlayerAsKicked(playerId); MarkPlayerAsKicked(playerId);
+26 -19
View File
@@ -65,6 +65,8 @@ using namespace std;
#define SERVER_AUTOSTART_GAME_DELAY_SEC 6 #define SERVER_AUTOSTART_GAME_DELAY_SEC 6
#define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60 #define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60
#define SERVER_GAME_ADMIN_TIMEOUT_SEC 300 // 5 min, MUST be > SERVER_GAME_ADMIN_WARNING_REMAINING_SEC #define SERVER_GAME_ADMIN_TIMEOUT_SEC 300 // 5 min, MUST be > SERVER_GAME_ADMIN_WARNING_REMAINING_SEC
#define SERVER_GAME_AUTOFOLD_TIMEOUT_SEC 60
#define SERVER_GAME_FORCED_TIMEOUT_SEC 120
#define SERVER_VOTE_KICK_TIMEOUT_SEC 30 #define SERVER_VOTE_KICK_TIMEOUT_SEC 30
#define SERVER_LOOP_DELAY_MSEC 50 #define SERVER_LOOP_DELAY_MSEC 50
@@ -179,8 +181,15 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptr<PlayerInte
curGame.getCurrentHand()->getBoard()->collectSets(); curGame.getCurrentHand()->getBoard()->collectSets();
} }
SendPlayerAction(server, player); SendPlayerAction(server, player);
// Check timeout.
if (player->getTimeSecSinceLastRemoteAction() >= SERVER_GAME_AUTOFOLD_TIMEOUT_SEC) {
player->setIsSessionActive(false);
if (player->getTimeSecSinceLastRemoteAction() >= SERVER_GAME_FORCED_TIMEOUT_SEC) {
server.KickPlayer(player->getMyUniqueID());
}
}
} }
static void static void
@@ -224,12 +233,6 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
{ {
if (packet->IsClientActivity()) { if (packet->IsClientActivity()) {
session->ResetActivityTimer(); session->ResetActivityTimer();
if (server->IsRunning()) {
boost::shared_ptr<PlayerInterface> tmpPlayer(server->GetGame().getPlayerByUniqueId(session->GetPlayerData()->GetUniqueId()));
if (tmpPlayer) {
tmpPlayer->setIsSessionActive(true);
}
}
} }
if (packet->GetMsg()->present == PokerTHMessage_PR_playerInfoRequestMessage) { if (packet->GetMsg()->present == PokerTHMessage_PR_playerInfoRequestMessage) {
// Delegate to Lobby. // Delegate to Lobby.
@@ -245,7 +248,7 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
KickPlayerRequestMessage_t *netKickRequest = &packet->GetMsg()->choice.kickPlayerRequestMessage; KickPlayerRequestMessage_t *netKickRequest = &packet->GetMsg()->choice.kickPlayerRequestMessage;
if (session->GetPlayerData()->IsGameAdmin() && !server->IsRunning() if (session->GetPlayerData()->IsGameAdmin() && !server->IsRunning()
&& netKickRequest->gameId == server->GetId() && server->GetGameData().gameType != GAME_TYPE_RANKING) { && netKickRequest->gameId == server->GetId() && server->GetGameData().gameType != GAME_TYPE_RANKING) {
server->InternalKickPlayer(netKickRequest->playerId); server->KickPlayer(netKickRequest->playerId);
} }
} else if (packet->GetMsg()->present == PokerTHMessage_PR_askKickPlayerMessage) { } else if (packet->GetMsg()->present == PokerTHMessage_PR_askKickPlayerMessage) {
if (server->GetGameData().gameType != GAME_TYPE_RANKING) { if (server->GetGameData().gameType != GAME_TYPE_RANKING) {
@@ -946,18 +949,20 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
boost::bind( boost::bind(
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server)); &ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
} }
// If the player we are waiting for left, continue without him. else {
else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID()) // If the player we are waiting for left, continue without him.
|| !curPlayer->isSessionActive()) { if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0); || !curPlayer->isSessionActive()) {
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
server->GetStateTimer1().expires_from_now( server->GetStateTimer1().expires_from_now(
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC)); boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
server->GetStateTimer1().async_wait( server->GetStateTimer1().async_wait(
boost::bind( boost::bind(
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server)); &ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
} else { } else {
server->SetState(ServerGameStateWaitPlayerAction::Instance()); server->SetState(ServerGameStateWaitPlayerAction::Instance());
}
} }
} else { // hand is over } else { // hand is over
// Engine will find out who won. // Engine will find out who won.
@@ -1401,6 +1406,8 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
} }
if (code == ACTION_CODE_VALID) { if (code == ACTION_CODE_VALID) {
tmpPlayer->setIsSessionActive(true);
tmpPlayer->markRemoteAction();
PerformPlayerAction(*server, tmpPlayer, static_cast<PlayerAction>(netMyAction->myAction), netMyAction->myRelativeBet); PerformPlayerAction(*server, tmpPlayer, static_cast<PlayerAction>(netMyAction->myAction), netMyAction->myRelativeBet);
server->SetState(ServerGameStateHand::Instance()); server->SetState(ServerGameStateHand::Instance());
} else { } else {
+1 -1
View File
@@ -65,7 +65,7 @@
#define SERVER_INIT_SESSION_TIMEOUT_SEC 60 #define SERVER_INIT_SESSION_TIMEOUT_SEC 60
#define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60 #define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60
#define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 180/*1800*/ // 30 min, MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC #define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 1800 // 30 min, MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC
#define SERVER_SESSION_FORCED_TIMEOUT_SEC 86400 // 1 day, should be quite large. #define SERVER_SESSION_FORCED_TIMEOUT_SEC 86400 // 1 day, should be quite large.
#define SERVER_ADDRESS_LOCALHOST_STR_V4 "127.0.0.1" #define SERVER_ADDRESS_LOCALHOST_STR_V4 "127.0.0.1"
+2 -1
View File
@@ -96,6 +96,8 @@ public:
const Game &GetGame() const; const Game &GetGame() const;
Game &GetGame(); Game &GetGame();
void KickPlayer(unsigned playerId);
protected: protected:
struct RankingData { struct RankingData {
@@ -117,7 +119,6 @@ protected:
void RemoveAutoLeavePlayers(); void RemoveAutoLeavePlayers();
void InternalEndGame(); void InternalEndGame();
void InternalKickPlayer(unsigned playerId);
void InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, unsigned timeoutSec); void InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, unsigned timeoutSec);
void InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason); void InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason);
void InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, KickVote vote); void InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, KickVote vote);