private void ReciveIPDetail(IPGeolocationDetail detail) { if (detail == null) { retryTimes++; if (retryTimes > 1) { retryTimes = 0; RunDownloadRegionServer(); } else { OnFlowStart(); } return; } iPGeolocationDetail = detail; if (detail.country_code == "CN") { IsChinaIP = true; } Debug.Log("IP地区:" + detail.ipv4 + " 国家:" + detail.country); GameInfoCollecter.AddNetworkStateInfoValue("Device IP", detail.ipv4); GameInfoCollecter.AddNetworkStateInfoValue("Device IP Country", detail.country); GameInfoCollecter.AddNetworkStateInfoValue("Device IP Country Code", detail.country_code); flowManager.SetVariable(P_IPGeolocationDetail, detail); RunDownloadRegionServer(); }
public void StartSelectServer(GameServerAreaData gameServerArea) { Debug.Log("开始选服"); if (ApplicationManager.Instance.m_AppMode == AppMode.Release) { RuntimePlatform platform = Application.platform; //if (Application.isEditor) //{ // if (platform == RuntimePlatform.OSXEditor) // platform = RuntimePlatform.IPhonePlayer; // else // { // platform = RuntimePlatform.Android; // } //} string defaultChannel = "GameCenter"; string channel = SDKManager.GetProperties(SDKInterfaceDefine.PropertiesKey_ChannelName, defaultChannel); GameInfoCollecter.AddNetworkStateInfoValue("渠道", channel); string selectNetworkPath = gameServerArea.m_SelectServerURL; SelectSeverController.Start(selectNetworkPath, Application.version, platform, channel, (data) => { SelectNetworkData select = null; bool isSelectRight = false; if (data == null || data.Count == 0) { Debug.LogError("没有合适的服务器!"); //return; string networkID = SDKManager.GetProperties("NetworkID", "3"); select = DataGenerateManager <SelectNetworkData> .GetData(networkID); } else { int r = UnityEngine.Random.Range(0, data.Count); select = data[r]; isSelectRight = true; } GameInfoCollecter.AddNetworkStateInfoValue("是否正确匹配服务器", isSelectRight); GameInfoCollecter.AddNetworkStateInfoValue("匹配服务器", select.m_serverIP + ":" + select.m_port); GameInfoCollecter.AddNetworkStateInfoValue("服务器描述", select.m_description); SelectServerCompleted(select); }); } else { if (OnSelectServerLocal != null) { OnSelectServerLocal(SelectServerCompleted); } } }
/// <summary> /// 下载大区服务器列表 /// </summary> public void DownloadRegionServerList(string url, string country_code, Action <string, GameServerAreaData> OnCompleted) { DataTableExtend.DownLoadTableConfig <GameServerAreaData>(url, (dataList, urlError) => { if (!string.IsNullOrEmpty(urlError)) { Debug.LogError("DownloadRegionServerList download fail!"); if (OnCompleted != null) { OnCompleted("download fail! " + urlError, null); } return; } if (dataList.Count == 0) { Debug.LogError("DownloadRegionServerList GameServerAreaData is Empty!"); if (OnCompleted != null) { OnCompleted("GameServerAreaData is Empty!", null); } return; } if (!string.IsNullOrEmpty(country_code)) { //根据国家选择大区 foreach (var item in dataList) { if (ArrayContains(item.m_CountryCode, country_code)) { Debug.Log("国家选定大区key:" + item.m_key); GameInfoCollecter.AddNetworkStateInfoValue("选定大区", item.m_key); if (OnCompleted != null) { OnCompleted(null, item); } return; } } } //根据大洲选择大区 string continentName = GetContinentByCountryCode(country_code); if (!string.IsNullOrEmpty(continentName)) { foreach (var item in dataList) { if (ArrayContains(item.m_ContinentName, continentName)) { Debug.Log("根据大洲选定大区key:" + item.m_key); GameInfoCollecter.AddNetworkStateInfoValue("选定大区", item.m_key); if (OnCompleted != null) { OnCompleted(null, item); } return; } } } Debug.Log("使用ping选择大区:" + dataList.Count); List <string> specialServerHostList = new List <string>(); foreach (var item in dataList) { specialServerHostList.Add(item.m_SpecialServerHost); } UnityPingManager.PingGetOptimalItem(specialServerHostList.ToArray(), (statistics) => { Debug.Log("选出最优Ping:" + statistics); GameServerAreaData saData = null; foreach (var item in dataList) { if (item.m_SpecialServerHost == statistics.host) { saData = item; break; } } string error = null; if (saData == null) { error = "Select Ping Result Error!"; } if (OnCompleted != null) { OnCompleted(error, saData); } }); }); }