From 00543b7560583fa86498428d706581b947b2b9a1 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 16 Jun 2013 10:43:13 +0200 Subject: [PATCH] More work on spectator mode. --- pokerth.proto | 1 + src/net/common/servergame.cpp | 11 ++- src/net/common/servergamestate.cpp | 57 ++++++++++++--- src/net/common/serverlobbythread.cpp | 44 +++++++++-- src/net/common/sessionmanager.cpp | 16 ++-- src/net/servergame.h | 2 +- src/net/servergamestate.h | 23 ++++-- src/net/serverlobbythread.h | 4 +- src/net/sessiondata.h | 2 +- src/net/sessionmanager.h | 8 +- src/third_party/protobuf/pokerth.pb.cc | 33 +++++++++ src/third_party/protobuf/pokerth.pb.h | 34 ++++++++- tests/src/de/pokerth/protocol/ProtoBuf.java | 81 +++++++++++++++++++++ 13 files changed, 271 insertions(+), 45 deletions(-) diff --git a/pokerth.proto b/pokerth.proto index 5cbfdbd1..f8563d69 100644 --- a/pokerth.proto +++ b/pokerth.proto @@ -307,6 +307,7 @@ message JoinGameAckMessage { required uint32 gameId = 1; required bool areYouGameAdmin = 2; required NetGameInfo gameInfo = 3; + optional bool spectateOnly = 4; } message JoinGameFailedMessage { diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 305529d8..4e6cbcb0 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -108,10 +108,15 @@ ServerGame::GetCreatorDBId() const } void -ServerGame::AddSession(boost::shared_ptr session) +ServerGame::AddSession(boost::shared_ptr session, bool spectateOnly) { - if (session) - GetState().HandleNewSession(shared_from_this(), session); + if (session) { + if (spectateOnly) { + GetState().HandleNewSpectator(shared_from_this(), session); + } else { + GetState().HandleNewPlayer(shared_from_this(), session); + } + } } void diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 2d7bd063..374b1f01 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -384,13 +384,25 @@ AbstractServerGameStateReceiving::CreateNetPacketPlayerJoined(unsigned gameId, c } boost::shared_ptr -AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData) +AbstractServerGameStateReceiving::CreateNetPacketSpectatorJoined(unsigned gameId, const PlayerData &playerData) +{ + boost::shared_ptr packet(new NetPacket); + packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameSpectatorJoinedMessage); + GameSpectatorJoinedMessage *netGameSpectator = packet->GetMsg()->mutable_gamespectatorjoinedmessage(); + netGameSpectator->set_gameid(gameId); + netGameSpectator->set_playerid(playerData.GetUniqueId()); + return packet; +} + +boost::shared_ptr +AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData, bool spectateOnly) { boost::shared_ptr packet(new NetPacket); packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinGameAckMessage); JoinGameAckMessage *netJoinReply = packet->GetMsg()->mutable_joingameackmessage(); netJoinReply->set_gameid(server.GetId()); netJoinReply->set_areyougameadmin(playerData.IsGameAdmin()); + netJoinReply->set_spectateonly(spectateOnly); NetGameInfo *gameInfo = netJoinReply->mutable_gameinfo(); NetPacket::SetGameData(server.GetGameData(), *gameInfo); @@ -399,13 +411,13 @@ AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &s } void -AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr server, boost::shared_ptr session) +AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr server, boost::shared_ptr session, bool spectateOnly) { // Set game admin, if applicable. session->GetPlayerData()->SetGameAdmin(session->GetPlayerData()->GetUniqueId() == server->GetAdminPlayerId()); // Send ack to client. - server->GetLobbyThread().GetSender().Send(session, CreateNetPacketJoinGameAck(*server, *session->GetPlayerData())); + server->GetLobbyThread().GetSender().Send(session, CreateNetPacketJoinGameAck(*server, *session->GetPlayerData(), spectateOnly)); // Send notifications for connected players to client. PlayerDataList tmpPlayerList(server->GetFullPlayerDataList()); @@ -416,14 +428,22 @@ AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr ++player_i; } - // Send "Player Joined" to other fully connected clients. - server->SendToAllPlayers(CreateNetPacketPlayerJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game); + // Send "Player Joined"/"Spectator Joined" to other fully connected clients. + if (spectateOnly) { + server->SendToAllPlayers(CreateNetPacketSpectatorJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game); + } else { + server->SendToAllPlayers(CreateNetPacketPlayerJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game); + } // Accept session. server->GetSessionManager().AddSession(session); // Notify lobby. - server->GetLobbyThread().NotifyPlayerJoinedGame(server->GetId(), session->GetPlayerData()->GetUniqueId()); + if (spectateOnly) { + server->GetLobbyThread().NotifySpectatorJoinedGame(server->GetId(), session->GetPlayerData()->GetUniqueId()); + } else { + server->GetLobbyThread().NotifyPlayerJoinedGame(server->GetId(), session->GetPlayerData()->GetUniqueId()); + } } //----------------------------------------------------------------------------- @@ -471,7 +491,7 @@ ServerGameStateInit::NotifySessionRemoved(boost::shared_ptr server) } void -ServerGameStateInit::HandleNewSession(boost::shared_ptr server, boost::shared_ptr session) +ServerGameStateInit::HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session) { if (session && session->GetPlayerData()) { const GameData &tmpGameData = server->GetGameData(); @@ -480,7 +500,7 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr server, boos server->MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL); } else { - AcceptNewSession(server, session); + AcceptNewSession(server, session, false); if (server->GetCurNumberOfPlayers() == tmpGameData.maxNumberOfPlayers) { // Automatically start the game if it is full. @@ -490,6 +510,11 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr server, boos } } +void +ServerGameStateInit::HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session) +{ +} + void ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr server) { @@ -701,12 +726,17 @@ ServerGameStateStartGame::Exit(boost::shared_ptr server) } void -ServerGameStateStartGame::HandleNewSession(boost::shared_ptr server, boost::shared_ptr session) +ServerGameStateStartGame::HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session) { // Do not accept new sessions in this state. server->MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING); } +void +ServerGameStateStartGame::HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session) +{ +} + void ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr server, boost::shared_ptr session, boost::shared_ptr packet) { @@ -774,7 +804,7 @@ AbstractServerGameStateRunning::~AbstractServerGameStateRunning() } void -AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr server, boost::shared_ptr session) +AbstractServerGameStateRunning::HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session) { // Verify that the user is allowed to rejoin. @@ -782,7 +812,7 @@ AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr s boost::shared_ptr tmpPlayer = server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetName()); if (tmpPlayer && tmpPlayer->getMyGuid() == session->GetPlayerData()->GetOldGuid()) { // The player wants to rejoin. - AcceptNewSession(server, session); + AcceptNewSession(server, session, false); // Remember: We need to initiate a rejoin when starting the next hand. server->AddRejoinPlayer(session->GetPlayerData()->GetUniqueId()); @@ -802,6 +832,11 @@ AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr s } } +void +AbstractServerGameStateRunning::HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session) +{ +} + void AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr server, boost::shared_ptr session, boost::shared_ptr packet) { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index dbb2865a..9b42e3b9 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -367,18 +367,18 @@ ServerLobbyThread::ReAddSession(boost::shared_ptr session, int reas } void -ServerLobbyThread::MoveSessionToGame(boost::shared_ptr game, boost::shared_ptr session, bool autoLeave) +ServerLobbyThread::MoveSessionToGame(boost::shared_ptr game, boost::shared_ptr session, bool autoLeave, bool spectateOnly) { // Remove session from the lobby. m_sessionManager.RemoveSession(session->GetId()); // Session is now in game state. - session->SetState(SessionData::Game); + session->SetState(spectateOnly ? SessionData::Spectating: SessionData::Game); // Store it in the list of game sessions. m_gameSessionManager.AddSession(session); // Set the game id of the session. session->SetGame(game); // Add session to the game. - game->AddSession(session); + game->AddSession(session, spectateOnly); // Optionally enable auto leave after game finish. if (autoLeave) game->SetPlayerAutoLeaveOnFinish(session->GetPlayerData()->GetUniqueId()); @@ -465,6 +465,34 @@ ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId) m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); } +void +ServerLobbyThread::NotifySpectatorJoinedGame(unsigned gameId, unsigned playerId) +{ + // Send notification to players in lobby. + boost::shared_ptr packet(new NetPacket); + packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameListSpectatorJoinedMessage); + GameListSpectatorJoinedMessage *netListMsg = packet->GetMsg()->mutable_gamelistspectatorjoinedmessage(); + netListMsg->set_gameid(gameId); + netListMsg->set_playerid(playerId); + + m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established); + m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); +} + +void +ServerLobbyThread::NotifySpectatorLeftGame(unsigned gameId, unsigned playerId) +{ + // Send notification to players in lobby. + boost::shared_ptr packet(new NetPacket); + packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameListSpectatorLeftMessage); + GameListSpectatorLeftMessage *netListMsg = packet->GetMsg()->mutable_gamelistspectatorleftmessage(); + netListMsg->set_gameid(gameId); + netListMsg->set_playerid(playerId); + + m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established); + m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); +} + void ServerLobbyThread::NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId) { @@ -1315,7 +1343,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr sess // Add game to list of games. InternalAddGame(game); - MoveSessionToGame(game, session, newGame.autoleave()); + MoveSessionToGame(game, session, newGame.autoleave(), false); } } @@ -1332,8 +1360,9 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr sessio if (pos != m_gameMap.end()) { boost::shared_ptr game = pos->second; const GameData &tmpData = game->GetGameData(); + // As guest, you are only allowed to join normal games or to join as spectator. if (session->GetPlayerData()->GetRights() == PLAYER_RIGHTS_GUEST - && tmpData.gameType != GAME_TYPE_NORMAL) { + && tmpData.gameType != GAME_TYPE_NORMAL && !joinGame.spectateonly()) { SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_GUEST_FORBIDDEN); } else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY && !game->IsPlayerInvited(session->GetPlayerData()->GetUniqueId())) { @@ -1341,13 +1370,14 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr sessio } else if (!game->CheckPassword(password)) { SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_INVALID_PASSWORD); } else if (tmpData.gameType == GAME_TYPE_RANKING + && !joinGame.spectateonly() && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6 && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4 && game->IsClientAddressConnected(session->GetClientAddr())) { SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); } else { - MoveSessionToGame(game, session, joinGame.autoleave()); + MoveSessionToGame(game, session, joinGame.autoleave(), joinGame.spectateonly()); } } else { SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_GAME_INVALID); @@ -1362,7 +1392,7 @@ ServerLobbyThread::HandleNetPacketRejoinGame(boost::shared_ptr sess if (pos != m_gameMap.end()) { boost::shared_ptr game = pos->second; - MoveSessionToGame(game, session, rejoinGame.autoleave()); + MoveSessionToGame(game, session, rejoinGame.autoleave(), false); } else { SendJoinGameFailed(session, rejoinGame.gameid(), NTF_NET_JOIN_GAME_INVALID); } diff --git a/src/net/common/sessionmanager.cpp b/src/net/common/sessionmanager.cpp index 8bc53b13..3d3f545b 100644 --- a/src/net/common/sessionmanager.cpp +++ b/src/net/common/sessionmanager.cpp @@ -169,7 +169,7 @@ SessionManager::GetPlayerDataList() const } PlayerIdList -SessionManager::GetPlayerIdList(SessionData::State state) const +SessionManager::GetPlayerIdList(int state) const { PlayerIdList playerList; boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -179,7 +179,7 @@ SessionManager::GetPlayerIdList(SessionData::State state) const while (session_i != session_end) { // Get all players in the game. - if (session_i->second->GetState() == state) { + if (session_i->second->GetState() & state != 0) { playerList.push_back(session_i->second->GetPlayerData()->GetUniqueId()); } ++session_i; @@ -319,7 +319,7 @@ SessionManager::GetEstablishedSessionCount() } void -SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr packet, SessionData::State state) +SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr packet, int state) { boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -331,14 +331,14 @@ SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptrsecond->GetState() == state) + if (i->second->GetState() & state != 0) sender.Send(i->second, packet); ++i; } } void -SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr packet, SessionData::State state) +SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr packet, int state) { boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -350,14 +350,14 @@ SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_pt throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0); // Send each client (with a certain state) a copy of the packet. - if (i->second->GetState() == state && i->second->WantsLobbyMsg()) + if (i->second->GetState() & state != 0 && i->second->WantsLobbyMsg()) sender.Send(i->second, packet); ++i; } } void -SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr packet, SessionId except, SessionData::State state) +SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr packet, SessionId except, int state) { boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); @@ -366,7 +366,7 @@ SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr< while (i != end) { // Send each fully connected client but one a copy of the packet. - if (i->second->GetState() == state) + if (i->second->GetState() & state != 0) if (i->first != except) sender.Send(i->second, packet); ++i; diff --git a/src/net/servergame.h b/src/net/servergame.h index 1d731d28..6d74b4d8 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -66,7 +66,7 @@ public: const std::string &GetName() const; unsigned GetCreatorDBId() const; - void AddSession(boost::shared_ptr session); + void AddSession(boost::shared_ptr session, bool spectateOnly); void RemovePlayer(unsigned playerId, unsigned errorCode); void MutePlayer(unsigned playerId, bool mute); void MarkPlayerAsInactive(unsigned playerId); diff --git a/src/net/servergamestate.h b/src/net/servergamestate.h index ca0ca57c..3999a3bd 100644 --- a/src/net/servergamestate.h +++ b/src/net/servergamestate.h @@ -60,8 +60,10 @@ public: virtual void NotifyGameAdminChanged(boost::shared_ptr server) = 0; virtual void NotifySessionRemoved(boost::shared_ptr server) = 0; - // Handling of a new session. - virtual void HandleNewSession(boost::shared_ptr server, boost::shared_ptr session) = 0; + // Handling of a new player session. + virtual void HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session) = 0; + // Handling of a new spectator session. + virtual void HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session) = 0; // Main processing function of the current state. virtual void ProcessPacket(boost::shared_ptr server, boost::shared_ptr session, boost::shared_ptr packet) = 0; @@ -78,9 +80,10 @@ public: virtual void ProcessPacket(boost::shared_ptr server, boost::shared_ptr session, boost::shared_ptr packet); static boost::shared_ptr CreateNetPacketPlayerJoined(unsigned gameId, const PlayerData &playerData); - static boost::shared_ptr CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData); + static boost::shared_ptr CreateNetPacketSpectatorJoined(unsigned gameId, const PlayerData &playerData); + static boost::shared_ptr CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData, bool spectateOnly); - static void AcceptNewSession(boost::shared_ptr server, boost::shared_ptr session); + static void AcceptNewSession(boost::shared_ptr server, boost::shared_ptr session, bool spectateOnly); protected: @@ -100,7 +103,8 @@ public: virtual void NotifyGameAdminChanged(boost::shared_ptr server); virtual void NotifySessionRemoved(boost::shared_ptr server); - virtual void HandleNewSession(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session); protected: ServerGameStateInit(); @@ -132,7 +136,8 @@ public: virtual void NotifyGameAdminChanged(boost::shared_ptr /*server*/) {} virtual void NotifySessionRemoved(boost::shared_ptr /*server*/) {} - virtual void HandleNewSession(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session); protected: ServerGameStateStartGame(); @@ -150,7 +155,8 @@ class AbstractServerGameStateRunning : public AbstractServerGameStateReceiving public: virtual ~AbstractServerGameStateRunning(); - virtual void HandleNewSession(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewPlayer(boost::shared_ptr server, boost::shared_ptr session); + virtual void HandleNewSpectator(boost::shared_ptr server, boost::shared_ptr session); protected: virtual void InternalProcessPacket(boost::shared_ptr server, boost::shared_ptr session, boost::shared_ptr packet); @@ -252,7 +258,8 @@ public: virtual void NotifySessionRemoved(boost::shared_ptr /*server*/) {} // Handling of a new session. - virtual void HandleNewSession(boost::shared_ptr /*server*/, boost::shared_ptr /*session*/) {} + virtual void HandleNewPlayer(boost::shared_ptr /*server*/, boost::shared_ptr /*session*/) {} + virtual void HandleNewSpectator(boost::shared_ptr /*server*/, boost::shared_ptr /*session*/) {} // Main processing function of the current state. virtual void ProcessPacket(boost::shared_ptr /*server*/, boost::shared_ptr /*session*/, boost::shared_ptr /*packet*/) {} diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index fd93a4aa..ee675e7d 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -72,13 +72,15 @@ public: void AddConnection(boost::shared_ptr sock); void ReAddSession(boost::shared_ptr session, int reason, unsigned gameId); - void MoveSessionToGame(boost::shared_ptr game, boost::shared_ptr session, bool autoLeave); + void MoveSessionToGame(boost::shared_ptr game, boost::shared_ptr session, bool autoLeave, bool spectateOnly); void SessionError(boost::shared_ptr session, int errorCode); void ResubscribeLobbyMsg(boost::shared_ptr session); void NotifyPlayerJoinedLobby(unsigned playerId); void NotifyPlayerLeftLobby(unsigned playerId); void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId); void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId); + void NotifySpectatorJoinedGame(unsigned gameId, unsigned playerId); + void NotifySpectatorLeftGame(unsigned gameId, unsigned playerId); void NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId); void NotifyStartingGame(unsigned gameId); void NotifyReopeningGame(unsigned gameId); diff --git a/src/net/sessiondata.h b/src/net/sessiondata.h index 20347722..591b5272 100644 --- a/src/net/sessiondata.h +++ b/src/net/sessiondata.h @@ -58,7 +58,7 @@ class ServerGame; class SessionData : public boost::enable_shared_from_this { public: - enum State { Init, ReceivingAvatar, Established, Game, Closed }; + enum State { Init = 1, ReceivingAvatar = 2, Established = 4, Game = 8, Spectating = 16, Closed = 32 }; SessionData(boost::shared_ptr sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService); ~SessionData(); diff --git a/src/net/sessionmanager.h b/src/net/sessionmanager.h index 526f5159..03247215 100644 --- a/src/net/sessionmanager.h +++ b/src/net/sessionmanager.h @@ -61,7 +61,7 @@ public: boost::shared_ptr GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const; PlayerDataList GetPlayerDataList() const; - PlayerIdList GetPlayerIdList(SessionData::State state) const; + PlayerIdList GetPlayerIdList(int state) const; bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(unsigned uniqueId) const; bool IsClientAddressConnected(const std::string &clientAddress) const; @@ -75,9 +75,9 @@ public: unsigned GetRawSessionCount(); unsigned GetEstablishedSessionCount(); - void SendToAllSessions(SenderHelper &sender, boost::shared_ptr packet, SessionData::State state); - void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr packet, SessionData::State state); - void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr packet, SessionId except, SessionData::State state); + void SendToAllSessions(SenderHelper &sender, boost::shared_ptr packet, int state); + void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr packet, int state); + void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr packet, SessionId except, int state); protected: diff --git a/src/third_party/protobuf/pokerth.pb.cc b/src/third_party/protobuf/pokerth.pb.cc index 43921e79..0f3c20e9 100644 --- a/src/third_party/protobuf/pokerth.pb.cc +++ b/src/third_party/protobuf/pokerth.pb.cc @@ -8012,6 +8012,7 @@ void RejoinExistingGameMessage::Swap(RejoinExistingGameMessage* other) { const int JoinGameAckMessage::kGameIdFieldNumber; const int JoinGameAckMessage::kAreYouGameAdminFieldNumber; const int JoinGameAckMessage::kGameInfoFieldNumber; +const int JoinGameAckMessage::kSpectateOnlyFieldNumber; #endif // !_MSC_VER JoinGameAckMessage::JoinGameAckMessage() @@ -8039,6 +8040,7 @@ void JoinGameAckMessage::SharedCtor() { gameid_ = 0u; areyougameadmin_ = false; gameinfo_ = NULL; + spectateonly_ = false; ::memset(_has_bits_, 0, sizeof(_has_bits_)); } @@ -8083,6 +8085,7 @@ void JoinGameAckMessage::Clear() { if (has_gameinfo()) { if (gameinfo_ != NULL) gameinfo_->::NetGameInfo::Clear(); } + spectateonly_ = false; } ::memset(_has_bits_, 0, sizeof(_has_bits_)); } @@ -8134,6 +8137,22 @@ bool JoinGameAckMessage::MergePartialFromCodedStream( } else { goto handle_uninterpreted; } + if (input->ExpectTag(32)) goto parse_spectateOnly; + break; + } + + // optional bool spectateOnly = 4; + case 4: { + if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { + parse_spectateOnly: + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( + input, &spectateonly_))); + set_has_spectateonly(); + } else { + goto handle_uninterpreted; + } if (input->ExpectAtEnd()) return true; break; } @@ -8171,6 +8190,11 @@ void JoinGameAckMessage::SerializeWithCachedSizes( 3, this->gameinfo(), output); } + // optional bool spectateOnly = 4; + if (has_spectateonly()) { + ::google::protobuf::internal::WireFormatLite::WriteBool(4, this->spectateonly(), output); + } + } int JoinGameAckMessage::ByteSize() const { @@ -8196,6 +8220,11 @@ int JoinGameAckMessage::ByteSize() const { this->gameinfo()); } + // optional bool spectateOnly = 4; + if (has_spectateonly()) { + total_size += 1 + 1; + } + } GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = total_size; @@ -8220,6 +8249,9 @@ void JoinGameAckMessage::MergeFrom(const JoinGameAckMessage& from) { if (from.has_gameinfo()) { mutable_gameinfo()->::NetGameInfo::MergeFrom(from.gameinfo()); } + if (from.has_spectateonly()) { + set_spectateonly(from.spectateonly()); + } } } @@ -8243,6 +8275,7 @@ void JoinGameAckMessage::Swap(JoinGameAckMessage* other) { std::swap(gameid_, other->gameid_); std::swap(areyougameadmin_, other->areyougameadmin_); std::swap(gameinfo_, other->gameinfo_); + std::swap(spectateonly_, other->spectateonly_); std::swap(_has_bits_[0], other->_has_bits_[0]); std::swap(_cached_size_, other->_cached_size_); } diff --git a/src/third_party/protobuf/pokerth.pb.h b/src/third_party/protobuf/pokerth.pb.h index c8e237b3..95a07c44 100644 --- a/src/third_party/protobuf/pokerth.pb.h +++ b/src/third_party/protobuf/pokerth.pb.h @@ -3950,6 +3950,13 @@ class JoinGameAckMessage : public ::google::protobuf::MessageLite { inline ::NetGameInfo* release_gameinfo(); inline void set_allocated_gameinfo(::NetGameInfo* gameinfo); + // optional bool spectateOnly = 4; + inline bool has_spectateonly() const; + inline void clear_spectateonly(); + static const int kSpectateOnlyFieldNumber = 4; + inline bool spectateonly() const; + inline void set_spectateonly(bool value); + // @@protoc_insertion_point(class_scope:JoinGameAckMessage) private: inline void set_has_gameid(); @@ -3958,13 +3965,16 @@ class JoinGameAckMessage : public ::google::protobuf::MessageLite { inline void clear_has_areyougameadmin(); inline void set_has_gameinfo(); inline void clear_has_gameinfo(); + inline void set_has_spectateonly(); + inline void clear_has_spectateonly(); ::google::protobuf::uint32 gameid_; bool areyougameadmin_; + bool spectateonly_; ::NetGameInfo* gameinfo_; mutable int _cached_size_; - ::google::protobuf::uint32 _has_bits_[(3 + 31) / 32]; + ::google::protobuf::uint32 _has_bits_[(4 + 31) / 32]; #ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER friend void protobuf_AddDesc_pokerth_2eproto_impl(); @@ -14528,6 +14538,28 @@ inline void JoinGameAckMessage::set_allocated_gameinfo(::NetGameInfo* gameinfo) } } +// optional bool spectateOnly = 4; +inline bool JoinGameAckMessage::has_spectateonly() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void JoinGameAckMessage::set_has_spectateonly() { + _has_bits_[0] |= 0x00000008u; +} +inline void JoinGameAckMessage::clear_has_spectateonly() { + _has_bits_[0] &= ~0x00000008u; +} +inline void JoinGameAckMessage::clear_spectateonly() { + spectateonly_ = false; + clear_has_spectateonly(); +} +inline bool JoinGameAckMessage::spectateonly() const { + return spectateonly_; +} +inline void JoinGameAckMessage::set_spectateonly(bool value) { + set_has_spectateonly(); + spectateonly_ = value; +} + // ------------------------------------------------------------------- // JoinGameFailedMessage diff --git a/tests/src/de/pokerth/protocol/ProtoBuf.java b/tests/src/de/pokerth/protocol/ProtoBuf.java index 48404e34..d3fb8bbb 100644 --- a/tests/src/de/pokerth/protocol/ProtoBuf.java +++ b/tests/src/de/pokerth/protocol/ProtoBuf.java @@ -17979,6 +17979,16 @@ public final class ProtoBuf { * required .NetGameInfo gameInfo = 3; */ de.pokerth.protocol.ProtoBuf.NetGameInfo getGameInfo(); + + // optional bool spectateOnly = 4; + /** + * optional bool spectateOnly = 4; + */ + boolean hasSpectateOnly(); + /** + * optional bool spectateOnly = 4; + */ + boolean getSpectateOnly(); } /** * Protobuf type {@code JoinGameAckMessage} @@ -18046,6 +18056,11 @@ public final class ProtoBuf { bitField0_ |= 0x00000004; break; } + case 32: { + bitField0_ |= 0x00000008; + spectateOnly_ = input.readBool(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -18121,10 +18136,27 @@ public final class ProtoBuf { return gameInfo_; } + // optional bool spectateOnly = 4; + public static final int SPECTATEONLY_FIELD_NUMBER = 4; + private boolean spectateOnly_; + /** + * optional bool spectateOnly = 4; + */ + public boolean hasSpectateOnly() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional bool spectateOnly = 4; + */ + public boolean getSpectateOnly() { + return spectateOnly_; + } + private void initFields() { gameId_ = 0; areYouGameAdmin_ = false; gameInfo_ = de.pokerth.protocol.ProtoBuf.NetGameInfo.getDefaultInstance(); + spectateOnly_ = false; } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -18163,6 +18195,9 @@ public final class ProtoBuf { if (((bitField0_ & 0x00000004) == 0x00000004)) { output.writeMessage(3, gameInfo_); } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeBool(4, spectateOnly_); + } } private int memoizedSerializedSize = -1; @@ -18183,6 +18218,10 @@ public final class ProtoBuf { size += com.google.protobuf.CodedOutputStream .computeMessageSize(3, gameInfo_); } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(4, spectateOnly_); + } memoizedSerializedSize = size; return size; } @@ -18280,6 +18319,8 @@ public final class ProtoBuf { bitField0_ = (bitField0_ & ~0x00000002); gameInfo_ = de.pokerth.protocol.ProtoBuf.NetGameInfo.getDefaultInstance(); bitField0_ = (bitField0_ & ~0x00000004); + spectateOnly_ = false; + bitField0_ = (bitField0_ & ~0x00000008); return this; } @@ -18315,6 +18356,10 @@ public final class ProtoBuf { to_bitField0_ |= 0x00000004; } result.gameInfo_ = gameInfo_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.spectateOnly_ = spectateOnly_; result.bitField0_ = to_bitField0_; return result; } @@ -18330,6 +18375,9 @@ public final class ProtoBuf { if (other.hasGameInfo()) { mergeGameInfo(other.getGameInfo()); } + if (other.hasSpectateOnly()) { + setSpectateOnly(other.getSpectateOnly()); + } return this; } @@ -18499,6 +18547,39 @@ public final class ProtoBuf { return this; } + // optional bool spectateOnly = 4; + private boolean spectateOnly_ ; + /** + * optional bool spectateOnly = 4; + */ + public boolean hasSpectateOnly() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional bool spectateOnly = 4; + */ + public boolean getSpectateOnly() { + return spectateOnly_; + } + /** + * optional bool spectateOnly = 4; + */ + public Builder setSpectateOnly(boolean value) { + bitField0_ |= 0x00000008; + spectateOnly_ = value; + + return this; + } + /** + * optional bool spectateOnly = 4; + */ + public Builder clearSpectateOnly() { + bitField0_ = (bitField0_ & ~0x00000008); + spectateOnly_ = false; + + return this; + } + // @@protoc_insertion_point(builder_scope:JoinGameAckMessage) }