private bool TCPCmdPacketEvent(object sender) { TCPInPacket tcpInPacket = sender as TCPInPacket; TCPOutPacket tcpOutPacket = null; int flag = 0; bool result2; if (!this.inputServers.TryGetValue(tcpInPacket.CurrentSocket, out flag)) { LogManager.WriteLog(LogTypes.Error, string.Format("未建立会话或会话已关闭: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket)), null, true); result2 = false; } else { long processBeginTime = TimeUtil.NowEx(); TCPProcessCmdResults result = PlatTCPManager.ProcessCmd(tcpInPacket.CurrentSocket, this.tcpOutPacketPool, (int)tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, out tcpOutPacket); long processTime = TimeUtil.NowEx() - processBeginTime; if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { this.socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket); } else if (result == TCPProcessCmdResults.RESULT_FAILED) { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket)), null, true); return(false); } result2 = true; } return(result2); }
public static TCPProcessCmdResults ProcessCmd(Socket socket, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; PlatTCPManager.NetCommandFunc func = null; TCPProcessCmdResults result; if (!PlatTCPManager.getInstance().ProcessCmdFuncDict.TryGetValue(nID, out func) || null == func) { LogManager.WriteLog(LogTypes.Error, string.Format("未指定处理方式的命令: {0}, 关闭连接", (TCPPlatCmds)nID), null, true); result = TCPProcessCmdResults.RESULT_FAILED; } else { result = func(pool, nID, data, count, out tcpOutPacket); } return(result); }