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());
|
||||
}
|
||||
|
||||
+15
-3
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <third_party/boost/timers.hpp>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
#include <net/sessionmanager.h>
|
||||
#include <db/serverdbcallback.h>
|
||||
@@ -92,12 +92,22 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
typedef std::deque<SessionWrapper> SessionQueue;
|
||||
struct RankingData
|
||||
{
|
||||
RankingData() : dbid(DB_ID_INVALID), place(0) {}
|
||||
RankingData(DB_id i, int p = 0) : dbid(i), place(p) {}
|
||||
DB_id dbid;
|
||||
int place;
|
||||
};
|
||||
|
||||
typedef std::map<unsigned, RankingData> RankingMap;
|
||||
|
||||
void TimerVoteKick(const boost::system::error_code &ec);
|
||||
|
||||
void InternalStartGame();
|
||||
void ResetGame();
|
||||
void InitRankingMap(const PlayerDataList &playerDataList);
|
||||
void SetPlayerPlace(unsigned playerId, int place);
|
||||
void InternalEndGame();
|
||||
|
||||
void InternalKickPlayer(unsigned playerId);
|
||||
void InternalAskVoteKick(SessionWrapper byWhom, unsigned playerIdWho, unsigned timeoutSec);
|
||||
@@ -153,6 +163,8 @@ private:
|
||||
PlayerIdList m_playerInvitationList;
|
||||
mutable boost::mutex m_playerInvitationListMutex;
|
||||
|
||||
RankingMap m_rankingMap;
|
||||
|
||||
unsigned m_adminPlayerId;
|
||||
|
||||
boost::shared_ptr<VoteKickData> m_voteKickData;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define _SERVERLOBBYTHREAD_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <deque>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
|
||||
#include <net/sessionmanager.h>
|
||||
@@ -113,7 +112,6 @@ public:
|
||||
protected:
|
||||
|
||||
typedef std::deque<boost::shared_ptr<boost::asio::ip::tcp::socket> > ConnectQueue;
|
||||
typedef std::deque<SessionWrapper> SessionQueue;
|
||||
typedef std::list<SessionWrapper> SessionList;
|
||||
typedef std::list<SessionId> SessionIdList;
|
||||
typedef std::map<SessionId, boost::timers::portable::microsec_timer> TimerSessionMap;
|
||||
|
||||
Reference in New Issue
Block a user