mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-13 21:34:43 +01:00
Init enter game
This commit is contained in:
31
GameServer/Server/Packet/HandlerManager.cs
Normal file
31
GameServer/Server/Packet/HandlerManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace KianaBH.GameServer.Server.Packet;
|
||||
|
||||
public static class HandlerManager
|
||||
{
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user