public KuaFuWorldRoleData QueryKuaFuWorldRoleData(int roleID, int ptid) { KuaFuWorldRoleData data = null; MySqlDataReader sdr = null; try { string strSql = string.Format("SELECT ptid,rid,temprid,userid,zoneid,channel,roledata FROM `t_pt_roles` where ptid={0} and rid={1}", ptid, roleID); sdr = DbHelperMySQL.ExecuteReader(strSql, false); if (sdr.Read()) { data = new KuaFuWorldRoleData(); data.PTID = Convert.ToInt32(sdr["ptid"].ToString()); data.LocalRoleID = Convert.ToInt32(sdr["rid"].ToString()); data.TempRoleID = Convert.ToInt32(sdr["temprid"].ToString()); data.UserID = sdr["userid"].ToString(); data.ZoneID = Convert.ToInt32(sdr["zoneid"].ToString()); data.Channel = sdr["channel"].ToString(); data.RoleData = (sdr["roledata"] as byte[]); } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } finally { if (null != sdr) { sdr.Close(); } } return(data); }
public int RegPTKuaFuRoleData(ref KuaFuWorldRoleData data) { data.WorldRoleID = ConstData.FormatWorldRoleID(data.LocalRoleID, data.PTID); KuaFuWorldRoleData roleData = this.LoadKuaFuWorldRoleData(data.LocalRoleID, data.PTID, data.WorldRoleID); int result; if (null != roleData) { if (data.RoleData != null) { roleData.RoleData = data.RoleData; int dbRet = YongZheZhanChangPersistence.Instance.WriteKuaFuWorldRoleData(roleData); if (dbRet < 0) { return(dbRet); } } data = roleData; result = 0; } else { for (int i = 0; i < 10; i++) { int tempRoleIDLimit = 0; int maxTempRoleID = YongZheZhanChangPersistence.Instance.GetKuaFoWorldMaxTempRoleID(out tempRoleIDLimit); if (maxTempRoleID >= tempRoleIDLimit) { return(-22); } roleData = YongZheZhanChangPersistence.Instance.InsertKuaFuWorldRoleData(data, maxTempRoleID + 1); if (null != roleData) { lock (this.Mutex) { KuaFuWorldRoleData temp; if (!this.RoleDataDict.TryGetValue(data.WorldRoleID, out temp) || temp == null) { this.RoleDataDict[data.WorldRoleID] = roleData; } } break; } Thread.Sleep(500); } if (null != roleData) { data = roleData; result = roleData.TempRoleID; } else { result = -15; } } return(result); }
public void SetTempRoleID(int localRoleID, int tempRoleID) { lock (this.Mutex) { KuaFuWorldRoleData data = new KuaFuWorldRoleData { LocalRoleID = localRoleID, TempRoleID = tempRoleID }; this.KuaFuWorldRoleDataDict[tempRoleID] = data; } }
public KuaFuWorldRoleData InsertKuaFuWorldRoleData(KuaFuWorldRoleData data, int tempRoleID) { try { object[] ptidAndRid; int result = DbHelperMySQL.GetSingleValues(string.Format("SELECT ptid,rid FROM `t_pt_roles` where temprid={0}", data.LocalRoleID), out ptidAndRid); bool flag; if (result >= 0) { flag = !ptidAndRid.All((object x) => x != null); } else { flag = true; } if (!flag) { if (!(data.PTID.ToString() != ptidAndRid[0].ToString())) { return(this.QueryKuaFuWorldRoleData(data.LocalRoleID, data.PTID)); } data.TempRoleID = tempRoleID; } else { data.TempRoleID = data.LocalRoleID; } List <Tuple <string, byte[]> > imgList = new List <Tuple <string, byte[]> >(); imgList.Add(new Tuple <string, byte[]>("content", data.RoleData)); string strSql = string.Format("insert into `t_pt_roles`(ptid,rid,temprid,userid,zoneid,channel,roledata) values('{0}','{1}','{2}','{3}','{4}','{5}',@content)", new object[] { data.PTID, data.LocalRoleID, data.TempRoleID, data.UserID, data.ZoneID, data.Channel }); result = DbHelperMySQL.ExecuteSqlInsertImg(strSql, imgList); if (result >= 0) { return(data); } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } return(null); }
public int RegPTKuaFuRoleData(ref KuaFuWorldRoleData data) { IKuaFuWorld kuaFuService = this.GetKuaFuService(false); if (null != kuaFuService) { try { return(kuaFuService.RegPTKuaFuRoleData(ref data)); } catch (Exception ex) { this.ResetKuaFuService(); } } return(-11000); }
public int WriteKuaFuWorldRoleData(KuaFuWorldRoleData data) { int result = -15; try { string strSql = string.Format("update `t_pt_roles` set roledata=@content where ptid={0} and rid={1}", data.PTID, data.PTID); result = DbHelperMySQL.ExecuteSqlInsertImg(strSql, new List <Tuple <string, byte[]> > { new Tuple <string, byte[]>("content", data.RoleData) }); } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } return(result); }
public void ChangeName(int ptId, int roleId, string roleName) { try { lock (this.Mutex) { KeyValuePair <int, int> key = new KeyValuePair <int, int>(ptId, roleId); KuaFuData <KFRebornRoleData> kfRebornRoleData = null; if (this.RebornRoleDataDict.TryGetValue(key, out kfRebornRoleData)) { kfRebornRoleData.V.RoleName = roleName; TimeUtil.AgeByNow(ref kfRebornRoleData.Age); this.Persistence.UpdateRebornRoleDataRoleName(kfRebornRoleData.V); bool refreshRank = false; foreach (KeyValuePair <int, List <KFRebornRankInfo> > kvp in this.RebornRankDict.V) { KFRebornRankInfo item = kvp.Value.Find((KFRebornRankInfo x) => x.PtID == ptId && x.Key == roleId); if (null != item) { string worldRoleID = ConstData.FormatWorldRoleID(roleId, ptId); KuaFuWorldRoleData worldRoleData = TSingleton <KuaFuWorldManager> .getInstance().LoadKuaFuWorldRoleData(roleId, ptId, worldRoleID); if (null != worldRoleData) { item.Param1 = KuaFuServerManager.FormatName(item.tagInfo.V.RoleName, worldRoleData.ZoneID); refreshRank = true; } } } if (refreshRank) { TimeUtil.AgeByNow(ref this.RebornRankDict.Age); } } } } catch (Exception ex) { LogManager.WriteException(ex.ToString()); } }
public KuaFuWorldRoleData GetWorldRoleData(int roleID, int serverID, string userID, int tempRoleID) { string channel = Data.GetChannelNameByUserID(userID); KuaFuWorldRoleData data = null; lock (this.Mutex) { if (roleID != tempRoleID) { this.TempRoleIDs.Add(tempRoleID); } if (!this.WorldRoleDataDict.TryGetValue(roleID, out data)) { data = new KuaFuWorldRoleData(); data.LocalRoleID = roleID; data.TempRoleID = roleID; data.UserID = userID; data.ServerID = serverID; data.Channel = channel; this.WorldRoleDataDict[roleID] = data; } else { if (data.TempRoleID == tempRoleID) { data.ServerID = serverID; return(data); } data = new KuaFuWorldRoleData(); data.LocalRoleID = roleID; data.TempRoleID = tempRoleID; data.UserID = userID; data.ServerID = serverID; data.Channel = channel; data.UseTempRoleID = true; } } return(data); }
public int EnterPTKuaFuMap(int serverID, int roleId, int ptid, int mapCode, int kuaFuLine, out string signToken, out string signKey, out int kuaFuServerID, out string[] ips, out int[] ports) { ips = null; ports = null; signToken = null; signKey = null; kuaFuServerID = 0; string worldRoleID = ConstData.FormatWorldRoleID(roleId, ptid); KuaFuWorldRoleData roleData = this.LoadKuaFuWorldRoleData(roleId, ptid, worldRoleID); int result; if (null == roleData) { result = -4010; } else { kuaFuServerID = KuaFuServerManager.EnterKuaFuMapLine(kuaFuLine, mapCode); if (kuaFuServerID <= 0) { result = -100; } else { KuaFuServerInfo serverInfo = KuaFuServerManager.GetKuaFuServerInfo(kuaFuServerID); if (null != serverInfo) { ips = new string[] { serverInfo.Ip }; ports = new int[] { serverInfo.Port }; } signToken = Guid.NewGuid().ToString("N"); signKey = Guid.NewGuid().ToString("N"); long utcTicks = TimeUtil.UTCTicks(); lock (this.Mutex) { KuaFuServerLoginData loginData; if (!this.WorldRoleIDDict.TryGetValue(worldRoleID, out loginData)) { loginData = new KuaFuServerLoginData(); loginData.TempRoleID = roleData.TempRoleID; this.WorldRoleIDDict[worldRoleID] = loginData; } loginData.SignKey = signKey; loginData.SignToken = signToken; loginData.EndTicks = utcTicks + 86400000L; loginData.TargetServerID = kuaFuServerID; loginData.ServerId = ConstData.ConvertToKuaFuServerID(serverID, ptid); loginData.RoleId = roleId; loginData.PTID = ptid; loginData.GameId = (long)mapCode; result = loginData.TempRoleID; } } } return(result); }
public int RegPTKuaFuRoleData(ref KuaFuWorldRoleData data) { return(TSingleton <KuaFuWorldManager> .getInstance().RegPTKuaFuRoleData(ref data)); }
public bool LoadRebornRankInfo(int rankType, KuaFuData <Dictionary <int, List <KFRebornRankInfo> > > RebornRankDict) { bool result; if (null == RebornRankDict) { result = false; } else { List <KFRebornRankInfo> rankList = null; if (!RebornRankDict.V.TryGetValue(rankType, out rankList)) { rankList = (RebornRankDict.V[rankType] = new List <KFRebornRankInfo>()); } else { rankList.Clear(); } try { string strSql = this.FormatLoadRebornRankSql(rankType); if (string.IsNullOrEmpty(strSql)) { return(false); } MySqlDataReader sdr = DbHelperMySQL.ExecuteReader(strSql, false); while (sdr != null && sdr.Read()) { KFRebornRankInfo rankInfo = new KFRebornRankInfo(); rankInfo.Key = Convert.ToInt32(sdr["a"]); rankInfo.Value = Convert.ToInt32(sdr["b"]); rankInfo.PtID = Convert.ToInt32(sdr["c"]); KuaFuData <KFRebornRoleData> kfRoleData = null; if (this.RebornRoleDataDict.TryGetValue(new KeyValuePair <int, int>(rankInfo.PtID, rankInfo.Key), out kfRoleData)) { string worldRoleID = ConstData.FormatWorldRoleID(rankInfo.Key, rankInfo.PtID); KuaFuWorldRoleData worldRoleData = TSingleton <KuaFuWorldManager> .getInstance().LoadKuaFuWorldRoleData(rankInfo.Key, rankInfo.PtID, worldRoleID); if (null != worldRoleData) { int KFZoneID = ConstData.ConvertToKuaFuServerID(worldRoleData.ZoneID, worldRoleData.PTID); rankInfo.Param1 = KuaFuServerManager.FormatName(kfRoleData.V.RoleName, KFZoneID); rankInfo.Param2 = worldRoleData.Channel; rankInfo.UserID = worldRoleData.UserID; rankInfo.tagInfo = kfRoleData; } } rankList.Add(rankInfo); } if (null != RebornRankDict) { TimeUtil.AgeByNow(ref RebornRankDict.Age); } if (sdr != null) { sdr.Close(); } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); return(false); } result = true; } return(result); }
public bool ProcessKuaFuMapEnterCmd(GameClient client, int nID, byte[] bytes, string[] cmdParams) { try { int result = 0; int toMapCode = Global.SafeConvertToInt32(cmdParams[0]); int line = Global.SafeConvertToInt32(cmdParams[1]); int toBoss = 0; int teleportId = 0; if (cmdParams.Length >= 3) { toBoss = Global.SafeConvertToInt32(cmdParams[2]); } if (cmdParams.Length >= 4) { teleportId = Global.SafeConvertToInt32(cmdParams[3]); } KuaFuLineData kuaFuLineData; if (!KuaFuMapManager.getInstance().IsKuaFuMap(toMapCode)) { result = -12; } else if (!this.RuntimeData.LineMap2KuaFuLineDataDict.TryGetValue(new IntPairKey(line, toMapCode), out kuaFuLineData)) { result = -12; } else if (!Global.CanEnterMap(client, toMapCode) || (toMapCode == client.ClientData.MapCode && kuaFuLineData.MapType != 1)) { result = -12; } else { if (toMapCode == client.ClientData.MapCode && kuaFuLineData.MapType == 1) { List <KuaFuLineData> list = KuaFuWorldClient.getInstance().GetKuaFuLineDataList(toMapCode) as List <KuaFuLineData>; if (null == list) { result = -12; goto IL_67F; } KuaFuLineData currentLineData = list.Find((KuaFuLineData x) => x.ServerId == GameManager.KuaFuServerId); if (currentLineData != null && currentLineData.Line == kuaFuLineData.Line) { result = -4011; goto IL_67F; } } if (!KuaFuMapManager.getInstance().IsKuaFuMap(client.ClientData.MapCode) && !this.CheckMap(client)) { result = -21; } else if (!this.IsGongNengOpened(client, false)) { result = -12; } else if (kuaFuLineData.OnlineCount >= kuaFuLineData.MaxOnlineCount) { result = -100; } else { int fromMapCode = client.ClientData.MapCode; if (teleportId > 0) { GameMap fromGameMap = null; if (!GameManager.MapMgr.DictMaps.TryGetValue(fromMapCode, out fromGameMap)) { result = -3; goto IL_67F; } MapTeleport mapTeleport = null; if (!fromGameMap.MapTeleportDict.TryGetValue(teleportId, out mapTeleport) || mapTeleport.ToMapID != toMapCode) { result = -12; goto IL_67F; } if (Global.GetTwoPointDistance(client.CurrentPos, new Point((double)mapTeleport.X, (double)mapTeleport.Y)) > 800.0) { result = -301; goto IL_67F; } } KuaFuServerLoginData kuaFuServerLoginData = Global.GetClientKuaFuServerLoginData(client); int kuaFuServerId; if (kuaFuLineData.MapType == 1) { if (!GlobalNew.IsGongNengOpened(client, GongNengIDs.Reborn, true)) { result = -400; goto IL_67F; } string signToken; string signKey; int rt = KuaFuWorldClient.getInstance().EnterPTKuaFuMap(client.ServerId, client.ClientData.LocalRoleID, client.ClientData.ServerPTID, kuaFuLineData.MapCode, kuaFuLineData.Line, kuaFuServerLoginData, out signToken, out signKey); if (rt == -4010) { KuaFuWorldRoleData kuaFuWorldRoleData = new KuaFuWorldRoleData { LocalRoleID = client.ClientData.LocalRoleID, UserID = client.strUserID, WorldRoleID = client.ClientData.WorldRoleID, Channel = client.ClientData.Channel, PTID = client.ClientData.ServerPTID, ServerID = client.ServerId, ZoneID = client.ClientData.ZoneID }; rt = KuaFuWorldClient.getInstance().RegPTKuaFuRoleData(ref kuaFuWorldRoleData); rt = KuaFuWorldClient.getInstance().EnterPTKuaFuMap(client.ServerId, client.ClientData.LocalRoleID, client.ClientData.ServerPTID, kuaFuLineData.MapCode, kuaFuLineData.Line, kuaFuServerLoginData, out signToken, out signKey); } if (rt < 0) { result = rt; goto IL_67F; } KFRebornRoleData rebornRoleData = KuaFuWorldClient.getInstance().Reborn_GetRebornRoleData(client.ClientData.ServerPTID, client.ClientData.LocalRoleID); if (null == rebornRoleData) { result = KuaFuWorldClient.getInstance().Reborn_RoleReborn(client.ClientData.ServerPTID, client.ClientData.LocalRoleID, client.ClientData.RoleName, client.ClientData.RebornLevel); if (result < 0) { goto IL_67F; } LogManager.WriteLog(LogTypes.Analysis, string.Format("Reborn_RoleReborn ptId={0} roleId={1} roleName={2} rebornLevel={3}", new object[] { client.ClientData.ServerPTID, client.ClientData.LocalRoleID, client.ClientData.RoleName, client.ClientData.RebornLevel }), null, true); } kuaFuServerLoginData.PTID = client.ClientData.ServerPTID; kuaFuServerLoginData.RoleId = client.ClientData.LocalRoleID; kuaFuServerLoginData.SignToken = signToken; kuaFuServerLoginData.TempRoleID = rt; kuaFuServerLoginData.SignCode = MD5Helper.get_md5_string(kuaFuServerLoginData.SignDataString() + signKey).ToLower(); kuaFuServerId = kuaFuServerLoginData.TargetServerID; } else { kuaFuServerLoginData.SignCode = null; kuaFuServerId = YongZheZhanChangClient.getInstance().EnterKuaFuMap(client.ClientData.LocalRoleID, kuaFuLineData.MapCode, kuaFuLineData.Line, client.ServerId, Global.GetClientKuaFuServerLoginData(client)); } kuaFuServerLoginData.Line = line; if (kuaFuServerId > 0) { bool flag = 0 == 0; int needMoney = (teleportId > 0) ? 0 : Global.GetMapTransNeedMoney(toMapCode); if (Global.GetTotalBindTongQianAndTongQianVal(client) < needMoney) { GameManager.ClientMgr.NotifyImportantMsg(client, StringUtil.substitute(GLang.GetLang(171, new object[0]), new object[] { needMoney, Global.GetMapName(toMapCode) }), GameInfoTypeIndexes.Error, ShowGameInfoTypes.ErrAndBox, 27); result = -9; Global.GetClientKuaFuServerLoginData(client).RoleId = 0; } else { int[] enterFlags = new int[5]; enterFlags[0] = fromMapCode; enterFlags[1] = teleportId; enterFlags[2] = toBoss; Global.SaveRoleParamsIntListToDB(client, new List <int>(enterFlags), "EnterKuaFuMapFlag", true); GlobalNew.RecordSwitchKuaFuServerLog(client); client.sendCmd <KuaFuServerLoginData>(14000, Global.GetClientKuaFuServerLoginData(client), false); } } else { Global.GetClientKuaFuServerLoginData(client).RoleId = 0; result = kuaFuServerId; } } } IL_67F: client.sendCmd <int>(nID, result, false); return(true); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(client.ClientSocket), false, false); } return(false); }