public bool NotifyUserEnter(LoginWaitLogic.UserInfo userInfo) { try { if (null == userInfo) { return(true); } if (userInfo.socket == null || !userInfo.socket.Connected) { return(true); } this.AddToAllow(userInfo.userID, this.GetConfig(LoginWaitLogic.UserType.Normal, LoginWaitLogic.ConfigType.AllowMSeconds)); if (!userInfo.socket.IsKuaFuLogin) { ChangeNameInfo info = SingletonTemplate <NameManager> .Instance().GetChangeNameInfo(userInfo.userID, userInfo.zoneID, userInfo.socket.ServerId); if (info != null) { Global._TCPManager.MySocketListener.SendData(userInfo.socket, DataHelper.ObjectToTCPOutPacket <ChangeNameInfo>(info, Global._TCPManager.TcpOutPacketPool, 14002), true); } } } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); return(false); } string strData = ""; try { string strcmd = string.Format("{0}:{1}", userInfo.userID, userInfo.zoneID); byte[] bytesData = Global.SendAndRecvData <string>(101, strcmd, userInfo.socket.ServerId, 0); int length = BitConverter.ToInt32(bytesData, 0); strData = new UTF8Encoding().GetString(bytesData, 6, length - 2); } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 向db请求角色列表 faild! userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); strData = "-1:"; } try { TCPOutPacket tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(Global._TCPManager.TcpOutPacketPool, strData, 101); Global._TCPManager.MySocketListener.SendData(userInfo.socket, tcpOutPacket, true); this.m_LastEnterSecs = (TimeUtil.NOW() - userInfo.startTick) / 1000L; this.m_LastEnterFromFirstSecs = (TimeUtil.NOW() - userInfo.firstTick) / 1000L; } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 发送角色列表Faild userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); return(false); } return(true); }
public TCPProcessCmdResults ProcQueryEachRoleInfo(DBManager dbMgr, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket) { tcpOutPacket = null; string cmdData = null; try { cmdData = new UTF8Encoding().GetString(data, 0, count); } catch (Exception) { LogManager.WriteLog(LogTypes.Error, string.Format("解析指令字符串错误, CMD={0}", (TCPGameServerCmds)nID), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } try { string[] fields = cmdData.Split(new char[] { ':' }); if (fields.Length != 2) { LogManager.WriteLog(LogTypes.Error, string.Format("指令参数个数错误, CMD={0}, Recv={1}, CmdData={2}", (TCPGameServerCmds)nID, fields.Length, cmdData), null, true); tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); } string uid = fields[0]; int zoneId = Convert.ToInt32(fields[1]); ChangeNameInfo info = new ChangeNameInfo(); DBUserInfo dbUserInfo = dbMgr.GetDBUserInfo(uid); if (dbUserInfo != null) { lock (dbUserInfo) { info.ZuanShi = dbUserInfo.Money; for (int i = 0; i < dbUserInfo.ListRoleIDs.Count; i++) { if (dbUserInfo.ListRoleZoneIDs[i] == zoneId) { int roleID = dbUserInfo.ListRoleIDs[i]; DBRoleInfo dbRoleInfo = dbMgr.GetDBRoleInfo(ref roleID); if (dbRoleInfo != null) { int roleId = dbUserInfo.ListRoleIDs[i]; int leftFreeTimes = Global.GetRoleParamsInt32(dbRoleInfo, "LeftFreeChangeNameTimes"); int alreadyZuanshiTimes = Global.GetRoleParamsInt32(dbRoleInfo, "AlreadyZuanShiChangeNameTimes"); info.RoleList.Add(new EachRoleChangeName { RoleId = roleId, LeftFreeTimes = leftFreeTimes, AlreadyZuanShiTimes = alreadyZuanshiTimes }); } } } } } tcpOutPacket = DataHelper.ObjectToTCPOutPacket <ChangeNameInfo>(info, pool, nID); return(TCPProcessCmdResults.RESULT_DATA); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, "", false, false); } tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, "0", 30767); return(TCPProcessCmdResults.RESULT_DATA); }
// 允许玩家进入 public bool NotifyUserEnter(UserInfo userInfo) { try { if (null == userInfo) { return(true); } if (null == userInfo.socket || !userInfo.socket.Connected) { return(true); } // 加进免排队列表 AddToAllow(userInfo.userID, GetConfig(UserType.Normal, ConfigType.AllowMSeconds)); if (!userInfo.socket.IsKuaFuLogin) { ChangeNameInfo info = NameManager.Instance().GetChangeNameInfo(userInfo.userID, userInfo.zoneID, userInfo.socket.ServerId); if (info != null) { Global._TCPManager.MySocketListener.SendData(userInfo.socket, DataHelper.ObjectToTCPOutPacket(info, Global._TCPManager.TcpOutPacketPool, (int)TCPGameServerCmds.CMD_NTF_EACH_ROLE_ALLOW_CHANGE_NAME)); } } } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); return(false); } string strData = ""; // 替玩家向db请求角色列表 try { string strcmd = string.Format("{0}:{1}", userInfo.userID, userInfo.zoneID); byte[] bytesData = Global.SendAndRecvData <string>((int)TCPGameServerCmds.CMD_ROLE_LIST, strcmd, userInfo.socket.ServerId); string[] fieldsData = null; Int32 length = BitConverter.ToInt32(bytesData, 0); strData = new UTF8Encoding().GetString(bytesData, 6, length - 2); } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 向db请求角色列表 faild! userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); //return false; //获取异常则通知客户端重新排队,防止客户端始终卡在那里 strData = "-1:"; } try { //SysConOut.WriteLine(strData); TCPOutPacket tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(Global._TCPManager.TcpOutPacketPool, strData, (int)TCPGameServerCmds.CMD_ROLE_LIST); Global._TCPManager.MySocketListener.SendData(userInfo.socket, tcpOutPacket); m_LastEnterSecs = (TimeUtil.NOW() - userInfo.startTick) / 1000; m_LastEnterFromFirstSecs = (TimeUtil.NOW() - userInfo.firstTick) / 1000; } catch (Exception ex) { DataHelper.WriteExceptionLogEx(ex, string.Format("LoginWaitLogic::NotifyUserEnter 发送角色列表Faild userID={0} zoneID={1}", userInfo.userID, userInfo.zoneID)); return(false); } return(true); }