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
+4 -1
View File
@@ -81,6 +81,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> 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<EngineFactory> 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<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->setMyGuid(myGuid);
+3
View File
@@ -43,6 +43,9 @@ public:
unsigned getMyUniqueID() const {
return myUniqueID;
}
void setMyUniqueID(unsigned newId) {
myUniqueID = newId;
}
void setMyGuid(const std::string &theValue) {
myGuid = theValue;
@@ -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;
}
+2 -1
View File
@@ -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;
+1
View File
@@ -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;
+1 -1
View File
@@ -1536,7 +1536,7 @@ ClientStateWaitStart::InternalHandlePacket(boost::shared_ptr<ClientThread> 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);
+4 -2
View File
@@ -595,8 +595,10 @@ ClientThread::InitGame()
boost::shared_ptr<EngineFactory> 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;
+27 -20
View File
@@ -1144,29 +1144,36 @@ ServerGameStateHand::StartNewHand(boost::shared_ptr<ServerGame> server)
while (i != end) {
boost::shared_ptr<SessionData> session(server->GetSessionManager().GetSessionByUniquePlayerId(*i));
if (session) {
boost::shared_ptr<NetPacket> 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<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));
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<PlayerInterface> 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<PlayerInterface> 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;
}
+19 -5
View File
@@ -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
{
+3
View File
@@ -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;