コード例 #1
0
        void CheckSameFPs(fp user)
        {
            List <fp> list = this.fplist.FindAll(x => x.hash == user.hash);

            if (list.Count > this.fp_limit)
            {
                list[list.Count - 1].client.Disconnect();
                this.fplist.Remove(list[list.Count - 1]);
                CheckSameFPs(user);
            }
        }
コード例 #2
0
        public override bool OnPacketReceived(Packet packet, IClient client)
        {
            if (packet.Opcode == 0x133D && !fp_enabled)
            {
                packet.Replace(new Packet(0x2002));
                return(true);
            }

            if (packet.Opcode == 0x133D)
            {
                if (!fp_enabled)
                {
                    return(false);
                }

                try {
                    ushort version = packet.ReadUInt16();
                    packet.ReadAscii();

                    int    size           = packet.ReadUInt16();
                    byte[] bytes          = packet.ReadBytes(size);
                    byte[] decryptedbytes = AES.Decrypt(bytes);

                    PacketReader reader = new PacketReader(decryptedbytes);

                    string fp       = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadUInt16()));
                    bool   isVMWare = reader.ReadByte() == 1;
                    bool   isVPC    = reader.ReadByte() == 1;
                    string key      = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadUInt16()));

                    fp user = new fp()
                    {
                        client      = client,
                        hash        = fp,
                        isvmware    = isVMWare,
                        isvpc       = isVPC,
                        providerkey = key
                    };

                    fp find = this.fplist.Find(x => x.client == client);

                    if (user.isvmware && !fp_allow_vmware)
                    {
                        client.Disconnect();
                        GetLogger().Trace("The user will be disconnected due use VMWare.");
                        return(false);
                    }

                    if (user.isvpc && !fp_allow_vpc)
                    {
                        client.Disconnect();
                        GetLogger().Trace("The user will be disconnected due use VPC.");
                        return(false);
                    }

                    if (key != provider_key)
                    {
                        client.Disconnect();
                        GetLogger().Trace("The user will be disconnected due wrong provider key.");
                        return(false);
                    }



                    if (find == null)
                    {
                        this.fplist.Add(user);
                        CheckSameFPs(user);
                    }
                    else
                    {
                        this.fplist.Remove(find);
                        this.fplist.Add(user);
                        CheckSameFPs(user);
                    }

                    GetLogger().Trace("FP:" + user.hash);
                }
                catch (Exception e)
                {
                    GetLogger().Warn(e);
                    GetLogger().Trace("Something went wrong. The User IP = {0}, Packet Hex Bytes = {1}", client.IPAddress, ByteArrayExtension.HexDump(packet.GetBytes()));
                }

                packet.Replace(new Packet(0x2002));
                return(true);
            }

            if (packet.Opcode == 0xA102)
            {
                if (ip_enabled)
                {
                    List <IClient> ips = GetSameIPs(client);

                    if (ips.Count > ip_limit)
                    {
                        Packet resp = new Packet(packet.Opcode, packet.Encrypted, packet.Massive);
                        resp.WriteUInt8(0x02);
                        resp.WriteUInt8(0xF);
                        resp.Lock();
                        packet.Replace(resp);
                    }
                }


                if (fp_enabled)
                {
                    List <fp> fps = GetSameFps(client);

                    if (fps.Count > fp_limit || fps.Count == 0)
                    {
                        Packet resp = new Packet(packet.Opcode, packet.Encrypted, packet.Massive);
                        resp.WriteUInt8(0x02);
                        resp.WriteUInt8(0xF);
                        resp.Lock();
                        packet.Replace(resp);
                    }
                }
            }

            return(true);
        }
コード例 #3
0
        List <fp> GetSameFps(IClient client)
        {
            fp find = this.fplist.Find(x => x.client == client);

            return(this.fplist.FindAll(x => x.hash == find.hash));
        }