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
|
// create player objects
|
||||||
boost::shared_ptr<PlayerInterface> tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, myStartCash, startQuantityPlayers > i, 0);
|
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);
|
tmpPlayer->setMyGuid(myGuid);
|
||||||
|
|
||||||
// fill player lists
|
// 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),
|
: 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),
|
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),
|
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 !!!!!!!!!!!!!!!!!!!!!!!!
|
// !!!!!!!!!!!!!!!!!!!!!!!! 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)
|
void LocalPlayer::setIsKicked(bool kicked)
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ public:
|
|||||||
|
|
||||||
void evaluation(int, int);
|
void evaluation(int, int);
|
||||||
|
|
||||||
void setIsConnected(bool connected);
|
void setIsSessionActive(bool active);
|
||||||
bool isConnected() const;
|
bool isSessionActive() const;
|
||||||
void setIsKicked(bool kicked);
|
void setIsKicked(bool kicked);
|
||||||
bool isKicked() const;
|
bool isKicked() const;
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ private:
|
|||||||
bool sBluffStatus;
|
bool sBluffStatus;
|
||||||
|
|
||||||
unsigned m_actionTimeoutCounter;
|
unsigned m_actionTimeoutCounter;
|
||||||
bool m_isConnected;
|
bool m_isSessionActive;
|
||||||
bool m_isKicked;
|
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),
|
: 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),
|
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),
|
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;
|
myBestHandPosition[0] = myBestHandPosition[1] = myBestHandPosition[2] = myBestHandPosition[3] = myBestHandPosition[4] = 0;
|
||||||
myNiveau[0] = myNiveau[1] = myNiveau[2] = 0;
|
myNiveau[0] = myNiveau[1] = myNiveau[2] = 0;
|
||||||
@@ -536,17 +536,17 @@ ClientPlayer::riverEngine3()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ClientPlayer::setIsConnected(bool connected)
|
ClientPlayer::setIsSessionActive(bool active)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
||||||
m_isConnected = connected;
|
m_isSessionActive = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ClientPlayer::isConnected() const
|
ClientPlayer::isSessionActive() const
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
|
||||||
return m_isConnected;
|
return m_isSessionActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ public:
|
|||||||
|
|
||||||
void evaluation(int, int);
|
void evaluation(int, int);
|
||||||
|
|
||||||
void setIsConnected(bool connected);
|
void setIsSessionActive(bool active);
|
||||||
bool isConnected() const;
|
bool isSessionActive() const;
|
||||||
void setIsKicked(bool kicked);
|
void setIsKicked(bool kicked);
|
||||||
bool isKicked() const;
|
bool isKicked() const;
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ private:
|
|||||||
int sBluff;
|
int sBluff;
|
||||||
bool sBluffStatus;
|
bool sBluffStatus;
|
||||||
|
|
||||||
bool m_isConnected;
|
bool m_isSessionActive;
|
||||||
bool m_isKicked;
|
bool m_isKicked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ public:
|
|||||||
virtual void turnEngine() =0;
|
virtual void turnEngine() =0;
|
||||||
virtual void riverEngine() =0;
|
virtual void riverEngine() =0;
|
||||||
|
|
||||||
virtual void setIsConnected(bool connected) =0;
|
virtual void setIsSessionActive(bool connected) =0;
|
||||||
virtual bool isConnected() const=0;
|
virtual bool isSessionActive() const=0;
|
||||||
virtual void setIsKicked(bool kicked) =0;
|
virtual void setIsKicked(bool kicked) =0;
|
||||||
virtual bool isKicked() const=0;
|
virtual bool isKicked() const=0;
|
||||||
|
|
||||||
|
|||||||
@@ -97,15 +97,37 @@ ServerGame::AddSession(boost::shared_ptr<SessionData> session)
|
|||||||
void
|
void
|
||||||
ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode)
|
ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode)
|
||||||
{
|
{
|
||||||
if (errorCode == ERR_NET_PLAYER_KICKED) {
|
|
||||||
MarkPlayerAsKicked(playerId);
|
|
||||||
}
|
|
||||||
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
|
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId);
|
||||||
// Only kick if the player was found.
|
// Only kick if the player was found.
|
||||||
if (tmpSession)
|
if (tmpSession)
|
||||||
SessionError(tmpSession, errorCode);
|
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
|
void
|
||||||
ServerGame::HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
ServerGame::HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||||
{
|
{
|
||||||
@@ -375,20 +397,6 @@ ServerGame::InternalEndGame()
|
|||||||
m_game.reset();
|
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
|
void
|
||||||
ServerGame::InternalKickPlayer(unsigned playerId)
|
ServerGame::InternalKickPlayer(unsigned playerId)
|
||||||
{
|
{
|
||||||
@@ -828,8 +836,9 @@ ServerGame::RemoveDisconnectedPlayers()
|
|||||||
// The player should only be deactivated if rejoin is not possible.
|
// The player should only be deactivated if rejoin is not possible.
|
||||||
if (tmpPlayer->isKicked() || tmpPlayer->getMyGuid().empty()) {
|
if (tmpPlayer->isKicked() || tmpPlayer->getMyGuid().empty()) {
|
||||||
tmpPlayer->setMyCash(0);
|
tmpPlayer->setMyCash(0);
|
||||||
|
tmpPlayer->setMyGuid("");
|
||||||
}
|
}
|
||||||
tmpPlayer->setIsConnected(false);
|
tmpPlayer->setIsSessionActive(false);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,8 +222,15 @@ AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving()
|
|||||||
void
|
void
|
||||||
AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
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();
|
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.
|
||||||
server->GetLobbyThread().HandleGameRetrievePlayerInfo(session, packet->GetMsg()->choice.playerInfoRequestMessage);
|
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));
|
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
|
||||||
}
|
}
|
||||||
// If the player we are waiting for left, continue without him.
|
// 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);
|
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
|
||||||
|
|
||||||
server->GetStateTimer1().expires_from_now(
|
server->GetStateTimer1().expires_from_now(
|
||||||
@@ -1138,10 +1146,10 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
|
|||||||
|
|
||||||
// Send cards to all players.
|
// Send cards to all players.
|
||||||
while (i != end) {
|
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<PlayerInterface> tmpPlayer = *i;
|
||||||
boost::shared_ptr<SessionData> tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
|
boost::shared_ptr<SessionData> tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
|
||||||
if (tmpPlayer->isConnected() && tmpSession) {
|
if (tmpSession) {
|
||||||
int cards[2];
|
int cards[2];
|
||||||
bool errorFlag = false;
|
bool errorFlag = false;
|
||||||
tmpPlayer->getMyCards(cards);
|
tmpPlayer->getMyCards(cards);
|
||||||
@@ -1274,7 +1282,7 @@ ServerGameStateHand::PerformRejoin(boost::shared_ptr<ServerGame> server, boost::
|
|||||||
// Change the Id in the poker engine.
|
// Change the Id in the poker engine.
|
||||||
rejoinPlayer->setMyUniqueID(session->GetPlayerData()->GetUniqueId());
|
rejoinPlayer->setMyUniqueID(session->GetPlayerData()->GetUniqueId());
|
||||||
rejoinPlayer->setMyGuid(session->GetPlayerData()->GetGuid());
|
rejoinPlayer->setMyGuid(session->GetPlayerData()->GetGuid());
|
||||||
rejoinPlayer->setIsConnected(true);
|
rejoinPlayer->setIsSessionActive(true);
|
||||||
|
|
||||||
// Send game start notification to rejoining client.
|
// Send game start notification to rejoining client.
|
||||||
packet.reset(new NetPacket(NetPacket::Alloc));
|
packet.reset(new NetPacket(NetPacket::Alloc));
|
||||||
|
|||||||
@@ -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 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_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"
|
||||||
@@ -1802,12 +1802,22 @@ ServerLobbyThread::SessionTimeoutWarning(boost::shared_ptr<SessionData> session,
|
|||||||
netWarning->timeoutReason = timeoutReason_timeoutNoDataReceived;
|
netWarning->timeoutReason = timeoutReason_timeoutNoDataReceived;
|
||||||
netWarning->remainingSeconds = remainingSec;
|
netWarning->remainingSeconds = remainingSec;
|
||||||
GetSender().Send(session, packet);
|
GetSender().Send(session, packet);
|
||||||
|
|
||||||
|
if (session->GetGame() && session->GetPlayerData()) {
|
||||||
|
session->GetGame()->MarkPlayerAsInactive(session->GetPlayerData()->GetUniqueId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerLobbyThread::SessionError(boost::shared_ptr<SessionData> session, int errorCode)
|
ServerLobbyThread::SessionError(boost::shared_ptr<SessionData> session, int errorCode)
|
||||||
{
|
{
|
||||||
if (session) {
|
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);
|
SendError(session, errorCode);
|
||||||
CloseSession(session);
|
CloseSession(session);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ public:
|
|||||||
|
|
||||||
void AddSession(boost::shared_ptr<SessionData> session);
|
void AddSession(boost::shared_ptr<SessionData> session);
|
||||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
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);
|
void HandlePacket(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||||
|
|
||||||
@@ -115,7 +117,6 @@ protected:
|
|||||||
void RemoveAutoLeavePlayers();
|
void RemoveAutoLeavePlayers();
|
||||||
void InternalEndGame();
|
void InternalEndGame();
|
||||||
|
|
||||||
void MarkPlayerAsKicked(unsigned playerId);
|
|
||||||
void InternalKickPlayer(unsigned playerId);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user