First parts of implementation of invite system in server.

This commit is contained in:
lotodore
2010-03-30 12:07:48 +00:00
parent f8d68d30c7
commit 499c2b72e6
6 changed files with 54 additions and 2 deletions
+11
View File
@@ -1390,6 +1390,9 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr<ClientThread> 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<ClientThread> 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);
}
}
}
//-----------------------------------------------------------------------------
+12 -2
View File
@@ -313,13 +313,23 @@ ClientThread::SendVoteKick(bool doKick)
void
ClientThread::SendInvitePlayerToCurrentGame(unsigned playerId)
{
// TODO
boost::shared_ptr<NetPacket> 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<NetPacket> 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<RejectGameInvReason_t>(reason);
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
void
+17
View File
@@ -462,6 +462,23 @@ ServerGameStateInit::InternalProcessPacket(boost::shared_ptr<ServerGame> 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<NetPacket> 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())
+11
View File
@@ -564,6 +564,14 @@ ServerLobbyThread::RemoveComputerPlayer(boost::shared_ptr<PlayerData> player)
m_computerPlayers.erase(player->GetUniqueId());
}
void
ServerLobbyThread::SendToLobbyPlayer(unsigned playerId, boost::shared_ptr<NetPacket> 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<SessionData> 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;
+2
View File
@@ -90,6 +90,8 @@ public:
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
void RemoveComputerPlayer(boost::shared_ptr<PlayerData> player);
void SendToLobbyPlayer(unsigned playerId, boost::shared_ptr<NetPacket> packet);
u_int32_t GetNextUniquePlayerId();
u_int32_t GetNextGameId();
ServerCallback &GetCallback();
+1
View File
@@ -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