Store all players of each game in the database.
This commit is contained in:
@@ -277,12 +277,53 @@ ServerGame::InternalStartGame()
|
||||
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum()));
|
||||
|
||||
GetLobbyThread().NotifyStartingGame(GetId());
|
||||
GetDatabase().AsyncCreateGame(GetId(), GetName());
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::ResetGame()
|
||||
ServerGame::InitRankingMap(const PlayerDataList &playerDataList)
|
||||
{
|
||||
PlayerDataList::const_iterator i = playerDataList.begin();
|
||||
PlayerDataList::const_iterator end = playerDataList.end();
|
||||
while (i != end)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer(*i);
|
||||
RankingData tmpData(tmpPlayer->GetDBId());
|
||||
m_rankingMap[tmpPlayer->GetUniqueId()] = tmpData;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::SetPlayerPlace(unsigned playerId, int place)
|
||||
{
|
||||
RankingMap::iterator pos = m_rankingMap.find(playerId);
|
||||
if (pos != m_rankingMap.end())
|
||||
{
|
||||
(*pos).second.place = place;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::InternalEndGame()
|
||||
{
|
||||
// Store players in database.
|
||||
if (GetDBId() != DB_ID_INVALID)
|
||||
{
|
||||
RankingMap::const_iterator i = m_rankingMap.begin();
|
||||
RankingMap::const_iterator end = m_rankingMap.end();
|
||||
while (i != end)
|
||||
{
|
||||
if ((*i).second.dbid != DB_ID_INVALID)
|
||||
{
|
||||
GetDatabase().SetGamePlayerPlace(GetDBId(), (*i).second.dbid, (*i).second.place);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
GetDatabase().EndGame(GetDBId());
|
||||
m_game.reset();
|
||||
m_rankingMap.clear();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -655,7 +655,6 @@ ServerGameStateStartGame::DoStart(boost::shared_ptr<ServerGame> server)
|
||||
else
|
||||
{
|
||||
server->InternalStartGame();
|
||||
server->GetDatabase().AsyncCreateGame(server->GetId(), server->GetName());
|
||||
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage;
|
||||
@@ -931,15 +930,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
|
||||
}
|
||||
else if (playersWithCash.size() == 1)
|
||||
{
|
||||
// Store winner in database.
|
||||
boost::shared_ptr<PlayerInterface> winnerPlayer = *(playersWithCash.begin());
|
||||
boost::shared_ptr<PlayerData> tmpPlayer = server->GetPlayerDataByUniqueId(winnerPlayer->getMyUniqueID());
|
||||
if (tmpPlayer && server->GetDBId())
|
||||
{
|
||||
cerr << "Setting winner for game " << server->GetDBId() << " player id " << tmpPlayer->GetDBId() << endl;
|
||||
server->GetDatabase().SetGamePlayerPlace(server->GetDBId(), tmpPlayer->GetDBId(), 1);
|
||||
server->GetDatabase().EndGame(server->GetDBId());
|
||||
}
|
||||
server->SetPlayerPlace(winnerPlayer->getMyUniqueID(), 1);
|
||||
server->InternalEndGame();
|
||||
|
||||
// View a dialog for a new game - delayed.
|
||||
server->GetStateTimer().expires_from_now(
|
||||
@@ -1019,7 +1012,6 @@ ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::s
|
||||
|
||||
// Wait for the start of a new game.
|
||||
server->ResetComputerPlayerList();
|
||||
server->ResetGame();
|
||||
server->GetLobbyThread().NotifyReopeningGame(server->GetId());
|
||||
server->SetState(ServerGameStateInit::Instance());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user