/// <summary> /// 处理消息包 /// </summary> /// <returns>是否执行成功</returns> protected bool DigestRecevedData(GameSession session, ArraySegment <byte> data) { string cmd = _serializer.DataToCmd(data.Array, data.Offset, data.Count); if (cmd == null || !this._handlers.ContainsKey(cmd)) { //如果没有处理器,先刷掉一批 return(false); } var handler = this._handlers[cmd]; var type = handler.RequestType; if (Filter(session, handler)) { return(false); } var request = _serializer.Deserialize(type, data.Array, data.Offset, data.Count); var task = new GameRequestTask(handler, session, request); if (handler.AllowAnonymous) { //当遇到allowanonymous的任务时,即表示此任务不需要其他游戏逻辑线程同步,只要session同步即可,那么可以不放入逻辑线程而直接执行 task.DoAction(); } else { this._workingQueue.Enqueue(task); } return(true); }
/// <summary> /// 处理消息包 /// </summary> /// <returns>是否执行成功</returns> protected bool ProcessRecevedData(GameSession session, ArraySegment <byte> data) { string cmd = _serializer.DataToCmd(data.Array, data.Offset, data.Count); if (cmd == null || !this._commands.ContainsKey(cmd)) { //如果没有处理器,先刷掉一批 return(false); } var cmdInfo = this._commands[cmd]; var type = cmdInfo.RequestType; if (!cmdInfo.AllowAnonymous && !session.IsAuthorized) { return(false); } var request = _serializer.Deserialize(type, data.Array, data.Offset, data.Count); var task = new GameRequestTask(cmdInfo.Command, session, request); if (cmdInfo.Asynchronous) { //当遇到allowanonymous的任务时,即表示此任务不需要其他游戏逻辑线程同步,只要session同步即可,那么可以不放入逻辑线程而直接执行 task.DoAction(); } else { this._workingQueue.Enqueue(task); } return(true); }