示例#1
0
        public Deck(Player owner, uint id, string name, ulong timestamp, DeckFlags flags)
        {
            Owner     = owner;
            Id        = id;
            Name      = name;
            Timestamp = timestamp;
            Flags     = flags;
            Scrolls   = new List<ScrollInstance>();

            CalculateAge();
        }
        public static bool AddPlayer(string roomName, Player player, bool welcomeMessage = true)
        {
            if (roomName == "Message")
                return true;

            if (player.CurrentRooms.Contains(roomName))
                return false;

            if (player.CurrentRooms.Count >= 10)
                return false;

            RoomInfo room;
            if (!roomStore.TryGetValue(roomName, out room))
            {
                if (!AddRoom(roomName))
                    return false;

                room = roomStore[roomName];
            }

            if (room.GetPlayerCount() >= ConfigManager.Config.Room.MaxPlayersPerRoom)
            {
                if (room.Incremental)
                {
                    // find next avaliable name to create new room
                    uint offset = 1u;
                    string newName = room.Name + "-" + (room.Id + offset);

                    while (!AddRoom(newName, room.Password, room.Permission, true, (room.Id + offset), false))
                        newName = room.Name + "-" + (room.Id + offset++);

                    room = roomStore[newName];
                }
                else
                    return false;
            }

            if (player.AdminRole < room.Permission)
                return false;

            if (!room.AddPlayer(player))
                return false;

            player.CurrentRooms.Add(room.Name);

            // notify client that joining room was successful
            var roomEnter = new PacketRoomEnter
            {
                RoomName = room.Name
            };

            player.Session.Send(roomEnter);

            // send current players in room to player joining
            var roomInfo = new PacketRoomInfo()
            {
                RoomName = room.Name,
                Reset    = false,
                Updated  = room.GeneratePlayerList(player)
            };

            player.Session.Send(roomInfo);

            // only display welcome message if player is not reconnecting to room
            if (welcomeMessage)
                player.SendRoomMessage(room.Name, "You have joined \"" + room.Name + "\"");

            return true;
        }
        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;
        }
        // returns information on all players in a room, this is called on inital join to a room
        public List<PacketRoomInfoProfile> GeneratePlayerList(Player player)
        {
            var roomInfoProfileList = new List<PacketRoomInfoProfile>();

            foreach (var otherPlayer in playerStore)
            {
                if (otherPlayer.Value.HasFlag(PlayerFlags.HidePlayer) && player.AdminRole != AdminRole.Mojang)
                    continue;

                roomInfoProfileList.Add(otherPlayer.Value.GenerateRoomInfoProfile());
            }

            return roomInfoProfileList;
        }
        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;
        }
        public static bool RemovePlayer(string roomName, Player player)
        {
            if (roomName == "Message")
                return true;

            if (!player.CurrentRooms.Contains(roomName))
                return false;

            RoomInfo room;
            if (!roomStore.TryGetValue(roomName, out room))
                return false;

            if (room.RemovePlayer(player))
                player.CurrentRooms.Remove(roomName);

            return true;
        }