private void GenerateHandlerReferences(Type type, bool isWorldServer)
{
IEnumerable<Type> handlerTypes = !isWorldServer ? type.Assembly.GetTypes().Where(t => t.Name.Equals("LoginPacketHandler")) // shitty but it works
: type.Assembly.GetTypes().Where(p => !p.IsInterface && type.GetInterfaces().FirstOrDefault().IsAssignableFrom(p));
// iterate thru each type in the given assembly
foreach (Type handlerType in handlerTypes)
{
IPacketHandler handler = (IPacketHandler)Activator.CreateInstance(handlerType, new object[] { this });
// include PacketDefinition
foreach (MethodInfo methodInfo in handlerType.GetMethods().Where(x => x.GetCustomAttributes(false).OfType<PacketAttribute>().Any() || x.GetParameters().FirstOrDefault()?.ParameterType?.BaseType == typeof(PacketDefinition)))
{
PacketAttribute packetAttribute = methodInfo.GetCustomAttributes(false).OfType<PacketAttribute>().FirstOrDefault();
// assume PacketDefinition based handler method
if (packetAttribute == null)
{
HandlerMethodReference methodReference = new HandlerMethodReference(DelegateBuilder.BuildDelegate<Action<object, object>>(methodInfo), handler, methodInfo.GetParameters().FirstOrDefault()?.ParameterType);
HandlerMethods.Add(methodReference.Identification, methodReference);
}
else
{
// assume string based handler method
HandlerMethodReference methodReference = new HandlerMethodReference(DelegateBuilder.BuildDelegate<Action<object, object>>(methodInfo), handler, packetAttribute);
HandlerMethods.Add(methodReference.Identification, methodReference);
}
}
}
}