예제 #1
0
        protected override void Handle()
        {
            if (Room.State == Enums.RoomState.Waiting)   // TODO Implement already in lobby ;)
            {
                if (!Player.InLobby)
                {
                    Player.BackToLobby();
                    respond    = true;
                    selfTarget = true;

                    //TODO: Lobby update if all players are back in the lobby :)
                    if (Room.Players.Values.All(p => p.InLobby))
                    {
                        // SEND THE ROOM UPDATE TO THE LOBBY //
                        byte roomPage   = (byte)Math.Floor((decimal)(Room.ID / 8));
                        var  targetList = Managers.ChannelManager.Instance.Get(Room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                        if (targetList.Count() > 0)
                        {
                            byte[] outBuffer = new Packets.RoomUpdate(Room, true).BuildEncrypted();
                            foreach (Entities.User usr in targetList)
                            {
                                usr.Send(outBuffer);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public void Remove(Entities.Room r)
        {
            Entities.Room rm;
            if (Rooms.ContainsKey(r.ID))
            {
                Rooms.TryRemove(r.ID, out rm);

                byte roomPage   = (byte)Math.Floor((decimal)(r.ID / 8));
                var  targetList = this.Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                if (targetList.Count() > 0)
                {
                    byte[] outBuffer = new Packets.RoomUpdate(r.ID).BuildEncrypted();
                    foreach (Entities.User u in targetList)
                    {
                        if (u.LastRoomId == r.ID)
                        {
                            u.LastRoomId = -1;
                        }
                        else
                        {
                            u.Send(outBuffer);
                        }
                    }
                }
            }

            lock (scanLock)
            {
                if (takenRoomIds.Contains((int)r.ID))
                {
                    takenRoomIds.Remove((int)r.ID);
                }
            }
        }
예제 #3
0
        public override void Handle(User sender, InPacket packetReader)
        {
            if (sender.Authenticated)
            {
                if (sender.Room != null)
                {
                    Room room = sender.Room;
                    room.Remove(sender);

                    if (room != null && room.Players.Count > 0)
                    {
                        // SEND THE ROOM UPDATE TO THE LOBBY //
                        byte roomPage   = (byte)Math.Floor((decimal)(room.ID / 8));
                        var  targetList = Managers.ChannelManager.Instance.Get(room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                        if (targetList.Count() > 0)
                        {
                            byte[] outBuffer = new Packets.RoomUpdate(room, false).BuildEncrypted();
                            foreach (User usr in targetList)
                            {
                                usr.Send(outBuffer);
                            }
                        }
                    }

                    //var result = Managers.ChannelManager.Instance.Get(sender.Channel).Rooms.Select(n => n.Value)
                    //        .Where(n => n.ID >= (uint)(8 * sender.RoomListPage) && n.ID < (uint)(8 * (sender.RoomListPage + 1))).OrderBy(n => n.ID);

                    //sender.Send(new Packets.RoomList(sender.RoomListPage, new ArrayList(result.ToArray())));
                }
            }
            else
            {
                sender.Disconnect();
            }
        }
예제 #4
0
        protected override void Process(Entities.User u)
        {
            if (u.Authorized)
            {
                if (u.Room != null)
                {
                    Entities.Room r = u.Room;
                    r.Remove(u);

                    if (r != null && r.Players.Count > 0)
                    {
                        // SEND THE ROOM UPDATE TO THE LOBBY //
                        byte roomPage   = (byte)Math.Floor((decimal)(r.ID / 8));
                        var  targetList = Managers.ChannelManager.Instance.Get(r.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                        if (targetList.Count() > 0)
                        {
                            byte[] outBuffer = new Packets.RoomUpdate(r, false).BuildEncrypted();
                            foreach (Entities.User usr in targetList)
                            {
                                usr.Send(outBuffer);
                            }
                        }
                    }
                    //this player needs an update of the userlist
                    ArrayList UserList = new ArrayList();
                    foreach (Entities.User User in Managers.UserManager.Instance.Sessions.Values)
                    {
                        UserList.Add(User);
                    }

                    u.UserListPage = 0;
                    u.Send(new Packets.UserList(0, UserList));
                }
            }
            else
            {
                u.Disconnect();
            }
        }
        protected override void Handle()
        {
            if (Room.State == Enums.RoomState.Waiting)
            {
                if (!Player.InLobby)
                {
                    Player.BackToLobby();
                    respond    = true;
                    selfTarget = true;
                    if (Room.Players.Values.All(p => p.InLobby))
                    {
                        // SEND THE ROOM UPDATE TO THE LOBBY //
                        byte roomPage   = (byte)Math.Floor((decimal)(Room.ID / 8));
                        var  targetList = Managers.ChannelManager.Instance.Get(Room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                        if (targetList.Count() > 0)
                        {
                            byte[] outBuffer = new Packets.RoomUpdate(Room, true).BuildEncrypted();
                            foreach (Entities.User usr in targetList)
                            {
                                usr.Send(outBuffer);
                            }
                        }
                        //this player needs an update of the userlist
                        if (Player.User.Room == null)
                        {
                            ArrayList UserList = new ArrayList();
                            foreach (Entities.User User in Managers.UserManager.Instance.Sessions.Values)
                            {
                                UserList.Add(User);
                            }

                            Player.User.UserListPage = 0;
                            Player.User.Send(new Packets.UserList(0, UserList));
                        }
                    }
                }
            }
        }
예제 #6
0
        protected override void Process(Entities.User u)
        {
            if (u.Authorized)
            {
                if (u.Room != null)
                {
                    u.Disconnect();
                }

                bool isRoomValid = true;
                // READING OUT THE ROOM DATA //
                string name           = GetString(0);
                bool   hasPassword    = (GetByte(1) > 0);
                string password       = GetString(2);
                byte   playerCount    = GetByte(3);
                byte   mapId          = GetByte(4);        // Ignore this from the client, we will use it server side.
                byte   unknown1       = GetByte(5);        // Unknown?
                byte   unknown2       = GetByte(6);        // Unknown?
                byte   type           = GetByte(7);        // type?
                byte   levelLimit     = GetByte(8);        // level limit
                bool   friendlyFire   = (GetByte(9) > 0);  // premium only?
                bool   enableVoteKick = (GetByte(10) > 0); // vote kick

                // VALIDATE ROOM NAME //
                if (name.Length == 0 || name.Length > 25)   // Name Length
                {
                    if (name.Length != 27)
                    {
                        isRoomValid = false;
                    }
                }

                // VALIDATE ROOM PASSWORD //
                if (hasPassword && (password.Length == 0 || password == "NULL"))   // Password Length
                {
                    isRoomValid = false;
                }

                // VALIDATE MAXIMUM PLAYERS //
                byte highestIndex = 0;
                switch (u.Channel)
                {
                case Enums.ChannelType.CQC: {
                    highestIndex = 1;
                    break;
                }

                case Enums.ChannelType.Urban_Ops: {
                    highestIndex = 3;
                    break;
                }

                case Enums.ChannelType.Battle_Group: {
                    highestIndex = 4;
                    break;
                }

                default: {
                    highestIndex = 1;
                    break;
                }
                }

                if (playerCount > highestIndex)
                {
                    isRoomValid = false;
                }

                if (levelLimit < 0 || levelLimit > 5)
                {
                    isRoomValid = false;
                }

                if (!SuitableLevel(levelLimit, Core.LevelCalculator.GetLevelforExp(u.XP)))
                {
                    isRoomValid = false;
                }

                // VALIDATE PREMIUM SETTING //
                //        if (u.Premium == Enums.Premium.Free2Play && premiumOnly) {
                //           isRoomValid = false;
                //     }
                //DARKRAPTOR: PREMIUM ONLY REPLACED FOR FRIENDLYFIRE

                if (!u.Inventory.Itemlist.Contains("CC02") && !enableVoteKick)
                {
                    isRoomValid = false;
                }


                if (isRoomValid)
                {
                    // FETCH OPEN ID //
                    Objects.Channel channel    = Managers.ChannelManager.Instance.Get(u.Channel);
                    int             openRoomId = channel.GetOpenRoomID();

                    if (openRoomId >= 0)
                    {
                        Entities.Room room = new Entities.Room(u, (uint)openRoomId, name, hasPassword, password, playerCount, type, levelLimit, friendlyFire, enableVoteKick, false);
                        if (room != null)
                        {
                            // ROOM CREATED SUCCESSFULLY //
                            Managers.ChannelManager.Instance.Get(room.Channel).Add(room);

                            u.Send(new Packets.RoomCreation(room));

                            // SEND THE ROOM UPDATE TO THE LOBBY //
                            byte roomPage   = (byte)Math.Floor((decimal)(room.ID / 8));
                            var  targetList = Managers.ChannelManager.Instance.Get(room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                            if (targetList.Count() > 0)
                            {
                                byte[] outBuffer = new Packets.RoomUpdate(room, false).BuildEncrypted();
                                foreach (Entities.User usr in targetList)
                                {
                                    usr.Send(outBuffer);
                                }
                            }
                            ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, String.Concat("Player ", u.Displayname, " created a room"));
                        }
                        else
                        {
                            channel.ForceFreeSlot(openRoomId); // Force the room slot open again.
                            u.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.GenericError));
                        }
                    }
                    else
                    {
                        u.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.MaxiumRoomsExceeded));
                    }
                }
                else
                {
                    u.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.GenericError));
                }
            }
            else
            {
                u.Disconnect();
            }
        }
예제 #7
0
        public void Process(User u, InPacket packet)
        {
            string[] blocks = packet.Blocks;
            ushort   subId  = 0;

            try
            {
                ushort.TryParse(blocks[3], out subId);
            }
            catch { subId = 0; }

            if (subId > 0 && Enum.IsDefined(typeof(Enums.GameSubs), subId))
            {
                lock (handleLock)
                {
                    this.type   = (Enums.GameSubs)subId;
                    this.packet = packet;
                    mapData     = false;
                    updateLobby = false;
                    selfTarget  = false;
                    respond     = false;

                    this.blocks = new string[blocks.Length - 4];
                    Array.Copy(blocks, 4, this.blocks, 0, this.blocks.Length);

                    Room = u.Room;
                    Player p = null;
                    selfTarget = false;

                    try
                    {
                        this.Room.Players.TryGetValue(u.RoomSlot, out p);
                    }
                    catch { p = null; }

                    if (p != null)
                    {
                        this.Player = p;
                        roomSlot    = p.Id;

                        try
                        {
                            Handle();
                        }
                        catch { respond = false; }

                        if (respond)
                        {
                            string[] packetData;
                            if (errorCode == 1)
                            {
                                packetData    = new string[this.blocks.Length + 5];
                                packetData[0] = errorCode.ToString();
                                packetData[1] = roomSlot.ToString();
                                packetData[2] = Room.ID.ToString();
                                packetData[3] = blocks[2];                 // 2 - 0
                                packetData[4] = ((ushort)type).ToString(); // Type

                                Array.Copy(this.blocks, 0, packetData, 5, this.blocks.Length);
                            }
                            else
                            {
                                packetData = new string[] { errorCode.ToString() };
                            }

                            // Generate packet buffer //
                            byte[] buffer = new Packets.GameData(packetData).BuildEncrypted();
                            if (errorCode > 1 || selfTarget)
                            {
                                u.Send(buffer);
                            }
                            else
                            {
                                Room.Send(buffer);
                            }

                            if (mapData)
                            {
                                u.Send(new Packets.MapData(Room));
                            }

                            if (updateLobby)
                            { // Send a update to the lobby :)
                                byte roomPage   = (byte)Math.Floor((decimal)(Room.ID / 8));
                                var  targetList = Managers.ChannelManager.Instance.Get(Room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                                if (targetList.Count() > 0)
                                {
                                    byte[] outBuffer = new Packets.RoomUpdate(Room, true).BuildEncrypted();
                                    foreach (User usr in targetList)
                                    {
                                        usr.Send(outBuffer);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                u.Disconnect(); // Wrong id?
            }
        }
예제 #8
0
        public override void Handle(User sender, InPacket packetReader)
        {
            if (sender.Authenticated)
            {
                if (sender.Room != null)
                {
                    sender.Disconnect();
                }

                bool isRoomValid = true;
                // READING OUT THE ROOM DATA //
                string name           = packetReader.ReadString(0);
                bool   hasPassword    = packetReader.ReadBool(1);
                string password       = packetReader.ReadString(2);
                byte   playerCount    = packetReader.ReadByte(3);
                byte   mapId          = packetReader.ReadByte(4); // Ignore this from the client, we will use it server side.
                byte   unknown1       = packetReader.ReadByte(5); // Unknown?
                byte   unknown2       = packetReader.ReadByte(6); // Unknown?
                byte   type           = 0;
                byte   levelLimit     = 0;
                bool   premiumOnly    = false;
                bool   enableVoteKick = true;

                // VALIDATE ROOM NAME //
                if (name.Length == 0 || name.Length > 25)
                { // Name Length
                    if (name.Length != 27)
                    {
                        isRoomValid = false;
                    }
                }

                // VALIDATE ROOM PASSWORD //
                if (hasPassword && (password.Length == 0 || password == "NULL"))
                { // Password Length
                    isRoomValid = false;
                }

                // VALIDATE MAXIMUM PLAYERS //
                byte highestIndex = 0;
                switch (sender.Channel)
                {
                case Enums.ChannelType.CQC:
                {
                    highestIndex = 1;
                    break;
                }

                case Enums.ChannelType.Urban_Ops:
                {
                    highestIndex = 3;
                    break;
                }

                case Enums.ChannelType.Battle_Group:
                {
                    highestIndex = 4;
                    break;
                }

                default:
                {
                    highestIndex = 1;
                    break;
                }
                }

                if (playerCount > highestIndex)
                {
                    isRoomValid = false;
                }

                // TODO: VALIDATE THE LEVEL TYPE.

                // VALIDATE PREMIUM SETTING //
                if (sender.Premium == Enums.Premium.Free2Play && premiumOnly)
                {
                    isRoomValid = false;
                }

                // TODO: VALIDATE SUPERMASTER & ENABLE VOTEKICK //

                if (isRoomValid)
                {
                    // FETCH OPEN ID //
                    Objects.Channel channel    = Managers.ChannelManager.Instance.Get(sender.Channel);
                    int             openRoomId = channel.GetOpenRoomID();

                    if (openRoomId >= 0)
                    {
                        Entities.Room room = new Entities.Room(sender, (uint)openRoomId, name, hasPassword, password, playerCount, type, levelLimit, premiumOnly, enableVoteKick);
                        if (room != null)
                        {
                            // ROOM CREATED SUCCESSFULLY //
                            Managers.ChannelManager.Instance.Get(room.Channel).Add(room);

                            sender.Send(new Packets.RoomCreation(room));

                            // SEND THE ROOM UPDATE TO THE LOBBY //
                            byte roomPage   = (byte)Math.Floor((decimal)(room.ID / 8));
                            var  targetList = Managers.ChannelManager.Instance.Get(room.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                            if (targetList.Count() > 0)
                            {
                                byte[] outBuffer = new Packets.RoomUpdate(room, false).BuildEncrypted();
                                foreach (Entities.User usr in targetList)
                                {
                                    usr.Send(outBuffer);
                                }
                            }
                        }
                        else
                        {
                            channel.ForceFreeSlot(openRoomId); // Force the room slot open again.
                            sender.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.GenericError));
                        }
                    }
                    else
                    {
                        sender.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.MaxiumRoomsExceeded));
                    }
                }
                else
                {
                    sender.Send(new Packets.RoomCreation(Enums.RoomCreationErrors.GenericError));
                }
            }
            else
            {
                sender.Disconnect();
            }
        }
예제 #9
0
        public bool Add(Entities.User u)
        {
            if (Players.Count < MaximumPlayers && !UserLimit)
            {
                if (isClanWar && u.ClanRank < 1)
                {
                    return(false);
                }

                lock (_playerLock) {
                    Team targetTeam = Team.Derbaran;

                    byte startScanIndex = 0;
                    byte endScanIndex   = (byte)(MaximumPlayers / 2);

                    var debTeam = Players.Select(n => n.Value).Where(n => n.Team == Team.Derbaran).Count();
                    var niuTeam = Players.Select(n => n.Value).Where(n => n.Team == Team.NIU).Count();

                    if (debTeam > niuTeam)
                    {
                        targetTeam     = Team.NIU;
                        startScanIndex = (byte)(MaximumPlayers / 2);
                        endScanIndex   = MaximumPlayers;
                    }

                    for (byte i = startScanIndex; i < endScanIndex; i++)
                    {
                        if (!Players.ContainsKey(i))
                        {
                            Player plr = new Player(i, u, targetTeam);

                            // Send Room //
                            if (Players.Count > 0)
                            {
                                Send((new Packets.RoomPlayers(new ArrayList()
                                {
                                    plr
                                }).BuildEncrypted()));
                            }
                            else
                            {
                                Master = i;
                            }

                            // Add Player
                            Players.TryAdd(i, plr);
                            u.SetRoom(this, i);

                            // Send Join Packet //
                            u.Send(new Packets.RoomJoin(i, this));
                            u.Send(new Packets.RoomPlayers(new ArrayList(Players.Select(n => n.Value).Where(n => n.Id != i).ToArray())));

                            // Send to all spectators
                            foreach (Entities.User Spectator in Spectators.Values)
                            {
                                u.Send(new Packets.RoomPlayers(new ArrayList(Players.Select(n => n.Value).Where(n => n.Id != i).ToArray())));
                            }

                            //Tell de players
                            if (State == RoomState.Playing)
                            {
                                //     string _message = Cristina.Core.Cristina.Localization.GetLocMessageFrom("PLAYER_JOINED");
                                //   if (_message.Contains("%/nickname/%"))
                                //     _message = _message.Replace("%/nickname/%", u.Displayname);

                                Cristina.Core.Cristina.Chat.SaytoRoom(u.Displayname + " se ha conectado", this);
                            }


                            // SEND THE ROOM UPDATE TO THE LOBBY //
                            byte roomPage   = (byte)Math.Floor((decimal)(this.ID / 8));
                            var  targetList = Managers.ChannelManager.Instance.Get(this.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                            if (targetList.Count() > 0)
                            {
                                byte[] outBuffer = new Packets.RoomUpdate(this, true).BuildEncrypted();
                                foreach (Entities.User usr in targetList)
                                {
                                    usr.Send(outBuffer);
                                }
                            }
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
예제 #10
0
        public bool Add(Entities.User u)
        {
            if (Players.Count < MaximumPlayers)
            {
                lock (_playerLock) {
                    Team targetTeam     = Team.Derbaran;
                    byte startScanIndex = 0;
                    byte endScanIndex   = (byte)(MaximumPlayers / 2);

                    var debTeam = Players.Select(n => n.Value).Where(n => n.Team == Team.Derbaran).Count();
                    var niuTeam = Players.Select(n => n.Value).Where(n => n.Team == Team.NIU).Count();

                    if (debTeam > niuTeam)
                    {
                        targetTeam     = Team.NIU;
                        startScanIndex = (byte)(MaximumPlayers / 2);
                        endScanIndex   = MaximumPlayers;
                    }

                    for (byte i = startScanIndex; i < endScanIndex; i++)
                    {
                        if (!Players.ContainsKey(i))
                        {
                            Player plr = new Player(i, u, targetTeam);

                            // Send Room //
                            if (Players.Count > 0)
                            {
                                Send((new Packets.RoomPlayers(new ArrayList()
                                {
                                    plr
                                }).BuildEncrypted()));
                            }
                            else
                            {
                                Master = i;
                            }

                            // Add Player
                            Players.TryAdd(i, plr);
                            u.SetRoom(this, i);

                            // Send Join Packet //
                            u.Send(new Packets.RoomJoin(i, this));
                            u.Send(new Packets.RoomPlayers(new ArrayList(Players.Select(n => n.Value).Where(n => n.Id != i).ToArray())));

                            // Send to all spectators: TODO //

                            // SEND THE ROOM UPDATE TO THE LOBBY //
                            byte roomPage   = (byte)Math.Floor((decimal)(this.ID / 8));
                            var  targetList = Managers.ChannelManager.Instance.Get(this.Channel).Users.Select(n => n.Value).Where(n => n.RoomListPage == roomPage && n.Room == null);
                            if (targetList.Count() > 0)
                            {
                                byte[] outBuffer = new Packets.RoomUpdate(this, true).BuildEncrypted();
                                foreach (Entities.User usr in targetList)
                                {
                                    usr.Send(outBuffer);
                                }
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }