/// <summary> /// 接收数据通知函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool SocketReceived(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; TCPInPacket tcpInPacket = null; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; lock (dictInPackets) //锁定接收包队列 { if (!dictInPackets.TryGetValue(s, out tcpInPacket)) { tcpInPacket = tcpInPacketPool.Pop(s, TCPCmdPacketEvent); dictInPackets[s] = tcpInPacket; } } //处理收到的包 if (!tcpInPacket.WriteData(e.Buffer, e.Offset, e.BytesTransferred)) { //LogManager.WriteLog(LogTypes.Error, string.Format("接收到非法数据长度的tcp命令, 需要立即端断开!")); //socketListener.CloseSocket(tcpInPacket.CurrentSocket); return(false); } return(true); }
private bool TCPCmdPacketEvent(object sender) { TCPInPacket tcpInPacket = sender as TCPInPacket; TCPOutPacket tcpOutPacket = null; GameServerClient client = null; bool result2; if (!this.gameServerClients.TryGetValue(tcpInPacket.CurrentSocket, out client)) { LogManager.WriteLog(LogTypes.Error, string.Format("未建立会话或会话已关闭: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); result2 = false; } else { TCPProcessCmdResults result = TCPCmdHandler.ProcessCmd(client, this.DBMgr, this.tcpOutPacketPool, (int)tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, out tcpOutPacket); 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))); return(false); } result2 = true; } return(result2); }
/// <summary> /// 断开成功通知函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SocketClosed(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; //将接收的缓冲删除 lock (dictInPackets) { if (dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = dictInPackets[s]; tcpInPacketPool.Push(tcpInPacket); //缓冲回收 dictInPackets.Remove(s); } } //断开连接时,清除会话实例 lock (gameServerClients) { GameServerClient client = null; if (gameServerClients.TryGetValue(s, out client)) { client.release(); gameServerClients.Remove(s); } } //通知主窗口显示连接数 //RootWindow.Dispatcher.BeginInvoke((MethodInvoker)delegate //{ RootWindow.TotalConnections = sl.ConnectedSocketsCount; //}); }
private void SocketClosed(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; lock (this.dictInPackets) { if (this.dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = this.dictInPackets[s]; this.tcpInPacketPool.Push(tcpInPacket); this.dictInPackets.Remove(s); } } lock (this.gameServerClients) { GameServerClient client = null; if (this.gameServerClients.TryGetValue(s, out client)) { client.release(); this.gameServerClients.Remove(s); } } this.RootWindow.TotalConnections = sl.ConnectedSocketsCount; }
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); }
/// <summary> /// 在多个线程内部循环调用 /// </summary> public void ProcessCmdPackets(Queue <CmdPacket> ls) { //dictInPackets.Values值的个数可能会变化,每次处理先保存好最大个数 //同时给出20个冗余数量 int maxCount = dictInPackets.Values.Count + 20; for (int n = 0; n < maxCount; n++) { TCPInPacket tcpInPacket = GetNextTcpInPacket(n); //这意味着列表数据包变少了 if (null == tcpInPacket) { break; } ls.Clear(); if (tcpInPacket.PopCmdPackets(ls)) //判断是否取到了指令列表 { try { while (ls.Count > 0) { CmdPacket cmdPacket = ls.Dequeue(); //接收到了完整的命令包 TCPOutPacket tcpOutPacket = null; TCPProcessCmdResults result = TCPProcessCmdResults.RESULT_FAILED; result = TCPCmdHandler.ProcessCmd(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, cmdPacket.CmdID, cmdPacket.Data, cmdPacket.Data.Length, out tcpOutPacket); if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { //向登陆客户端返回数据 socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket); } else if (result == TCPProcessCmdResults.RESULT_FAILED)//解析失败, 直接关闭连接 { if (cmdPacket.CmdID != (int)TCPGameServerCmds.CMD_LOG_OUT) { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); } SysConOut.WriteLine("========================ProcessCmdPackets CloseSocket================"); // Console.WriteLine("========================ProcessCmdPackets CloseSocket================"); //这儿需要关闭链接--->这样关闭对吗? socketListener.CloseSocket(tcpInPacket.CurrentSocket); break; } } } finally { //处理结束之后设置相关标志位 tcpInPacket.OnThreadDealingComplete(); } } } }
private bool TCPCmdPacketEvent(object sender) { TCPInPacket tcpInPacket = sender as TCPInPacket; Socket s = tcpInPacket.CurrentSocket; //接收到了完整的命令包 bool ret = false; ret = TCPCmdHandler.ProcessServerCmd(this, tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize); return(ret); }
/// <summary> /// 关闭某个socket对应的角色连接 /// </summary> /// <param name="s"></param> public void ForceCloseSocket(TMSKSocket s) { //删除延迟关闭的TMSKSocket信息 DelayForceClosingMgr.RemoveDelaySocket(s); //将接收的缓冲删除 lock (dictInPackets) { if (dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = dictInPackets[s]; tcpInPacketPool.Push(tcpInPacket); //缓冲回收 dictInPackets.Remove(s); } } //删除客户端信息 GameClient gameClient = GameManager.ClientMgr.FindClient(s); if (null != gameClient) { //客户端离线 GameManager.ClientMgr.Logout(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, gameClient); gameClient = null; } string userID = GameManager.OnlineUserSession.FindUserID(s); //添加到在线回话中 GameManager.OnlineUserSession.RemoveSession(s); //删除用户名称 GameManager.OnlineUserSession.RemoveUserName(s); //删除用户是否成人标志 GameManager.OnlineUserSession.RemoveUserAdult(s); //注销UserID, 放到最后,但是获取userID放前边 if ("" != userID) { Global.RegisterUserIDToDBServer(userID, 0); } //已经关闭之后再调用一次 Global._SendBufferManager.Remove(s); //通知主窗口显示连接数 //RootWindow.Dispatcher.BeginInvoke((MethodInvoker)delegate //{ // // 通知界面修改连接数 // RootWindow.textBlock1.Text = string.Format("{0}/{1}", GameManager.ClientMgr.GetClientCount(), socketListener.ConnectedSocketsCount); //}); }
/// <summary> /// 接收数据通知函数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool SocketReceived(object sender, SocketAsyncEventArgs e) { try { SocketListener sl = sender as SocketListener; TCPInPacket tcpInPacket = null; AsyncUserToken userToken = (e.UserToken as AsyncUserToken); TMSKSocket s = userToken.CurrentSocket; if (GameManager.FlagOptimizeLock) { tcpInPacket = s._TcpInPacket; if (null == tcpInPacket) { lock (dictInPackets) //锁定接收包队列 { if (!dictInPackets.TryGetValue(s, out tcpInPacket)) { tcpInPacket = tcpInPacketPool.Pop(s, TCPCmdPacketEvent); dictInPackets[s] = tcpInPacket; } } s._TcpInPacket = tcpInPacket; } } else { lock (dictInPackets) //锁定接收包队列 { if (!dictInPackets.TryGetValue(s, out tcpInPacket)) { tcpInPacket = tcpInPacketPool.Pop(s, TCPCmdPacketEvent); dictInPackets[s] = tcpInPacket; } } } //处理收到的包 if (!tcpInPacket.WriteData(e.Buffer, e.Offset, e.BytesTransferred)) { SysConOut.WriteLine(string.Format("接收到非法数据长度的tcp命令, 需要立即断开! {0} {1}", e.Offset, e.BytesTransferred)); //LogManager.WriteLog(LogTypes.Error, string.Format("接收到非法数据长度的tcp命令, 需要立即断开!")); return(false); } } catch (Exception ex) { SysConOut.WriteLine("SocketReceived 异常-------------------" + ex.Message); } return(true); }
public void ProcessCmdPackets(Queue <CmdPacket> ls) { int maxCount = this.dictInPackets.Values.Count + 20; for (int i = 0; i < maxCount; i++) { TCPInPacket tcpInPacket = this.GetNextTcpInPacket(i); if (null == tcpInPacket) { break; } ls.Clear(); if (tcpInPacket.PopCmdPackets(ls)) { try { while (ls.Count > 0) { CmdPacket cmdPacket = ls.Dequeue(); TCPOutPacket tcpOutPacket = null; TCPProcessCmdResults result = TCPCmdHandler.ProcessCmd(this, tcpInPacket.CurrentSocket, this.tcpClientPool, this.tcpRandKey, this.tcpOutPacketPool, cmdPacket.CmdID, cmdPacket.Data, cmdPacket.Data.Length, out tcpOutPacket); if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { this.socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket, true); } else { if (result == TCPProcessCmdResults.RESULT_FAILED) { if (cmdPacket.CmdID != 22) { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false)), null, true); } this.socketListener.CloseSocket(tcpInPacket.CurrentSocket, ""); break; } if (result == TCPProcessCmdResults.RESULT_DATA_CLOSE && null != tcpOutPacket) { this.socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket, true); tcpInPacket.CurrentSocket.DelayClose = 250; } } } } finally { tcpInPacket.OnThreadDealingComplete(); } } } }
private void DirectSendPolicyFileData(TCPInPacket tcpInPacket) { TMSKSocket s = tcpInPacket.CurrentSocket; try { s.Send(TCPPolicy.PolicyServerFileContent, TCPPolicy.PolicyServerFileContent.Length, SocketFlags.None); LogManager.WriteLog(LogTypes.Info, string.Format("向客户端返回策略文件数据: {0}", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false)), null, true); } catch (Exception) { LogManager.WriteLog(LogTypes.Info, string.Format("向客户端返回策略文件时,socket出现异常,对方已经关闭: {0}", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false)), null, true); } }
/// <summary> /// 命令包接收完毕后的回调事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool TCPCmdPacketEvent(object sender) { TCPInPacket tcpInPacket = sender as TCPInPacket; //接收到了完整的命令包 TCPOutPacket tcpOutPacket = null; TCPProcessCmdResults result = TCPProcessCmdResults.RESULT_FAILED; GameServerClient client = null; if (!gameServerClients.TryGetValue(tcpInPacket.CurrentSocket, out client)) { LogManager.WriteLog(LogTypes.Error, string.Format("未建立会话或会话已关闭: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); return(false); } //接收到了完整的命令包 long processBeginTime = TimeUtil.NowEx(); result = TCPCmdHandler.ProcessCmd(client, DBMgr, tcpOutPacketPool, tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, out tcpOutPacket); long processTime = (TimeUtil.NowEx() - processBeginTime); if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { //向对方发送数据 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))); //socketListener.CloseSocket(tcpInPacket.CurrentSocket); return(false); } lock (cmdMoniter) //锁定命令监控对象 { int cmdID = tcpInPacket.PacketCmdID; PorcessCmdMoniter moniter = null; if (!cmdMoniter.TryGetValue(cmdID, out moniter)) { moniter = new PorcessCmdMoniter(cmdID, processTime); cmdMoniter.Add(cmdID, moniter); } moniter.onProcessNoWait(processTime); } return(true); }
private bool SocketReceived(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; TCPInPacket tcpInPacket = null; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; lock (this.dictInPackets) { if (!this.dictInPackets.TryGetValue(s, out tcpInPacket)) { tcpInPacket = this.tcpInPacketPool.Pop(s, new TCPCmdPacketEventHandler(this.TCPCmdPacketEvent)); this.dictInPackets[s] = tcpInPacket; } } return(tcpInPacket.WriteData(e.Buffer, e.Offset, e.BytesTransferred)); }
public ushort LastPacketCmdID(TMSKSocket s) { ushort cmd = 0; if (s != null && this.dictInPackets != null) { lock (this.dictInPackets) { TCPInPacket inPacket = null; if (this.dictInPackets.TryGetValue(s, out inPacket)) { cmd = inPacket.LastPacketCmdID; } } } return(cmd); }
public UInt16 LastPacketCmdID(TMSKSocket s) { UInt16 cmd = (UInt16)TCPGameServerCmds.CMD_UNKNOWN; if (s != null && dictInPackets != null) { lock (dictInPackets) { TCPInPacket inPacket = null; if (dictInPackets.TryGetValue(s, out inPacket)) { cmd = inPacket.LastPacketCmdID; } } } return(cmd); }
public string GetAllCacheCmdPacketInfo() { int nTotal = 0; int nMaxNum = 0; lock (this.dictInPackets) { for (int i = 0; i < this.dictInPackets.Values.Count; i++) { TCPInPacket tcpInPacket = this.dictInPackets.Values.ElementAt(i); if (tcpInPacket.GetCacheCmdPacketCount() > nMaxNum) { nMaxNum = tcpInPacket.GetCacheCmdPacketCount(); } nTotal += tcpInPacket.GetCacheCmdPacketCount(); } } return(string.Format("总共缓存命令包{0}个,单个连接最大缓存{1}个", nTotal, nMaxNum)); }
private void SocketClosed(object sender, SocketAsyncEventArgs e) { SocketListener sl = sender as SocketListener; Socket s = (e.UserToken as AsyncUserToken).CurrentSocket; lock (this.dictInPackets) { if (this.dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = this.dictInPackets[s]; this.tcpInPacketPool.Push(tcpInPacket); this.dictInPackets.Remove(s); } } lock (this.inputServers) { this.inputServers.Remove(s); } }
private bool TCPCmdPacketEvent(object sender) { TCPInPacket tcpInPacket = sender as TCPInPacket; TCPOutPacket tcpOutPacket = null; GameServerClient client = null; bool result2; if (!this.gameServerClients.TryGetValue(tcpInPacket.CurrentSocket, out client)) { LogManager.WriteLog(LogTypes.Error, string.Format("未建立会话或会话已关闭: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket)), null, true); result2 = false; } else { TCPManager.CurrentClient = client; long processBeginTime = TimeUtil.NowEx(); TCPProcessCmdResults result = TCPCmdHandler.ProcessCmd(client, this.DBMgr, 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); } lock (TCPManager.cmdMoniter) { int cmdID = (int)tcpInPacket.PacketCmdID; PorcessCmdMoniter moniter = null; if (!TCPManager.cmdMoniter.TryGetValue(cmdID, out moniter)) { moniter = new PorcessCmdMoniter(cmdID, processTime); TCPManager.cmdMoniter.Add(cmdID, moniter); } moniter.onProcessNoWait(processTime); } TCPManager.CurrentClient = null; result2 = true; } return(result2); }
/// <summary> /// 返回待处理数据包信息 用于界面显示用 /// </summary> /// <returns></returns> public String GetAllCacheCmdPacketInfo() { int nTotal = 0; int nMaxNum = 0; lock (dictInPackets) //锁定接收包队列 { for (int n = 0; n < dictInPackets.Values.Count; n++) { TCPInPacket tcpInPacket = dictInPackets.Values.ElementAt(n); if (tcpInPacket.GetCacheCmdPacketCount() > nMaxNum) { nMaxNum = tcpInPacket.GetCacheCmdPacketCount(); } nTotal += tcpInPacket.GetCacheCmdPacketCount(); } } /**/ return(String.Format("总共缓存命令包{0}个,单个连接最大缓存{1}个", nTotal, nMaxNum)); }
public void ForceCloseSocket(TMSKSocket s) { DelayForceClosingMgr.RemoveDelaySocket(s); lock (this.dictInPackets) { if (this.dictInPackets.ContainsKey(s)) { TCPInPacket tcpInPacket = this.dictInPackets[s]; this.tcpInPacketPool.Push(tcpInPacket); this.dictInPackets.Remove(s); } } bool bIsExistClient = false; GameClient gameClient = GameManager.ClientMgr.FindClient(s); if (null != gameClient) { GameManager.ClientMgr.Logout(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, gameClient); bIsExistClient = true; } string userID = GameManager.OnlineUserSession.FindUserID(s); GameManager.OnlineUserSession.RemoveSession(s); GameManager.OnlineUserSession.RemoveUserName(s); GameManager.OnlineUserSession.RemoveUserAdult(s); if (!string.IsNullOrEmpty(userID)) { Global.RegisterUserIDToDBServer(userID, 0, s.ServerId, ref s.session.LastLogoutServerTicks); } GameManager.loginWaitLogic.RemoveWait(userID); if (!bIsExistClient) { GameManager.loginWaitLogic.RemoveAllow(userID); } Global._SendBufferManager.Remove(s); }
/// <summary> /// 命令包接收完毕后的回调事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool TCPCmdPacketEvent(object sender, int doType) { TCPInPacket tcpInPacket = sender as TCPInPacket; if (0 == doType) //正常的登录指令包 { int thisTimeCheckTicks = 0; int checkErrorCode = 0; //这里实际上是有一个指令流的拷贝,占用的很零碎的内存,这个是否考虑使用内存池???? byte[] bytesData = CheckClientDataValid(tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, tcpInPacket.LastCheckTicks, out thisTimeCheckTicks, out checkErrorCode); if (null != bytesData) { tcpInPacket.LastCheckTicks = thisTimeCheckTicks; //记忆此次的心跳数据 //#if false if (UseWorkerPool) { //杰隆的异步处理指令入口代码 TCPCmdWrapper wrapper = TCPCmdWrapper.Get(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4); TCPSession session = null; if (GameManager.FlagOptimizeLock3) { if (null != tcpInPacket.CurrentSocket) { session = tcpInPacket.CurrentSocket.session; } if (null == session) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } else { lock (tcpSessions) { if (!tcpSessions.TryGetValue(tcpInPacket.CurrentSocket, out session)) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } } int posCmdNum = 0; session.addTCPCmdWrapper(wrapper, out posCmdNum); if (posCmdNum > 0) { int banSpeedUpMinutes = GameManager.GameConfigMgr.GetGameConfigItemInt("ban-speed-up-minutes2", 10); //加速禁止登陆的时间 GameClient client = GameManager.ClientMgr.FindClient(tcpInPacket.CurrentSocket); if (null != client) { GameManager.ClientMgr.NotifyImportantMsg(this.MySocketListener, tcpOutPacketPool, client, StringUtil.substitute(Global.GetLang("本游戏禁止使用加速软件,{0}分钟内将禁止登陆!"), banSpeedUpMinutes), GameInfoTypeIndexes.Error, ShowGameInfoTypes.HintAndBox); BanManager.BanRoleName(Global.FormatRoleName(client, client.ClientData.RoleName), banSpeedUpMinutes); } LogManager.WriteLog(LogTypes.Error, string.Format("通过POSITION指令判断客户端加速: {0}, 指令个数:{1}, 断开连接", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), posCmdNum)); return(false); } taskExecutor.execute(new ProcessSessionTask(session)); } //#else else { TCPSession session = null; if (GameManager.FlagOptimizeLock3) { if (null != tcpInPacket.CurrentSocket) { session = tcpInPacket.CurrentSocket.session; } if (null == session) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } else { lock (tcpSessions) { if (!tcpSessions.TryGetValue(tcpInPacket.CurrentSocket, out session)) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } } int posCmdNum = 0; session.CheckCmdNum(tcpInPacket.PacketCmdID, out posCmdNum); if (posCmdNum > 0) { int banSpeedUpMinutes = GameManager.GameConfigMgr.GetGameConfigItemInt("ban-speed-up-minutes2", 10); //加速禁止登陆的时间 GameClient client = GameManager.ClientMgr.FindClient(tcpInPacket.CurrentSocket); if (null != client) { GameManager.ClientMgr.NotifyImportantMsg(this.MySocketListener, tcpOutPacketPool, client, StringUtil.substitute(Global.GetLang("本游戏禁止使用加速软件,{0}分钟内将禁止登陆!"), banSpeedUpMinutes), GameInfoTypeIndexes.Error, ShowGameInfoTypes.HintAndBox); BanManager.BanRoleName(Global.FormatRoleName(client, client.ClientData.RoleName), banSpeedUpMinutes); } LogManager.WriteLog(LogTypes.Error, string.Format("通过POSITION指令判断客户端加速: {0}, 指令个数:{1}, 断开连接", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), posCmdNum)); return(false); } TCPOutPacket tcpOutPacket = null; long processBeginTime = TimeUtil.NowEx(); TCPProcessCmdResults result = TCPCmdHandler.ProcessCmd(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4, out tcpOutPacket); long processTime = (TimeUtil.NowEx() - processBeginTime); if (GameManager.StatisticsMode > 0 || processTime > 50 || result == TCPProcessCmdResults.RESULT_FAILED) { lock (ProcessSessionTask.cmdMoniter) //锁定命令监控对象 { int cmdID = tcpInPacket.PacketCmdID; PorcessCmdMoniter moniter = null; if (!ProcessSessionTask.cmdMoniter.TryGetValue(cmdID, out moniter)) { moniter = new PorcessCmdMoniter(cmdID, processTime); ProcessSessionTask.cmdMoniter.Add(cmdID, moniter); } moniter.onProcessNoWait(processTime, result); } } if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { //向登陆客户端返回数据 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))); return(false); } } //#endif } else { LogManager.WriteLog(LogTypes.Error, string.Format("校验客户端发送的指令数据完整性失败: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } else if (1 == doType) //正常的登录指令包//策略验证请求 { //直接发送策略数据 DirectSendPolicyFileData(tcpInPacket); } else { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令时类型未知: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); //socketListener.CloseSocket(tcpInPacket.CurrentSocket); return(false); } return(true); }
/// <summary> /// 命令包接收完毕后的回调事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private bool TCPCmdPacketEvent(object sender, int doType) { TCPInPacket tcpInPacket = sender as TCPInPacket; if (0 == doType) //正常的登录指令包 { int thisTimeCheckTicks = 0; int checkErrorCode = 0; if (0xffff == tcpInPacket.PacketCmdID) { String cmdData = new UTF8Encoding().GetString(tcpInPacket.GetPacketBytes(), 0, tcpInPacket.PacketDataSize); if (cmdData == "serveripinfo") { String strinfo = string.Format("{0}_{1}", ServerPort, Global.GetLocalAddressIPs()); byte [] arrSendData = Encoding.UTF8.GetBytes(strinfo); if (null != arrSendData) { tcpInPacket.CurrentSocket.Send(arrSendData, arrSendData.Length, SocketFlags.None); } } return(false); } //这里实际上是有一个指令流的拷贝,占用的很零碎的内存,这个是否考虑使用内存池???? byte[] bytesData = CheckClientDataValid(tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, tcpInPacket.LastCheckTicks, out thisTimeCheckTicks, out checkErrorCode); if (null != bytesData) { tcpInPacket.LastCheckTicks = thisTimeCheckTicks; //记忆此次的心跳数据 //#if false if (UseWorkerPool) { //杰隆的异步处理指令入口代码 TCPCmdWrapper wrapper = TCPCmdWrapper.Get(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4); TCPSession session = null; if (GameManager.FlagOptimizeLock3) { if (null != tcpInPacket.CurrentSocket) { session = tcpInPacket.CurrentSocket.session; } if (null == session) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } else { lock (tcpSessions) { if (!tcpSessions.TryGetValue(tcpInPacket.CurrentSocket, out session)) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } } int posCmdNum = 0; session.addTCPCmdWrapper(wrapper, out posCmdNum); if (posCmdNum > 0) { int banSpeedUpMinutes = GameManager.PlatConfigMgr.GetGameConfigItemInt(PlatConfigNames.BanSpeedUpMinutes2, 10); //加速禁止登陆的时间 GameClient client = GameManager.ClientMgr.FindClient(tcpInPacket.CurrentSocket); if (null != client) { GameManager.ClientMgr.NotifyImportantMsg(this.MySocketListener, tcpOutPacketPool, client, StringUtil.substitute(Global.GetLang("本游戏禁止使用加速软件,{0}分钟内将禁止登陆!"), banSpeedUpMinutes), GameInfoTypeIndexes.Error, ShowGameInfoTypes.HintAndBox); BanManager.BanRoleName(Global.FormatRoleName(client, client.ClientData.RoleName), banSpeedUpMinutes); } LogManager.WriteLog(LogTypes.Error, string.Format("通过POSITION指令判断客户端加速: {0}, 指令个数:{1}, 断开连接", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), posCmdNum)); return(false); } taskExecutor.execute(new ProcessSessionTask(session)); } //#else else { TCPSession session = null; if (GameManager.FlagOptimizeLock3) { if (null != tcpInPacket.CurrentSocket) { session = tcpInPacket.CurrentSocket.session; } if (null == session) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } else { lock (tcpSessions) { if (!tcpSessions.TryGetValue(tcpInPacket.CurrentSocket, out session)) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode)); return(false); } } } int posCmdNum = 0; session.CheckCmdNum(tcpInPacket.PacketCmdID, out posCmdNum); if (posCmdNum > 0) { int banSpeedUpMinutes = GameManager.PlatConfigMgr.GetGameConfigItemInt(PlatConfigNames.BanSpeedUpMinutes2, 10); //加速禁止登陆的时间 GameClient client = GameManager.ClientMgr.FindClient(tcpInPacket.CurrentSocket); if (null != client) { if (client.CheckCheatData.ProcessBooster) { GameManager.ClientMgr.NotifyImportantMsg(this.MySocketListener, tcpOutPacketPool, client, StringUtil.substitute(Global.GetLang("本游戏禁止使用加速软件,{0}分钟内将禁止登陆!"), banSpeedUpMinutes), GameInfoTypeIndexes.Error, ShowGameInfoTypes.HintAndBox); BanManager.BanRoleName(Global.FormatRoleName(client, client.ClientData.RoleName), banSpeedUpMinutes); LogManager.WriteLog(LogTypes.Error, string.Format("通过POSITION指令判断客户端加速: {0}, 指令个数:{1}, 断开连接", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), posCmdNum)); return(false); } else if (client.CheckCheatData.ProcessBoosterTicks == 0) { client.CheckCheatData.ProcessBoosterTicks = TimeUtil.NOW(); } } } TCPOutPacket tcpOutPacket = null; TCPProcessCmdResults result = TCPProcessCmdResults.RESULT_FAILED; long processBeginTime = TimeUtil.NowEx(); if (tcpInPacket.PacketCmdID > 30000) { result = CCTCPCmdHandler.CCProcessCmd(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4, out tcpOutPacket); } else { result = TCPCmdHandler.ProcessCmd(this, tcpInPacket.CurrentSocket, tcpClientPool, tcpRandKey, tcpOutPacketPool, tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4, out tcpOutPacket); } long processTime = (TimeUtil.NowEx() - processBeginTime); if (GameManager.StatisticsMode > 0 || processTime > 50 || result == TCPProcessCmdResults.RESULT_FAILED) { RecordCmdDetail(tcpInPacket.PacketCmdID, processTime, tcpInPacket.PacketDataSize, result); } if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { // Console.WriteLine("===>>> tcpOutPacket==== " + tcpOutPacket.PacketCmdID.ToString()); //向登陆客户端返回数据 socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket); } else if (result == TCPProcessCmdResults.RESULT_FAILED)//解析失败, 直接关闭连接 { if (tcpInPacket.PacketCmdID != (int)TCPGameServerCmds.CMD_LOG_OUT) { SysConOut.WriteLine(string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); } return(false); } } //#endif } else { var _s = tcpInPacket.CurrentSocket; string uid = _s != null?GameManager.OnlineUserSession.FindUserID(_s) : "socket is nil"; SysConOut.WriteLine(string.Format("校验客户端发送的指令数据完整性失败: {0},{1}, 错误码:{2}, uid={3}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode, uid)); LogManager.WriteLog(LogTypes.Error, string.Format("校验客户端发送的指令数据完整性失败: {0},{1}, 错误码:{2}, uid={3}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket), checkErrorCode, uid)); return(false); } } else if (1 == doType) //正常的登录指令包//策略验证请求 { //直接发送策略数据 DirectSendPolicyFileData(tcpInPacket); } else { SysConOut.WriteLine(string.Format("解析并执行命令时类型未知: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令时类型未知: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket))); //socketListener.CloseSocket(tcpInPacket.CurrentSocket); return(false); } return(true); }
private bool TCPCmdPacketEvent(object sender, int doType) { TCPInPacket tcpInPacket = sender as TCPInPacket; if (0 == doType) { int thisTimeCheckTicks = 0; int checkErrorCode = 0; byte[] bytesData = this.CheckClientDataValid((int)tcpInPacket.PacketCmdID, tcpInPacket.GetPacketBytes(), tcpInPacket.PacketDataSize, tcpInPacket.LastCheckTicks, out thisTimeCheckTicks, out checkErrorCode); if (null == bytesData) { TMSKSocket _s = tcpInPacket.CurrentSocket; string uid = (_s != null) ? GameManager.OnlineUserSession.FindUserID(_s) : "socket is nil"; LogManager.WriteLog(LogTypes.Error, string.Format("校验客户端发送的指令数据完整性失败: {0},{1}, 错误码:{2}, uid={3}, 关闭连接", new object[] { (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false), checkErrorCode, uid }), null, true); return(false); } tcpInPacket.LastCheckTicks = thisTimeCheckTicks; tcpInPacket.CurrentSocket.ClientCmdSecs = thisTimeCheckTicks; TCPSession session = null; if (null != tcpInPacket.CurrentSocket) { session = tcpInPacket.CurrentSocket.session; } if (null == session) { LogManager.WriteLog(LogTypes.Error, string.Format("未与客户端建立会话: {0},{1}, 错误码:{2}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false), checkErrorCode), null, true); return(false); } int posCmdNum = 0; session.CheckCmdNum((int)tcpInPacket.PacketCmdID, (long)thisTimeCheckTicks, out posCmdNum); if (posCmdNum > 0) { int banSpeedUpMinutes = GameManager.PlatConfigMgr.GetGameConfigItemInt("ban-speed-up-minutes2", 10); GameClient client = GameManager.ClientMgr.FindClient(tcpInPacket.CurrentSocket); if (null != client) { if (GameManager.PlatConfigMgr.GetGameConfigItemInt("ban_speed_up_delay", 0) == 0 || client.CheckCheatData.ProcessBooster) { GameManager.ClientMgr.NotifyImportantMsg(this.MySocketListener, this.tcpOutPacketPool, client, StringUtil.substitute(GLang.GetLang(663, new object[0]), new object[] { banSpeedUpMinutes }), GameInfoTypeIndexes.Error, ShowGameInfoTypes.HintAndBox, 0); BanManager.BanRoleName(Global.FormatRoleName(client, client.ClientData.RoleName), banSpeedUpMinutes, 1); LogManager.WriteLog(LogTypes.Error, string.Format("通过POSITION指令判断客户端加速: {0}, 指令个数:{1}, 断开连接", Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false), posCmdNum), null, true); return(false); } if (client.CheckCheatData.ProcessBoosterTicks == 0L) { client.CheckCheatData.ProcessBoosterTicks = TimeUtil.NOW(); } } } TCPOutPacket tcpOutPacket = null; long processBeginTime = TimeUtil.NowEx(); TCPProcessCmdResults result = TCPCmdHandler.ProcessCmd(this, tcpInPacket.CurrentSocket, this.tcpClientPool, this.tcpRandKey, this.tcpOutPacketPool, (int)tcpInPacket.PacketCmdID, bytesData, tcpInPacket.PacketDataSize - 1 - 4, out tcpOutPacket); long processTime = TimeUtil.NowEx() - processBeginTime; if (GameManager.StatisticsMode > 0 || processTime > 50L || result == TCPProcessCmdResults.RESULT_FAILED) { TCPManager.RecordCmdDetail((int)tcpInPacket.PacketCmdID, processTime, (long)tcpInPacket.PacketDataSize, result); } if (result == TCPProcessCmdResults.RESULT_DATA && null != tcpOutPacket) { this.socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket, true); } else { if (result == TCPProcessCmdResults.RESULT_FAILED) { if (tcpInPacket.PacketCmdID != 22) { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令失败: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false)), null, true); } return(false); } if (result == TCPProcessCmdResults.RESULT_DATA_CLOSE && null != tcpOutPacket) { this.socketListener.SendData(tcpInPacket.CurrentSocket, tcpOutPacket, true); tcpInPacket.CurrentSocket.DelayClose = 250; } } } else { if (1 != doType) { LogManager.WriteLog(LogTypes.Error, string.Format("解析并执行命令时类型未知: {0},{1}, 关闭连接", (TCPGameServerCmds)tcpInPacket.PacketCmdID, Global.GetSocketRemoteEndPoint(tcpInPacket.CurrentSocket, false)), null, true); return(false); } this.DirectSendPolicyFileData(tcpInPacket); } return(true); }
public TCPClient() { _MyTCPInPacket = new TCPInPacket((int)TCPCmdPacketSize.MAX_SIZE); _MyTCPInPacket.TCPCmdPacketEvent += TCPCmdPacketEvent; }
public bool TCPCmdPacketEventHandler(object sender, int doType) { TCPInPacket inPacket = sender as TCPInPacket; //LogSys.Log(LOG_TYPE.ERROR, "cmdid={0} bytes={1}", inPacket.PacketCmdID, DataHelper.Bytes2HexString(inPacket.GetPacketBytes())); try { switch ((TCPGameServerCmds)inPacket.PacketCmdID) { case TCPGameServerCmds.CMD_LOGIN_ON: { string cmdData = new System.Text.UTF8Encoding().GetString(inPacket.GetPacketBytes(), 0, inPacket.PacketDataSize); string[] fields = cmdData.Split(':'); //LogManager.WriteLog(LogTypes.Info, string.Format("登录指令参数, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), cmdData)); //if (fields.Length < 10) //{ // LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Client={1}, Recv={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), fields.Length)); // return TCPProcessCmdResults.RESULT_FAILED; //} ChangeStatus(ClientStatus.Login); int randomKey = Convert.ToInt32(fields[0]); string userID = fields[1]; LogSys.Log(LOG_TYPE.ERROR, "CMD_LOGIN_ON err={0} userID={1}", randomKey, userID); if (randomKey <= 0) { Close(); break; } m_UserId = userID; m_RandomKey = randomKey; if (string.IsNullOrEmpty(m_UserId) == false) { RoleList(); } break; } case TCPGameServerCmds.CMD_ROLE_LIST: { string cmdData = new System.Text.UTF8Encoding().GetString(inPacket.GetPacketBytes(), 0, inPacket.PacketDataSize); string[] fields = cmdData.Split(':'); int roleCount = Convert.ToInt32(fields[0]); LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_ROLE_LIST, cmdData); string[] roleList = fields[1].Split('|'); //roleList += string.Format("{0}${1}${2}${3}${4}${5}|", // dbUserInfo.ListRoleIDs[i], dbUserInfo.ListRoleSexes[i], dbUserInfo.ListRoleOccups[i], dbUserInfo.ListRoleNames[i], dbUserInfo.ListRoleLevels[i], dbUserInfo.ListRoleChangeLifeCount[i]); ChangeStatus(ClientStatus.RoleList); for (int i = 0; i < m_RoleList.Length; i++) { m_RoleList[i] = null; } int count = 0; for (int i = 0; i < roleList.Length; ++i) { string strRole = roleList[i]; string[] roleSubFields = strRole.Split('$'); if (roleSubFields.Length >= 5) { Role role = new Role(); role.RoleId = Convert.ToInt32(roleSubFields[0]); role.RoleSex = Convert.ToInt32(roleSubFields[1]); role.RoleOccup = Convert.ToInt32(roleSubFields[2]); role.RoleName = roleSubFields[3]; role.RoleLevel = Convert.ToInt32(roleSubFields[4]); role.RoleChangeCount = Convert.ToInt32(roleSubFields[5]); m_RoleList[i] = role; count++; } } if (count > 0) { InitGame(); } else { CreateRole(); } break; } case TCPGameServerCmds.CMD_CREATE_ROLE: { string cmdData = new System.Text.UTF8Encoding().GetString(inPacket.GetPacketBytes(), 0, inPacket.PacketDataSize); string[] fields = cmdData.Split(':'); string[] roleSubFields = fields[1].Split('$'); ChangeStatus(ClientStatus.CreateRole); int code = Convert.ToInt32(fields[0]); LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_CREATE_ROLE, cmdData); if (code == 1) { if (roleSubFields.Length >= 5) { Role role = new Role(); role.RoleId = Convert.ToInt32(roleSubFields[0]); role.RoleSex = Convert.ToInt32(roleSubFields[1]); role.RoleOccup = Convert.ToInt32(roleSubFields[2]); role.RoleName = roleSubFields[3]; role.RoleLevel = Convert.ToInt32(roleSubFields[4]); role.RoleChangeCount = Convert.ToInt32(roleSubFields[5]); for (int i = 0; i < m_RoleList.Length; i++) { if (m_RoleList[i] == null) { m_RoleList[i] = role; InitGame(); break; } } } } break; } case TCPGameServerCmds.CMD_INIT_GAME: { LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_INIT_GAME, 0); //var roleData = DataHelper.BytesToObject<RoleData>(inPacket.GetPacketBytes(), 0, inPacket.PacketDataSize); //if(roleData != null) //{ // LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_INIT_GAME, roleData.RoleID); //} ChangeStatus(ClientStatus.InitGame); if (inPacket.PacketDataSize > 100) { PlayGame(); } break; } case TCPGameServerCmds.CMD_PLAY_GAME: { string cmdData = new System.Text.UTF8Encoding().GetString(inPacket.GetPacketBytes(), 0, inPacket.PacketDataSize); string[] fields = cmdData.Split(':'); ChangeStatus(ClientStatus.PlayGame); LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_PLAY_GAME, cmdData); if (fields != null && fields.Length >= 1) { LogSys.Log(LOG_TYPE.ERROR, "msg = {0} cmd={1}", TCPGameServerCmds.CMD_PLAY_GAME, cmdData); } break; } default: { LogSys.Log(LOG_TYPE.ERROR, "msg = {0} bytes={1}", (TCPGameServerCmds)inPacket.PacketCmdID, inPacket.PacketDataSize); break; } } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "msg = {0} exception={1}", (TCPGameServerCmds)inPacket.PacketCmdID, ex.Message); } return(true); }