mirror of
https://github.com/EggLinks/DanhengServer-OpenSource.git
synced 2026-01-02 20:26:03 +08:00
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using EggLink.DanhengServer.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EggLink.DanhengServer.Server.Packet
|
|
{
|
|
public class HandlerManager
|
|
{
|
|
public Dictionary<int, Handler> handlers = [];
|
|
|
|
public HandlerManager()
|
|
{
|
|
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 Handler? GetHandler(int cmdId)
|
|
{
|
|
try
|
|
{
|
|
return handlers[cmdId];
|
|
} catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|