Implementing automatic kick of players after a certain timeout within a game.
This commit is contained in:
@@ -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,18 +949,20 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
|
||||
}
|
||||
// If the player we are waiting for left, continue without him.
|
||||
else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
|
||||
|| !curPlayer->isSessionActive()) {
|
||||
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||
else {
|
||||
// If the player we are waiting for left, continue without him.
|
||||
if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
|
||||
|| !curPlayer->isSessionActive()) {
|
||||
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
} else {
|
||||
server->SetState(ServerGameStateWaitPlayerAction::Instance());
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
|
||||
server->GetStateTimer1().async_wait(
|
||||
boost::bind(
|
||||
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
|
||||
} else {
|
||||
server->SetState(ServerGameStateWaitPlayerAction::Instance());
|
||||
}
|
||||
}
|
||||
} else { // hand is over
|
||||
// Engine will find out who won.
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user