From e0f119396356b076872cfc1d3c5aca10380af4db Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 25 Oct 2007 21:59:06 +0000 Subject: [PATCH] Clarified initialization order to prevent possible race condition when initializing a new game. --- src/net/common/servergamethread.cpp | 11 +++-------- src/net/common/serverlobbythread.cpp | 2 +- src/net/servergamethread.h | 6 ++---- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index 217cc1fe..9b9e12aa 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -52,9 +52,10 @@ private: }; -ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) +ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) : m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id), - m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1) + m_name(name), m_password(pwd), m_gameData(gameData), m_playerConfig(playerConfig), + m_curState(NULL), m_gameNum(1) { m_senderCallback.reset(new ServerSenderCallback(*this)); m_sender.reset(new SenderThread(GetSenderCallback())); @@ -65,12 +66,6 @@ ServerGameThread::~ServerGameThread() { } -void -ServerGameThread::Init(const GameData &gameData) -{ - m_gameData = gameData; -} - u_int32_t ServerGameThread::GetId() const { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 677847d4..d1bff883 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -588,10 +588,10 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const NetPa GetNextGameId(), createGameData.gameName, createGameData.password, + createGameData.gameData, session.playerData->GetUniqueId(), GetGui(), m_playerConfig)); - game->Init(createGameData.gameData); MoveSessionToGame(*game, session); diff --git a/src/net/servergamethread.h b/src/net/servergamethread.h index b3e839f6..ec0fecfe 100644 --- a/src/net/servergamethread.h +++ b/src/net/servergamethread.h @@ -43,11 +43,9 @@ class ServerGameThread : public Thread { public: ServerGameThread( - ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig); + ServerLobbyThread &lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig); virtual ~ServerGameThread(); - void Init(const GameData &gameData); - u_int32_t GetId() const; const std::string &GetName() const; @@ -140,7 +138,7 @@ private: std::auto_ptr m_senderCallback; GuiInterface &m_gui; - GameData m_gameData; + const GameData m_gameData; StartData m_startData; boost::shared_ptr m_game; const u_int32_t m_id;