Esempio n. 1
0
        public static PacketHandlerDefinition GetPacketHandler(long Opcode)
        {
            PacketHandlerDefinition Handler;

            Definitions.TryGetValue(Opcode, out Handler);

            if (Handler == null)
            {
                Log.Error("PacketProcessor", "Unhandled Opcode : " + Opcode.ToString("X8"));
                Handler = new PacketHandlerDefinition(Opcode, typeof(ISerializablePacket));
            }

            return(Handler);
        }
Esempio n. 2
0
        public static void RegisterDefinitions()
        {
            Definitions = new Dictionary <long, PacketHandlerDefinition>();
            FieldsTypes = new Dictionary <EPacketFieldType, ISerializableField>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type[] types = null;

                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    types = e.Types;
                }

                foreach (Type Class in types)
                {
                    if (Class.BaseType == typeof(ISerializablePacket) && Class.GetCustomAttributes(typeof(ISerializableAttribute), true) != null)
                    {
                        ISerializableAttribute  PacketAttribute = Class.GetCustomAttributes(typeof(ISerializableAttribute), true)[0] as ISerializableAttribute;
                        PacketHandlerDefinition PacketDef       = new PacketHandlerDefinition(PacketAttribute.GetOpcode(), Class);

                        Log.Success("RegisterDefinitions", "Registering Handler : " + PacketAttribute.GetOpcode().ToString("X8"));
                        if (!Definitions.ContainsKey(PacketAttribute.GetOpcode()))
                        {
                            Definitions.Add(PacketAttribute.GetOpcode(), PacketDef);
                        }
                        else
                        {
                            Log.Error("RegisterDefinitions", "Handler already registered : " + PacketAttribute.GetOpcode().ToString("X8"));
                        }
                    }
                }
            }

            FieldsTypes.Add(EPacketFieldType.True, new BoolBitField());
            FieldsTypes.Add(EPacketFieldType.False, new BoolBitField());
            FieldsTypes.Add(EPacketFieldType.List, new ListBitField());
            FieldsTypes.Add(EPacketFieldType.Packet, new PacketBitField());
            FieldsTypes.Add(EPacketFieldType.ByteArray, new ArrayBitField());
            FieldsTypes.Add(EPacketFieldType.Raw4Bytes, new Raw4BitField());
            FieldsTypes.Add(EPacketFieldType.Raw8Bytes, new Raw8BitBitField());
            FieldsTypes.Add(EPacketFieldType.Dictionary, new DicBitField());
            FieldsTypes.Add(EPacketFieldType.Signed7BitEncoded, new Encoded7BitField());
            FieldsTypes.Add(EPacketFieldType.Unsigned7BitEncoded, new Unsigned7BitField());
        }
Esempio n. 3
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;

            Packet.Opcode = Opcode;

            ISerializableField Field = null;

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

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

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

            Packet.ApplyToFieldInfo();
            val = Packet;
        }
Esempio n. 4
0
        public static PacketHandlerDefinition GetPacketHandler(long Opcode)
        {
            PacketHandlerDefinition Handler;
            Definitions.TryGetValue(Opcode, out Handler);

            if (Handler == null)
            {
                Log.Error("PacketProcessor","Unhandled Opcode : " + Opcode.ToString("X8"));
                Handler = new PacketHandlerDefinition(Opcode, typeof(ISerializablePacket));
            }

            return Handler;
        }
Esempio n. 5
0
        public static void RegisterDefinitions()
        {
            Definitions = new Dictionary<long, PacketHandlerDefinition>();
            FieldsTypes = new Dictionary<EPacketFieldType, ISerializableField>();

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type[] types = null;

                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException e)
                {
                    types = e.Types;
                }

                foreach (Type Class in types)
                {
                    if (Class.BaseType == typeof(ISerializablePacket) && Class.GetCustomAttributes(typeof(ISerializableAttribute), true) != null)
                    {
                        ISerializableAttribute PacketAttribute = Class.GetCustomAttributes(typeof(ISerializableAttribute), true)[0] as ISerializableAttribute;
                        PacketHandlerDefinition PacketDef = new PacketHandlerDefinition(PacketAttribute.GetOpcode(), Class);

                        Log.Success("RegisterDefinitions", "Registering Handler : " + PacketAttribute.GetOpcode().ToString("X8"));
                        if(!Definitions.ContainsKey(PacketAttribute.GetOpcode()))
                            Definitions.Add(PacketAttribute.GetOpcode(), PacketDef);
                        else
                            Log.Error("RegisterDefinitions","Handler already registered : " + PacketAttribute.GetOpcode().ToString("X8"));
                    }
                }
            }

            FieldsTypes.Add(EPacketFieldType.True, new BoolBitField());
            FieldsTypes.Add(EPacketFieldType.False, new BoolBitField());
            FieldsTypes.Add(EPacketFieldType.List, new ListBitField());
            FieldsTypes.Add(EPacketFieldType.Packet, new PacketBitField());
            FieldsTypes.Add(EPacketFieldType.ByteArray, new ArrayBitField());
            FieldsTypes.Add(EPacketFieldType.Raw4Bytes, new Raw4BitField());
            FieldsTypes.Add(EPacketFieldType.Raw8Bytes, new Raw8BitBitField());
            FieldsTypes.Add(EPacketFieldType.Dictionary, new DicBitField());
            FieldsTypes.Add(EPacketFieldType.Signed7BitEncoded, new Encoded7BitField());
            FieldsTypes.Add(EPacketFieldType.Unsigned7BitEncoded, new Unsigned7BitField());
        }