示例#1
0
 public IEnumerator HandleCommand()
 {
     while (true)
     {
         Command command = CommandDispatcher.GetCommand();
         if (command == null)
         {
             yield return(null);
         }
         else
         {
             Logger.v("Find command : " + command.cmd + " value :" + command.recvObj);
             try
             {
                 CmdHandler handler = null;
                 if (handlers.TryGetValue(command.cmd, out handler))
                 {
                     long beg = DateTime.Now.Ticks / 10000;
                     handler(command);
                     StringBuilder sb = new StringBuilder();
                     sb.Append("[");
                     sb.Append(command.socket);
                     sb.Append("] Cmd: ");
                     sb.Append(command.cmd);
                     sb.Append(" costs: ");
                     sb.Append(DateTime.Now.Ticks / 10000 - beg);
                     sb.Append("ms");
                     Debug.Log(sb.ToString());
                     sdkUseTime += (DateTime.Now.Ticks / 10000 - beg) / 1000;
                 }
                 else
                 {
                     //没法找到
                     command.status = ResponseStatus.NO_SUCH_CMD;
                     CommandDispatcher.SendCommand(command);
                 }
             }
             catch (System.Exception ex)
             {
                 Logger.d("Handle Command expection =>" + ex.Message + " \n" + ex.StackTrace);
                 command.status = ResponseStatus.UN_KNOW_ERROR;
                 CommandDispatcher.SendCommand(command);
             }
         }
         yield return(null);
     }
 }