예제 #1
0
        public void OnPlayerAddedToSession(PlayerData player)
        {
            AddLobbyPlayerEntry(player.Name, player.PlayerId);

            // Send all players information to this new player
            if (player.ConnectionId >= 0)
            {
                foreach (var pd in JoinedPlayers)
                {
                    PlayerAddMsg newMsg1 = new PlayerAddMsg();
                    newMsg1.Add        = true;
                    newMsg1.PlayerId   = pd.Value.PlayerId;
                    newMsg1.PlayerName = pd.Value.Name;

                    // For the new added connection, send msg to add as local player
                    if (pd.Value.ConnectionId == player.ConnectionId)
                    {
                        newMsg1.ForLocalPlayer = true;
                        newMsg1.Serialize(GameStatics.OnlineSession.NetBuffer);
                        GameStatics.OnlineSession.SendBufferToConnection(player.ConnectionId, OnlineSession.ReliableSequencedChannelId);
                    }
                    else
                    {
                        newMsg1.ForLocalPlayer = false;
                        newMsg1.Serialize(GameStatics.OnlineSession.NetBuffer);
                        GameStatics.OnlineSession.SendBufferToConnection(player.ConnectionId, OnlineSession.ReliableSequencedChannelId);
                    }
                }
            }

            // Send new player information to other players
            PlayerAddMsg newMsg2 = new PlayerAddMsg();

            newMsg2.Add            = true;
            newMsg2.ForLocalPlayer = false;
            newMsg2.PlayerId       = player.PlayerId;
            newMsg2.PlayerName     = player.Name;
            newMsg2.Serialize(GameStatics.OnlineSession.NetBuffer);
            GameStatics.OnlineSession.SendBufferToAllClientsExcept(player.ConnectionId, OnlineSession.ReliableSequencedChannelId);
        }
예제 #2
0
        public void OnPlayerRemovedFromSession(PlayerData player)
        {
            // Remove player from gameSession
            RemoveLobbyPlayerEntry(player.PlayerId);

            // Send remove notification of disconnected player to all other players
            PlayerAddMsg msg = new PlayerAddMsg();

            msg.Add      = false;
            msg.PlayerId = player.PlayerId;
            msg.Serialize(GameStatics.OnlineSession.NetBuffer);
            GameStatics.OnlineSession.SendBufferToAllClients(OnlineSession.ReliableSequencedChannelId);
        }