/// <summary> /// Initializes the <see cref="Kamilla.Network.Protocols.ProtocolManager"/>. /// </summary> public static void Initialize() { if (s_initialized) { return; } s_initialized = true; var protocolTypes = new List <Type>(16); var parserTypes = new List <Type>(2048); var basePacketParser = typeof(PacketParser); var baseProtocol = typeof(Protocol); foreach (var type in TypeManager.Types) { if (type.IsSubclassOf(baseProtocol)) { protocolTypes.Add(type); } else if (type.IsSubclassOf(basePacketParser)) { parserTypes.Add(type); } } // Load Protocols var nProtocols = protocolTypes.Count; s_wrappers = new ProtocolWrapper[nProtocols]; for (int i = 0; i < nProtocols; ++i) { try { s_wrappers[i] = new ProtocolWrapper(i, protocolTypes[i]); } catch { Console.WriteLine("Error: Failed to initialize protocol {0}", protocolTypes[i]); } } // Load Parsers var parserAttrType = typeof(PacketParserAttribute); foreach (var type in parserTypes) { var attrs = (PacketParserAttribute[])type.GetCustomAttributes(parserAttrType, true); foreach (var attr in attrs) { if (attr.Opcode == SpecialOpcodes.UnknownOpcode) { continue; } var protocol = FindWrapper(attr.ProtocolType); if (protocol == null) { Console.WriteLine("Error: Cannot find protocol '{0}' for parser type '{1}'", protocol, type); continue; } protocol.m_parsers.Add(attr.Opcode, type); } } }
/// <summary> /// Initializes the <see cref="Kamilla.Network.Protocols.ProtocolManager"/>. /// </summary> public static void Initialize() { if (s_initialized) return; s_initialized = true; var protocolTypes = new List<Type>(16); var parserTypes = new List<Type>(2048); var basePacketParser = typeof(PacketParser); var baseProtocol = typeof(Protocol); foreach (var type in TypeManager.Types) { if (type.IsSubclassOf(baseProtocol)) protocolTypes.Add(type); else if (type.IsSubclassOf(basePacketParser)) parserTypes.Add(type); } // Load Protocols var nProtocols = protocolTypes.Count; s_wrappers = new ProtocolWrapper[nProtocols]; for (int i = 0; i < nProtocols; ++i) { try { s_wrappers[i] = new ProtocolWrapper(i, protocolTypes[i]); } catch { Console.WriteLine("Error: Failed to initialize protocol {0}", protocolTypes[i]); } } // Load Parsers var parserAttrType = typeof(PacketParserAttribute); foreach (var type in parserTypes) { var attrs = (PacketParserAttribute[])type.GetCustomAttributes(parserAttrType, true); foreach (var attr in attrs) { if (attr.Opcode == SpecialOpcodes.UnknownOpcode) continue; var protocol = FindWrapper(attr.ProtocolType); if (protocol == null) { Console.WriteLine("Error: Cannot find protocol '{0}' for parser type '{1}'", protocol, type); continue; } protocol.m_parsers.Add(attr.Opcode, type); } } }