More work on spectator mode.
This commit is contained in:
@@ -307,6 +307,7 @@ message JoinGameAckMessage {
|
||||
required uint32 gameId = 1;
|
||||
required bool areYouGameAdmin = 2;
|
||||
required NetGameInfo gameInfo = 3;
|
||||
optional bool spectateOnly = 4;
|
||||
}
|
||||
|
||||
message JoinGameFailedMessage {
|
||||
|
||||
@@ -108,10 +108,15 @@ ServerGame::GetCreatorDBId() const
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::AddSession(boost::shared_ptr<SessionData> session)
|
||||
ServerGame::AddSession(boost::shared_ptr<SessionData> 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
|
||||
|
||||
@@ -384,13 +384,25 @@ AbstractServerGameStateReceiving::CreateNetPacketPlayerJoined(unsigned gameId, c
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData)
|
||||
AbstractServerGameStateReceiving::CreateNetPacketSpectatorJoined(unsigned gameId, const PlayerData &playerData)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> 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<NetPacket>
|
||||
AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData, bool spectateOnly)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> 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<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> 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<ServerGame>
|
||||
++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<ServerGame> server)
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
ServerGameStateInit::HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
if (session && session->GetPlayerData()) {
|
||||
const GameData &tmpGameData = server->GetGameData();
|
||||
@@ -480,7 +500,7 @@ ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> 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<ServerGame> server, boos
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateInit::HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server)
|
||||
{
|
||||
@@ -701,12 +726,17 @@ ServerGameStateStartGame::Exit(boost::shared_ptr<ServerGame> server)
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateStartGame::HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
ServerGameStateStartGame::HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
// Do not accept new sessions in this state.
|
||||
server->MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateStartGame::HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
@@ -774,7 +804,7 @@ AbstractServerGameStateRunning::~AbstractServerGameStateRunning()
|
||||
}
|
||||
|
||||
void
|
||||
AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
AbstractServerGameStateRunning::HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
|
||||
// Verify that the user is allowed to rejoin.
|
||||
@@ -782,7 +812,7 @@ AbstractServerGameStateRunning::HandleNewSession(boost::shared_ptr<ServerGame> s
|
||||
boost::shared_ptr<PlayerInterface> 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<ServerGame> s
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AbstractServerGameStateRunning::HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
|
||||
@@ -367,18 +367,18 @@ ServerLobbyThread::ReAddSession(boost::shared_ptr<SessionData> session, int reas
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::MoveSessionToGame(boost::shared_ptr<ServerGame> game, boost::shared_ptr<SessionData> session, bool autoLeave)
|
||||
ServerLobbyThread::MoveSessionToGame(boost::shared_ptr<ServerGame> game, boost::shared_ptr<SessionData> 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<NetPacket> 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<NetPacket> 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<SessionData> 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<SessionData> sessio
|
||||
if (pos != m_gameMap.end()) {
|
||||
boost::shared_ptr<ServerGame> 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<SessionData> 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<SessionData> sess
|
||||
|
||||
if (pos != m_gameMap.end()) {
|
||||
boost::shared_ptr<ServerGame> game = pos->second;
|
||||
MoveSessionToGame(game, session, rejoinGame.autoleave());
|
||||
MoveSessionToGame(game, session, rejoinGame.autoleave(), false);
|
||||
} else {
|
||||
SendJoinGameFailed(session, rejoinGame.gameid(), NTF_NET_JOIN_GAME_INVALID);
|
||||
}
|
||||
|
||||
@@ -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<NetPacket> packet, SessionData::State state)
|
||||
SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||
|
||||
@@ -331,14 +331,14 @@ SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPac
|
||||
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)
|
||||
if (i->second->GetState() & state != 0)
|
||||
sender.Send(i->second, packet);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
|
||||
SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> 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<NetPacket> packet, SessionId except, SessionData::State state)
|
||||
SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> 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;
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
const std::string &GetName() const;
|
||||
unsigned GetCreatorDBId() const;
|
||||
|
||||
void AddSession(boost::shared_ptr<SessionData> session);
|
||||
void AddSession(boost::shared_ptr<SessionData> session, bool spectateOnly);
|
||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||
void MutePlayer(unsigned playerId, bool mute);
|
||||
void MarkPlayerAsInactive(unsigned playerId);
|
||||
|
||||
@@ -60,8 +60,10 @@ public:
|
||||
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server) = 0;
|
||||
virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> server) = 0;
|
||||
|
||||
// Handling of a new session.
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session) = 0;
|
||||
// Handling of a new player session.
|
||||
virtual void HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session) = 0;
|
||||
// Handling of a new spectator session.
|
||||
virtual void HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session) = 0;
|
||||
|
||||
// Main processing function of the current state.
|
||||
virtual void ProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) = 0;
|
||||
@@ -78,9 +80,10 @@ public:
|
||||
virtual void ProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketPlayerJoined(unsigned gameId, const PlayerData &playerData);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketSpectatorJoined(unsigned gameId, const PlayerData &playerData);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketJoinGameAck(const ServerGame &server, const PlayerData &playerData, bool spectateOnly);
|
||||
|
||||
static void AcceptNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
static void AcceptNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, bool spectateOnly);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -100,7 +103,8 @@ public:
|
||||
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server);
|
||||
virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> server);
|
||||
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
|
||||
protected:
|
||||
ServerGameStateInit();
|
||||
@@ -132,7 +136,8 @@ public:
|
||||
|
||||
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> /*server*/) {}
|
||||
virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> /*server*/) {}
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
|
||||
protected:
|
||||
ServerGameStateStartGame();
|
||||
@@ -150,7 +155,8 @@ class AbstractServerGameStateRunning : public AbstractServerGameStateReceiving
|
||||
public:
|
||||
virtual ~AbstractServerGameStateRunning();
|
||||
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewPlayer(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
virtual void HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session);
|
||||
|
||||
protected:
|
||||
virtual void InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||
@@ -252,7 +258,8 @@ public:
|
||||
virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> /*server*/) {}
|
||||
|
||||
// Handling of a new session.
|
||||
virtual void HandleNewSession(boost::shared_ptr<ServerGame> /*server*/, boost::shared_ptr<SessionData> /*session*/) {}
|
||||
virtual void HandleNewPlayer(boost::shared_ptr<ServerGame> /*server*/, boost::shared_ptr<SessionData> /*session*/) {}
|
||||
virtual void HandleNewSpectator(boost::shared_ptr<ServerGame> /*server*/, boost::shared_ptr<SessionData> /*session*/) {}
|
||||
|
||||
// Main processing function of the current state.
|
||||
virtual void ProcessPacket(boost::shared_ptr<ServerGame> /*server*/, boost::shared_ptr<SessionData> /*session*/, boost::shared_ptr<NetPacket> /*packet*/) {}
|
||||
|
||||
@@ -72,13 +72,15 @@ public:
|
||||
|
||||
void AddConnection(boost::shared_ptr<boost::asio::ip::tcp::socket> sock);
|
||||
void ReAddSession(boost::shared_ptr<SessionData> session, int reason, unsigned gameId);
|
||||
void MoveSessionToGame(boost::shared_ptr<ServerGame> game, boost::shared_ptr<SessionData> session, bool autoLeave);
|
||||
void MoveSessionToGame(boost::shared_ptr<ServerGame> game, boost::shared_ptr<SessionData> session, bool autoLeave, bool spectateOnly);
|
||||
void SessionError(boost::shared_ptr<SessionData> session, int errorCode);
|
||||
void ResubscribeLobbyMsg(boost::shared_ptr<SessionData> 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);
|
||||
|
||||
@@ -58,7 +58,7 @@ class ServerGame;
|
||||
class SessionData : public boost::enable_shared_from_this<SessionData>
|
||||
{
|
||||
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<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService);
|
||||
~SessionData();
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
boost::shared_ptr<SessionData> 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<NetPacket> packet, SessionData::State state);
|
||||
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||
void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
||||
void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||
void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, int state);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
+33
@@ -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_);
|
||||
}
|
||||
|
||||
+33
-1
@@ -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
|
||||
|
||||
@@ -17979,6 +17979,16 @@ public final class ProtoBuf {
|
||||
* <code>required .NetGameInfo gameInfo = 3;</code>
|
||||
*/
|
||||
de.pokerth.protocol.ProtoBuf.NetGameInfo getGameInfo();
|
||||
|
||||
// optional bool spectateOnly = 4;
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
boolean hasSpectateOnly();
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
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_;
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
public boolean hasSpectateOnly() {
|
||||
return ((bitField0_ & 0x00000008) == 0x00000008);
|
||||
}
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
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_ ;
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
public boolean hasSpectateOnly() {
|
||||
return ((bitField0_ & 0x00000008) == 0x00000008);
|
||||
}
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
public boolean getSpectateOnly() {
|
||||
return spectateOnly_;
|
||||
}
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
public Builder setSpectateOnly(boolean value) {
|
||||
bitField0_ |= 0x00000008;
|
||||
spectateOnly_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional bool spectateOnly = 4;</code>
|
||||
*/
|
||||
public Builder clearSpectateOnly() {
|
||||
bitField0_ = (bitField0_ & ~0x00000008);
|
||||
spectateOnly_ = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:JoinGameAckMessage)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user