Implementing automatic kick of players after a certain timeout within a game.
This commit is contained in:
@@ -5123,3 +5123,13 @@ bool LocalPlayer::checkIfINeedToShowCards()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocalPlayer::markRemoteAction()
|
||||
{
|
||||
m_lastRemoteActionTimer.restart();
|
||||
}
|
||||
|
||||
unsigned LocalPlayer::getTimeSecSinceLastRemoteAction() const
|
||||
{
|
||||
return m_lastRemoteActionTimer.elapsed().total_seconds();
|
||||
}
|
||||
|
||||
@@ -285,12 +285,11 @@ public:
|
||||
void setIsKicked(bool kicked);
|
||||
bool isKicked() const;
|
||||
|
||||
unsigned getActionTimeoutCounter() const;
|
||||
void incrementActionTimeoutCounter();
|
||||
void resetActionTimeoutCounter();
|
||||
|
||||
bool checkIfINeedToShowCards();
|
||||
|
||||
void markRemoteAction();
|
||||
unsigned getTimeSecSinceLastRemoteAction() const;
|
||||
|
||||
private:
|
||||
|
||||
ConfigFile *myConfig;
|
||||
@@ -336,6 +335,7 @@ private:
|
||||
unsigned m_actionTimeoutCounter;
|
||||
bool m_isSessionActive;
|
||||
bool m_isKicked;
|
||||
boost::timers::portable::microsec_timer m_lastRemoteActionTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -140,6 +140,9 @@ public:
|
||||
|
||||
bool checkIfINeedToShowCards();
|
||||
|
||||
void markRemoteAction() {}
|
||||
unsigned getTimeSecSinceLastRemoteAction() const {return 0;}
|
||||
|
||||
private:
|
||||
mutable boost::recursive_mutex m_syncMutex;
|
||||
|
||||
|
||||
@@ -124,6 +124,9 @@ public:
|
||||
virtual bool isKicked() const=0;
|
||||
|
||||
virtual bool checkIfINeedToShowCards() =0;
|
||||
|
||||
virtual void markRemoteAction() =0;
|
||||
virtual unsigned getTimeSecSinceLastRemoteAction() const =0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -220,7 +220,7 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
|
||||
|
||||
// Perform kick.
|
||||
if (doKick)
|
||||
InternalKickPlayer(m_voteKickData->kickPlayerId);
|
||||
KickPlayer(m_voteKickData->kickPlayerId);
|
||||
// This petition has ended.
|
||||
m_voteKickData.reset();
|
||||
}
|
||||
@@ -398,7 +398,7 @@ ServerGame::InternalEndGame()
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::InternalKickPlayer(unsigned playerId)
|
||||
ServerGame::KickPlayer(unsigned playerId)
|
||||
{
|
||||
MarkPlayerAsKicked(playerId);
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ using namespace std;
|
||||
#define SERVER_AUTOSTART_GAME_DELAY_SEC 6
|
||||
#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_AUTOFOLD_TIMEOUT_SEC 60
|
||||
#define SERVER_GAME_FORCED_TIMEOUT_SEC 120
|
||||
#define SERVER_VOTE_KICK_TIMEOUT_SEC 30
|
||||
#define SERVER_LOOP_DELAY_MSEC 50
|
||||
|
||||
@@ -179,8 +181,15 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptr<PlayerInte
|
||||
curGame.getCurrentHand()->getBoard()->collectSets();
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
@@ -224,12 +233,6 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
|
||||
{
|
||||
if (packet->IsClientActivity()) {
|
||||
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) {
|
||||
// Delegate to Lobby.
|
||||
@@ -245,7 +248,7 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
|
||||
KickPlayerRequestMessage_t *netKickRequest = &packet->GetMsg()->choice.kickPlayerRequestMessage;
|
||||
if (session->GetPlayerData()->IsGameAdmin() && !server->IsRunning()
|
||||
&& 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) {
|
||||
if (server->GetGameData().gameType != GAME_TYPE_RANKING) {
|
||||
@@ -946,8 +949,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
|
||||
}
|
||||
else {
|
||||
// If the player we are waiting for left, continue without him.
|
||||
else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
|
||||
if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
|
||||
|| !curPlayer->isSessionActive()) {
|
||||
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||
|
||||
@@ -959,6 +963,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
} else {
|
||||
server->SetState(ServerGameStateWaitPlayerAction::Instance());
|
||||
}
|
||||
}
|
||||
} else { // hand is over
|
||||
// Engine will find out who won.
|
||||
curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun();
|
||||
@@ -1401,6 +1406,8 @@ ServerGameStateWaitPlayerAction::InternalProcessPacket(boost::shared_ptr<ServerG
|
||||
}
|
||||
|
||||
if (code == ACTION_CODE_VALID) {
|
||||
tmpPlayer->setIsSessionActive(true);
|
||||
tmpPlayer->markRemoteAction();
|
||||
PerformPlayerAction(*server, tmpPlayer, static_cast<PlayerAction>(netMyAction->myAction), netMyAction->myRelativeBet);
|
||||
server->SetState(ServerGameStateHand::Instance());
|
||||
} else {
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
#define SERVER_INIT_SESSION_TIMEOUT_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_ADDRESS_LOCALHOST_STR_V4 "127.0.0.1"
|
||||
|
||||
@@ -96,6 +96,8 @@ public:
|
||||
const Game &GetGame() const;
|
||||
Game &GetGame();
|
||||
|
||||
void KickPlayer(unsigned playerId);
|
||||
|
||||
protected:
|
||||
|
||||
struct RankingData {
|
||||
@@ -117,7 +119,6 @@ protected:
|
||||
void RemoveAutoLeavePlayers();
|
||||
void InternalEndGame();
|
||||
|
||||
void InternalKickPlayer(unsigned playerId);
|
||||
void InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, unsigned timeoutSec);
|
||||
void InternalDenyAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned playerIdWho, DenyKickPlayerReason reason);
|
||||
void InternalVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned petitionId, KickVote vote);
|
||||
|
||||
Reference in New Issue
Block a user