예제 #1
0
        public bool RemovePlayer(Player player)
        {
            Player removedPlayer;
            if (!playerStore.TryRemove(player.Username, out removedPlayer))
                return false;

            // don't modify room player count if player is hidden
            if (!player.HasFlag(PlayerFlags.HidePlayer))
                Interlocked.Decrement(ref sessionCounter);

            var roomInfo = new PacketRoomInfo()
            {
                RoomName = Name,
                Removed  = new List<PacketRoomInfoProfile>()
                {
                    player.GenerateRoomInfoProfile()
                }
            };

            // notify other players in the room that a new player has left
            foreach (var otherPlayer in playerStore)
            {
                if (otherPlayer.Value == player)
                    continue;

                if (player.HasFlag(PlayerFlags.HidePlayer) && otherPlayer.Value.AdminRole != AdminRole.Mojang)
                    continue;

                otherPlayer.Value.Session.Send(roomInfo);
            }

            return true;
        }
예제 #2
0
        public bool AddPlayer(Player player)
        {
            if (!playerStore.TryAdd(player.Username, player))
                return false;

            // don't modify room player count if player is hidden
            bool isHidden = player.HasFlag(PlayerFlags.HidePlayer);
            if (!isHidden)
                Interlocked.Increment(ref sessionCounter);

            var roomInfo = new PacketRoomInfo()
            {
                RoomName = Name,
                Reset    = false,
                Updated  = new List<PacketRoomInfoProfile>()
                {
                    player.GenerateRoomInfoProfile()
                }
            };

            // notify other players in the room that a new player has joined
            foreach (var otherPlayer in playerStore)
            {
                if (otherPlayer.Value == player)
                    continue;

                // hidden players will only be visible to staff members
                if (isHidden && otherPlayer.Value.AdminRole != AdminRole.Mojang)
                    continue;

                otherPlayer.Value.Session.Send(roomInfo);
            }

            return true;
        }