Game database entry is created only once the game is started.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <net/receiverhelper.h>
|
||||
#include <net/socket_msg.h>
|
||||
#include <core/loghelper.h>
|
||||
#include <db/serverdbinterface.h>
|
||||
#include <game.h>
|
||||
#include <localenginefactory.h>
|
||||
#include <tools.h>
|
||||
@@ -41,8 +42,9 @@ using namespace std;
|
||||
|
||||
ServerGame::ServerGame(boost::shared_ptr<ServerLobbyThread> 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
|
||||
|
||||
@@ -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<ServerGame> game = InternalGetGameFromId(gameId);
|
||||
if (game)
|
||||
game->SetDBId(gameDBId);
|
||||
}
|
||||
|
||||
ServerIrcBotCallback &
|
||||
ServerLobbyThread::GetIrcBotCallback()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <deque>
|
||||
|
||||
#include <net/sessionmanager.h>
|
||||
#include <db/serverdbcallback.h>
|
||||
#include <gui/guiinterface.h>
|
||||
#include <gamedata.h>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user