예제 #1
0
        public bool AddSpectator(Entities.User u)
        {
            int _maxSpectators = 5; //TODO, CONFIG

            if (Spectators.Count <= _maxSpectators)
            {
                for (byte i = 0; i < _maxSpectators; i++)
                {
                    if (!Spectators.ContainsKey(i))
                    {
                        //Add spectator
                        u.SetRoomSpectator(this, i);
                        Spectators.TryAdd(i, u);

                        ArrayList RegularPlayers    = new ArrayList();
                        ArrayList CurrentSpectators = new ArrayList();

                        foreach (Entities.Player Player in this.Players.Values)
                        {
                            RegularPlayers.Add(Player);
                        }

                        foreach (Entities.User Spectator in Spectators.Values)
                        {
                            CurrentSpectators.Add(Spectator);
                        }

                        //Room info for the spectator
                        u.Send(new Packets.RoomSpectate(u, this).BuildEncrypted());

                        //regular players in the room
                        u.Send(new Packets.RoomPlayers(RegularPlayers));

                        //spectators in the room
                        u.Send(new Packets.RoomSpectators(CurrentSpectators));

                        //update for room players
                        if (Players.Count > 0)
                        {
                            Send((new Packets.RoomSpectators(new ArrayList()
                            {
                                u
                            }).BuildEncrypted()));
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }