public void Update() { if (!IsNeedDownload()) { return; } try { ClientServerListData clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); byte[] clientBytes = DataHelper2.ObjectToBytes <ClientServerListData>(clientListData); byte[] responseData = WebHelper.RequestByPost(KuaFuServerManager.GetPlatChargeKingUrl, clientBytes, 2000, 30000); if (responseData == null) { return; } InputKingPaiHangDataEx tmpRankEx = DataHelper2.BytesToObject <InputKingPaiHangDataEx>(responseData, 0, responseData.Length); if (tmpRankEx != null) { rankEx = tmpRankEx; } } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, "PlatChargeKingManager.Update exception", ex); } }
public void Update() { try { lock (this.Mutex) { if (this.IsNeedDownload()) { bool flag = false; List <InputKingPaiHangDataEx> list = new List <InputKingPaiHangDataEx>(); if (KuaFuServerManager.GetPlatChargeKingUrl != null) { for (int i = 0; i < KuaFuServerManager.GetPlatChargeKingUrl.Length; i++) { ClientServerListData clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); byte[] clientBytes = DataHelper2.ObjectToBytes <ClientServerListData>(clientListData); byte[] responseData = WebHelper.RequestByPost(KuaFuServerManager.GetPlatChargeKingUrl[i], clientBytes, 2000, 30000); if (responseData == null) { flag = true; break; } InputKingPaiHangDataEx tmpRankEx = DataHelper2.BytesToObject <InputKingPaiHangDataEx>(responseData, 0, responseData.Length); if (tmpRankEx == null) { flag = true; break; } list.Add(tmpRankEx); } if (flag) { this.rankEx = new InputKingPaiHangDataEx(); } else { this.rankEx = this.MergePlatfromInputKingList(list); } } } if (this.IsNeedDownloadEveryDay()) { if (KuaFuServerManager.GetPlatChargeKingUrl_EveryDay != null) { bool flag = false; Dictionary <int, List <InputKingPaiHangDataEx> > dict = new Dictionary <int, List <InputKingPaiHangDataEx> >(); for (int i = 0; i < KuaFuServerManager.GetPlatChargeKingUrl_EveryDay.Length; i++) { List <InputKingPaiHangDataEx> tempRankExList = new List <InputKingPaiHangDataEx>(); if (this.MeiRiPCKingFromDate < this.MeiRiPCKingToDate) { DateTime timeLoop = this.MeiRiPCKingFromDate; while (timeLoop < this.MeiRiPCKingToDate && timeLoop < TimeUtil.NowDateTime()) { InputKingPaiHangDataEx tmpRankEx = null; byte[] clientBytes = DataHelper2.ObjectToBytes <InputKingPaiHangDataSearch>(new InputKingPaiHangDataSearch { startDate = timeLoop.ToString("yyyy-MM-dd HH:mm:ss"), endDate = timeLoop.AddDays(1.0).AddSeconds(-1.0).ToString("yyyy-MM-dd HH:mm:ss") }); byte[] responseData = WebHelper.RequestByPost(KuaFuServerManager.GetPlatChargeKingUrl_EveryDay[i], clientBytes, 2000, 30000); if (responseData != null) { tmpRankEx = DataHelper2.BytesToObject <InputKingPaiHangDataEx>(responseData, 0, responseData.Length); } if (null != tmpRankEx) { tempRankExList.Add(tmpRankEx); } else { tempRankExList.Add(new InputKingPaiHangDataEx()); flag = true; } if (flag) { break; } timeLoop = timeLoop.AddDays(1.0); } if (flag) { break; } if (!dict.ContainsKey(i)) { dict.Add(i, tempRankExList); } } } if (flag) { this.rankExList = new List <InputKingPaiHangDataEx>(); } else { this.rankExList = this.MergePlatfromInputKingListEveryDay(dict); } } } } } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, "PlatChargeKingManager.Update exception", ex, true); } }
public static bool UpdateDataFromServer() { if (Monitor.TryEnter(MutexServerList)) { try { int nextServerListAge = DataHelper2.UnixSecondsNow(); int nextServerGameConfigAge = DataHelper2.UnixSecondsNow(); if (Math.Abs(nextServerListAge - _ServerListAge) < 3) { return(false); } if (!LoadConfigFromServer) { return(false); } //确认是否配置了获取接口地址 if (string.IsNullOrEmpty(KuaFuServerListUrl) || string.IsNullOrEmpty(ServerListUrl)) { return(false); } //首先获取普通服务器列表 //1其次获取跨服活动服务器列表 ClientServerListData clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); byte[] clientBytes = DataHelper2.ObjectToBytes <ClientServerListData>(clientListData); byte[] responseData = WebHelper.RequestByPost(ServerListUrl, clientBytes, 2000, 30000); if (responseData == null) { return(false); } bool serverInfoChanged = false; HashSet <int> existAllIds = new HashSet <int>(); HashSet <int> existKfIds = new HashSet <int>(); BuffServerListData serverListResponseData; BuffServerListData kuaFuServerListResponseData; serverListResponseData = DataHelper2.BytesToObject <BuffServerListData>(responseData, 0, responseData.Length); if (null == serverListResponseData || null == serverListResponseData.listServerData || serverListResponseData.listServerData.Count == 0) { return(false); } //其次获取跨服活动服务器列表 clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); clientBytes = DataHelper2.ObjectToBytes <ClientServerListData>(clientListData); responseData = WebHelper.RequestByPost(KuaFuServerListUrl, clientBytes, 2000, 30000); if (responseData == null) { return(false); } kuaFuServerListResponseData = DataHelper2.BytesToObject <BuffServerListData>(responseData, 0, responseData.Length); if (null == kuaFuServerListResponseData || null == kuaFuServerListResponseData.listServerData || kuaFuServerListResponseData.listServerData.Count == 0) { return(false); } if (null != serverListResponseData && null != serverListResponseData.listServerData) { lock (Mutex) { foreach (var item in serverListResponseData.listServerData) { existAllIds.Add(item.nServerID); KuaFuServerInfo data; if (UpdateServerInfo(item, _ServerListAge, ServerFlags.NormalServer, out data, _ServerIdServerInfoDict)) { serverInfoChanged = true; } } } } if (null != kuaFuServerListResponseData && null != kuaFuServerListResponseData.listServerData) { lock (Mutex) { foreach (var item in kuaFuServerListResponseData.listServerData) { existAllIds.Add(item.nServerID); KuaFuServerInfo data; if (UpdateServerInfo(item, _ServerListAge, ServerFlags.KuaFuServer, out data, _ServerIdServerInfoDict)) { serverInfoChanged = true; } } foreach (var id in _ServerIdServerInfoDict.Keys) { if (!existAllIds.Contains(id)) { RemoveServerInfo(id, _ServerIdServerInfoDict); serverInfoChanged = true; } } if (serverInfoChanged) { _ServerListAge = nextServerListAge; } //默认所有跨服服务器都允许分配幻影寺院活动 foreach (var item in _ServerIdServerInfoDict.Values) { if ((item.Flags & ServerFlags.KuaFuServer) > 0) { existKfIds.Add(item.ServerId); } item.Age = _ServerListAge; } } } ClientAgentManager.Instance().SetAllKfServerId(existKfIds); } catch (System.Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); return(false); } finally { Monitor.Exit(MutexServerList); } } return(true); }
/// <summary> /// 从中心后台检查更新配置 /// </summary> /// <returns></returns> public bool UpdateDataFromServer2() { try { //确认是否配置了获取接口地址 if (string.IsNullOrEmpty(KuaFuServerListUrl) || string.IsNullOrEmpty(ServerListUrl)) { return(false); } //首先获取普通服务器列表 //1其次获取跨服活动服务器列表 ClientServerListData clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); byte[] clientBytes = DataHelper.ObjectToBytes <ClientServerListData>(clientListData); byte[] responseData = WebHelper.RequestByPost(ServerListUrl, clientBytes, 2000, 30000); if (responseData == null) { return(false); } HashSet <int> existIds = new HashSet <int>(); BuffServerListData kuaFuServerListResponseData = DataHelper.BytesToObject <BuffServerListData>(responseData, 0, responseData.Length); if (null != kuaFuServerListResponseData && null != kuaFuServerListResponseData.listServerData) { lock (Mutex) { bool serverInfoChanged = false; foreach (var item in kuaFuServerListResponseData.listServerData) { KuaFuServerInfo data; if (!ServerIdServerInfoDict.TryGetValue(item.nServerID, out data)) { serverInfoChanged = true; data = new KuaFuServerInfo() { ServerId = item.nServerID, }; ServerIdServerInfoDict[item.nServerID] = data; } if (data.Ip != item.strURL || data.Port != item.nServerPort) { data.Ip = data.DbIp = data.LogDbIp = item.strURL; data.Port = item.nServerPort; data.DbPort = item.nServerPort + 10000; data.LogDbPort = item.nServerPort + 20000; data.Flags = ServerFlags.NormalServerOnly; data.Age = ServerListAge; UpdateServerInfo(data.ServerId, data.Ip, data.Port, data.DbPort, data.LogDbPort, data.Flags); serverInfoChanged = true; } existIds.Add(item.nServerID); } } } //其次获取跨服活动服务器列表 clientListData = new ClientServerListData(); clientListData.lTime = TimeUtil.NOW(); clientListData.strMD5 = MD5Helper.get_md5_string(ConstData.HTTP_MD5_KEY + clientListData.lTime.ToString()); clientBytes = DataHelper.ObjectToBytes <ClientServerListData>(clientListData); responseData = WebHelper.RequestByPost(KuaFuServerListUrl, clientBytes, 2000, 30000); if (responseData == null) { return(false); } kuaFuServerListResponseData = DataHelper.BytesToObject <BuffServerListData>(responseData, 0, responseData.Length); if (null != kuaFuServerListResponseData && null != kuaFuServerListResponseData.listServerData) { lock (Mutex) { bool serverInfoChanged = false; bool serverGameConfigChanged = false; foreach (var item in kuaFuServerListResponseData.listServerData) { KuaFuServerInfo data; if (!ServerIdServerInfoDict.TryGetValue(item.nServerID, out data)) { serverInfoChanged = true; data = new KuaFuServerInfo() { ServerId = item.nServerID, }; ServerIdServerInfoDict[item.nServerID] = data; } if (data.Ip != item.strURL || data.Port != item.nServerPort) { data.Ip = data.DbIp = data.LogDbIp = item.strURL; data.Port = item.nServerPort; data.DbPort = item.nServerPort + 10000; data.LogDbPort = item.nServerPort + 20000; data.Flags = ServerFlags.KuaFuServer; data.Age = ServerListAge; UpdateServerInfo(data.ServerId, data.Ip, data.Port, data.DbPort, data.LogDbPort, data.Flags); serverInfoChanged = true; } existIds.Add(item.nServerID); } foreach (var id in ServerIdServerInfoDict.Keys) { if (!existIds.Contains(id)) { KuaFuServerInfo data; ServerIdServerInfoDict.TryRemove(id, out data); RemoveServerInfo(id); serverInfoChanged = true; } } if (serverInfoChanged) { ServerListAge++; } existIds.Clear(); //默认所有跨服服务器都允许分配幻影寺院活动 foreach (var item in ServerIdServerInfoDict.Values) { if ((item.Flags & ServerFlags.KuaFuServer) > 0) { UpdateServerGameConfig(item.ServerId, (int)GameTypes.HuanYingSiYuan, HuanYingSiYuanGameConfigData.MaxCount, ref serverGameConfigChanged); existIds.Add(item.ServerId); } item.Age = ServerListAge; } //从列表移除已不存在的服务器 foreach (var id in ServerIdGameConfigDict.Keys) { if (!existIds.Contains(id)) { RemoveServerGameConfig(id, ref serverGameConfigChanged); RemoveServerGameConfigToDb(id, (int)GameTypes.HuanYingSiYuan); } } if (serverGameConfigChanged) { ServerGameConfigAge++; } } } } catch (System.Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); return(false); } return(true); }