Remove players from game (without possibility to rejoin) if they did not act within a certain time. Feature is still broken, because the timer is canceled on disconnect.
This commit is contained in:
+1
-1
@@ -96,7 +96,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
|
||||
|
||||
// create player objects
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, myStartCash, startQuantityPlayers > i, 0);
|
||||
tmpPlayer->setIsConnected(true);
|
||||
tmpPlayer->setIsSessionActive(true);
|
||||
tmpPlayer->setMyGuid(myGuid);
|
||||
|
||||
// fill player lists
|
||||
|
||||
@@ -849,7 +849,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty
|
||||
: PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar),
|
||||
myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(PLAYER_ACTION_NONE),
|
||||
myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0),
|
||||
sBluff(0), sBluffStatus(false), m_actionTimeoutCounter(0), m_isConnected(false), m_isKicked(false)
|
||||
sBluff(0), sBluffStatus(false), m_actionTimeoutCounter(0), m_isSessionActive(false), m_isKicked(false)
|
||||
{
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!
|
||||
@@ -5094,14 +5094,14 @@ void LocalPlayer::riverEngine3()
|
||||
|
||||
}
|
||||
|
||||
void LocalPlayer::setIsConnected(bool connected)
|
||||
void LocalPlayer::setIsSessionActive(bool active)
|
||||
{
|
||||
m_isConnected = connected;
|
||||
m_isSessionActive = active;
|
||||
}
|
||||
|
||||
bool LocalPlayer::isConnected() const
|
||||
bool LocalPlayer::isSessionActive() const
|
||||
{
|
||||
return m_isConnected;
|
||||
return m_isSessionActive;
|
||||
}
|
||||
|
||||
void LocalPlayer::setIsKicked(bool kicked)
|
||||
|
||||
@@ -280,8 +280,8 @@ public:
|
||||
|
||||
void evaluation(int, int);
|
||||
|
||||
void setIsConnected(bool connected);
|
||||
bool isConnected() const;
|
||||
void setIsSessionActive(bool active);
|
||||
bool isSessionActive() const;
|
||||
void setIsKicked(bool kicked);
|
||||
bool isKicked() const;
|
||||
|
||||
@@ -334,7 +334,7 @@ private:
|
||||
bool sBluffStatus;
|
||||
|
||||
unsigned m_actionTimeoutCounter;
|
||||
bool m_isConnected;
|
||||
bool m_isSessionActive;
|
||||
bool m_isKicked;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ ClientPlayer::ClientPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType
|
||||
: PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type),
|
||||
myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0),
|
||||
myAction(PLAYER_ACTION_NONE), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(true), myTurn(false), myCardsFlip(false), myRoundStartCash(0),
|
||||
lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_isConnected(false), m_isKicked(false)
|
||||
lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_isSessionActive(false), m_isKicked(false)
|
||||
{
|
||||
myBestHandPosition[0] = myBestHandPosition[1] = myBestHandPosition[2] = myBestHandPosition[3] = myBestHandPosition[4] = 0;
|
||||
myNiveau[0] = myNiveau[1] = myNiveau[2] = 0;
|
||||
@@ -536,17 +536,17 @@ ClientPlayer::riverEngine3()
|
||||
|
||||
|
||||
void
|
||||
ClientPlayer::setIsConnected(bool connected)
|
||||
ClientPlayer::setIsSessionActive(bool active)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
||||
m_isConnected = connected;
|
||||
m_isSessionActive = active;
|
||||
}
|
||||
|
||||
bool
|
||||
ClientPlayer::isConnected() const
|
||||
ClientPlayer::isSessionActive() const
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
||||
return m_isConnected;
|
||||
return m_isSessionActive;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -133,8 +133,8 @@ public:
|
||||
|
||||
void evaluation(int, int);
|
||||
|
||||
void setIsConnected(bool connected);
|
||||
bool isConnected() const;
|
||||
void setIsSessionActive(bool active);
|
||||
bool isSessionActive() const;
|
||||
void setIsKicked(bool kicked);
|
||||
bool isKicked() const;
|
||||
|
||||
@@ -183,7 +183,7 @@ private:
|
||||
int sBluff;
|
||||
bool sBluffStatus;
|
||||
|
||||
bool m_isConnected;
|
||||
bool m_isSessionActive;
|
||||
bool m_isKicked;
|
||||
};
|
||||
|
||||
|
||||
@@ -118,8 +118,8 @@ public:
|
||||
virtual void turnEngine() =0;
|
||||
virtual void riverEngine() =0;
|
||||
|
||||
virtual void setIsConnected(bool connected) =0;
|
||||
virtual bool isConnected() const=0;
|
||||
virtual void setIsSessionActive(bool connected) =0;
|
||||
virtual bool isSessionActive() const=0;
|
||||
virtual void setIsKicked(bool kicked) =0;
|
||||
virtual bool isKicked() const=0;
|
||||
|
||||
|
||||
@@ -97,15 +97,37 @@ ServerGame::AddSession(boost::shared_ptr<SessionData> session)
|
||||
void
|
||||
ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode)
|
||||
{
|
||||
if (errorCode == ERR_NET_PLAYER_KICKED) {
|
||||
MarkPlayerAsKicked(playerId);
|
||||
}
|
||||
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
|
||||
// Only kick if the player was found.
|
||||
if (tmpSession)
|
||||
SessionError(tmpSession, errorCode);
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::MarkPlayerAsInactive(unsigned playerId)
|
||||
{
|
||||
if (m_game) {
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
||||
if (tmpPlayer) {
|
||||
tmpPlayer->setIsSessionActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::MarkPlayerAsKicked(unsigned playerId)
|
||||
{
|
||||
// Mark the player as kicked in the engine.
|
||||
if (m_game) {
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
||||
if (tmpPlayer) {
|
||||
// Player was kicked, so he is not allowed to rejoin.
|
||||
tmpPlayer->setIsKicked(true);
|
||||
tmpPlayer->setMyGuid("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
@@ -375,20 +397,6 @@ ServerGame::InternalEndGame()
|
||||
m_game.reset();
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::MarkPlayerAsKicked(unsigned playerId)
|
||||
{
|
||||
// Mark the player as kicked in the engine.
|
||||
if (m_game) {
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer(m_game->getPlayerByUniqueId(playerId));
|
||||
if (tmpPlayer) {
|
||||
// Player was kicked, so he is not allowed to rejoin.
|
||||
tmpPlayer->setIsKicked(true);
|
||||
tmpPlayer->setMyGuid("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::InternalKickPlayer(unsigned playerId)
|
||||
{
|
||||
@@ -828,8 +836,9 @@ ServerGame::RemoveDisconnectedPlayers()
|
||||
// The player should only be deactivated if rejoin is not possible.
|
||||
if (tmpPlayer->isKicked() || tmpPlayer->getMyGuid().empty()) {
|
||||
tmpPlayer->setMyCash(0);
|
||||
tmpPlayer->setMyGuid("");
|
||||
}
|
||||
tmpPlayer->setIsConnected(false);
|
||||
tmpPlayer->setIsSessionActive(false);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -222,8 +222,15 @@ AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving()
|
||||
void
|
||||
AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
if (packet->IsClientActivity())
|
||||
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.
|
||||
server->GetLobbyThread().HandleGameRetrievePlayerInfo(session, packet->GetMsg()->choice.playerInfoRequestMessage);
|
||||
@@ -940,7 +947,8 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
&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())) {
|
||||
else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())
|
||||
|| !curPlayer->isSessionActive()) {
|
||||
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||
|
||||
server->GetStateTimer1().expires_from_now(
|
||||
@@ -1138,10 +1146,10 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
|
||||
|
||||
// Send cards to all players.
|
||||
while (i != end) {
|
||||
// also send to inactive players, but not to disconnected players.
|
||||
// Also send to inactive players.
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
|
||||
boost::shared_ptr<SessionData> tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
|
||||
if (tmpPlayer->isConnected() && tmpSession) {
|
||||
if (tmpSession) {
|
||||
int cards[2];
|
||||
bool errorFlag = false;
|
||||
tmpPlayer->getMyCards(cards);
|
||||
@@ -1274,7 +1282,7 @@ ServerGameStateHand::PerformRejoin(boost::shared_ptr<ServerGame> server, boost::
|
||||
// Change the Id in the poker engine.
|
||||
rejoinPlayer->setMyUniqueID(session->GetPlayerData()->GetUniqueId());
|
||||
rejoinPlayer->setMyGuid(session->GetPlayerData()->GetGuid());
|
||||
rejoinPlayer->setIsConnected(true);
|
||||
rejoinPlayer->setIsSessionActive(true);
|
||||
|
||||
// Send game start notification to rejoining client.
|
||||
packet.reset(new NetPacket(NetPacket::Alloc));
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
|
||||
#define SERVER_INIT_SESSION_TIMEOUT_SEC 60
|
||||
#define SERVER_TIMEOUT_WARNING_REMAINING_SEC 60
|
||||
#define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 1800 // 30 min, MUST be > SERVER_TIMEOUT_WARNING_REMAINING_SEC
|
||||
#define SERVER_SESSION_ACTIVITY_TIMEOUT_SEC 180/*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"
|
||||
@@ -1802,12 +1802,22 @@ ServerLobbyThread::SessionTimeoutWarning(boost::shared_ptr<SessionData> session,
|
||||
netWarning->timeoutReason = timeoutReason_timeoutNoDataReceived;
|
||||
netWarning->remainingSeconds = remainingSec;
|
||||
GetSender().Send(session, packet);
|
||||
|
||||
if (session->GetGame() && session->GetPlayerData()) {
|
||||
session->GetGame()->MarkPlayerAsInactive(session->GetPlayerData()->GetUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::SessionError(boost::shared_ptr<SessionData> session, int errorCode)
|
||||
{
|
||||
if (session) {
|
||||
if (errorCode == ERR_NET_PLAYER_KICKED || errorCode == ERR_NET_SESSION_TIMED_OUT) {
|
||||
if (session->GetGame() && session->GetPlayerData()) {
|
||||
session->GetGame()->MarkPlayerAsKicked(session->GetPlayerData()->GetUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
SendError(session, errorCode);
|
||||
CloseSession(session);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
|
||||
void AddSession(boost::shared_ptr<SessionData> session);
|
||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||
void MarkPlayerAsInactive(unsigned playerId);
|
||||
void MarkPlayerAsKicked(unsigned playerId);
|
||||
|
||||
void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||
|
||||
@@ -115,7 +117,6 @@ protected:
|
||||
void RemoveAutoLeavePlayers();
|
||||
void InternalEndGame();
|
||||
|
||||
void MarkPlayerAsKicked(unsigned playerId);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user