Exemple #1
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.IsSubclassOf(typeof(ISerializablePacket)))
     {
         Info.SetValue(Packet, val);
     }
 }
Exemple #2
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(bool)))
         Info.SetValue(Packet, val);
     else
         Info.SetValue(Packet, Convert.ChangeType((bool)val, Info.FieldType));
 }
        public static void BytesToField(ISerializablePacket Packet, byte[] Bytes, string FieldName)
        {
            if (Bytes == null || Bytes.Length <= 0)
            {
                return;
            }

            FieldInfo Info = Packet.GetType().GetField(FieldName);

            ISerializableFieldAttribute[] FieldsAttr = Info.GetCustomAttributes(typeof(ISerializableFieldAttribute), true) as ISerializableFieldAttribute[];
            if (FieldsAttr != null && FieldsAttr.Length > 0)
            {
                ISerializableField Field = Activator.CreateInstance(FieldsAttr[0].GetSerializableType()) as ISerializableField;
                Field.Index      = FieldsAttr[0].Index;
                Field.val        = Info.GetValue(Packet);
                Field.PacketType = PacketProcessor.GetFieldType(Field);

                PacketInStream Str = new PacketInStream(Bytes, Bytes.Length);
                Field.Deserialize(ref Str);
                Field.ApplyToFieldInfo(Info, Packet, Info.FieldType);
            }
            else
            {
                Info.SetValue(Packet, null);
            }
        }
        public void SendSerialized(ISerializablePacket Packet)
        {
            PacketOutStream Out = PacketProcessor.WritePacket(Packet);

            byte[] ToSend = Out.ToArray();
            SendTCP(ToSend);
            Out.Dispose();
        }
        public static PacketOutStream WritePacket(ISerializablePacket Packet)
        {
            PacketOutStream Stream = new PacketOutStream();

            WritePacket(ref Stream, Packet, true, true, true);

            return(Stream);
        }
Exemple #6
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(byte[])))
     {
         Info.SetValue(Packet, val);
     }
     else if (Field.Equals(typeof(string)))
     {
         Info.SetValue(Packet, Marshal.ConvertToString((byte[])val));
     }
 }
Exemple #7
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(bool)))
     {
         Info.SetValue(Packet, val);
     }
     else
     {
         Info.SetValue(Packet, Convert.ChangeType((bool)val, Info.FieldType));
     }
 }
Exemple #8
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(byte[])))
     {
         Info.SetValue(Packet, (byte[])val);
     }
     else if (Field.Equals(typeof(long)))
     {
         //Array.Reverse((val as byte[]));
         Info.SetValue(Packet, BitConverter.ToInt64((byte[])val, 0));
     }
 }
Exemple #9
0
        static public CacheUpdate BuildCache(uint CacheID, long CacheType, ISerializablePacket Packet)
        {
            CacheUpdate Data = new CacheUpdate();

            Data.CacheType  = CacheType;
            Data.CacheID    = CacheID;
            Data.CacheDatas = new List <ISerializablePacket>()
            {
                Packet
            };
            return(Data);
        }
Exemple #10
0
        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            if (Field.Equals(typeof(Dictionary <long, ISerializablePacket>)))
            {
                Dictionary <long, ISerializablePacket> Dic = new Dictionary <long, ISerializablePacket>();

                foreach (KeyValuePair <ISerializableField, ISerializableField> KP in (val as Dictionary <ISerializableField, ISerializableField>))
                {
                    Dic.Add((long)KP.Key.GetLong(), KP.Value.GetPacket());
                }

                Info.SetValue(Packet, Dic);
            }
        }
