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 RunPowerShellScriptCommandProvider(MainWindow mainWindow, ICmdProcessor cmdProcessor, ILog logger) { _mainWindow = mainWindow; _cmdProcessor = cmdProcessor; _cmdProcessor.ProcessExited += CmdProcessorProcessExited; _cmdProcessor.StandardErrorReceived += CmdProcessorStandardErrorReceived; _cmdProcessor.StandardOutReceived += CmdProcessorStandardOutReceived; _logger = logger; }
public void Register(ICmdProcessor processor, bool usageProcessor = false) { var cmd = processor.Keyword.ToUpper(); if (_processors.ContainsKey(cmd)) throw new InvalidOperationException( string.Format("The processor for command '{0}' is already registered.", cmd)); _processors[cmd] = processor; if (usageProcessor) _regCommandsProcessor = processor; }
public void Register(ICmdProcessor processor, bool usageProcessor = false) { var cmd = processor.Keyword.ToUpper(); if (_processors.ContainsKey(cmd)) { throw new InvalidOperationException( string.Format("The processor for command '{0}' is already registered.", cmd)); } _processors[cmd] = processor; if (usageProcessor) { _regCommandsProcessor = processor; } }
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); }
public void registerStreamProcessorEx(int cmdId, ICmdProcessor processor) { registerProcessorEx(cmdId, -1, -1, processor, TCPCmdFlags.IsBinaryStreamParams); }
public void registerProcessorEx(int cmdId, short minParamCount, short maxParamCount, ICmdProcessor processor, TCPCmdFlags cmdFlags = TCPCmdFlags.IsStringArrayParams) { Debug.Assert(processor != null); CmdHandler cmdHandler = new CmdHandler { CmdFlags = (uint)cmdFlags, MinParamCount = minParamCount, MaxParamCount = maxParamCount, CmdProcessor = processor, }; cmdProcesserMapping.Add(cmdId, cmdHandler); }
public void registerProcessor(int cmdId, short paramNum, ICmdProcessor processor) { registerProcessorEx(cmdId, paramNum, paramNum, processor, TCPCmdFlags.IsStringArrayParams); }
private void TriggerProcessor(ICmdProcessor icp) { }
public void registerProcessor(int cmdId, /*short paramNum,*/ ICmdProcessor processor) { //cmdParamNumMapping.Add(cmdId, paramNum); cmdProcesserMapping.Add(cmdId, processor); }
public void registerProcessor(int cmdId, ICmdProcessor processor) { this.cmdProcesserMapping.Add(cmdId, processor); }
/// <summary> /// Creates a new instance of <see cref="ProcessorException"/> /// </summary> /// <param name="processor">The processor that failed (not null).</param> /// <param name="message">A message to explain the failure.</param> /// <param name="ex">Any inner exception (may be null).</param> /// <exception cref="ArgumentNullException">Undefined processor</exception> public ProcessorException(ICmdProcessor processor, string message, Exception ex = null) : base(message, ex) { Processor = processor ?? throw new ArgumentNullException("Undefined processor"); }
/// <summary> /// 开始出发指令处理流程 /// </summary> /// <param name="icp"></param> private void TriggerProcessor(ICmdProcessor icp) { ;//不做任何处理 }
/// <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); }