Implementing ticket #2 - optionally remove players from games after it was finished. This breaks protocol compatibility with 0.8. Config file option is NetAutoLeaveGameAfterFinish.

This commit is contained in:
lotodore
2011-02-06 13:17:07 +00:00
parent 851528f290
commit e823b7b788
73 changed files with 318 additions and 242 deletions
+6 -3
View File
@@ -231,13 +231,14 @@ ClientThread::SendPrivateChatMessage(unsigned targetPlayerId, const std::string
}
void
ClientThread::SendJoinFirstGame(const std::string &password)
ClientThread::SendJoinFirstGame(const std::string &password, bool autoLeave)
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet to request joining a game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage;
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage;
netJoinGame->autoLeave = autoLeave;
if (!password.empty())
{
netJoinGame->password = OCTET_STRING_new_fromBuf(
@@ -253,13 +254,14 @@ ClientThread::SendJoinFirstGame(const std::string &password)
}
void
ClientThread::SendJoinGame(unsigned gameId, const std::string &password)
ClientThread::SendJoinGame(unsigned gameId, const std::string &password, bool autoLeave)
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet to request joining a game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage;
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage;
netJoinGame->autoLeave = autoLeave;
if (!password.empty())
{
netJoinGame->password = OCTET_STRING_new_fromBuf(
@@ -275,13 +277,14 @@ ClientThread::SendJoinGame(unsigned gameId, const std::string &password)
}
void
ClientThread::SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password)
ClientThread::SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password, bool autoLeave)
{
// Warning: This function is called in the context of the GUI thread.
// Create a network packet to request creating a new game.
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_joinGameRequestMessage;
JoinGameRequestMessage_t *netJoinGame = &packet->GetMsg()->choice.joinGameRequestMessage;
netJoinGame->autoLeave = autoLeave;
if (!password.empty())
{
netJoinGame->password = OCTET_STRING_new_fromBuf(
+44 -16
View File
@@ -369,7 +369,7 @@ ServerGame::SetPlayerPlace(unsigned playerId, int place)
}
void
ServerGame::InternalEndGame()
ServerGame::StoreAndResetRanking()
{
// Store players in database.
if (GetDBId() != DB_ID_INVALID)
@@ -386,10 +386,33 @@ ServerGame::InternalEndGame()
}
}
GetDatabase().EndGame(GetDBId());
m_game.reset();
m_rankingMap.clear();
}
void
ServerGame::RemoveAutoLeavePlayers()
{
boost::mutex::scoped_lock lock(m_autoLeavePlayerListMutex);
PlayerIdList::const_iterator i = m_autoLeavePlayerList.begin();
PlayerIdList::const_iterator end = m_autoLeavePlayerList.end();
while (i != end)
{
SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(*i);
// Only remove if the player was found.
if (tmpSession.sessionData.get())
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_ON_REQUEST);
++i;
}
m_autoLeavePlayerList.clear();
}
void
ServerGame::InternalEndGame()
{
StoreAndResetRanking();
m_game.reset();
}
void
ServerGame::InternalKickPlayer(unsigned playerId)
{
@@ -646,21 +669,10 @@ ServerGame::IsPlayerInvited(unsigned playerId) const
}
void
ServerGame::AddReportedAvatar(unsigned playerId)
ServerGame::SetPlayerAutoLeaveOnFinish(unsigned playerId)
{
boost::mutex::scoped_lock lock(m_reportedAvatarListMutex);
m_reportedAvatarList.push_back(playerId);
}
bool
ServerGame::IsAvatarReported(unsigned playerId) const
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_reportedAvatarListMutex);
PlayerIdList::const_iterator pos = find(m_reportedAvatarList.begin(), m_reportedAvatarList.end(), playerId);
if (pos != m_reportedAvatarList.end())
retVal = true;
return retVal;
boost::mutex::scoped_lock lock(m_autoLeavePlayerListMutex);
m_autoLeavePlayerList.push_back(playerId);
}
void
@@ -884,6 +896,22 @@ ServerGame::IsValidPlayer(unsigned playerId) const
return retVal;
}
void
ServerGame::AddReportedAvatar(unsigned playerId)
{
m_reportedAvatarList.push_back(playerId);
}
bool
ServerGame::IsAvatarReported(unsigned playerId) const
{
bool retVal = false;
PlayerIdList::const_iterator pos = find(m_reportedAvatarList.begin(), m_reportedAvatarList.end(), playerId);
if (pos != m_reportedAvatarList.end())
retVal = true;
return retVal;
}
SessionManager &
ServerGame::GetSessionManager()
{
+1
View File
@@ -1128,6 +1128,7 @@ ServerGameStateHand::TimerNextGame(const boost::system::error_code &ec, boost::s
server->SendToAllPlayers(endGame, SessionData::Game);
// Wait for the start of a new game.
server->RemoveAutoLeavePlayers();
server->ResetComputerPlayerList();
server->GetLobbyThread().NotifyReopeningGame(server->GetId());
server->SetState(ServerGameStateInit::Instance());
+10 -7
View File
@@ -362,7 +362,7 @@ ServerLobbyThread::ReAddSession(SessionWrapper session, int reason)
}
void
ServerLobbyThread::MoveSessionToGame(ServerGame &game, SessionWrapper session)
ServerLobbyThread::MoveSessionToGame(ServerGame &game, SessionWrapper session, bool autoLeave)
{
// Remove session from the lobby.
m_sessionManager.RemoveSession(session.sessionData->GetId());
@@ -374,6 +374,9 @@ ServerLobbyThread::MoveSessionToGame(ServerGame &game, SessionWrapper session)
session.sessionData->SetGameId(game.GetId());
// Add session to the game.
game.AddSession(session);
// Optionally enable auto leave after game finish.
if (autoLeave)
game.SetPlayerAutoLeaveOnFinish(session.playerData->GetUniqueId());
}
void
@@ -1030,9 +1033,9 @@ ServerLobbyThread::HandlePacket(SessionWrapper session, boost::shared_ptr<NetPac
if (joinRequest->password)
password = string((char *)joinRequest->password->buf, joinRequest->password->size);
if (joinRequest->joinGameAction.present == joinGameAction_PR_joinNewGame)
HandleNetPacketCreateGame(session, password, joinRequest->joinGameAction.choice.joinNewGame);
HandleNetPacketCreateGame(session, password, joinRequest->autoLeave, joinRequest->joinGameAction.choice.joinNewGame);
else if (joinRequest->joinGameAction.present == joinGameAction_PR_joinExistingGame)
HandleNetPacketJoinGame(session, password, joinRequest->joinGameAction.choice.joinExistingGame);
HandleNetPacketJoinGame(session, password, joinRequest->autoLeave, joinRequest->joinGameAction.choice.joinExistingGame);
}
else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage)
HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage);
@@ -1382,7 +1385,7 @@ ServerLobbyThread::HandleNetPacketRetrieveAvatar(SessionWrapper session, const A
}
void
ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, const JoinNewGame_t &newGame)
ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, bool autoLeave, const JoinNewGame_t &newGame)
{
LOG_VERBOSE("Creating new game, initiated by session #" << session.sessionData->GetId() << ".");
@@ -1427,12 +1430,12 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
// Add game to list of games.
InternalAddGame(game);
MoveSessionToGame(*game, session);
MoveSessionToGame(*game, session, autoLeave);
}
}
void
ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame)
ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, bool autoLeave, const JoinExistingGame_t &joinGame)
{
// Join an existing game.
GameMap::iterator pos = m_gameMap.find(joinGame.gameId);
@@ -1464,7 +1467,7 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
}
else
{
MoveSessionToGame(game, session);
MoveSessionToGame(game, session, autoLeave);
}
}
else