Exemple #11
0
        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            if (Field.Equals(typeof(List <uint>)))
            {
                List <uint> Luint = new List <uint>();
                foreach (ISerializableField Value in (List <ISerializableField>)val)
                {
                    Luint.Add(Value.GetUint());
                }
                Info.SetValue(Packet, Luint);
            }
            else if (Field.Equals(typeof(List <ISerializablePacket>)))
            {
                List <ISerializablePacket> Packets = new List <ISerializablePacket>();
                foreach (ISerializableField Value in (List <ISerializableField>)val)
                {
                    Packets.Add(Value.GetPacket());
                }
                Info.SetValue(Packet, Packets);
            }
            else if (Field.Equals(typeof(ISerializablePacket[])))
            {
                List <ISerializablePacket> Packets = new List <ISerializablePacket>();
                foreach (ISerializableField Value in (List <ISerializableField>)val)
                {
                    Packets.Add(Value.GetPacket());
                }
                Info.SetValue(Packet, Packets.ToArray());
            }
            else if (Field.Equals(typeof(List <bool>)))
            {
                List <bool> Bools = new List <bool>();
                foreach (ISerializableField Value in (List <ISerializableField>)val)
                {
                    Bools.Add((bool)Value.val);
                }
                Info.SetValue(Packet, Bools);
            }
            else if (Field.Equals(typeof(List <float>)))
            {
                List <float> floats = new List <float>();
                foreach (ISerializableField Value in (List <ISerializableField>)val)
                {
                    floats.Add(Value.GetFloat());
                }

                Info.SetValue(Packet, floats);
            }
        }
Exemple #12
0
        public override void OnRead(RiftClient From)
        {
            if (From.Acct == null || From.Rm == null)
            {
                return;
            }

            CharactersMgr Mgr = From.Rm.GetObject <CharactersMgr>();

            if (Mgr.GetCharactersCount(From.Acct.Id) >= 6)
            {
                From.Disconnect();
                return;
            }

            ISerializablePacket Response = new ISerializablePacket();

            Response.Opcode = (int)Opcodes.LobbyCharacterCreateResponse;
            if (Mgr.CharacterExist(Name))
            {
                Response.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)CharacterCreateResponses.INVALID_NAME);
            }
            else
            {
                Character Char = new Character();
                Char.AccountId     = From.Acct.Id;
                Char.CharacterName = Name;
                Char.Email         = From.Acct.Email;

                Char.Info              = new CharacterInfo();
                Char.Info.Class        = Class;
                Char.Info.CustomPacket = this.CharacterCustom;
                Char.Info.Level        = Mgr.StartingLevel;
                Char.Info.Race         = Race;
                Char.Info.Sex          = Sex;

                long CharacterID = Mgr.AddCharacter(Char);

                Response.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)CharacterCreateResponses.CREATE_OK);
                From.JustCreatedCharacter = CharacterID;
            }

            From.SendSerialized(Response);
        }
Exemple #13
0
        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            byte[] Data   = val as byte[];
            object Result = Data;

            if (Field.Equals(typeof(UInt32)))
            {
                Result = Marshal.ConvertToUInt32(Data[3], Data[2], Data[1], Data[0]);
            }
            else if (Field.Equals(typeof(Int32)))
            {
                Result = BitConverter.ToInt32(Data, 0);
            }
            else if (Field.Equals(typeof(long)))
            {
                Result = (long)BitConverter.ToUInt32(Data, 0);
            }

            Info.SetValue(Packet, Result);
        }
        public static bool WritePacket(ref PacketOutStream Stream, ISerializablePacket Packet, bool WithSize = true, bool WithTerminator = true, bool WithOpcode = true)
        {
            if (Packet == null)
            {
                return(false);
            }

            lock (Packet)
            {
                Packet.ConvertToField();

                PacketOutStream Data = new PacketOutStream();

                if (WithOpcode)
                {
                    Data.WriteEncoded7Bit(Packet.Opcode);
                }

                foreach (ISerializableField Field in Packet.GetFields().Values)
                {
                    WriteField(ref Data, Field);
                }

                if (WithTerminator && Packet.Opcode != (int)Opcodes.ProtocolHandshakeCompression)
                {
                    WriteField(ref Data, null, 0, (int)EPacketFieldType.Terminator);
                }

                if (WithSize)
                {
                    Stream.WriteEncoded7Bit(Data.Length);
                }

                Stream.Write(Data.ToArray());

                Packet.Fields.Clear();
            }

            return(true);
        }
        public static byte[] FieldToBytes(ISerializablePacket Packet, string FieldName)
        {
            FieldInfo Info = Packet.GetType().GetField(FieldName);

            ISerializableFieldAttribute[] FieldsAttr = Info.GetCustomAttributes(typeof(ISerializableFieldAttribute), true) as ISerializableFieldAttribute[];
            if (FieldsAttr != null && FieldsAttr.Length > 0)
            {
                ISerializableField Field = Activator.CreateInstance(FieldsAttr[0].GetSerializableType()) as ISerializableField;
                Field.Index      = FieldsAttr[0].Index;
                Field.val        = Info.GetValue(Packet);
                Field.PacketType = PacketProcessor.GetFieldType(Field);

                PacketOutStream Str = new PacketOutStream();
                Field.Serialize(ref Str, true);
                byte[] Result = Str.ToArray();
                return(Result);
            }
            else
            {
                return(null);
            }
        }
