Merge remote-tracking branch 'origin/master'

This commit is contained in:
doitux
2013-06-17 09:53:07 +02:00
16 changed files with 42658 additions and 24892 deletions
+1
View File
@@ -307,6 +307,7 @@ message JoinGameAckMessage {
required uint32 gameId = 1; required uint32 gameId = 1;
required bool areYouGameAdmin = 2; required bool areYouGameAdmin = 2;
required NetGameInfo gameInfo = 3; required NetGameInfo gameInfo = 3;
optional bool spectateOnly = 4;
} }
message JoinGameFailedMessage { message JoinGameFailedMessage {
+1 -1
View File
@@ -359,12 +359,12 @@ win32 {
-lcrypto \ -lcrypto \
-lssh2 \ -lssh2 \
-lgnutls \ -lgnutls \
-lnettle \
-lhogweed \ -lhogweed \
-lgmp \ -lgmp \
-lgcrypt \ -lgcrypt \
-lgpg-error \ -lgpg-error \
-lgsasl \ -lgsasl \
-lnettle \
-lidn \ -lidn \
-lintl \ -lintl \
-lprotobuf -lprotobuf
+1 -1
View File
@@ -131,7 +131,7 @@ win32 {
debug:LIBPATH += debug/lib debug:LIBPATH += debug/lib
release:LIBPATH += release/lib release:LIBPATH += release/lib
LIBS += -lssl -lcrypto -lssh2 -lgnutls -lnettle -lhogweed -lgmp -lgcrypt -lgpg-error -lgsasl -lidn -lintl -lprotobuf -ltinyxml -lsqlite3 -lntlm LIBS += -lssl -lcrypto -lssh2 -lgnutls -lhogweed -lgmp -lgcrypt -lgpg-error -lgsasl -lnettle -lidn -lintl -lprotobuf -ltinyxml -lsqlite3 -lntlm
LIBS += -lboost_thread_win32-mt LIBS += -lboost_thread_win32-mt
LIBS += -lboost_filesystem-mt LIBS += -lboost_filesystem-mt
LIBS += -lboost_regex-mt LIBS += -lboost_regex-mt
-2
View File
@@ -42,8 +42,6 @@
#include <SDL/SDL_mixer.h> #include <SDL/SDL_mixer.h>
#endif #endif
struct Mix_Chunk;
/** /**
@author FThauer FHammer <webmaster@pokerth.net> @author FThauer FHammer <webmaster@pokerth.net>
*/ */
+8 -3
View File
@@ -108,10 +108,15 @@ ServerGame::GetCreatorDBId() const
} }
void void
ServerGame::AddSession(boost::shared_ptr<SessionData> session) ServerGame::AddSession(boost::shared_ptr<SessionData> session, bool spectateOnly)
{ {
if (session) if (session) {
GetState().HandleNewSession(shared_from_this(), session); if (spectateOnly) {
GetState().HandleNewSpectator(shared_from_this(), session);
} else {
GetState().HandleNewPlayer(shared_from_this(), session);
}
}
} }
void void
+46 -11
View File
@@ -384,13 +384,25 @@ AbstractServerGameStateReceiving::CreateNetPacketPlayerJoined(unsigned gameId, c
} }
boost::shared_ptr<NetPacket> 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); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinGameAckMessage); packet->GetMsg()->set_messagetype(PokerTHMessage::Type_JoinGameAckMessage);
JoinGameAckMessage *netJoinReply = packet->GetMsg()->mutable_joingameackmessage(); JoinGameAckMessage *netJoinReply = packet->GetMsg()->mutable_joingameackmessage();
netJoinReply->set_gameid(server.GetId()); netJoinReply->set_gameid(server.GetId());
netJoinReply->set_areyougameadmin(playerData.IsGameAdmin()); netJoinReply->set_areyougameadmin(playerData.IsGameAdmin());
netJoinReply->set_spectateonly(spectateOnly);
NetGameInfo *gameInfo = netJoinReply->mutable_gameinfo(); NetGameInfo *gameInfo = netJoinReply->mutable_gameinfo();
NetPacket::SetGameData(server.GetGameData(), *gameInfo); NetPacket::SetGameData(server.GetGameData(), *gameInfo);
@@ -399,13 +411,13 @@ AbstractServerGameStateReceiving::CreateNetPacketJoinGameAck(const ServerGame &s
} }
void 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. // Set game admin, if applicable.
session->GetPlayerData()->SetGameAdmin(session->GetPlayerData()->GetUniqueId() == server->GetAdminPlayerId()); session->GetPlayerData()->SetGameAdmin(session->GetPlayerData()->GetUniqueId() == server->GetAdminPlayerId());
// Send ack to client. // 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. // Send notifications for connected players to client.
PlayerDataList tmpPlayerList(server->GetFullPlayerDataList()); PlayerDataList tmpPlayerList(server->GetFullPlayerDataList());
@@ -416,14 +428,22 @@ AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr<ServerGame>
++player_i; ++player_i;
} }
// Send "Player Joined" to other fully connected clients. // Send "Player Joined"/"Spectator Joined" to other fully connected clients.
server->SendToAllPlayers(CreateNetPacketPlayerJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game); if (spectateOnly) {
server->SendToAllPlayers(CreateNetPacketSpectatorJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game);
} else {
server->SendToAllPlayers(CreateNetPacketPlayerJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game);
}
// Accept session. // Accept session.
server->GetSessionManager().AddSession(session); server->GetSessionManager().AddSession(session);
// Notify lobby. // 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 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()) { if (session && session->GetPlayerData()) {
const GameData &tmpGameData = server->GetGameData(); 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); server->MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL);
} else { } else {
AcceptNewSession(server, session); AcceptNewSession(server, session, false);
if (server->GetCurNumberOfPlayers() == tmpGameData.maxNumberOfPlayers) { if (server->GetCurNumberOfPlayers() == tmpGameData.maxNumberOfPlayers) {
// Automatically start the game if it is full. // 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 void
ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server) ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server)
{ {
@@ -701,12 +726,17 @@ ServerGameStateStartGame::Exit(boost::shared_ptr<ServerGame> server)
} }
void 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. // Do not accept new sessions in this state.
server->MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING); server->MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING);
} }
void
ServerGameStateStartGame::HandleNewSpectator(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session)
{
}
void void
ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) ServerGameStateStartGame::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{ {
@@ -774,7 +804,7 @@ AbstractServerGameStateRunning::~AbstractServerGameStateRunning()
} }
void 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. // 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()); boost::shared_ptr<PlayerInterface> tmpPlayer = server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetName());
if (tmpPlayer && tmpPlayer->getMyGuid() == session->GetPlayerData()->GetOldGuid()) { if (tmpPlayer && tmpPlayer->getMyGuid() == session->GetPlayerData()->GetOldGuid()) {
// The player wants to rejoin. // The player wants to rejoin.
AcceptNewSession(server, session); AcceptNewSession(server, session, false);
// Remember: We need to initiate a rejoin when starting the next hand. // Remember: We need to initiate a rejoin when starting the next hand.
server->AddRejoinPlayer(session->GetPlayerData()->GetUniqueId()); 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 void
AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) AbstractServerGameStateRunning::InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
{ {
+37 -7
View File
@@ -367,18 +367,18 @@ ServerLobbyThread::ReAddSession(boost::shared_ptr<SessionData> session, int reas
} }
void 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. // Remove session from the lobby.
m_sessionManager.RemoveSession(session->GetId()); m_sessionManager.RemoveSession(session->GetId());
// Session is now in game state. // 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. // Store it in the list of game sessions.
m_gameSessionManager.AddSession(session); m_gameSessionManager.AddSession(session);
// Set the game id of the session. // Set the game id of the session.
session->SetGame(game); session->SetGame(game);
// Add session to the game. // Add session to the game.
game->AddSession(session); game->AddSession(session, spectateOnly);
// Optionally enable auto leave after game finish. // Optionally enable auto leave after game finish.
if (autoLeave) if (autoLeave)
game->SetPlayerAutoLeaveOnFinish(session->GetPlayerData()->GetUniqueId()); game->SetPlayerAutoLeaveOnFinish(session->GetPlayerData()->GetUniqueId());
@@ -465,6 +465,34 @@ ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId)
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); 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 void
ServerLobbyThread::NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId) ServerLobbyThread::NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId)
{ {
@@ -1315,7 +1343,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> sess
// Add game to list of games. // Add game to list of games.
InternalAddGame(game); 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()) { if (pos != m_gameMap.end()) {
boost::shared_ptr<ServerGame> game = pos->second; boost::shared_ptr<ServerGame> game = pos->second;
const GameData &tmpData = game->GetGameData(); 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 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); SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_GUEST_FORBIDDEN);
} else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY } else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY
&& !game->IsPlayerInvited(session->GetPlayerData()->GetUniqueId())) { && !game->IsPlayerInvited(session->GetPlayerData()->GetUniqueId())) {
@@ -1341,13 +1370,14 @@ ServerLobbyThread::HandleNetPacketJoinGame(boost::shared_ptr<SessionData> sessio
} else if (!game->CheckPassword(password)) { } else if (!game->CheckPassword(password)) {
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_INVALID_PASSWORD); SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_INVALID_PASSWORD);
} else if (tmpData.gameType == GAME_TYPE_RANKING } else if (tmpData.gameType == GAME_TYPE_RANKING
&& !joinGame.spectateonly()
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6 && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4V6
&& session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4 && session->GetClientAddr() != SERVER_ADDRESS_LOCALHOST_STR_V4
&& game->IsClientAddressConnected(session->GetClientAddr())) { && game->IsClientAddressConnected(session->GetClientAddr())) {
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED); SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_IP_BLOCKED);
} else { } else {
MoveSessionToGame(game, session, joinGame.autoleave()); MoveSessionToGame(game, session, joinGame.autoleave(), joinGame.spectateonly());
} }
} else { } else {
SendJoinGameFailed(session, joinGame.gameid(), NTF_NET_JOIN_GAME_INVALID); 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()) { if (pos != m_gameMap.end()) {
boost::shared_ptr<ServerGame> game = pos->second; boost::shared_ptr<ServerGame> game = pos->second;
MoveSessionToGame(game, session, rejoinGame.autoleave()); MoveSessionToGame(game, session, rejoinGame.autoleave(), false);
} else { } else {
SendJoinGameFailed(session, rejoinGame.gameid(), NTF_NET_JOIN_GAME_INVALID); SendJoinGameFailed(session, rejoinGame.gameid(), NTF_NET_JOIN_GAME_INVALID);
} }
+8 -8
View File
@@ -169,7 +169,7 @@ SessionManager::GetPlayerDataList() const
} }
PlayerIdList PlayerIdList
SessionManager::GetPlayerIdList(SessionData::State state) const SessionManager::GetPlayerIdList(int state) const
{ {
PlayerIdList playerList; PlayerIdList playerList;
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
@@ -179,7 +179,7 @@ SessionManager::GetPlayerIdList(SessionData::State state) const
while (session_i != session_end) { while (session_i != session_end) {
// Get all players in the game. // 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()); playerList.push_back(session_i->second->GetPlayerData()->GetUniqueId());
} }
++session_i; ++session_i;
@@ -319,7 +319,7 @@ SessionManager::GetEstablishedSessionCount()
} }
void 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); 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); throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
// Send each client (with a certain state) a copy of the packet. // 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); sender.Send(i->second, packet);
++i; ++i;
} }
} }
void 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); 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); throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
// Send each client (with a certain state) a copy of the packet. // 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); sender.Send(i->second, packet);
++i; ++i;
} }
} }
void 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); boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
@@ -366,7 +366,7 @@ SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<
while (i != end) { while (i != end) {
// Send each fully connected client but one a copy of the packet. // 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) if (i->first != except)
sender.Send(i->second, packet); sender.Send(i->second, packet);
++i; ++i;
+1 -1
View File
@@ -66,7 +66,7 @@ public:
const std::string &GetName() const; const std::string &GetName() const;
unsigned GetCreatorDBId() 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 RemovePlayer(unsigned playerId, unsigned errorCode);
void MutePlayer(unsigned playerId, bool mute); void MutePlayer(unsigned playerId, bool mute);
void MarkPlayerAsInactive(unsigned playerId); void MarkPlayerAsInactive(unsigned playerId);
+15 -8
View File
@@ -60,8 +60,10 @@ public:
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server) = 0; virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server) = 0;
virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> server) = 0; virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> server) = 0;
// Handling of a new session. // Handling of a new player session.
virtual void HandleNewSession(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session) = 0; 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. // 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; 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); 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> 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: protected:
@@ -100,7 +103,8 @@ public:
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server); virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server);
virtual void NotifySessionRemoved(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: protected:
ServerGameStateInit(); ServerGameStateInit();
@@ -132,7 +136,8 @@ public:
virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> /*server*/) {} virtual void NotifyGameAdminChanged(boost::shared_ptr<ServerGame> /*server*/) {}
virtual void NotifySessionRemoved(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: protected:
ServerGameStateStartGame(); ServerGameStateStartGame();
@@ -150,7 +155,8 @@ class AbstractServerGameStateRunning : public AbstractServerGameStateReceiving
public: public:
virtual ~AbstractServerGameStateRunning(); 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: protected:
virtual void InternalProcessPacket(boost::shared_ptr<ServerGame> server, boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet); 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*/) {} virtual void NotifySessionRemoved(boost::shared_ptr<ServerGame> /*server*/) {}
// Handling of a new session. // 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. // 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*/) {} virtual void ProcessPacket(boost::shared_ptr<ServerGame> /*server*/, boost::shared_ptr<SessionData> /*session*/, boost::shared_ptr<NetPacket> /*packet*/) {}
+3 -1
View File
@@ -72,13 +72,15 @@ public:
void AddConnection(boost::shared_ptr<boost::asio::ip::tcp::socket> sock); void AddConnection(boost::shared_ptr<boost::asio::ip::tcp::socket> sock);
void ReAddSession(boost::shared_ptr<SessionData> session, int reason, unsigned gameId); 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 SessionError(boost::shared_ptr<SessionData> session, int errorCode);
void ResubscribeLobbyMsg(boost::shared_ptr<SessionData> session); void ResubscribeLobbyMsg(boost::shared_ptr<SessionData> session);
void NotifyPlayerJoinedLobby(unsigned playerId); void NotifyPlayerJoinedLobby(unsigned playerId);
void NotifyPlayerLeftLobby(unsigned playerId); void NotifyPlayerLeftLobby(unsigned playerId);
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId); void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
void NotifyPlayerLeftGame(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 NotifyGameAdminChanged(unsigned gameId, unsigned newAdminPlayerId);
void NotifyStartingGame(unsigned gameId); void NotifyStartingGame(unsigned gameId);
void NotifyReopeningGame(unsigned gameId); void NotifyReopeningGame(unsigned gameId);
+1 -1
View File
@@ -58,7 +58,7 @@ class ServerGame;
class SessionData : public boost::enable_shared_from_this<SessionData> class SessionData : public boost::enable_shared_from_this<SessionData>
{ {
public: 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(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService);
~SessionData(); ~SessionData();
+4 -4
View File
@@ -61,7 +61,7 @@ public:
boost::shared_ptr<SessionData> GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const; boost::shared_ptr<SessionData> GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const;
PlayerDataList GetPlayerDataList() const; PlayerDataList GetPlayerDataList() const;
PlayerIdList GetPlayerIdList(SessionData::State state) const; PlayerIdList GetPlayerIdList(int state) const;
bool IsPlayerConnected(const std::string &playerName) const; bool IsPlayerConnected(const std::string &playerName) const;
bool IsPlayerConnected(unsigned uniqueId) const; bool IsPlayerConnected(unsigned uniqueId) const;
bool IsClientAddressConnected(const std::string &clientAddress) const; bool IsClientAddressConnected(const std::string &clientAddress) const;
@@ -75,9 +75,9 @@ public:
unsigned GetRawSessionCount(); unsigned GetRawSessionCount();
unsigned GetEstablishedSessionCount(); unsigned GetEstablishedSessionCount();
void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state); void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state); void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state); void SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, int state);
protected: protected:
+2617 -1285
View File
File diff suppressed because it is too large Load Diff
+4729 -1836
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff