public TCPProcessCmdResults dispathProcessor(GameServerClient client, int nID, byte[] data, int count)
        {
            //tring cmdData = null;

//             try
//             {
//                 cmdData = new UTF8Encoding().GetString(data, 0, count);
//             }
//             catch (Exception) //解析错误
//             {
//                 LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(client.CurrentSocket)));
//                 return TCPProcessCmdResults.RESULT_FAILED;
//             }

            try
            {
//                 //获取指令参数数量
//                 short cmdParamNum = -1;
//                 if (!cmdParamNumMapping.TryGetValue(nID, out cmdParamNum))
//                 {
//                     LogManager.WriteLog(LogTypes.Error, string.Format("未注册指令, CMD={0}, Client={1}",
//                         (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(client.CurrentSocket)));
//                     return TCPProcessCmdResults.RESULT_FAILED;
//                 };
                //解析用户名称和用户密码
//                 string[] cmdParams = cmdData.Split(':');
//                 if (cmdParams.Length != cmdParamNum)
//                 {
//                     LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}",
//                         (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(client.CurrentSocket), cmdParams.Length));
//                     return TCPProcessCmdResults.RESULT_FAILED;
//                 }


                //获取相对应的指令处理器
                ICmdProcessor cmdProcessor = null;
                if (!cmdProcesserMapping.TryGetValue(nID, out cmdProcessor))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("未注册指令, CMD={0}, Client={1}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(client.CurrentSocket)));

                    client.sendCmd((int)TCPGameServerCmds.CMD_DB_ERR_RETURN, "0");
                    return(TCPProcessCmdResults.RESULT_DATA);
                }

                cmdProcessor.processCmd(client, data, count);

                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                // 格式化异常错误信息
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.CurrentSocket), false);
            }

            client.sendCmd((int)TCPGameServerCmds.CMD_DB_ERR_RETURN, "0");
            return(TCPProcessCmdResults.RESULT_DATA);
        }
 public TCPProcessCmdResults dispathProcessor(GameServerClient client, int nID, byte[] data, int count)
 {
     try
     {
         ICmdProcessor cmdProcessor = null;
         if (!this.cmdProcesserMapping.TryGetValue(nID, out cmdProcessor))
         {
             LogManager.WriteLog(LogTypes.Error, string.Format("未注册指令, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(client.CurrentSocket)), null, true);
             client.sendCmd(30767, "0");
             return(TCPProcessCmdResults.RESULT_DATA);
         }
         cmdProcessor.processCmd(client, nID, data, count);
         return(TCPProcessCmdResults.RESULT_OK);
     }
     catch (Exception ex)
     {
         DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.CurrentSocket), false, false);
     }
     client.sendCmd(30767, "0");
     return(TCPProcessCmdResults.RESULT_DATA);
 }
Exemple #3
0
        /// <summary>
        /// 本地处理
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="nID"></param>
        /// <param name="data"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public TCPProcessCmdResults dispathProcessor(TMSKSocket socket, int nID, byte[] data, int count)
        {
            string cmdData = null;

            try
            {
                cmdData = new UTF8Encoding().GetString(data, 0, count);
            }
            catch (Exception) //解析错误
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                return(TCPProcessCmdResults.RESULT_FAILED);
            }

            try
            {
                //获取指令参数数量
                short cmdParamNum = -1;
                if (!cmdParamNumMapping.TryGetValue(nID, out cmdParamNum))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("未注册指令, CMD={0}, Client={1}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                ;
                //解析用户名称和用户密码
                string[] cmdParams = cmdData.Split(':');
                if (cmdParams.Length != cmdParamNum)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), cmdParams.Length));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                //根据socket获取GameClient
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                //获取相对应的指令处理器
                ICmdProcessor cmdProcessor = null;
                if (!cmdProcesserMapping.TryGetValue(nID, out cmdProcessor))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("未注册指令, CMD={0}, Client={1}",
                                                                      (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket)));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                if (!cmdProcessor.processCmd(client, cmdParams))
                {
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                // 格式化异常错误信息
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }