using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Threading; using LitJson; public class ServerListParser : SingletonMonobehaviour { bool hasCommonResult = false; ServerInfoCommon serverInfoCommon; bool hasPlayerResult = false; ServerInfoPlayer serverInfoPlayer; List serverGroupTitlesNoShow = new List(); //不显示的区服组 Dictionary areaSpecialServerDict = new Dictionary(); //根据地区特殊附加的区服组 public void PushCommonServerListRawData(string content) { hasCommonResult = false; ThreadPool.QueueUserWorkItem((object aaa) => { serverInfoCommon = JsonMapper.ToObject(content); FilterServerList(); hasCommonResult = true; }); } //过滤不显示的服务器 public void FilterServerList() { if (serverInfoCommon == null) return; if (serverGroupTitlesNoShow.IsNullOrEmpty()) { var config = InitialFunctionConfig.Get("serverListGroup"); serverGroupTitlesNoShow = JsonMapper.ToObject>(config.Numerical1); areaSpecialServerDict = JsonMapper.ToObject>(config.Numerical2); } //按 group_title删除不显示的服务器组 List common = new List(); for (int i = serverInfoCommon.common.Length - 1; i >= 0; i--) { ServerGroup serverGroup = serverInfoCommon.common[i]; var title = serverInfoCommon.common[i].group_title; if (serverGroupTitlesNoShow.Contains(title)) { if (areaSpecialServerDict.ContainsKey(VersionConfig.Get().sdkFileName) && areaSpecialServerDict[VersionConfig.Get().sdkFileName] == title) { //特殊指定的服务器组 common.Add(serverGroup); } continue; } else { common.Add(serverGroup); } } serverInfoCommon.common = common.ToArray(); } public void PushPlayerServerListRawData(string content) { hasPlayerResult = false; Debug.Log("ServerListParser:" + content); if (content == "" || content == "{}") return; JsonData RankArr = JsonMapper.ToObject(content); if (RankArr["player"]["group_list"].Count == 0) return; ThreadPool.QueueUserWorkItem((object aaa) => { serverInfoPlayer = JsonMapper.ToObject(content); hasPlayerResult = true; SetIsInWhiteList(); }); } public void ReportCommonResult() { if (serverInfoCommon != null) { ServerListCenter.Instance.SetServerlistCommon(serverInfoCommon); } } public void ReportPlayerResult() { if (serverInfoPlayer != null) { ServerListCenter.Instance.SetServerListPlayer(serverInfoPlayer); } } public void SetIsInWhiteList() { DebugUtility.Instance.isWhiteListAccount = serverInfoPlayer.white == 1; } private void Update() { if (hasCommonResult) { ReportCommonResult(); hasCommonResult = false; } if (hasPlayerResult) { ReportPlayerResult(); hasPlayerResult = false; } } }