using System; using System.Collections.Generic; using System.Reflection; using Zepheus.FiestaLib.Networking; using Zepheus.Util; using Zepheus.InterLib.Networking; namespace Zepheus.Login.InterServer { [ServerModule(Util.InitializationStage.Metadata)] public class InterHandlerStore { private static Dictionary handlers; [InitializerMethod] public static bool Load() { handlers = new Dictionary(); foreach (var info in Reflector.FindMethodsByAttribute()) { InterPacketHandlerAttribute attribute = info.First; MethodInfo method = info.Second; if (!handlers.ContainsKey(attribute.Header)) { handlers[attribute.Header] = method; } else { Log.WriteLine(LogLevel.Warn, "Duplicate interhandler found: {0}", attribute.Header.ToString()); } } Log.WriteLine(LogLevel.Info, "{0} InterHandlers loaded.", handlers.Count); return true; } public static MethodInfo GetHandler(InterHeader ih) { MethodInfo meth; if (handlers.TryGetValue(ih, out meth)) { return meth; } return null; } public static Action GetCallback(MethodInfo method, params object[] parameters) { return () => method.Invoke(null, parameters); } } }