using XGame.Framework;
namespace XGame.Framework.Network
{
public enum MsgCodeDefine
{
SUCCESS_CODE = 0,
UNIFIED_ERROR_CODE = 1,
}
///
/// 网络消息控制器基类
///
/// 消息类型
public abstract class MsgController : IMsgController where T : IMsgData
{
#if FINAL_RELEASE
public void Process(IMessage msg, IMsgReceiverListener listener)
#else
void IMsgController.Process(IMessage msg, IMsgReceiverListener listener)
#endif
{
if (msg is IMsgPush)
{
OnProcess((T)msg, msg.Context);
}
else if (msg is IMsgResponse resp)
{
var code = resp.GetCode();
if (code == (int)MsgCodeDefine.SUCCESS_CODE)
{
OnProcess((T)msg, msg.Context);
}
else if (this is IMsgFailProcess failProcess)
{
failProcess.FailProcess((T)msg, msg.Context);
}
var args = new ResponseEventArgs()
{
errorCode = code,
info = resp.GetInfo(),
seqId = resp.InstanceID,
protoId = resp.ProtocolID,
};
listener.OnResponseFinish(args);
}
else
{
Log.Error($"[MsgController] 消息类型错误,Type:{msg.GetType()}");
}
}
protected abstract void OnProcess(T message, object context);
}
}