diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 07a10ee0..e1e8993a 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -847,7 +847,10 @@ static const RoundData FlopValues[] = { #define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) - : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), sBluff(0), sBluffStatus(0), myWinnerState(false), m_actionTimeoutCounter(0) + : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), + myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), + myButton(mB), myActiveStatus(aS), myStayOnTableStatus(1), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), + sBluff(0), sBluffStatus(0), myWinnerState(false), m_actionTimeoutCounter(0), m_isConnected(false) { // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!! @@ -5111,14 +5114,14 @@ void LocalPlayer::riverEngine3() } -void LocalPlayer::setNetSessionData(boost::shared_ptr session) +void LocalPlayer::setIsConnected(bool connected) { - myNetSessionData = session; + m_isConnected = connected; } -boost::shared_ptr LocalPlayer::getNetSessionData() +bool LocalPlayer::isConnected() const { - return myNetSessionData; + return m_isConnected; } unsigned diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 49dbcc82..f91cda15 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -271,8 +271,8 @@ public: void evaluation(int, int); - void setNetSessionData(boost::shared_ptr session); - boost::shared_ptr getNetSessionData(); + void setIsConnected(bool connected); + bool isConnected() const; unsigned getActionTimeoutCounter() const; void incrementActionTimeoutCounter(); @@ -323,7 +323,7 @@ private: bool myWinnerState; unsigned m_actionTimeoutCounter; - boost::shared_ptr myNetSessionData; + bool m_isConnected; }; #endif diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index 4cb5633d..4c5410a7 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -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), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(true), myTurn(false), myCardsFlip(false), myRoundStartCash(0), - lastMoneyWon(0), sBluff(0), sBluffStatus(false), myWinnerState(false) + lastMoneyWon(0), sBluff(0), sBluffStatus(false), myWinnerState(false), m_isConnected(false) { myBestHandPosition[0] = myBestHandPosition[1] = myBestHandPosition[2] = myBestHandPosition[3] = myBestHandPosition[4] = 0; myNiveau[0] = myNiveau[1] = myNiveau[2] = 0; @@ -513,16 +513,19 @@ ClientPlayer::riverEngine3() { } -void ClientPlayer::setNetSessionData(boost::shared_ptr session) + +void +ClientPlayer::setIsConnected(bool connected) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - myNetSessionData = session; + m_isConnected = connected; } -boost::shared_ptr ClientPlayer::getNetSessionData() +bool +ClientPlayer::isConnected() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - return myNetSessionData; + return m_isConnected; } bool ClientPlayer::checkIfINeedToShowCards() diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index 8c9c3372..988ffc46 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -130,8 +130,8 @@ public: void evaluation(int, int); - void setNetSessionData(boost::shared_ptr session); - boost::shared_ptr getNetSessionData(); + void setIsConnected(bool connected); + bool isConnected() const; // unused as client unsigned getActionTimeoutCounter() const { @@ -184,8 +184,7 @@ private: bool sBluffStatus; bool myWinnerState; - - boost::shared_ptr myNetSessionData; + bool m_isConnected; }; #endif diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index 139f7ef6..96b5ffec 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -114,8 +114,8 @@ public: virtual void turnEngine() =0; virtual void riverEngine() =0; - virtual void setNetSessionData(boost::shared_ptr session) =0; - virtual boost::shared_ptr getNetSessionData() =0; + virtual void setIsConnected(bool connected) =0; + virtual bool isConnected() const=0; virtual unsigned getActionTimeoutCounter() const =0; virtual void incrementActionTimeoutCounter() =0; diff --git a/src/game.cpp b/src/game.cpp index d8bd3377..e96aa016 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -81,21 +81,18 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, string myAvatarFile; unsigned uniqueId = 0; PlayerType type = PLAYER_TYPE_COMPUTER; - boost::shared_ptr myNetSession; if (player_i != player_end) { uniqueId = (*player_i)->GetUniqueId(); type = (*player_i)->GetType(); myName = (*player_i)->GetName(); myAvatarFile = (*player_i)->GetAvatarFile(); - myNetSession = (*player_i)->GetNetSessionData(); ++player_i; } // create player objects boost::shared_ptr tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); - - tmpPlayer->setNetSessionData(myNetSession); + tmpPlayer->setIsConnected(true); // fill player lists seatsList->push_back(tmpPlayer); diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 360c3c89..c9880684 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -801,7 +801,7 @@ ServerGame::RemoveDisconnectedPlayers() || (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER && !IsComputerPlayerActive(tmpPlayer->getMyUniqueID()))) { // Setting player cash to 0 will deactivate the player. tmpPlayer->setMyCash(0); - tmpPlayer->setNetSessionData(boost::shared_ptr()); + tmpPlayer->setIsConnected(false); } ++i; } diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index ef052020..0b2aafb8 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -1088,7 +1088,8 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr server) while (i != end) { // also send to inactive players, but not to disconnected players. boost::shared_ptr tmpPlayer = *i; - if (tmpPlayer->getNetSessionData()) { + SessionWrapper tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID()); + if (tmpPlayer->isConnected() && tmpSession.sessionData) { int cards[2]; bool errorFlag = false; tmpPlayer->getMyCards(cards); @@ -1097,7 +1098,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr server) notifyCards->GetMsg()->present = PokerTHMessage_PR_handStartMessage; HandStartMessage_t *netHandStart = ¬ifyCards->GetMsg()->choice.handStartMessage; netHandStart->gameId = server->GetId(); - string tmpPassword(tmpPlayer->getNetSessionData()->AuthGetPassword()); + string tmpPassword(tmpSession.sessionData->AuthGetPassword()); if (tmpPassword.empty()) { // encrypt only if password is present netHandStart->yourCards.present = yourCards_PR_plainCards; PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards; @@ -1130,7 +1131,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr server) } if (!errorFlag) { netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind(); - server->GetLobbyThread().GetSender().Send(tmpPlayer->getNetSessionData(), notifyCards); + server->GetLobbyThread().GetSender().Send(tmpSession.sessionData, notifyCards); } } ++i; @@ -1308,6 +1309,9 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e boost::shared_ptr curPlayer = curGame.getCurrentPlayer(); if (!curPlayer) throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); + SessionWrapper tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(curPlayer->getMyUniqueID()); + if (!tmpSession.sessionData) + throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); // Player did not act fast enough. Act for him. if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() == curPlayer->getMySet()) @@ -1324,7 +1328,7 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e warning->GetMsg()->present = PokerTHMessage_PR_afkWarningMessage; AfkWarningMessage_t *netWarning = &warning->GetMsg()->choice.afkWarningMessage; netWarning->remainingTimeouts = SERVER_KICK_ACTION_TIMEOUT_REMAINING; - server->GetLobbyThread().GetSender().Send(curPlayer->getNetSessionData(), warning); + server->GetLobbyThread().GetSender().Send(tmpSession.sessionData, warning); } else if (curPlayer->getActionTimeoutCounter() > SERVER_WARNING_ACTION_TIMEOUT_THRESHOLD + SERVER_KICK_ACTION_TIMEOUT_REMAINING) { server->InternalKickPlayer(curPlayer->getMyUniqueID()); } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 6f645e62..ff9d6062 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1051,7 +1051,6 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage boost::shared_ptr tmpPlayerData( new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, false)); tmpPlayerData->SetName(playerName); - tmpPlayerData->SetNetSessionData(session.sessionData); tmpPlayerData->SetAvatarMD5(avatarMD5); // Set player data for session. diff --git a/src/playerdata.cpp b/src/playerdata.cpp index 572c9982..c644af2f 100644 --- a/src/playerdata.cpp +++ b/src/playerdata.cpp @@ -30,7 +30,7 @@ PlayerData::PlayerData(const PlayerData &other) : m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_name(other.GetName()), m_password(), m_country(other.GetCountry()), m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_type(other.GetType()), m_rights(other.GetRights()), m_isGameAdmin(other.IsGameAdmin()), - m_netSessionData(other.GetNetSessionData()), m_netAvatarFile(), m_dataMutex() + m_netAvatarFile(), m_dataMutex() { } @@ -93,20 +93,6 @@ PlayerData::SetAvatarMD5(const MD5Buf &avatarMD5) m_avatarMD5 = avatarMD5; } -boost::shared_ptr -PlayerData::GetNetSessionData() const -{ - // setting/getting boost::shared_ptr is thread safe. - return m_netSessionData; -} - -void -PlayerData::SetNetSessionData(boost::shared_ptr session) -{ - // setting/getting boost::shared_ptr is thread safe. - m_netSessionData = session; -} - boost::shared_ptr PlayerData::GetNetAvatarFile() const { diff --git a/src/playerdata.h b/src/playerdata.h index bec13aeb..e172c9a7 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -83,8 +83,6 @@ public: void SetAvatarFile(const std::string &avatarFile); MD5Buf GetAvatarMD5() const; void SetAvatarMD5(const MD5Buf &avatarMD5); - boost::shared_ptr GetNetSessionData() const; - void SetNetSessionData(boost::shared_ptr session); boost::shared_ptr GetNetAvatarFile() const; void SetNetAvatarFile(boost::shared_ptr AvatarFile); PlayerType GetType() const; @@ -112,7 +110,6 @@ private: PlayerType m_type; PlayerRights m_rights; bool m_isGameAdmin; - boost::shared_ptr m_netSessionData; boost::shared_ptr m_netAvatarFile; mutable boost::mutex m_dataMutex;