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/receiverhelper.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
#include <core/loghelper.h>
|
#include <core/loghelper.h>
|
||||||
|
#include <db/serverdbinterface.h>
|
||||||
#include <game.h>
|
#include <game.h>
|
||||||
#include <localenginefactory.h>
|
#include <localenginefactory.h>
|
||||||
#include <tools.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)
|
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_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_gameData(gameData), m_curState(NULL), m_id(id), m_dbId(DB_ID_INVALID), m_name(name),
|
||||||
m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()), m_stateTimer(lobbyThread->GetIOService())
|
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.");
|
LOG_VERBOSE("Game object " << GetId() << " created.");
|
||||||
|
|
||||||
@@ -85,6 +87,18 @@ ServerGame::GetName() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db_id
|
||||||
|
ServerGame::GetDBId() const
|
||||||
|
{
|
||||||
|
return m_dbId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerGame::SetDBId(db_id newId)
|
||||||
|
{
|
||||||
|
m_dbId = newId;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerGame::AddSession(SessionWrapper session)
|
ServerGame::AddSession(SessionWrapper session)
|
||||||
{
|
{
|
||||||
@@ -250,6 +264,7 @@ ServerGame::InternalStartGame()
|
|||||||
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum()));
|
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum()));
|
||||||
|
|
||||||
GetLobbyThread().NotifyStartingGame(GetId());
|
GetLobbyThread().NotifyStartingGame(GetId());
|
||||||
|
GetLobbyThread().GetDatabase().AsyncCreateGame(GetId(), GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ public:
|
|||||||
|
|
||||||
virtual void CreateGameSuccess(unsigned requestId, db_id gameId)
|
virtual void CreateGameSuccess(unsigned requestId, db_id gameId)
|
||||||
{
|
{
|
||||||
|
m_server.SetGameDBId((u_int32_t)requestId, gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void CreateGameFailed(unsigned requestId)
|
virtual void CreateGameFailed(unsigned requestId)
|
||||||
@@ -1135,7 +1136,6 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
|
|||||||
m_playerConfig));
|
m_playerConfig));
|
||||||
game->Init();
|
game->Init();
|
||||||
|
|
||||||
m_database->AsyncCreateGame(game->GetId(), game->GetName());
|
|
||||||
// Add game to list of games.
|
// Add game to list of games.
|
||||||
InternalAddGame(game);
|
InternalAddGame(game);
|
||||||
|
|
||||||
@@ -1773,6 +1773,14 @@ ServerLobbyThread::GetCallback()
|
|||||||
return m_gui;
|
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 &
|
ServerIrcBotCallback &
|
||||||
ServerLobbyThread::GetIrcBotCallback()
|
ServerLobbyThread::GetIrcBotCallback()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
#include <net/sessionmanager.h>
|
#include <net/sessionmanager.h>
|
||||||
|
#include <db/serverdbcallback.h>
|
||||||
#include <gui/guiinterface.h>
|
#include <gui/guiinterface.h>
|
||||||
#include <gamedata.h>
|
#include <gamedata.h>
|
||||||
|
|
||||||
@@ -50,6 +51,9 @@ public:
|
|||||||
u_int32_t GetId() const;
|
u_int32_t GetId() const;
|
||||||
const std::string &GetName() const;
|
const std::string &GetName() const;
|
||||||
|
|
||||||
|
db_id GetDBId() const;
|
||||||
|
void SetDBId(db_id newId);
|
||||||
|
|
||||||
void AddSession(SessionWrapper session);
|
void AddSession(SessionWrapper session);
|
||||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||||
|
|
||||||
@@ -151,6 +155,7 @@ private:
|
|||||||
ServerGameState *m_curState;
|
ServerGameState *m_curState;
|
||||||
|
|
||||||
const u_int32_t m_id;
|
const u_int32_t m_id;
|
||||||
|
db_id m_dbId;
|
||||||
const std::string m_name;
|
const std::string m_name;
|
||||||
const std::string m_password;
|
const std::string m_password;
|
||||||
ConfigFile *m_playerConfig;
|
ConfigFile *m_playerConfig;
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ public:
|
|||||||
u_int32_t GetNextGameId();
|
u_int32_t GetNextGameId();
|
||||||
ServerCallback &GetCallback();
|
ServerCallback &GetCallback();
|
||||||
|
|
||||||
|
void SetGameDBId(u_int32_t gameId, db_id gameDBId);
|
||||||
|
|
||||||
AvatarManager &GetAvatarManager();
|
AvatarManager &GetAvatarManager();
|
||||||
|
|
||||||
ServerStats GetStats() const;
|
ServerStats GetStats() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user