try to fix protocol factory Invoke

This commit is contained in:
rfi 2024-04-25 11:47:15 +07:00
parent 5ca05509fc
commit 9b0a4075f6
2 changed files with 4 additions and 4 deletions

View File

@ -59,7 +59,7 @@ namespace SCHALE.GameServer.Controllers.Api
var payload = (JsonSerializer.Deserialize(payloadStr, requestType) as RequestPacket)!; var payload = (JsonSerializer.Deserialize(payloadStr, requestType) as RequestPacket)!;
var rsp = protocolHandlerFactory.Invoke(protocol, [payload]); var rsp = protocolHandlerFactory.Invoke(protocol, payload);
if (rsp is null) if (rsp is null)
{ {
logger.LogDebug("{Protocol} {Payload:j}", payload.Protocol, payloadStr); logger.LogDebug("{Protocol} {Payload:j}", payload.Protocol, payloadStr);

View File

@ -18,7 +18,7 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
public interface IProtocolHandlerFactory public interface IProtocolHandlerFactory
{ {
public ResponsePacket? Invoke(Protocol protocol, params object?[]? args); public ResponsePacket? Invoke(Protocol protocol, RequestPacket? req);
public MethodInfo? GetProtocolHandler(Protocol protocol); public MethodInfo? GetProtocolHandler(Protocol protocol);
public Type? GetRequestPacketTypeByProtocol(Protocol protocol); public Type? GetRequestPacketTypeByProtocol(Protocol protocol);
public void RegisterInstance(Type t, object? inst); public void RegisterInstance(Type t, object? inst);
@ -62,14 +62,14 @@ namespace SCHALE.GameServer.Controllers.Api.ProtocolHandlers
} }
} }
public ResponsePacket? Invoke(Protocol protocol, params object?[]? args) public ResponsePacket? Invoke(Protocol protocol, RequestPacket? req)
{ {
var handler = GetProtocolHandler(protocol); var handler = GetProtocolHandler(protocol);
if (handler is null) if (handler is null)
return null; return null;
handlerInstances.TryGetValue(handler.DeclaringType!, out var inst); handlerInstances.TryGetValue(handler.DeclaringType!, out var inst);
return (ResponsePacket?)handler.Invoke(inst, args); return (ResponsePacket?)handler.Invoke(inst, [req]);
} }
public MethodInfo? GetProtocolHandler(Protocol protocol) public MethodInfo? GetProtocolHandler(Protocol protocol)