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:
@@ -74,9 +74,9 @@ public:
|
||||
void SendGameChatMessage(const std::string &msg);
|
||||
void SendLobbyChatMessage(const std::string &msg);
|
||||
void SendPrivateChatMessage(unsigned targetPlayerId, const std::string &msg);
|
||||
void SendJoinFirstGame(const std::string &password);
|
||||
void SendJoinGame(unsigned gameId, const std::string &password);
|
||||
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
|
||||
void SendJoinFirstGame(const std::string &password, bool autoLeave);
|
||||
void SendJoinGame(unsigned gameId, const std::string &password, bool autoLeave);
|
||||
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password, bool autoLeave);
|
||||
void SendResetTimeout();
|
||||
void SendAskKickPlayer(unsigned playerId);
|
||||
void SendVoteKick(bool doKick);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
#include <third_party/asn1/PokerTHMessage.h>
|
||||
#include <gamedata.h>
|
||||
|
||||
#define NET_VERSION_MAJOR 1
|
||||
#define NET_VERSION_MAJOR 2
|
||||
#define NET_VERSION_MINOR 0
|
||||
|
||||
#define MAX_FILE_DATA_SIZE 256
|
||||
|
||||
@@ -88,8 +88,7 @@ public:
|
||||
void RemovePlayerInvitation(unsigned playerId);
|
||||
bool IsPlayerInvited(unsigned playerId) const;
|
||||
|
||||
void AddReportedAvatar(unsigned playerId);
|
||||
bool IsAvatarReported(unsigned playerId) const;
|
||||
void SetPlayerAutoLeaveOnFinish(unsigned playerId);
|
||||
|
||||
unsigned GetSmallDelaySec() const;
|
||||
|
||||
@@ -115,6 +114,8 @@ protected:
|
||||
void InitRankingMap(const PlayerDataList &playerDataList);
|
||||
void UpdateRankingMap();
|
||||
void SetPlayerPlace(unsigned playerId, int place);
|
||||
void StoreAndResetRanking();
|
||||
void RemoveAutoLeavePlayers();
|
||||
void InternalEndGame();
|
||||
|
||||
void InternalKickPlayer(unsigned playerId);
|
||||
@@ -141,6 +142,9 @@ protected:
|
||||
void AssignPlayerNumbers(PlayerDataList &playerList);
|
||||
bool IsValidPlayer(unsigned playerId) const;
|
||||
|
||||
void AddReportedAvatar(unsigned playerId);
|
||||
bool IsAvatarReported(unsigned playerId) const;
|
||||
|
||||
ServerLobbyThread &GetLobbyThread();
|
||||
|
||||
ServerGameState &GetState();
|
||||
@@ -172,8 +176,10 @@ private:
|
||||
PlayerIdList m_playerInvitationList;
|
||||
mutable boost::mutex m_playerInvitationListMutex;
|
||||
|
||||
PlayerIdList m_autoLeavePlayerList;
|
||||
mutable boost::mutex m_autoLeavePlayerListMutex;
|
||||
|
||||
PlayerIdList m_reportedAvatarList;
|
||||
mutable boost::mutex m_reportedAvatarListMutex;
|
||||
|
||||
RankingMap m_rankingMap;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
void AddConnection(boost::shared_ptr<boost::asio::ip::tcp::socket> sock);
|
||||
void ReAddSession(SessionWrapper session, int reason);
|
||||
void MoveSessionToGame(ServerGame &game, SessionWrapper session);
|
||||
void MoveSessionToGame(ServerGame &game, SessionWrapper session, bool autoLeave);
|
||||
void RemoveSessionFromGame(SessionWrapper session);
|
||||
void SessionError(SessionWrapper session, int errorCode);
|
||||
void ResubscribeLobbyMsg(SessionWrapper session);
|
||||
@@ -140,8 +140,8 @@ protected:
|
||||
void HandleNetPacketAvatarEnd(SessionWrapper session, unsigned requestId, const AvatarEnd_t &avatarEnd);
|
||||
void HandleNetPacketRetrievePlayerInfo(SessionWrapper session, const PlayerInfoRequestMessage_t &playerInfoRequest);
|
||||
void HandleNetPacketRetrieveAvatar(SessionWrapper session, const AvatarRequestMessage_t &retrieveAvatar);
|
||||
void HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, const JoinNewGame_t &newGame);
|
||||
void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame);
|
||||
void HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, bool autoLeave, const JoinNewGame_t &newGame);
|
||||
void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, bool autoLeave, const JoinExistingGame_t &joinGame);
|
||||
void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest);
|
||||
void HandleNetPacketRejectGameInvitation(SessionWrapper session, const RejectGameInvitationMessage_t &reject);
|
||||
// TODO would be better to use state pattern here.
|
||||
|
||||
Reference in New Issue
Block a user