From 4a10d6188c7ffb08f6c054ac84316c56564cba05 Mon Sep 17 00:00:00 2001 From: lotodore Date: Tue, 8 May 2007 06:45:46 +0000 Subject: [PATCH] Fixed player counting bug. Fixed player number. Joining/leaving network game should work now. Added player type to localplayer. --- src/engine/enginefactory.h | 2 +- .../local_engine/localenginefactory.cpp | 2 +- src/engine/local_engine/localenginefactory.h | 2 +- src/engine/local_engine/localplayer.cpp | 3 +- src/engine/local_engine/localplayer.h | 10 +- src/engine/local_engine/localpreflop.cpp | 2 +- src/engine/playerinterface.h | 4 +- src/game.cpp | 6 +- src/net/common/serverrecvstate.cpp | 10 +- src/net/common/serverrecvthread.cpp | 326 ++++++++++-------- src/net/serverrecvthread.h | 19 +- src/playerdata.cpp | 4 +- src/playerdata.h | 7 +- src/session.cpp | 2 +- 14 files changed, 216 insertions(+), 183 deletions(-) diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index ba17019a..7d928bcb 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -36,7 +36,7 @@ public: virtual HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) =0; virtual BoardInterface* createBoard() =0; - virtual PlayerInterface* createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) =0; + virtual PlayerInterface* createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0; virtual PreflopInterface* createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) =0; virtual FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB) =0; virtual TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB) =0; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index b903dfc6..df057ecb 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -35,7 +35,7 @@ HandInterface* LocalEngineFactory::createHand(EngineFactory *f, GuiInterface *g, BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } -PlayerInterface* LocalEngineFactory::createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(b, id, name, avatar, sC, aS, mB); } +PlayerInterface* LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(b, id, uniqueId, type, name, avatar, sC, aS, mB); } PreflopInterface* LocalEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) { return new LocalPreflop(hi, id, aP, dP, sB); } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 885ce2b4..8caf13ab 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -39,7 +39,7 @@ public: HandInterface* createHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC); BoardInterface* createBoard(); - PlayerInterface* createPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB); + PlayerInterface* createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); PreflopInterface* createPreflop(HandInterface* hi, int id, int aP, int dP, int sB); FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index dea654b6..1339593e 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -23,7 +23,8 @@ using namespace std; -LocalPlayer::LocalPlayer(BoardInterface *b, int id, std::string name, std::string avatar, int sC, bool aS, int mB) : PlayerInterface(), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) +LocalPlayer::LocalPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) +: PlayerInterface(), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) { // for statistic development diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 0e4a18c3..e5549f7d 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -36,14 +36,16 @@ class BoardInterface; class LocalPlayer : public PlayerInterface{ public: - LocalPlayer(BoardInterface*, int, std::string, std::string, int, bool, int); + LocalPlayer( + BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); - ~LocalPlayer(); + ~LocalPlayer(); void setHand(HandInterface*); - void setMyID(const int& theValue) { myID = theValue; } int getMyID() const { return myID; } + unsigned getMyUniqueID() const { return myUniqueID; } + PlayerType getMyType() const { return myType; } void setMyDude(const int& theValue) { myDude = theValue; } int getMyDude() const { return myDude; } @@ -147,6 +149,8 @@ private: // Konstanten int myID; + unsigned myUniqueID; + PlayerType myType; std::string myName; std::string myAvatar; int myDude; diff --git a/src/engine/local_engine/localpreflop.cpp b/src/engine/local_engine/localpreflop.cpp index 83a353a4..6467908d 100755 --- a/src/engine/local_engine/localpreflop.cpp +++ b/src/engine/local_engine/localpreflop.cpp @@ -95,7 +95,7 @@ void LocalPreflop::preflopRun() { else { // Preflop ist wirklich dran - // n�hsten Spieler ermitteln + // naechsten Spieler ermitteln do { playersTurn = (playersTurn+1)%(MAX_NUMBER_OF_PLAYERS); diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index 3ba9edef..c035577c 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -21,6 +21,7 @@ #define PLAYERINTERFACE_H #include "handinterface.h" +#include class PlayerInterface{ public: @@ -29,8 +30,9 @@ public: virtual void setHand(HandInterface*) =0; - virtual void setMyID(const int& theValue) =0; virtual int getMyID() const =0; + virtual unsigned getMyUniqueID() const =0; + virtual PlayerType getMyType() const =0; virtual void setMyDude(const int& theValue) =0; virtual int getMyDude() const =0; diff --git a/src/game.cpp b/src/game.cpp index 486a8a92..2094f90d 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -65,9 +65,13 @@ Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameDa string myName; string myAvatarFile; + unsigned uniqueId = 0; + PlayerType type = PLAYER_TYPE_COMPUTER; if (player_i != player_end) { + uniqueId = (*player_i)->GetUniqueId(); + type = (*player_i)->GetType(); myName = (*player_i)->GetName(); myAvatarFile = (*player_i)->GetAvatarFile(); // TODO: set player type @@ -75,7 +79,7 @@ Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameDa } //PlayerObjekte erzeugen - playerArray[i] = myFactory->createPlayer(actualBoard, i, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); + playerArray[i] = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); } actualBoard->setPlayer(playerArray); diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index d8f9d89b..8c489d60 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -96,7 +96,6 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (session->GetState() != SessionData::Init) { server.SessionError(session, ERR_SOCK_INVALID_STATE); - server.CloseSessionDelayed(session); return retVal; } @@ -105,7 +104,6 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (!tmpPacket) { server.SessionError(session, ERR_SOCK_INVALID_PACKET); - server.CloseSessionDelayed(session); return retVal; } @@ -116,7 +114,6 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (joinGameData.versionMajor != NET_VERSION_MAJOR) { server.SessionError(session, ERR_NET_VERSION_NOT_SUPPORTED); - server.CloseSessionDelayed(session); return retVal; } @@ -124,7 +121,6 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (!server.CheckPassword(joinGameData.password)) { server.SessionError(session, ERR_NET_INVALID_PASSWORD); - server.CloseSessionDelayed(session); return retVal; } @@ -134,7 +130,6 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (curNumPlayers >= (size_t)server.GetGameData().numberOfPlayers) { server.SessionError(session, ERR_NET_SERVER_FULL); - server.CloseSessionDelayed(session); return retVal; } @@ -142,14 +137,13 @@ ServerRecvStateInit::Process(ServerRecvThread &server) if (server.IsPlayerConnected(joinGameData.playerName)) { server.SessionError(session, ERR_NET_PLAYER_NAME_IN_USE); - server.CloseSessionDelayed(session); return retVal; } // Create player data object. - boost::shared_ptr tmpPlayerData(new PlayerData(m_curUniquePlayerId++, 0)); + boost::shared_ptr tmpPlayerData( + new PlayerData(m_curUniquePlayerId++, server.GetNextPlayerNumber(), joinGameData.ptype)); tmpPlayerData->SetName(joinGameData.playerName); - tmpPlayerData->SetPlayerType(joinGameData.ptype); // Send ACK to client. boost::shared_ptr answer(new NetPacketJoinGameAck); diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index 1eae433b..4e404fcd 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -26,6 +26,8 @@ #include #include +#include + #define SERVER_CLOSE_SESSION_DELAY_SEC 10 using namespace std; @@ -70,79 +72,6 @@ ServerRecvThread::Init(const string &pwd, const GameData &gameData) *m_gameData = gameData; } -void -ServerRecvThread::SendError(SOCKET s, int errorCode) -{ - boost::shared_ptr packet(new NetPacketError); - NetPacketError::Data errorData; - errorData.errorCode = errorCode; - static_cast(packet.get())->SetData(errorData); - GetSender().Send(s, packet); -} - -void -ServerRecvThread::SendToAllPlayers(boost::shared_ptr packet) -{ - // This function needs to be thread safe. - boost::mutex::scoped_lock lock(m_sessionMapMutex); - - SocketSessionMap::iterator i = m_sessionMap.begin(); - SocketSessionMap::iterator end = m_sessionMap.end(); - - while (i != end) - { - // Send each client a copy of the packet. - GetSender().Send(i->first, boost::shared_ptr(packet->Clone())); - ++i; - } -} - -void -ServerRecvThread::SendToAllButOnePlayers(boost::shared_ptr packet, SOCKET except) -{ - // This function needs to be thread safe. - boost::mutex::scoped_lock lock(m_sessionMapMutex); - - SocketSessionMap::iterator i = m_sessionMap.begin(); - SocketSessionMap::iterator end = m_sessionMap.end(); - - while (i != end) - { - // Send each client but one a copy of the packet. - if (i->first != except) - GetSender().Send(i->first, boost::shared_ptr(packet->Clone())); - ++i; - } -} - -void -ServerRecvThread::CloseSessionDelayed(boost::shared_ptr sessionData) -{ - { - boost::mutex::scoped_lock lock(m_sessionMapMutex); - - m_sessionMap.erase(sessionData->GetSocket()); - } - - boost::shared_ptr tmpPlayerData = sessionData->GetPlayerData(); - if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) - { - GetCallback().SignalNetServerPlayerLeft(tmpPlayerData->GetName()); - - // Send "Player Left" to clients. - boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); - NetPacketPlayerLeft::Data thisPlayerLeftData; - thisPlayerLeftData.playerId = tmpPlayerData->GetUniqueId(); - static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); - SendToAllPlayers(thisPlayerLeft); - } - - boost::microsec_timer closeTimer; - closeTimer.start(); - CloseSessionList::value_type closeSessionData(closeTimer, sessionData); - m_closeSessionList.push_back(closeSessionData); -} - void ServerRecvThread::AddConnection(boost::shared_ptr data) { @@ -157,12 +86,6 @@ ServerRecvThread::AddNotification(unsigned notification) m_notificationQueue.push_back(notification); } -ServerCallback & -ServerRecvThread::GetCallback() -{ - return m_callback; -} - void ServerRecvThread::Main() { @@ -318,19 +241,6 @@ ServerRecvThread::CleanupSessionMap() m_sessionMap.clear(); } -ServerRecvState & -ServerRecvThread::GetState() -{ - assert(m_curState); - return *m_curState; -} - -void -ServerRecvThread::SetState(ServerRecvState &newState) -{ - m_curState = &newState; -} - boost::shared_ptr ServerRecvThread::GetSession(SOCKET sock) { @@ -366,6 +276,180 @@ ServerRecvThread::SessionError(boost::shared_ptr sessionData, int e { assert(sessionData.get()); SendError(sessionData->GetSocket(), errorCode); + CloseSessionDelayed(sessionData); +} + +void +ServerRecvThread::CloseSessionDelayed(boost::shared_ptr sessionData) +{ + { + boost::mutex::scoped_lock lock(m_sessionMapMutex); + + m_sessionMap.erase(sessionData->GetSocket()); + } + + boost::shared_ptr tmpPlayerData = sessionData->GetPlayerData(); + if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) + { + GetCallback().SignalNetServerPlayerLeft(tmpPlayerData->GetName()); + + // Send "Player Left" to clients. + boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); + NetPacketPlayerLeft::Data thisPlayerLeftData; + thisPlayerLeftData.playerId = tmpPlayerData->GetUniqueId(); + static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); + SendToAllPlayers(thisPlayerLeft); + } + + boost::microsec_timer closeTimer; + closeTimer.start(); + CloseSessionList::value_type closeSessionData(closeTimer, sessionData); + m_closeSessionList.push_back(closeSessionData); +} + +size_t +ServerRecvThread::GetCurNumberOfPlayers() const +{ + PlayerDataList playerList = GetPlayerDataList(); + return playerList.size(); +} + +bool +ServerRecvThread::IsPlayerConnected(const std::string &playerName) const +{ + bool retVal = false; + PlayerDataList playerList = GetPlayerDataList(); + + PlayerDataList::const_iterator player_i = playerList.begin(); + PlayerDataList::const_iterator player_end = playerList.end(); + + while (player_i != player_end) + { + if ((*player_i)->GetName() == playerName) + { + retVal = true; + break; + } + + ++player_i; + } + return retVal; +} + +void +ServerRecvThread::SetSessionPlayerData(boost::shared_ptr sessionData, boost::shared_ptr playerData) +{ + sessionData->SetPlayerData(playerData); + // Signal joining player to GUI. + if (playerData.get() && !playerData->GetName().empty()) + GetCallback().SignalNetServerPlayerJoined(playerData->GetName()); +} + +PlayerDataList +ServerRecvThread::GetPlayerDataList() const +{ + PlayerDataList playerList; + boost::mutex::scoped_lock lock(m_sessionMapMutex); + + SocketSessionMap::const_iterator session_i = m_sessionMap.begin(); + SocketSessionMap::const_iterator session_end = m_sessionMap.end(); + + while (session_i != session_end) + { + boost::shared_ptr tmpPlayer(session_i->second->GetPlayerData()); + if (tmpPlayer.get() && !tmpPlayer->GetName().empty()) + playerList.push_back(tmpPlayer); + ++session_i; + } + // Sort the list by player number. + playerList.sort(*boost::lambda::_1 < *boost::lambda::_2); + return playerList; +} + +int +ServerRecvThread::GetNextPlayerNumber() const +{ + int playerNumber = 0; + + PlayerDataList playerList = GetPlayerDataList(); + PlayerDataList::const_iterator player_i = playerList.begin(); + PlayerDataList::const_iterator player_end = playerList.end(); + + // Assume the player list is sorted by player number. + while (player_i != player_end) + { + if ((*player_i)->GetNumber() == playerNumber) + playerNumber++; + else + break; + ++player_i; + } + + return playerNumber; +} + +void +ServerRecvThread::SendError(SOCKET s, int errorCode) +{ + boost::shared_ptr packet(new NetPacketError); + NetPacketError::Data errorData; + errorData.errorCode = errorCode; + static_cast(packet.get())->SetData(errorData); + GetSender().Send(s, packet); +} + +void +ServerRecvThread::SendToAllPlayers(boost::shared_ptr packet) +{ + // This function needs to be thread safe. + boost::mutex::scoped_lock lock(m_sessionMapMutex); + + SocketSessionMap::iterator i = m_sessionMap.begin(); + SocketSessionMap::iterator end = m_sessionMap.end(); + + while (i != end) + { + // Send each client a copy of the packet. + GetSender().Send(i->first, boost::shared_ptr(packet->Clone())); + ++i; + } +} + +void +ServerRecvThread::SendToAllButOnePlayers(boost::shared_ptr packet, SOCKET except) +{ + // This function needs to be thread safe. + boost::mutex::scoped_lock lock(m_sessionMapMutex); + + SocketSessionMap::iterator i = m_sessionMap.begin(); + SocketSessionMap::iterator end = m_sessionMap.end(); + + while (i != end) + { + // Send each client but one a copy of the packet. + if (i->first != except) + GetSender().Send(i->first, boost::shared_ptr(packet->Clone())); + ++i; + } +} + +ServerCallback & +ServerRecvThread::GetCallback() +{ + return m_callback; +} + +ServerRecvState & +ServerRecvThread::GetState() +{ + assert(m_curState); + return *m_curState; +} + +void +ServerRecvThread::SetState(ServerRecvState &newState) +{ + m_curState = &newState; } SenderThread & @@ -395,64 +479,6 @@ ServerRecvThread::CheckPassword(const std::string &password) const return (password == m_password); } -size_t -ServerRecvThread::GetCurNumberOfPlayers() const -{ - boost::mutex::scoped_lock lock(m_sessionMapMutex); - return m_sessionMap.size(); -} - -bool -ServerRecvThread::IsPlayerConnected(const std::string &playerName) const -{ - bool retVal = false; - boost::mutex::scoped_lock lock(m_sessionMapMutex); - - SocketSessionMap::const_iterator session_i = m_sessionMap.begin(); - SocketSessionMap::const_iterator session_end = m_sessionMap.end(); - - while (session_i != session_end) - { - const boost::shared_ptr tmpPlayerData = session_i->second->GetPlayerData(); - if (tmpPlayerData.get() && tmpPlayerData->GetName() == playerName) - { - retVal = true; - break; - } - - ++session_i; - } - return retVal; -} - -void -ServerRecvThread::SetSessionPlayerData(boost::shared_ptr sessionData, boost::shared_ptr playerData) -{ - boost::mutex::scoped_lock lock(m_sessionMapMutex); // Paranoia - sessionData->SetPlayerData(playerData); - // Signal joining player to GUI. - GetCallback().SignalNetServerPlayerJoined(playerData->GetName()); -} - -PlayerDataList -ServerRecvThread::GetPlayerDataList() const -{ - PlayerDataList playerList; - boost::mutex::scoped_lock lock(m_sessionMapMutex); - - SocketSessionMap::const_iterator session_i = m_sessionMap.begin(); - SocketSessionMap::const_iterator session_end = m_sessionMap.end(); - - while (session_i != session_end) - { - boost::shared_ptr tmpPlayer(session_i->second->GetPlayerData()); - if (tmpPlayer.get() && !tmpPlayer->GetName().empty()) - playerList.push_back(tmpPlayer); - ++session_i; - } - return playerList; -} - ServerSenderCallback & ServerRecvThread::GetSenderCallback() { diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index 6991ec69..23c76391 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -76,18 +76,24 @@ protected: void CleanupConnectQueue(); void CleanupSessionMap(); - ServerRecvState &GetState(); - void SetState(ServerRecvState &newState); - boost::shared_ptr GetSession(SOCKET sock); void AddSession(boost::shared_ptr sessionData); void SessionError(boost::shared_ptr sessionData, int errorCode); + void CloseSessionDelayed(boost::shared_ptr sessionData); + + size_t GetCurNumberOfPlayers() const; + bool IsPlayerConnected(const std::string &playerName) const; + void SetSessionPlayerData(boost::shared_ptr sessionData, boost::shared_ptr playerData); + PlayerDataList GetPlayerDataList() const; + + int GetNextPlayerNumber() const; void SendError(SOCKET s, int errorCode); void SendToAllPlayers(boost::shared_ptr packet); void SendToAllButOnePlayers(boost::shared_ptr packet, SOCKET except); - void CloseSessionDelayed(boost::shared_ptr sessionData); + ServerRecvState &GetState(); + void SetState(ServerRecvState &newState); SenderThread &GetSender(); ReceiverHelper &GetReceiver(); @@ -95,11 +101,6 @@ protected: const GameData &GetGameData() const; bool CheckPassword(const std::string &password) const; - size_t GetCurNumberOfPlayers() const; - bool IsPlayerConnected(const std::string &playerName) const; - void SetSessionPlayerData(boost::shared_ptr sessionData, boost::shared_ptr playerData); - PlayerDataList GetPlayerDataList() const; - ServerSenderCallback &GetSenderCallback(); private: diff --git a/src/playerdata.cpp b/src/playerdata.cpp index 575dc8fc..6d3ad608 100644 --- a/src/playerdata.cpp +++ b/src/playerdata.cpp @@ -19,8 +19,8 @@ #include -PlayerData::PlayerData(unsigned uniqueId, int number) -: m_uniqueId(uniqueId), m_number(number), m_type(PLAYER_TYPE_COMPUTER) +PlayerData::PlayerData(unsigned uniqueId, int number, PlayerType type) +: m_uniqueId(uniqueId), m_number(number), m_type(type) { } diff --git a/src/playerdata.h b/src/playerdata.h index a6e38067..15d2ef06 100644 --- a/src/playerdata.h +++ b/src/playerdata.h @@ -35,7 +35,7 @@ enum PlayerType class PlayerData { public: - PlayerData(unsigned uniqueId, int number); + PlayerData(unsigned uniqueId, int number, PlayerType type); ~PlayerData(); const std::string &GetName() const @@ -48,13 +48,14 @@ public: {m_avatarFile = avatarFile;} PlayerType GetType() const {return m_type;} - void SetPlayerType(PlayerType type) - {m_type = type;} unsigned GetUniqueId() const {return m_uniqueId;} int GetNumber() const {return m_number;} + bool operator<(const PlayerData &other) + {return m_number < other.GetNumber();} + private: unsigned m_uniqueId; int m_number; diff --git a/src/session.cpp b/src/session.cpp index b3106d8f..1a1dea61 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -69,7 +69,7 @@ void Session::startGame(const GameData &gameData) { //PlayerData erzeugen // TODO: PlayerType setzen // UniqueId = PlayerNumber for local games. - boost::shared_ptr playerData(new PlayerData(i, i)); + boost::shared_ptr playerData(new PlayerData(i, i, i == 0 ? PLAYER_TYPE_HUMAN : PLAYER_TYPE_COMPUTER)); playerData->SetName(myConfig->readConfigString(myName.str())); playerData->SetAvatarFile(myConfig->readConfigString(myAvatar.str()));