Remove reference to network session from player objects.

This commit is contained in:
lotodore
2011-03-10 19:26:04 +00:00
parent 5ab043d533
commit 5857f07309
11 changed files with 35 additions and 47 deletions
+8 -5
View File
@@ -847,7 +847,10 @@ static const RoundData FlopValues[] = {
#define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) #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) 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 !!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!
@@ -5111,14 +5114,14 @@ void LocalPlayer::riverEngine3()
} }
void LocalPlayer::setNetSessionData(boost::shared_ptr<SessionData> session) void LocalPlayer::setIsConnected(bool connected)
{ {
myNetSessionData = session; m_isConnected = connected;
} }
boost::shared_ptr<SessionData> LocalPlayer::getNetSessionData() bool LocalPlayer::isConnected() const
{ {
return myNetSessionData; return m_isConnected;
} }
unsigned unsigned
+3 -3
View File
@@ -271,8 +271,8 @@ public:
void evaluation(int, int); void evaluation(int, int);
void setNetSessionData(boost::shared_ptr<SessionData> session); void setIsConnected(bool connected);
boost::shared_ptr<SessionData> getNetSessionData(); bool isConnected() const;
unsigned getActionTimeoutCounter() const; unsigned getActionTimeoutCounter() const;
void incrementActionTimeoutCounter(); void incrementActionTimeoutCounter();
@@ -323,7 +323,7 @@ private:
bool myWinnerState; bool myWinnerState;
unsigned m_actionTimeoutCounter; unsigned m_actionTimeoutCounter;
boost::shared_ptr<SessionData> myNetSessionData; bool m_isConnected;
}; };
#endif #endif
+8 -5
View File
@@ -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), myCash(sC), mySet(0), myLastRelativeSet(0), 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), 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; 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;
@@ -513,16 +513,19 @@ ClientPlayer::riverEngine3()
{ {
} }
void ClientPlayer::setNetSessionData(boost::shared_ptr<SessionData> session)
void
ClientPlayer::setIsConnected(bool connected)
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex); boost::recursive_mutex::scoped_lock lock(m_syncMutex);
myNetSessionData = session; m_isConnected = connected;
} }
boost::shared_ptr<SessionData> ClientPlayer::getNetSessionData() bool
ClientPlayer::isConnected() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex); boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return myNetSessionData; return m_isConnected;
} }
bool ClientPlayer::checkIfINeedToShowCards() bool ClientPlayer::checkIfINeedToShowCards()
+3 -4
View File
@@ -130,8 +130,8 @@ public:
void evaluation(int, int); void evaluation(int, int);
void setNetSessionData(boost::shared_ptr<SessionData> session); void setIsConnected(bool connected);
boost::shared_ptr<SessionData> getNetSessionData(); bool isConnected() const;
// unused as client // unused as client
unsigned getActionTimeoutCounter() const { unsigned getActionTimeoutCounter() const {
@@ -184,8 +184,7 @@ private:
bool sBluffStatus; bool sBluffStatus;
bool myWinnerState; bool myWinnerState;
bool m_isConnected;
boost::shared_ptr<SessionData> myNetSessionData;
}; };
#endif #endif
+2 -2
View File
@@ -114,8 +114,8 @@ public:
virtual void turnEngine() =0; virtual void turnEngine() =0;
virtual void riverEngine() =0; virtual void riverEngine() =0;
virtual void setNetSessionData(boost::shared_ptr<SessionData> session) =0; virtual void setIsConnected(bool connected) =0;
virtual boost::shared_ptr<SessionData> getNetSessionData() =0; virtual bool isConnected() const=0;
virtual unsigned getActionTimeoutCounter() const =0; virtual unsigned getActionTimeoutCounter() const =0;
virtual void incrementActionTimeoutCounter() =0; virtual void incrementActionTimeoutCounter() =0;
+1 -4
View File
@@ -81,21 +81,18 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
string myAvatarFile; string myAvatarFile;
unsigned uniqueId = 0; unsigned uniqueId = 0;
PlayerType type = PLAYER_TYPE_COMPUTER; PlayerType type = PLAYER_TYPE_COMPUTER;
boost::shared_ptr<SessionData> myNetSession;
if (player_i != player_end) { if (player_i != player_end) {
uniqueId = (*player_i)->GetUniqueId(); uniqueId = (*player_i)->GetUniqueId();
type = (*player_i)->GetType(); type = (*player_i)->GetType();
myName = (*player_i)->GetName(); myName = (*player_i)->GetName();
myAvatarFile = (*player_i)->GetAvatarFile(); myAvatarFile = (*player_i)->GetAvatarFile();
myNetSession = (*player_i)->GetNetSessionData();
++player_i; ++player_i;
} }
// create player objects // create player objects
boost::shared_ptr<PlayerInterface> tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); boost::shared_ptr<PlayerInterface> tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0);
tmpPlayer->setIsConnected(true);
tmpPlayer->setNetSessionData(myNetSession);
// fill player lists // fill player lists
seatsList->push_back(tmpPlayer); seatsList->push_back(tmpPlayer);
+1 -1
View File
@@ -801,7 +801,7 @@ ServerGame::RemoveDisconnectedPlayers()
|| (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER && !IsComputerPlayerActive(tmpPlayer->getMyUniqueID()))) { || (tmpPlayer->getMyType() == PLAYER_TYPE_COMPUTER && !IsComputerPlayerActive(tmpPlayer->getMyUniqueID()))) {
// Setting player cash to 0 will deactivate the player. // Setting player cash to 0 will deactivate the player.
tmpPlayer->setMyCash(0); tmpPlayer->setMyCash(0);
tmpPlayer->setNetSessionData(boost::shared_ptr<SessionData>()); tmpPlayer->setIsConnected(false);
} }
++i; ++i;
} }
+8 -4
View File
@@ -1088,7 +1088,8 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (i != end) { while (i != end) {
// also send to inactive players, but not to disconnected players. // also send to inactive players, but not to disconnected players.
boost::shared_ptr<PlayerInterface> tmpPlayer = *i; boost::shared_ptr<PlayerInterface> tmpPlayer = *i;
if (tmpPlayer->getNetSessionData()) { SessionWrapper tmpSession = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
if (tmpPlayer->isConnected() && tmpSession.sessionData) {
int cards[2]; int cards[2];
bool errorFlag = false; bool errorFlag = false;
tmpPlayer->getMyCards(cards); tmpPlayer->getMyCards(cards);
@@ -1097,7 +1098,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
notifyCards->GetMsg()->present = PokerTHMessage_PR_handStartMessage; notifyCards->GetMsg()->present = PokerTHMessage_PR_handStartMessage;
HandStartMessage_t *netHandStart = &notifyCards->GetMsg()->choice.handStartMessage; HandStartMessage_t *netHandStart = &notifyCards->GetMsg()->choice.handStartMessage;
netHandStart->gameId = server->GetId(); netHandStart->gameId = server->GetId();
string tmpPassword(tmpPlayer->getNetSessionData()->AuthGetPassword()); string tmpPassword(tmpSession.sessionData->AuthGetPassword());
if (tmpPassword.empty()) { // encrypt only if password is present if (tmpPassword.empty()) { // encrypt only if password is present
netHandStart->yourCards.present = yourCards_PR_plainCards; netHandStart->yourCards.present = yourCards_PR_plainCards;
PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards; PlainCards_t *plainCards = &netHandStart->yourCards.choice.plainCards;
@@ -1130,7 +1131,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
} }
if (!errorFlag) { if (!errorFlag) {
netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind(); netHandStart->smallBlind = curGame.getCurrentHand()->getSmallBlind();
server->GetLobbyThread().GetSender().Send(tmpPlayer->getNetSessionData(), notifyCards); server->GetLobbyThread().GetSender().Send(tmpSession.sessionData, notifyCards);
} }
} }
++i; ++i;
@@ -1308,6 +1309,9 @@ ServerGameStateWaitPlayerAction::TimerTimeout(const boost::system::error_code &e
boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer(); boost::shared_ptr<PlayerInterface> curPlayer = curGame.getCurrentPlayer();
if (!curPlayer) if (!curPlayer)
throw ServerException(__FILE__, __LINE__, ERR_NET_NO_CURRENT_PLAYER, 0); 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. // Player did not act fast enough. Act for him.
if (curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() == curPlayer->getMySet()) 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; warning->GetMsg()->present = PokerTHMessage_PR_afkWarningMessage;
AfkWarningMessage_t *netWarning = &warning->GetMsg()->choice.afkWarningMessage; AfkWarningMessage_t *netWarning = &warning->GetMsg()->choice.afkWarningMessage;
netWarning->remainingTimeouts = SERVER_KICK_ACTION_TIMEOUT_REMAINING; 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) { } else if (curPlayer->getActionTimeoutCounter() > SERVER_WARNING_ACTION_TIMEOUT_THRESHOLD + SERVER_KICK_ACTION_TIMEOUT_REMAINING) {
server->InternalKickPlayer(curPlayer->getMyUniqueID()); server->InternalKickPlayer(curPlayer->getMyUniqueID());
} }
-1
View File
@@ -1051,7 +1051,6 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
boost::shared_ptr<PlayerData> tmpPlayerData( boost::shared_ptr<PlayerData> tmpPlayerData(
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, false)); new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, validGuest ? PLAYER_RIGHTS_GUEST : PLAYER_RIGHTS_NORMAL, false));
tmpPlayerData->SetName(playerName); tmpPlayerData->SetName(playerName);
tmpPlayerData->SetNetSessionData(session.sessionData);
tmpPlayerData->SetAvatarMD5(avatarMD5); tmpPlayerData->SetAvatarMD5(avatarMD5);
// Set player data for session. // Set player data for session.
+1 -15
View File
@@ -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_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_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_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; m_avatarMD5 = avatarMD5;
} }
boost::shared_ptr<SessionData>
PlayerData::GetNetSessionData() const
{
// setting/getting boost::shared_ptr is thread safe.
return m_netSessionData;
}
void
PlayerData::SetNetSessionData(boost::shared_ptr<SessionData> session)
{
// setting/getting boost::shared_ptr is thread safe.
m_netSessionData = session;
}
boost::shared_ptr<AvatarFile> boost::shared_ptr<AvatarFile>
PlayerData::GetNetAvatarFile() const PlayerData::GetNetAvatarFile() const
{ {
-3
View File
@@ -83,8 +83,6 @@ public:
void SetAvatarFile(const std::string &avatarFile); void SetAvatarFile(const std::string &avatarFile);
MD5Buf GetAvatarMD5() const; MD5Buf GetAvatarMD5() const;
void SetAvatarMD5(const MD5Buf &avatarMD5); void SetAvatarMD5(const MD5Buf &avatarMD5);
boost::shared_ptr<SessionData> GetNetSessionData() const;
void SetNetSessionData(boost::shared_ptr<SessionData> session);
boost::shared_ptr<AvatarFile> GetNetAvatarFile() const; boost::shared_ptr<AvatarFile> GetNetAvatarFile() const;
void SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile); void SetNetAvatarFile(boost::shared_ptr<AvatarFile> AvatarFile);
PlayerType GetType() const; PlayerType GetType() const;
@@ -112,7 +110,6 @@ private:
PlayerType m_type; PlayerType m_type;
PlayerRights m_rights; PlayerRights m_rights;
bool m_isGameAdmin; bool m_isGameAdmin;
boost::shared_ptr<SessionData> m_netSessionData;
boost::shared_ptr<AvatarFile> m_netAvatarFile; boost::shared_ptr<AvatarFile> m_netAvatarFile;
mutable boost::mutex m_dataMutex; mutable boost::mutex m_dataMutex;