Feature:Asynchronous Operation & Formatting Code

- Now the async operation is enabled!
- Code formatted by Resharper plugin <3
This commit is contained in:
Somebody
2024-07-22 17:12:03 +08:00
parent e983375620
commit 87d228eb79
793 changed files with 34764 additions and 40190 deletions

View File

@@ -1,34 +1,31 @@
using System.Reflection;
namespace EggLink.DanhengServer.Server.Packet
namespace EggLink.DanhengServer.Server.Packet;
public static class HandlerManager
{
public static class HandlerManager
public static Dictionary<int, Handler> handlers = [];
public static void Init()
{
public static Dictionary<int, Handler> handlers = [];
public static void Init()
var classes = Assembly.GetExecutingAssembly().GetTypes(); // Get all classes in the assembly
foreach (var cls in classes)
{
var classes = Assembly.GetExecutingAssembly().GetTypes(); // Get all classes in the assembly
foreach (var cls in classes)
{
var attribute = (Opcode)Attribute.GetCustomAttribute(cls, typeof(Opcode))!;
var attribute = (Opcode)Attribute.GetCustomAttribute(cls, typeof(Opcode))!;
if (attribute != null)
{
handlers.Add(attribute.CmdId, (Handler)Activator.CreateInstance(cls)!);
}
}
}
public static Handler? GetHandler(int cmdId)
{
try
{
return handlers[cmdId];
} catch
{
return null;
}
if (attribute != null) handlers.Add(attribute.CmdId, (Handler)Activator.CreateInstance(cls)!);
}
}
}
public static Handler? GetHandler(int cmdId)
{
try
{
return handlers[cmdId];
}
catch
{
return null;
}
}
}