| | |
| | | using UnityEngine; |
| | | using LitJson; |
| | | using System; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | public class ServerListCenter : Singleton<ServerListCenter> |
| | | { |
| | | public static readonly string[] JUMP_URL = new string[] |
| | | { |
| | | "http://xssgcenter.secondworld.net.cn:11000/center/server_list.php/?", |
| | | "http://gamecenter.secondworld.net.cn:11000/center/server_list.php/?", |
| | | "http://106.55.151.92:11000/center/server_list_new.php/?" |
| | | }; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public void RequestJumpUrl() |
| | | public async UniTask RequestJumpUrl() |
| | | { |
| | | if (VersionUtility.Instance.InIosAuditTime()) |
| | | if (await VersionUtility.Instance.InIosAuditTime()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var url = StringUtility.Concat(JUMP_URL[jumpUrlIndex % JUMP_URL.Length], "game=xssg&flag=", VersionConfig.Get().appId, "_", VersionConfig.Get().branch.ToString(), "_", VersionConfig.Get().version); |
| | | if (VersionConfig.config == null) |
| | | { |
| | | throw new System.Exception("VersionConfig is null when RequestJumpUrl, check VersionConfig.GetAsync for more details"); |
| | | } |
| | | |
| | | var url = StringUtility.Concat(JUMP_URL[jumpUrlIndex % JUMP_URL.Length], "game=xssg&flag=", VersionConfig.config.appId, "_", VersionConfig.config.branch.ToString(), "_", VersionConfig.config.version); |
| | | jumpUrlIndex++; |
| | | serverUrl = url; |
| | | // 加时间戳防止浏览器/CDN缓存 |
| | | url = StringUtility.Concat(url, "&_t=", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()); |
| | | Debug.Log("http地址:serverlist " + url); |
| | | HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnRequestJumpUrl); |
| | | } |
| | |
| | | { |
| | | if (_ok) |
| | | { |
| | | // 去除响应开头可能存在的 UTF-8 BOM(\uFEFF),否则 WebGL 下会拼成 localhost:8080/%EF%BB%BF... 导致 404 |
| | | _result = _result.TrimStart('\uFEFF'); |
| | | |
| | | var serverUrls = _result.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries); |
| | | SERVERLIST_URL_COMMON = serverUrls[0]; |
| | | SERVERLIST_URL_PLAYER = serverUrls[1]; |
| | | |
| | | Debug.LogError("SERVERLIST_URL_COMMON is " + SERVERLIST_URL_COMMON); |
| | | Debug.LogError("SERVERLIST_URL_PLAYER is " + SERVERLIST_URL_PLAYER); |
| | | RequestServerList(); |
| | | } |
| | | else |
| | | { |
| | | Debug.Log("http 数据通讯: ServerlistCenter:" + serverUrl + " result:" + _result); |
| | | //BuglyAgent.ReportException(new System.Exception(), "http 数据通讯: ServerlistCenter:" + serverUrl + " result:" + _result); |
| | | Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestJumpUrl); |
| | | Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), () => RequestJumpUrl().Forget()); |
| | | } |
| | | } |
| | | |
| | |
| | | serverListPlayerPartGot = false; |
| | | RequestServerCommonList(); |
| | | |
| | | if (VersionConfig.Get().versionAuthority == VersionAuthority.InterTest) |
| | | if (VersionConfig.config == null) |
| | | { |
| | | throw new System.Exception("VersionConfig is null when RequestServerList, check VersionConfig.GetAsync for more details"); |
| | | } |
| | | |
| | | if (VersionConfig.config.versionAuthority == VersionAuthority.InterTest) |
| | | { |
| | | var localSaveAccountName = LocalSave.GetString(LoginManager.USER_ACCOUNT); |
| | | RequestServerListPlayer(localSaveAccountName); |
| | |
| | | |
| | | public void RequestServerCommonList() |
| | | { |
| | | HttpRequest.Instance.RequestHttpGet(SERVERLIST_URL_COMMON, HttpRequest.defaultHttpContentType, 1, OnGetServerList); |
| | | // 加时间戳防止浏览器/CDN缓存 |
| | | var url = SERVERLIST_URL_COMMON; |
| | | var separator = url.Contains("?") ? "&" : "?"; |
| | | url = StringUtility.Concat(url, separator, "_t=", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()); |
| | | HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnGetServerList); |
| | | } |
| | | |
| | | private void OnGetServerList(bool _ok, string _result) |
| | | { |
| | | if (_ok) |
| | | { |
| | | _result = _result.TrimStart('\uFEFF'); |
| | | Debug.LogError("get server list string is " + _result); |
| | | ServerListParser.Instance.PushCommonServerListRawData(_result); |
| | | NetLinkWin.Hide(); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("failure to get server list " + _result); |
| | | Clock.AlarmAt(DateTime.Now + new TimeSpan(TimeSpan.TicksPerSecond), RequestServerCommonList); |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public void RequestServerListPlayer(string _accountName) |
| | | public async void RequestServerListPlayer(string _accountName) |
| | | { |
| | | if (VersionUtility.Instance.InIosAuditTime()) |
| | | if (await VersionUtility.Instance.InIosAuditTime()) |
| | | { |
| | | return; |
| | | } |
| | |
| | | url = StringUtility.Concat(SERVERLIST_URL_PLAYER, "&", HttpRequest.HashtablaToString(tables)); |
| | | } |
| | | |
| | | // 加时间戳防止浏览器/CDN缓存 |
| | | url = StringUtility.Concat(url, "&_t=", DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()); |
| | | HttpRequest.Instance.RequestHttpGet(url, HttpRequest.defaultHttpContentType, 1, OnGetServerListPlayer); |
| | | } |
| | | |
| | |
| | | if (_ok) |
| | | { |
| | | serverListPlayerPartGot = true; |
| | | _result = _result.TrimStart('\uFEFF'); |
| | | ServerListParser.Instance.PushPlayerServerListRawData(_result); |
| | | } |
| | | else |