Exemple #16
0
        public override void Deserialize(ref PacketInStream Data)
        {
            long Opcode = Data.ReadEncoded7Bit();
            PacketHandlerDefinition Handler = PacketProcessor.GetPacketHandler(Opcode);
            ISerializablePacket     Packet  = Activator.CreateInstance(Handler.GetClass()) as ISerializablePacket;

            ISerializableField Field = null;

            Log.Debug("Packet", "----------------------> New " + Opcode.ToString("X8"));
            Packet.Opcode = Opcode;

            while ((Field = PacketProcessor.ReadField(ref Data)) != null)
            {
                Log.Debug("Packet", "------> ++T : " + Field.PacketType);
                Packet.AddField(Field.Index, Field);
            }

            Log.Debug("Packet", "----------------------> End ");

            Packet.ApplyToFieldInfo();
            val = Packet;
        }
Exemple #17
0
 public abstract void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field);
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     Info.SetValue(Packet, Convert.ChangeType(val,Info.FieldType));
 }
Exemple #19
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     Info.SetValue(Packet, Convert.ChangeType(val, Info.FieldType));
 }
Exemple #20
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     Info.SetValue(Packet, (long)val);
 }
        public bool ReadPacket()
        {
            if (Received.Count <= 0)
            {
                return(false);
            }

            if (!ReceiveCompress && !Crypted)
            {
                PacketInStream Packet = new PacketInStream(Received.ToArray(), Received.Count);
                long           Size   = Packet.ReadEncoded7Bit();

                if (Size > Packet.Length)
                {
                    return(false);
                }

                Received.RemoveRange(0, (int)(Packet.Position + Size));

                ISerializablePacket Pack = PacketProcessor.ReadPacket(ref Packet);
                if (Pack != null)
                {
                    Pack.OnRead(this);
                }

                return(true);
            }

            if (Crypted)
            {
                byte[] Packet = Received.ToArray();
                Received.Clear();
                Decrypt(Packet);
            }

            if (ReceiveCompress)
            {
                int End = -1;
                while ((End = GetEndCompression(ref Decrypted)) >= 0)
                {
                    byte[] ToUnCompress = new byte[End];
                    Buffer.BlockCopy(Decrypted.ToArray(), 0, ToUnCompress, 0, End);
                    Decrypted.RemoveRange(0, End);

                    byte[] Result = UnCompress(ToUnCompress);

                    Log.Dump("Decrypted", Result, 0, Result.Length);
                    PacketInStream Packet = new PacketInStream(Result, Result.Length);
                    long           Size   = Packet.ReadEncoded7Bit();

                    if (Size > Packet.Length)
                    {
                        Log.Error("ReadPacket", "Size > Packet.Lenght,Size=" + Size + ",Lenght=" + Packet.Length);
                        Packet.Dispose();
                        continue;
                    }

                    ISerializablePacket Pack = PacketProcessor.ReadPacket(ref Packet);
                    if (Pack != null)
                    {
                        Pack.OnRead(this);
                    }

                    Packet.Dispose();
                }
            }

            return(false);
        }
Exemple #22
0
 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     Info.SetValue(Packet, (long)val);
 }