From 499c2b72e6af34676e2e4689ab7ee00986959f7b Mon Sep 17 00:00:00 2001 From: lotodore Date: Tue, 30 Mar 2010 12:07:48 +0000 Subject: [PATCH] First parts of implementation of invite system in server. --- src/net/common/clientstate.cpp | 11 +++++++++++ src/net/common/clientthread.cpp | 14 ++++++++++++-- src/net/common/servergamestate.cpp | 17 +++++++++++++++++ src/net/common/serverlobbythread.cpp | 11 +++++++++++ src/net/serverlobbythread.h | 2 ++ src/net/socket_msg.h | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 0e80dc1c..c4e4b94d 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -1390,6 +1390,9 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr client case joinGameFailureReason_notAllowedAsGuest : failureCode = NTF_NET_JOIN_GUEST_FORBIDDEN; break; + case joinGameFailureReason_notInvited : + failureCode = NTF_NET_JOIN_NOT_INVITED; + break; default : failureCode = NTF_NET_INTERNAL; break; @@ -1398,6 +1401,14 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr client client->GetCallback().SignalNetClientNotification(failureCode); } } + else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_inviteNotifyMessage) + { + InviteNotifyMessage_t *netInvNotify = &tmpPacket->GetMsg()->choice.inviteNotifyMessage; + if (netInvNotify->playerIdWho == client->GetGuiPlayerId()) + { + client->GetCallback().SignalSelfGameInvitation(netInvNotify->gameId, netInvNotify->playerIdByWhom); + } + } } //----------------------------------------------------------------------------- diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 28f6c358..0cc1e2e9 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -313,13 +313,23 @@ ClientThread::SendVoteKick(bool doKick) void ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId) { - // TODO + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_invitePlayerToGameMessage; + InvitePlayerToGameMessage_t *netInvite = &packet->GetMsg()->choice.invitePlayerToGameMessage; + netInvite->gameId = GetGameId(); + netInvite->playerId = playerId; + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); } void ClientThread::SendRejectGameInvitation(unsigned gameId, DenyGameInvitationReason reason) { - // TODO + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_rejectGameInvitationMessage; + RejectGameInvitationMessage_t *netReject = &packet->GetMsg()->choice.rejectGameInvitationMessage; + netReject->gameId = GetGameId(); + netReject->myRejectReason = static_cast(reason); + m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); } void diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index c7f3d378..0fcf6b71 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -462,6 +462,23 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr server, server->SetState(ServerGameStateStartGame::Instance()); } } + else if (packet->GetMsg()->present == PokerTHMessage_PR_invitePlayerToGameMessage) + { + InvitePlayerToGameMessage_t *netInvite = &packet->GetMsg()->choice.invitePlayerToGameMessage; + + if (netInvite->gameId == server->GetId()) + { + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_inviteNotifyMessage; + InviteNotifyMessage_t *netInvNotif = &packet->GetMsg()->choice.inviteNotifyMessage; + netInvNotif->gameId = netInvite->gameId; + netInvNotif->playerIdByWhom = session.playerData->GetUniqueId(); + netInvNotif->playerIdWho = netInvite->playerId; + + server->GetLobbyThread().SendToLobbyPlayer(netInvite->playerId, packet); + server->SendToAllPlayers(packet, SessionData::Game); + } + } else if (packet->GetMsg()->present == PokerTHMessage_PR_resetTimeoutMessage) { if (session.playerData->IsGameAdmin()) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index cbd50d75..913fbfbd 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -564,6 +564,14 @@ ServerLobbyThread::RemoveComputerPlayer(boost::shared_ptr player) m_computerPlayers.erase(player->GetUniqueId()); } +void +ServerLobbyThread::SendToLobbyPlayer(unsigned playerId, boost::shared_ptr packet) +{ + SessionWrapper tmpSession = m_sessionManager.GetSessionByUniquePlayerId(playerId); + if (tmpSession.sessionData) + GetSender().Send(tmpSession.sessionData, packet); +} + AvatarManager & ServerLobbyThread::GetAvatarManager() { @@ -1798,6 +1806,9 @@ ServerLobbyThread::SendJoinGameFailed(boost::shared_ptr s, int reas case NTF_NET_JOIN_GUEST_FORBIDDEN : joinFailed->joinGameFailureReason = joinGameFailureReason_notAllowedAsGuest; break; + case NTF_NET_JOIN_NOT_INVITED : + joinFailed->joinGameFailureReason = joinGameFailureReason_notInvited; + break; default : joinFailed->joinGameFailureReason = joinGameFailureReason_invalidGame; break; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index 3e8a117d..9d744552 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -90,6 +90,8 @@ public: void AddComputerPlayer(boost::shared_ptr player); void RemoveComputerPlayer(boost::shared_ptr player); + void SendToLobbyPlayer(unsigned playerId, boost::shared_ptr packet); + u_int32_t GetNextUniquePlayerId(); u_int32_t GetNextGameId(); ServerCallback &GetCallback(); diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index f45c5ccb..06f4e396 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -112,6 +112,7 @@ #define NTF_NET_JOIN_ALREADY_RUNNING 212 #define NTF_NET_JOIN_INVALID_PASSWORD 213 #define NTF_NET_JOIN_GUEST_FORBIDDEN 214 +#define NTF_NET_JOIN_NOT_INVITED 215 // Notifications - version #define NTF_NET_NEW_RELEASE_AVAILABLE 220