Finishing server side invitation system.

This commit is contained in:
lotodore
2010-03-30 17:10:37 +00:00
parent 1eadf21051
commit 5239f496f3
6 changed files with 74 additions and 6 deletions
+1 -1
View File
@@ -1160,7 +1160,7 @@ ClientStateWaitAuthChallenge::~ClientStateWaitAuthChallenge()
} }
void void
ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> client) ClientStateWaitAuthChallenge::Enter(boost::shared_ptr<ClientThread> /*client*/)
{ {
} }
+25
View File
@@ -482,6 +482,31 @@ ServerGame::SetAdminPlayerId(unsigned playerId)
m_adminPlayerId = playerId; m_adminPlayerId = playerId;
} }
void
ServerGame::AddPlayerInvitation(unsigned playerId)
{
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
m_playerInvitationList.push_back(playerId);
}
void
ServerGame::RemovePlayerInvitation(unsigned playerId)
{
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
m_playerInvitationList.remove(playerId);
}
bool
ServerGame::IsPlayerInvited(unsigned playerId) const
{
bool retVal = false;
boost::mutex::scoped_lock lock(m_playerInvitationListMutex);
PlayerIdList::const_iterator pos = find(m_playerInvitationList.begin(), m_playerInvitationList.end(), playerId);
if (pos != m_playerInvitationList.end())
retVal = true;
return retVal;
}
void void
ServerGame::AddComputerPlayer(boost::shared_ptr<PlayerData> player) ServerGame::AddComputerPlayer(boost::shared_ptr<PlayerData> player)
{ {
+9 -3
View File
@@ -316,12 +316,13 @@ ServerGameStateInit::NotifyGameAdminChanged(boost::shared_ptr<ServerGame> server
void void
ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, SessionWrapper session) ServerGameStateInit::HandleNewSession(boost::shared_ptr<ServerGame> server, SessionWrapper session)
{ {
if (session.sessionData.get() && session.playerData.get()) if (session.sessionData && session.playerData)
{ {
size_t curNumPlayers = server->GetCurNumberOfPlayers(); size_t curNumPlayers = server->GetCurNumberOfPlayers();
const GameData &tmpGameData = server->GetGameData();
// Check the number of players. // Check the number of players.
if (curNumPlayers >= (size_t)server->GetGameData().maxNumberOfPlayers) if (curNumPlayers >= (size_t)tmpGameData.maxNumberOfPlayers)
{ {
server->MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL); server->MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL);
} }
@@ -477,7 +478,12 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> server,
bool requestSent = server->GetLobbyThread().SendToLobbyPlayer(netInvite->playerId, packet); bool requestSent = server->GetLobbyThread().SendToLobbyPlayer(netInvite->playerId, packet);
server->SendToAllPlayers(packet, SessionData::Game); server->SendToAllPlayers(packet, SessionData::Game);
if (!requestSent) if (requestSent)
{
// This player has been invited.
server->AddPlayerInvitation(netInvite->playerId);
}
else
{ {
// Player is not in lobby - send reject message. // Player is not in lobby - send reject message.
boost::shared_ptr<NetPacket> p2(new NetPacket(NetPacket::Alloc)); boost::shared_ptr<NetPacket> p2(new NetPacket(NetPacket::Alloc));
+31 -2
View File
@@ -933,6 +933,8 @@ ServerLobbyThread::HandlePacket(SessionWrapper session, boost::shared_ptr<NetPac
} }
else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage) else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage)
HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage); HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage);
else if (packet->GetMsg()->present == PokerTHMessage_PR_rejectGameInvitationMessage)
HandleNetPacketRejectGameInvitation(session, packet->GetMsg()->choice.rejectGameInvitationMessage);
else else
SessionError(session, ERR_SOCK_INVALID_STATE); SessionError(session, ERR_SOCK_INVALID_STATE);
} }
@@ -1318,6 +1320,12 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN); SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GUEST_FORBIDDEN);
joinGame = false; joinGame = false;
} }
else if (tmpData.gameType == GAME_TYPE_INVITE_ONLY
&& !game.IsPlayerInvited(session.playerData->GetUniqueId()))
{
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_NOT_INVITED);
joinGame = false;
}
else if (!game.CheckPassword(password)) else if (!game.CheckPassword(password))
{ {
SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_INVALID_PASSWORD); SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_INVALID_PASSWORD);
@@ -1328,8 +1336,7 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
} }
else else
{ {
// TODO do not remove session SendJoinGameFailed(session.sessionData, NTF_NET_JOIN_GAME_INVALID);
SessionError(session, ERR_NET_UNKNOWN_GAME);
} }
} }
@@ -1366,6 +1373,28 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat
} }
} }
void
ServerLobbyThread::HandleNetPacketRejectGameInvitation(SessionWrapper session, const RejectGameInvitationMessage_t &reject)
{
GameMap::iterator pos = m_gameMap.find(reject.gameId);
if (pos != m_gameMap.end() && session.playerData)
{
ServerGame &game = *pos->second;
if (game.IsPlayerInvited(session.playerData->GetUniqueId()))
{
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
packet->GetMsg()->present = PokerTHMessage_PR_rejectInvNotifyMessage;
RejectInvNotifyMessage_t *netReject = &packet->GetMsg()->choice.rejectInvNotifyMessage;
netReject->gameId = reject.gameId;
netReject->playerId = session.playerData->GetUniqueId();
netReject->playerRejectReason = reject.myRejectReason;
game.SendToAllPlayers(packet, SessionData::Game);
}
}
}
void void
ServerLobbyThread::AuthChallenge(SessionWrapper session, const string &secret) ServerLobbyThread::AuthChallenge(SessionWrapper session, const string &secret)
{ {
+7
View File
@@ -78,6 +78,10 @@ public:
unsigned GetAdminPlayerId() const; unsigned GetAdminPlayerId() const;
void SetAdminPlayerId(unsigned playerId); void SetAdminPlayerId(unsigned playerId);
void AddPlayerInvitation(unsigned playerId);
void RemovePlayerInvitation(unsigned playerId);
bool IsPlayerInvited(unsigned playerId) const;
// should be protected, but is needed in function. // should be protected, but is needed in function.
const Game &GetGame() const; const Game &GetGame() const;
Game &GetGame(); Game &GetGame();
@@ -141,6 +145,9 @@ private:
PlayerDataList m_computerPlayerList; PlayerDataList m_computerPlayerList;
mutable boost::mutex m_computerPlayerListMutex; mutable boost::mutex m_computerPlayerListMutex;
PlayerIdList m_playerInvitationList;
mutable boost::mutex m_playerInvitationListMutex;
unsigned m_adminPlayerId; unsigned m_adminPlayerId;
boost::shared_ptr<VoteKickData> m_voteKickData; boost::shared_ptr<VoteKickData> m_voteKickData;
+1
View File
@@ -140,6 +140,7 @@ protected:
void HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, const JoinNewGame_t &newGame); void HandleNetPacketCreateGame(SessionWrapper session, const std::string &password, const JoinNewGame_t &newGame);
void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame); void HandleNetPacketJoinGame(SessionWrapper session, const std::string &password, const JoinExistingGame_t &joinGame);
void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest); void HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest);
void HandleNetPacketRejectGameInvitation(SessionWrapper session, const RejectGameInvitationMessage_t &reject);
void AuthChallenge(SessionWrapper session, const std::string &secret); void AuthChallenge(SessionWrapper session, const std::string &secret);
void InitAfterLogin(SessionWrapper session); void InitAfterLogin(SessionWrapper session);
void EstablishSession(SessionWrapper session); void EstablishSession(SessionWrapper session);