Clarified initialization order to prevent possible race condition when initializing a new game.
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<ServerSenderCallback> m_senderCallback;
|
||||
GuiInterface &m_gui;
|
||||
|
||||
GameData m_gameData;
|
||||
const GameData m_gameData;
|
||||
StartData m_startData;
|
||||
boost::shared_ptr<Game> m_game;
|
||||
const u_int32_t m_id;
|
||||
|
||||
Reference in New Issue
Block a user