Exemplo n.º 1
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))
                    {
                        ISerializableAttribute[] PacketAttributes = Class.GetCustomAttributes(typeof(ISerializableAttribute), true) as ISerializableAttribute[];
                        if (PacketAttributes == null || PacketAttributes.Length <= 0)
                            continue;

                        ISerializableAttribute PacketAttribute = PacketAttributes[0];
                        PacketHandlerDefinition PacketDef = new PacketHandlerDefinition(PacketAttribute.GetOpcode(), Class);

                        Log.Debug("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());
        }
Exemplo n.º 2
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;
        }