From d6ab25d8169e3d5171c4dd18ece81e8ea683a56c Mon Sep 17 00:00:00 2001 From: lotodore Date: Wed, 28 Sep 2011 20:20:08 +0000 Subject: [PATCH] Trying to make rejoin work, still broken due to change of unique id during game. --- docs/pokerth.asn1 | 3 +- src/engine/game.cpp | 5 ++- src/engine/local_engine/localplayer.h | 3 ++ src/engine/network_engine/clientplayer.cpp | 8 ++++ src/engine/network_engine/clientplayer.h | 3 +- src/engine/playerinterface.h | 1 + src/net/common/clientstate.cpp | 2 +- src/net/common/clientthread.cpp | 6 ++- src/net/common/servergamestate.cpp | 47 +++++++++++++--------- src/playerdata.cpp | 24 ++++++++--- src/playerdata.h | 3 ++ 11 files changed, 74 insertions(+), 31 deletions(-) diff --git a/docs/pokerth.asn1 b/docs/pokerth.asn1 index 3b537fb5..558efd8f 100644 --- a/docs/pokerth.asn1 +++ b/docs/pokerth.asn1 @@ -283,16 +283,17 @@ JoinGameRequestMessage ::= [APPLICATION 11] SEQUENCE { joinNewGame [1] JoinNewGame, rejoinExistingGame [2] RejoinExistingGame }, - password UTF8String (SIZE(1..64)) OPTIONAL, autoLeave BOOLEAN } JoinExistingGame ::= SEQUENCE { gameId NonZeroId + password UTF8String (SIZE(1..64)) OPTIONAL, } JoinNewGame ::= SEQUENCE { gameInfo NetGameInfo + password UTF8String (SIZE(1..64)) OPTIONAL, } RejoinExistingGame ::= SEQUENCE { diff --git a/src/engine/game.cpp b/src/engine/game.cpp index 46313dac..3de5bbf3 100755 --- a/src/engine/game.cpp +++ b/src/engine/game.cpp @@ -81,6 +81,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, string myGuid; unsigned uniqueId = 0; PlayerType type = PLAYER_TYPE_COMPUTER; + int myStartCash = startCash; if (player_i != player_end) { uniqueId = (*player_i)->GetUniqueId(); @@ -88,11 +89,13 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, myName = (*player_i)->GetName(); myAvatarFile = (*player_i)->GetAvatarFile(); myGuid = (*player_i)->GetGuid(); + if ((*player_i)->GetStartCash() > 0) + myStartCash = (*player_i)->GetStartCash(); ++player_i; } // create player objects - boost::shared_ptr tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); + boost::shared_ptr tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, myStartCash, startQuantityPlayers > i, 0); tmpPlayer->setIsConnected(true); tmpPlayer->setMyGuid(myGuid); diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 452543aa..1a71c1e3 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -43,6 +43,9 @@ public: unsigned getMyUniqueID() const { return myUniqueID; } + void setMyUniqueID(unsigned newId) { + myUniqueID = newId; + } void setMyGuid(const std::string &theValue) { myGuid = theValue; diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index d02b0881..f2e8760e 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -54,9 +54,17 @@ ClientPlayer::getMyID() const return myID; } +void +ClientPlayer::setMyUniqueID(unsigned newId) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + myUniqueID = newId; +} + unsigned ClientPlayer::getMyUniqueID() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return myUniqueID; } diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index 79f4ed2d..ecc52193 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -37,6 +37,7 @@ public: void setHand(HandInterface *); int getMyID() const; + void setMyUniqueID(unsigned newId); unsigned getMyUniqueID() const; void setMyGuid(const std::string &theValue); std::string getMyGuid() const; @@ -152,7 +153,7 @@ private: // Konstanten const int myID; - const unsigned myUniqueID; + unsigned myUniqueID; std::string myGuid; const PlayerType myType; std::string myName; diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index 93345ddf..bd875f44 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -33,6 +33,7 @@ public: virtual void setHand(HandInterface *) =0; virtual int getMyID() const =0; + virtual void setMyUniqueID(unsigned newId) =0; virtual unsigned getMyUniqueID() const =0; virtual void setMyGuid(const std::string &theValue) =0; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 9d38eefc..7ff8b379 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -1536,7 +1536,7 @@ ClientStateWaitStart::InternalHandlePacket(boost::shared_ptr clien if (!tmpPlayer.get()) throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); tmpPlayer->SetNumber(i); - // TODO set money + tmpPlayer->SetStartCash(playerData->playerMoney); } } else throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index d96fa1e3..00c79fd5 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -595,8 +595,10 @@ ClientThread::InitGame() boost::shared_ptr factory(new ClientEngineFactory); // LocalEngine erstellen MapPlayerDataList(); - if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) - throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); + // TODO + //if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) + // throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); + m_startData.numberOfPlayers = GetPlayerDataList().size(); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++, m_clientLog.get())); // Initialize Minimum GUI speed. int minimumGuiSpeed = 1; diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 4ebd5e14..545afda7 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -1144,29 +1144,36 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr server) while (i != end) { boost::shared_ptr session(server->GetSessionManager().GetSessionByUniquePlayerId(*i)); if (session) { - boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); - packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; - GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage; - netGameStart->gameId = server->GetId(); - netGameStart->startDealerPlayerId = curGame.getDealerPosition(); - netGameStart->gameStartMode.present = gameStartMode_PR_gameStartModeRejoin; - GameStartModeRejoin_t *netStartModeRejoin = &netGameStart->gameStartMode.choice.gameStartModeRejoin; + // Set new player id. + boost::shared_ptr rejoinPlayer = curGame.getPlayerByName(session->GetPlayerData()->GetName()); + if (rejoinPlayer) + { + rejoinPlayer->setMyUniqueID(session->GetPlayerData()->GetUniqueId()); + rejoinPlayer->setIsConnected(true); + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; + GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage; + netGameStart->gameId = server->GetId(); + netGameStart->startDealerPlayerId = curGame.getDealerPosition(); + netGameStart->gameStartMode.present = gameStartMode_PR_gameStartModeRejoin; + GameStartModeRejoin_t *netStartModeRejoin = &netGameStart->gameStartMode.choice.gameStartModeRejoin; - // Send player data to client. - PlayerListIterator player_i = curGame.getSeatsList()->begin(); - PlayerListIterator player_end = curGame.getSeatsList()->end(); - while (player_i != player_end) { - boost::shared_ptr tmpPlayer = *player_i; - if (tmpPlayer->getMyActiveStatus()) { - RejoinPlayerData_t *playerSlot = (RejoinPlayerData_t *)calloc(1, sizeof(RejoinPlayerData_t)); - playerSlot->playerId = tmpPlayer->getMyUniqueID(); - playerSlot->playerMoney = tmpPlayer->getMyCash(); - ASN_SEQUENCE_ADD(&netStartModeRejoin->rejoinPlayerData.list, playerSlot); + // Send player data to client. + PlayerListIterator player_i = curGame.getSeatsList()->begin(); + PlayerListIterator player_end = curGame.getSeatsList()->end(); + while (player_i != player_end) { + boost::shared_ptr tmpPlayer = *player_i; + if (tmpPlayer->getMyActiveStatus()) { + RejoinPlayerData_t *playerSlot = (RejoinPlayerData_t *)calloc(1, sizeof(RejoinPlayerData_t)); + playerSlot->playerId = tmpPlayer->getMyUniqueID(); + playerSlot->playerMoney = tmpPlayer->getMyCash(); + ASN_SEQUENCE_ADD(&netStartModeRejoin->rejoinPlayerData.list, playerSlot); + } + ++player_i; } - ++player_i; - } - server->GetLobbyThread().GetSender().Send(session, packet); + server->GetLobbyThread().GetSender().Send(session, packet); + } } ++i; } diff --git a/src/playerdata.cpp b/src/playerdata.cpp index 32742fb2..e309506b 100644 --- a/src/playerdata.cpp +++ b/src/playerdata.cpp @@ -21,15 +21,15 @@ using namespace std; PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin) - : m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_type(type), m_rights(rights), m_isGameAdmin(isGameAdmin) + : m_uniqueId(uniqueId), m_dbId(DB_ID_INVALID), m_number(number), m_startCash(0), m_type(type), m_rights(rights), m_isGameAdmin(isGameAdmin) { } PlayerData::PlayerData(const PlayerData &other) - : m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_guid(other.GetGuid()), 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_netAvatarFile(), m_dataMutex() + : m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_startCash(other.GetStartCash()), + m_guid(other.GetGuid()), m_oldGuid(other.GetOldGuid()), 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_netAvatarFile(), m_dataMutex() { } @@ -202,6 +202,20 @@ PlayerData::SetDBId(DB_id id) m_dbId = id; } +int +PlayerData::GetStartCash() const +{ + boost::mutex::scoped_lock lock(m_dataMutex); + return m_startCash; +} + +void +PlayerData::SetStartCash(int cash) +{ + boost::mutex::scoped_lock lock(m_dataMutex); + m_startCash = cash; +} + bool PlayerData::operator<(const PlayerData &other) const { diff --git a/src/playerdata.h b/src/playerdata.h index f477543f..f82f7fad 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -98,6 +98,8 @@ public: void SetOldGuid(const std::string &guid); DB_id GetDBId() const; void SetDBId(DB_id id); + int GetStartCash() const; + void SetStartCash(int cash); bool operator<(const PlayerData &other) const; @@ -105,6 +107,7 @@ private: const unsigned m_uniqueId; DB_id m_dbId; int m_number; + int m_startCash; // only used if > 0 std::string m_guid; std::string m_oldGuid; std::string m_name;