Exemplo n.º 1
0
        /// <summary>
        /// This is called on the Server when a Mirror Client disconnects from the Server
        /// </summary>
        /// <param name="obj"></param>
        private void OnMirrorClientDisconnectedEvent(NetworkConnection connection)
        {
            MstTimer.WaitForSeconds(0.2f, () =>
            {
                // Try to find player in filtered list
                if (roomPlayersByMirrorPeerId.TryGetValue(connection.connectionId, out RoomPlayer player))
                {
                    logger.Debug($"Room server player {player.Username} with room client Id {connection.connectionId} left the room");

                    // Remove thisplayer from filtered list
                    roomPlayersByMirrorPeerId.Remove(player.MirrorPeer.connectionId);
                    roomPlayersByMsfPeerId.Remove(player.MasterPeerId);
                    roomPlayersByUsername.Remove(player.Username);

                    // Notify master server about disconnected player
                    if (RoomController.IsActive)
                    {
                        RoomController.NotifyPlayerLeft(player.MasterPeerId);
                    }

                    // Dispose profile
                    player.Profile?.Dispose();

                    // Inform subscribers about this bad guy
                    OnPlayerLeftRoomEvent?.Invoke(player);

                    // Calling termination conditions check
                    OnCheckTerminationConditionEvent?.Invoke();
                }
                else
                {
                    logger.Debug($"Room server client {connection.connectionId} left the room");
                }
            });
        }
        /// <summary>
        /// This is called on the Server when a Mirror Client disconnects from the Server
        /// </summary>
        /// <param name="obj"></param>
        private void OnMirrorClientDisconnectedEvent(NetworkConnection connection)
        {
            MsfTimer.WaitForSeconds(0.2f, () =>
            {
                // Try to find player in filtered list
                if (roomPlayersByMirrorPeerId.TryGetValue(connection.connectionId, out MirrorRoomPlayer player))
                {
                    logger.Debug($"Room server player {player.Username} with room client Id {connection.connectionId} left the room");

                    // Remove thisplayer from filtered list
                    roomPlayersByMirrorPeerId.Remove(player.MirrorPeer.connectionId);
                    roomPlayersByMsfPeerId.Remove(player.MsfPeerId);
                    roomPlayersByUsername.Remove(player.Username);

                    // Notify master server about disconnected player
                    if (CurrentRoomController.IsActive)
                    {
                        CurrentRoomController.NotifyPlayerLeft(player.MsfPeerId);
                    }

                    // Inform subscribers about this bad guy
                    OnPlayerLeftRoomEvent?.Invoke(player);

                    // If we need to terminate empty room
                    if (terminateRoomWhenLastPlayerQuits && roomPlayersByMirrorPeerId.Count <= 0 && !Msf.Runtime.IsEditor)
                    {
                        Msf.Runtime.Quit();
                    }
                }
                else
                {
                    logger.Debug($"Room server client {connection.connectionId} left the room");
                }
            });
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="peer"></param>
        protected override void OnPeerDisconnected(IPeer peer)
        {
            MstTimer.WaitForSeconds(0.2f, () =>
            {
                // Try to find player in filtered list
                if (roomPlayersByRoomPeerId.TryGetValue(peer.Id, out IRoomPlayerPeerExtension player))
                {
                    logger.Debug($"Room server player {player.Username} with room client Id {peer.Id} left the room");

                    // Remove this player from filtered list
                    roomPlayersByRoomPeerId.Remove(player.Peer.Id);
                    roomPlayersByMsfPeerId.Remove(player.MasterPeerId);
                    roomPlayersByUsername.Remove(player.Username);

                    // Notify master server about disconnected player
                    if (RoomController.IsActive)
                    {
                        RoomController.NotifyPlayerLeft(player.MasterPeerId);
                    }

                    // Inform subscribers about this bad guy
                    OnPlayerLeftRoomEvent?.Invoke(player);

                    // Calling termination conditions check
                    OnCheckTerminationConditionEvent?.Invoke();
                }
                else
                {
                    logger.Debug($"Room server client {peer.Id} left the room");
                }
            });
        }
        /// <summary>
        /// Fired when mirror client disconnected
        /// </summary>
        /// <param name="mirrorConn"></param>
        public void OnPlayerLeftRoomHandler(NetworkConnection mirrorConn)
        {
            // Try to find player in filtered list
            if (roomPlayersByMirrorPeerId.TryGetValue(mirrorConn.connectionId, out MirrorRoomPlayer player))
            {
                logger.Debug($"Room server player {player.Username} with room client Id {mirrorConn.connectionId} left the room");

                // Remove thisplayer from filtered list
                roomPlayersByMirrorPeerId.Remove(player.MirrorPeer.connectionId);
                roomPlayersByMsfPeerId.Remove(player.MsfPeerId);
                roomPlayersByUsername.Remove(player.Username);

                // Notify master server about disconnected player
                CurrentRoomController.NotifyPlayerLeft(player.MsfPeerId);

                // Inform subscribers about this bad guy
                OnPlayerLeftRoomEvent?.Invoke(player);
            }
            else
            {
                logger.Debug($"Room server client {mirrorConn.connectionId} left the room");
            }
        }