using System.Collections.Generic; using System.IO; using Games.GlobeDefine; using Module.Log; using UnityEngine; public class SdkEditor : SdkBase { private static readonly IntSetting _lastServerId = new IntSetting("EditorLastServer", 2); protected List ipDataList; private bool _login; protected override string noticeUri { get { return "http://rk.qyyjj.99you.cn/JjyApi/notice/cid/3-10001"; } } public override string platformId { get { return "Editor"; } } public override string sdkAccount { get { return string.Empty; } } protected override string redemptionUri { get { return string.Empty; } } public override bool useGm { get { return true; } } public override void Logout() { _login = false; SdkControl.instance.LogoutComplete(string.Empty); } public override void SwitchAccount() { Logout(); } public override void ShakeDevice() { LogModule.WarningLog("Shake device is not possible in Editor!"); } public override void CloseGame() { Debug.LogError("Unable to close game in Editor!"); } public override bool IsLogin() { return _login; } protected void ParseIpList(IEnumerable lines) { ipDataList = new List(); var pageList = new List(); foreach (var line in lines) if (!string.IsNullOrEmpty(line)) { var segments = line.Trim().Split('\t'); int id; int port; if (segments.Length > 4 && int.TryParse(segments[0], out id) && int.TryParse(segments[4], out port)) { var serverData = new LoginData.ServerListData(id, segments[2], ServerListItem.State.NORAML, 0, 0); if (serverData.m_id == _lastServerId) serverData.isDefault = true; var pageName = segments[1].Trim(); var page = pageList.Find(a => a.pageName == pageName); if (page == null) { page = new LoginData.ServerPageData(pageName); pageList.Add(page); } page.pageList.Add(serverData); var ipData = new ServerIpData(id, segments[3].Trim(), port); ipDataList.Add(ipData); } else LogModule.ErrorLog("Unable to parse server data from\n{0}!", line); } defaultServer = PlayerPreferenceData.LastServer; SdkControl.instance.PostServerList(pageList); } public override void GetServerList() { Debug.Log( "GetServerList"); var lines = File.ReadAllLines(GlobeVar.testConfigPath.Open("IPList.txt")); ParseIpList(lines); } public override void LoginPhp(int serverId) { var ipData = ipDataList.Find(a => a.id == serverId); string ip; int port; var success = ipData != null; if (success) { ip = ipData.ip; port = ipData.port; _lastServerId.Set(serverId); } else { ip = default(string); port = default(int); LogModule.ErrorLog("Unable to find serverId {0} in ipList!", serverId); } SdkControl.instance.LoginPhpComplete(ip, port); } public override void LoginSdk(bool isAuto) { _login = true; SdkControl.instance.LoginComplete("EditorPlayer"); } public override void Payment(int goodsId) { Debug.LogError("Unable to pay in Editor!"); } public override bool LoginComplete(string args) { // 无需保存和检验玩家信息 return true; } public override bool LogOutComplete(string args) { Debug.LogError("Unable to logout in Editor!"); return false; } public override bool PaymentComplete(string data) { Debug.LogError("Unable to pay in Editor!"); return false; } public override void Dispose() { // 无需任何析构操作 } protected class ServerIpData { public readonly int id; public readonly string ip; public readonly int port; public ServerIpData(int id, string ip, int port) { this.id = id; this.ip = ip; this.port = port; } } }