Trying to make rejoin work, still broken due to change of unique id during game.

This commit is contained in:
lotodore
2011-09-28 20:20:08 +00:00
parent 2488ea43cd
commit d6ab25d816
11 changed files with 74 additions and 31 deletions
+2 -1
View File
@@ -283,16 +283,17 @@ JoinGameRequestMessage ::= [APPLICATION 11] SEQUENCE {
joinNewGame [1] JoinNewGame, joinNewGame [1] JoinNewGame,
rejoinExistingGame [2] RejoinExistingGame rejoinExistingGame [2] RejoinExistingGame
}, },
password UTF8String (SIZE(1..64)) OPTIONAL,
autoLeave BOOLEAN autoLeave BOOLEAN
} }
JoinExistingGame ::= SEQUENCE { JoinExistingGame ::= SEQUENCE {
gameId NonZeroId gameId NonZeroId
password UTF8String (SIZE(1..64)) OPTIONAL,
} }
JoinNewGame ::= SEQUENCE { JoinNewGame ::= SEQUENCE {
gameInfo NetGameInfo gameInfo NetGameInfo
password UTF8String (SIZE(1..64)) OPTIONAL,
} }
RejoinExistingGame ::= SEQUENCE { RejoinExistingGame ::= SEQUENCE {
+4 -1
View File
@@ -81,6 +81,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
string myGuid; string myGuid;
unsigned uniqueId = 0; unsigned uniqueId = 0;
PlayerType type = PLAYER_TYPE_COMPUTER; PlayerType type = PLAYER_TYPE_COMPUTER;
int myStartCash = startCash;
if (player_i != player_end) { if (player_i != player_end) {
uniqueId = (*player_i)->GetUniqueId(); uniqueId = (*player_i)->GetUniqueId();
@@ -88,11 +89,13 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
myName = (*player_i)->GetName(); myName = (*player_i)->GetName();
myAvatarFile = (*player_i)->GetAvatarFile(); myAvatarFile = (*player_i)->GetAvatarFile();
myGuid = (*player_i)->GetGuid(); myGuid = (*player_i)->GetGuid();
if ((*player_i)->GetStartCash() > 0)
myStartCash = (*player_i)->GetStartCash();
++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, myStartCash, startQuantityPlayers > i, 0);
tmpPlayer->setIsConnected(true); tmpPlayer->setIsConnected(true);
tmpPlayer->setMyGuid(myGuid); tmpPlayer->setMyGuid(myGuid);
+3
View File
@@ -43,6 +43,9 @@ public:
unsigned getMyUniqueID() const { unsigned getMyUniqueID() const {
return myUniqueID; return myUniqueID;
} }
void setMyUniqueID(unsigned newId) {
myUniqueID = newId;
}
void setMyGuid(const std::string &theValue) { void setMyGuid(const std::string &theValue) {
myGuid = theValue; myGuid = theValue;
@@ -54,9 +54,17 @@ ClientPlayer::getMyID() const
return myID; return myID;
} }
void
ClientPlayer::setMyUniqueID(unsigned newId)
{
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
myUniqueID = newId;
}
unsigned unsigned
ClientPlayer::getMyUniqueID() const ClientPlayer::getMyUniqueID() const
{ {
boost::recursive_mutex::scoped_lock lock(m_syncMutex);
return myUniqueID; return myUniqueID;
} }
+2 -1
View File
@@ -37,6 +37,7 @@ public:
void setHand(HandInterface *); void setHand(HandInterface *);
int getMyID() const; int getMyID() const;
void setMyUniqueID(unsigned newId);
unsigned getMyUniqueID() const; unsigned getMyUniqueID() const;
void setMyGuid(const std::string &theValue); void setMyGuid(const std::string &theValue);
std::string getMyGuid() const; std::string getMyGuid() const;
@@ -152,7 +153,7 @@ private:
// Konstanten // Konstanten
const int myID; const int myID;
const unsigned myUniqueID; unsigned myUniqueID;
std::string myGuid; std::string myGuid;
const PlayerType myType; const PlayerType myType;
std::string myName; std::string myName;
+1
View File
@@ -33,6 +33,7 @@ public:
virtual void setHand(HandInterface *) =0; virtual void setHand(HandInterface *) =0;
virtual int getMyID() const =0; virtual int getMyID() const =0;
virtual void setMyUniqueID(unsigned newId) =0;
virtual unsigned getMyUniqueID() const =0; virtual unsigned getMyUniqueID() const =0;
virtual void setMyGuid(const std::string &theValue) =0; virtual void setMyGuid(const std::string &theValue) =0;
+1 -1
View File
@@ -1536,7 +1536,7 @@ ClientStateWaitStart::InternalHandlePacket(boost::shared_ptr<ClientThread> clien
if (!tmpPlayer.get()) if (!tmpPlayer.get())
throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0); throw ClientException(__FILE__, __LINE__, ERR_NET_UNKNOWN_PLAYER_ID, 0);
tmpPlayer->SetNumber(i); tmpPlayer->SetNumber(i);
// TODO set money tmpPlayer->SetStartCash(playerData->playerMoney);
} }
} else } else
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0);
+4 -2
View File
@@ -595,8 +595,10 @@ ClientThread::InitGame()
boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen boost::shared_ptr<EngineFactory> factory(new ClientEngineFactory); // LocalEngine erstellen
MapPlayerDataList(); MapPlayerDataList();
if (GetPlayerDataList().size() != (unsigned)GetStartData().numberOfPlayers) // TODO
throw ClientException(__FILE__, __LINE__, ERR_NET_INVALID_PLAYER_COUNT, 0); //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())); m_game.reset(new Game(&m_gui, factory, GetPlayerDataList(), GetGameData(), GetStartData(), m_curGameNum++, m_clientLog.get()));
// Initialize Minimum GUI speed. // Initialize Minimum GUI speed.
int minimumGuiSpeed = 1; int minimumGuiSpeed = 1;
+7
View File
@@ -1144,6 +1144,12 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (i != end) { while (i != end) {
boost::shared_ptr<SessionData> session(server->GetSessionManager().GetSessionByUniquePlayerId(*i)); boost::shared_ptr<SessionData> session(server->GetSessionManager().GetSessionByUniquePlayerId(*i));
if (session) { if (session) {
// Set new player id.
boost::shared_ptr<PlayerInterface> rejoinPlayer = curGame.getPlayerByName(session->GetPlayerData()->GetName());
if (rejoinPlayer)
{
rejoinPlayer->setMyUniqueID(session->GetPlayerData()->GetUniqueId());
rejoinPlayer->setIsConnected(true);
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage;
GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage; GameStartMessage_t *netGameStart = &packet->GetMsg()->choice.gameStartMessage;
@@ -1168,6 +1174,7 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
server->GetLobbyThread().GetSender().Send(session, packet); server->GetLobbyThread().GetSender().Send(session, packet);
} }
}
++i; ++i;
} }
} }
+19 -5
View File
@@ -21,15 +21,15 @@
using namespace std; using namespace std;
PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type, PlayerRights rights, bool isGameAdmin) 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) 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_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_startCash(other.GetStartCash()),
m_password(), m_country(other.GetCountry()), m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_guid(other.GetGuid()), m_oldGuid(other.GetOldGuid()), m_name(other.GetName()), m_password(), m_country(other.GetCountry()),
m_type(other.GetType()), m_rights(other.GetRights()), m_isGameAdmin(other.IsGameAdmin()), m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_type(other.GetType()), m_rights(other.GetRights()),
m_netAvatarFile(), m_dataMutex() m_isGameAdmin(other.IsGameAdmin()), m_netAvatarFile(), m_dataMutex()
{ {
} }
@@ -202,6 +202,20 @@ PlayerData::SetDBId(DB_id id)
m_dbId = 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 bool
PlayerData::operator<(const PlayerData &other) const PlayerData::operator<(const PlayerData &other) const
{ {
+3
View File
@@ -98,6 +98,8 @@ public:
void SetOldGuid(const std::string &guid); void SetOldGuid(const std::string &guid);
DB_id GetDBId() const; DB_id GetDBId() const;
void SetDBId(DB_id id); void SetDBId(DB_id id);
int GetStartCash() const;
void SetStartCash(int cash);
bool operator<(const PlayerData &other) const; bool operator<(const PlayerData &other) const;
@@ -105,6 +107,7 @@ private:
const unsigned m_uniqueId; const unsigned m_uniqueId;
DB_id m_dbId; DB_id m_dbId;
int m_number; int m_number;
int m_startCash; // only used if > 0
std::string m_guid; std::string m_guid;
std::string m_oldGuid; std::string m_oldGuid;
std::string m_name; std::string m_name;