Set winner before game delay.

This commit is contained in:
lotodore
2010-07-22 22:18:56 +00:00
parent 384e1e78d4
commit 3df2c28271
2 changed files with 23 additions and 40 deletions
+22 -39
View File
@@ -921,12 +921,21 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
} }
else if (playersWithCash.size() == 1) 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)
{
cerr << "Setting winner for game " << server->GetDBId() << " player id " << tmpPlayer->GetDBId() << endl;
server->GetLobbyThread().GetDatabase().SetGamePlayerPlace(server->GetDBId(), tmpPlayer->GetDBId(), 1);
}
// View a dialog for a new game - delayed. // View a dialog for a new game - delayed.
server->GetStateTimer().expires_from_now( server->GetStateTimer().expires_from_now(
boost::posix_time::seconds(SERVER_DELAY_NEXT_GAME_SEC)); boost::posix_time::seconds(SERVER_DELAY_NEXT_GAME_SEC));
server->GetStateTimer().async_wait( server->GetStateTimer().async_wait(
boost::bind( boost::bind(
&ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server)); &ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server, winnerPlayer->getMyUniqueID()));
} }
else else
{ {
@@ -986,48 +995,22 @@ ServerGameStateHand::TimerNextHand(const boost::system::error_code &ec, boost::s
} }
void void
ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server) ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server, unsigned winnerPlayerId)
{ {
if (!ec && &server->GetState() == this) if (!ec && &server->GetState() == this)
{ {
// The game has ended. Notify all clients. boost::shared_ptr<NetPacket> endGame(new NetPacket(NetPacket::Alloc));
boost::shared_ptr<PlayerInterface> winnerPlayer; endGame->GetMsg()->present = PokerTHMessage_PR_endOfGameMessage;
PlayerListIterator i = server->GetGame().getActivePlayerList()->begin(); EndOfGameMessage_t *netEndGame = &endGame->GetMsg()->choice.endOfGameMessage;
PlayerListIterator end = server->GetGame().getActivePlayerList()->end(); netEndGame->gameId = server->GetId();
while (i != end) netEndGame->winnerPlayerId = winnerPlayerId;
{ server->SendToAllPlayers(endGame, SessionData::Game);
winnerPlayer = *i;
if (winnerPlayer->getMyCash() > 0)
break;
++i;
}
if (winnerPlayer) // Wait for the start of a new game.
{ server->ResetComputerPlayerList();
boost::shared_ptr<NetPacket> endGame(new NetPacket(NetPacket::Alloc)); server->ResetGame();
endGame->GetMsg()->present = PokerTHMessage_PR_endOfGameMessage; server->GetLobbyThread().NotifyReopeningGame(server->GetId());
EndOfGameMessage_t *netEndGame = &endGame->GetMsg()->choice.endOfGameMessage; server->SetState(ServerGameStateInit::Instance());
netEndGame->gameId = server->GetId();
netEndGame->winnerPlayerId = winnerPlayer->getMyUniqueID();
server->SendToAllPlayers(endGame, SessionData::Game);
// Set winner in database.
boost::shared_ptr<PlayerData> tmpPlayer = server->GetPlayerDataByUniqueId(winnerPlayer->getMyUniqueID());
cerr << "Setting winner for game " << server->GetDBId() << " player id " << tmpPlayer->GetDBId() << endl;
if (tmpPlayer)
server->GetLobbyThread().GetDatabase().SetGamePlayerPlace(server->GetDBId(), tmpPlayer->GetDBId(), 1);
// Wait for the start of a new game.
server->ResetComputerPlayerList();
server->ResetGame();
server->GetLobbyThread().NotifyReopeningGame(server->GetId());
server->SetState(ServerGameStateInit::Instance());
}
else
{
LOG_ERROR("Game " << server->GetId() << " - Has no winner!");
server->RemoveAllSessions(); // This is fatal, close this game.
}
} }
} }
+1 -1
View File
@@ -145,7 +145,7 @@ protected:
void TimerShowCards(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server); void TimerShowCards(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server); void TimerComputerAction(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void TimerNextHand(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server); void TimerNextHand(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server);
void TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server); void TimerNextGame(const boost::system::error_code &ec, boost::shared_ptr<ServerGame> server, unsigned winnerPlayerId);
int GetDealCardsDelaySec(ServerGame &server); int GetDealCardsDelaySec(ServerGame &server);
static void StartNewHand(boost::shared_ptr<ServerGame> server); static void StartNewHand(boost::shared_ptr<ServerGame> server);