diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 16bf5019..281a6774 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,8 +42,9 @@ using namespace std; ServerGame::ServerGame(boost::shared_ptr lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) : m_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui), - m_gameData(gameData), m_curState(NULL), m_id(id), m_name(name), m_password(pwd), m_playerConfig(playerConfig), - m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()), m_stateTimer(lobbyThread->GetIOService()) + m_gameData(gameData), m_curState(NULL), m_id(id), m_dbId(DB_ID_INVALID), m_name(name), + m_password(pwd), m_playerConfig(playerConfig), m_gameNum(1), m_curPetitionId(1), + m_voteKickTimer(lobbyThread->GetIOService()), m_stateTimer(lobbyThread->GetIOService()) { LOG_VERBOSE("Game object " << GetId() << " created."); @@ -85,6 +87,18 @@ ServerGame::GetName() const return m_name; } +db_id +ServerGame::GetDBId() const +{ + return m_dbId; +} + +void +ServerGame::SetDBId(db_id newId) +{ + m_dbId = newId; +} + void ServerGame::AddSession(SessionWrapper session) { @@ -250,6 +264,7 @@ ServerGame::InternalStartGame() m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum())); GetLobbyThread().NotifyStartingGame(GetId()); + GetLobbyThread().GetDatabase().AsyncCreateGame(GetId(), GetName()); } void diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 009a77a7..cdd70527 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -122,6 +122,7 @@ public: virtual void CreateGameSuccess(unsigned requestId, db_id gameId) { + m_server.SetGameDBId((u_int32_t)requestId, gameId); } virtual void CreateGameFailed(unsigned requestId) @@ -1135,7 +1136,6 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: m_playerConfig)); game->Init(); - m_database->AsyncCreateGame(game->GetId(), game->GetName()); // Add game to list of games. InternalAddGame(game); @@ -1773,6 +1773,14 @@ ServerLobbyThread::GetCallback() return m_gui; } +void +ServerLobbyThread::SetGameDBId(u_int32_t gameId, db_id gameDBId) +{ + boost::shared_ptr game = InternalGetGameFromId(gameId); + if (game) + game->SetDBId(gameDBId); +} + ServerIrcBotCallback & ServerLobbyThread::GetIrcBotCallback() { diff --git a/src/net/servergame.h b/src/net/servergame.h index 81edce81..9d1afe89 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -50,6 +51,9 @@ public: u_int32_t GetId() const; const std::string &GetName() const; + db_id GetDBId() const; + void SetDBId(db_id newId); + void AddSession(SessionWrapper session); void RemovePlayer(unsigned playerId, unsigned errorCode); @@ -151,6 +155,7 @@ private: ServerGameState *m_curState; const u_int32_t m_id; + db_id m_dbId; const std::string m_name; const std::string m_password; ConfigFile *m_playerConfig; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index 480caeee..88136c86 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -93,6 +93,8 @@ public: u_int32_t GetNextGameId(); ServerCallback &GetCallback(); + void SetGameDBId(u_int32_t gameId, db_id gameDBId); + AvatarManager &GetAvatarManager(); ServerStats GetStats() const;