//处理客户端的请求 protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { //OperationRequest封装了请求的信息 //SendParameters 参数,传递的数据 //通过客户端的OperationCode从HandlerDict里面获取到了需要的Hander BaseHandler handler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode); //如果找到了需要的hander就调用我们hander里面处理请求的方法 if (handler != null) { handler.OnOperationRequest(operationRequest, sendParameters, this); } else//否则我们就使用默认的hander { BaseHandler defaultHandler = DictTool.GetValue <OperationCode, BaseHandler>(GameServer.Instance.HandlerDict, OperationCode.Default); defaultHandler.OnOperationRequest(operationRequest, sendParameters, this); } }
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { GameApplication application = GameApplication.Instance; if (application == null) { return; } BaseHandler handler = application.GetHandler((OperationCode)operationRequest.OperationCode); if (handler == null) { return; } byte[] data = null; object p; if (operationRequest.Parameters.TryGetValue(0, out p)) { data = p as byte[]; } handler.OnOperateRequest(data, this, sendParameters); }
private void RegisterHandler(BaseHandler handler) { handlers.Add(handler.OpCode, handler); }