/// <summary> /// 获得本地记录的服务器*千万不要在游戏内调用,请调lastServer* /// </summary> /// <returns>The local save server.</returns> public Json_ServerInfo getLocalSaveServer() { Json_ServerInfo server = null; string layelyServerInfo = getLastLoginServer(); //有记录,并且记录的服务器存在 if (!string.IsNullOrEmpty(layelyServerInfo)) { setLatelyServer(layelyServerInfo); } Json_ServerInfo jsi = getJsonServerInfoByName(lastServer); if (jsi == null) //记录的服务器不存在 { removeLoginServer(lastServer); lastServer = null; } else // 更新存在服务器的信息,防止ip,端口等数据修改后导致问题 { string serverInfo = getServerInfo(jsi); setLatelyServer(serverInfo); setLatelyLoginServer(serverInfo); } // 设置最后一次登录的服务器 if (lastServer != null && Contains(lastServer)) { server = lastServer; } else if (getAllServer() != null && getAllServer().Count > 0) { lastServer = getAllServer() [0]; server = lastServer; } return(server); }
/** 设置最近3次登陆的服务器 */ public void setLatelyLoginServer(string currentServer) { // 这里用Json_ServerInfo方便以后统一修改 Json_ServerInfo currentJsonServerInfo = createJsonServerInfo(currentServer); string oldServerInfo = PlayerPrefs.GetString(PlayerPrefsComm.LOGIN_LATELY_SERVER); string[] temps = null; if (!string.IsNullOrEmpty(oldServerInfo)) { string[] oldServerInfoData = StringKit.stringToStringList(oldServerInfo, new char[] { StringKit.USD_SIGN }); Json_ServerInfo tempJsonServerInfos; int jsonIndex = -1; for (int i = 0; i < oldServerInfoData.Length; i++) { tempJsonServerInfos = createJsonServerInfo(oldServerInfoData [i]); if (tempJsonServerInfos.name == currentJsonServerInfo.name) // 将最新的数据赋予老数据 { oldServerInfoData [i] = getServerInfo(currentJsonServerInfo); jsonIndex = i; } } if (jsonIndex == -1) // 没有更新数据表示之前不存在此信息,添加之 { int saveNumber = 3; if (oldServerInfoData.Length >= saveNumber) // >=3条顶掉第一条 { temps = new string[saveNumber]; System.Array.Copy(oldServerInfoData, 1, temps, 0, saveNumber - 1); temps [temps.Length - 1] = currentServer; } else // <3条添加 { temps = new string[oldServerInfoData.Length + 1]; System.Array.Copy(oldServerInfoData, 0, temps, 0, oldServerInfoData.Length); temps [temps.Length - 1] = currentServer; } } else { temps = new string[oldServerInfoData.Length]; if (jsonIndex > 0) { System.Array.Copy(oldServerInfoData, 0, temps, 0, jsonIndex); } if (jsonIndex < oldServerInfoData.Length - 1) { System.Array.Copy(oldServerInfoData, jsonIndex + 1, temps, jsonIndex, oldServerInfoData.Length - (jsonIndex + 1)); } temps [temps.Length - 1] = currentServer; } } else { temps = new string[1]; temps [0] = currentServer; } string newServerInfo = StringKit.stringListTostring(temps, StringKit.USD_SIGN); PlayerPrefs.SetString(PlayerPrefsComm.LOGIN_LATELY_SERVER, newServerInfo); }
private void pcLogin(Json_ServerInfo server) { bool isload = setMsg(server); if (isload == false) { return; } //如果有自定义服务器ip,那么当前选中的服务器ip换掉 string ip = serverIPInput.value; if (ip != "" && !SdkManager.INSTANCE.IS_SDK) { if (ServerManagerment.Instance.lastServer != null && ServerManagerment.Instance.lastServer.ipEndPoint != null) { ServerManagerment.Instance.lastServer.ipEndPoint = null; } string[] str = ip.Split(':'); if (str != null && str.Length == 2) { server.domainName = str[0]; server.port = StringKit.toInt(str[1]); } } if (server != null) { MaskWindow.NetLock(); ConnectManager.manager().beginConnect(server.domainName, server.port, PcConnectOK); } }
public void connetGameServer(Json_ServerInfo server) { MaskWindow.NetLock(); ConnectManager.manager().beginConnect(server.domainName, server.port, () => { connectGameServerOK(server); }); }
/// <summary> /// 添加服务器信息 /// </summary> /// <param name="json">Json.</param> public void addServer(Json_ServerInfo json) { if (servers.Contains(json)) { return; } servers.Add(json); }
void connectGameServerOK(Json_ServerInfo server) { LoginFPort port = FPortManager.Instance.getFPort("LoginFPort") as LoginFPort; Debug.Log(SdkManager.URL); port.login(SdkManager.URL, StringKit.toInt(server.sid), () => { GameManager.Instance.loginBack(UiManager.Instance.getWindow <LoginWindow>()); }); }
public void setLatelyServer(string str) { string[] serverInfoData = StringKit.stringToStringList(str, new char[] { StringKit.POUND_SIGN }); lastServer = createJsonServerInfo(serverInfoData); if (ServerManagerment.Instance.userName == null || ServerManagerment.Instance.userName == "") { ServerManagerment.Instance.userName = serverInfoData [0]; } }
protected override void DoEnable() { base.DoEnable(); latelyServer = ServerManagerment.Instance.lastServer; if (latelyServer != null) { serverName = latelyServer.name; } shareCodeContent.text = LanguageConfigManager.Instance.getLanguage("shareContent01", serverName, UserManager.Instance.self.nickname, StringKit.serverIdToFrontId(UserManager.Instance.self.uid)); }
public void InitTestServers() { if (GameManager.Instance.isShowTestServer) { ServerManagerment manager = ServerManagerment.Instance; Json_ServerInfo xzns_int = new Json_ServerInfo("1", "192.168.2.18", 7610, "xzns_int"); xzns_int.isTestServer = true; manager.addServer(xzns_int); Json_ServerInfo xzns_patch = new Json_ServerInfo("2", "server.natappfree.cc", 35814, "xzns_patch"); xzns_patch.isTestServer = true; manager.addServer(xzns_patch); } }
public bool setMsg(Json_ServerInfo server) { if (NameInput.value == "") { MessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("loginwindow004")); return(false); } ServerManagerment.Instance.saveLastServer(server); saveLoginInfo(); if (GuideManager.Instance.guideUI != null) { GuideManager.Instance.hideGuideUI(); } return(true); }
protected override void begin() { base.begin(); MaskWindow.UnlockUI(true); loadLoginInfo(); if (GuideManager.Instance.guideUI != null) { GuideManager.Instance.hideGuideUI(); } latelyServer = ServerManagerment.Instance.getLocalSaveServer(); if (latelyServer != null) { buttonServer.textLabel.text = latelyServer.name; } }
/** 初始化服务器按钮 */ private void initServerButtons(Json_ServerInfo selectServer) { if (selectServer == null) { return; } string[] serverInfos = ServerManagerment.Instance.getLatelyLoginServer(); resetLatelyServersActive(); ServerButton latelyServer; if (serverInfos == null) { latelyServer = latelyServers [0]; latelyServer.server = selectServer; latelyServer.platform.text = selectServer.name; latelyServer.gameObject.SetActive(true); } else { Json_ServerInfo server; string[] servers; int len = serverInfos.Length > latelyServers.Length ? latelyServers.Length : serverInfos.Length; for (int i = 0, j = len - 1; i < len; i++, j--) { string serverInfo = serverInfos [i]; server = ServerManagerment.Instance.createJsonServerInfo(serverInfo); if (server == null) { continue; } latelyServer = latelyServers [j]; if (selectServer.name == server.name) { latelyServer.server = selectServer; latelyServer.platform.text = selectServer.name; UpdateSelectBgPosition(latelyServer); } else { latelyServer.server = server; latelyServer.platform.text = server.name; } latelyServer.gameObject.SetActive(true); } } }
void wantToIntoGame(Json_ServerInfo server) { if (server.is_open == "1") { MaskWindow.LockUI(); UiManager.Instance.openDialogWindow <MessageLineWindow>((win) => { win.dialogCloseUnlockUI = false; win.Initialize(LanguageConfigManager.Instance.getLanguage("serverState09"), false); }); return; } else { MaskWindow.LockUI(); connetGameServer(server); } }
/** 创建Json服务器信息 */ public Json_ServerInfo createJsonServerInfo(string[] serverInfoData) { if (serverInfoData == null || serverInfoData.Length < 5) { return(null); } Json_ServerInfo jsonServerInfo = new Json_ServerInfo(serverInfoData [1], serverInfoData [2], StringKit.toInt(serverInfoData [3]), serverInfoData [4]); jsonServerInfo.payUrl = serverInfoData[5]; if (serverInfoData.Length >= 7) { if (serverInfoData[6] == "True") { jsonServerInfo.isTestServer = true; } } return(jsonServerInfo); }
public void initButton(Json_ServerInfo _server) { this.server = _server; platform.gameObject.SetActive(true); platform.text = server.name; if (server.is_new == "1") { textLabel.color = Colors.SERVER_NEW; } else if (server.is_hot == "1") { textLabel.color = Colors.SERVER_HOT; } else { textLabel.color = Colors.SERVER_NORMAL; } }
private void ClickLogin() { Json_ServerInfo server = ServerManagerment.Instance.lastServer; if (server != null && server.is_open == "1") { MessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("serverState09")); return; } if (SdkManager.INSTANCE.IS_SDK) { Debug.Log(server.payUrl); wantToIntoGame(server); } else { pcLogin(server); } ServerManagerment.Instance.setLatelyLoginServer(ServerManagerment.Instance.getServerInfo(server)); }
public static Json_ServerInfo[] readFile(string path, string name) { StreamReader sr = null; string[] servers = null; try{ sr = File.OpenText(path + "//" + name); } catch (Exception e) { return(null); } Json_ServerInfo[] serverc = null; string line = sr.ReadToEnd(); servers = line.Split('\n'); string[] serverMsg = null; if (servers != null && servers.Length > 0) { serverc = new Json_ServerInfo[servers.Length]; for (int i = 0; i < servers.Length; i++) { serverMsg = servers[i].Split(','); if (serverMsg.Length != 4) { continue; } serverc [i] = new Json_ServerInfo(serverMsg[0], serverMsg[1], int.Parse(serverMsg[2]), serverMsg[3]); } } sr.Close(); sr.Dispose(); return(serverc.Where(t => t != null).ToArray()); }
/// <summary> /// 获取指定服务器名字的JsonServer /// </summary> /// <param name="server">Server.</param> public Json_ServerInfo getJsonServerInfoByName(Json_ServerInfo server) { if (server == null) { return(null); } servers = getAllServer(); if (servers == null) { return(null); } Json_ServerInfo jsi; for (int i = 0; i < servers.Count; i++) { jsi = servers [i]; if (jsi.name.Equals(server.name)) { return(jsi); } } return(null); }
/** 移除指定名字的保存服务器信息 */ public void removeLoginServer(Json_ServerInfo removeJson) { if (removeJson == null) { return; } string oldServer = PlayerPrefs.GetString(PlayerPrefsComm.LOGIN_LATELY_SERVER); if (string.IsNullOrEmpty(oldServer)) { return; } string[] oldServerInfoData = StringKit.stringToStringList(oldServer, new char[] { StringKit.USD_SIGN }); Json_ServerInfo tempJsonServerInfos; int jsonIndex = -1; for (int i = 0; i < oldServerInfoData.Length; i++) { tempJsonServerInfos = createJsonServerInfo(oldServerInfoData [i]); if (tempJsonServerInfos.name == removeJson.name) // 将最新的数据赋予老数据 { jsonIndex = i; } } string[] temps = new string[oldServerInfoData.Length - 1]; if (jsonIndex > 0) { System.Array.Copy(oldServerInfoData, 0, temps, 0, jsonIndex); } if (jsonIndex < oldServerInfoData.Length - 1) { System.Array.Copy(oldServerInfoData, jsonIndex + 1, temps, jsonIndex, oldServerInfoData.Length - (jsonIndex + 1)); } string newServerInfo = StringKit.stringListTostring(temps, StringKit.USD_SIGN); PlayerPrefs.SetString(PlayerPrefsComm.LOGIN_LATELY_SERVER, newServerInfo); }
public bool Contains(Json_ServerInfo server) { if (server == null) { return(false); } servers = getAllServer(); bool istrue = false; if (servers == null) { return(false); } for (int i = 0; i < servers.Count; i++) { if (servers [i].name.Equals(server.name)) { istrue = true; return(istrue); } } return(istrue); }
public static Json_ServerInfo[] readFile() { TextAsset asset = (TextAsset)Resources.Load("server/serverlist", typeof(TextAsset)); // if (GameManager.Instance == null || GameManager.Instance.serverAsset == null) // { // return null; // } string[] servers = null; Json_ServerInfo[] serverc = null; string line = asset.text; servers = line.Split('\n'); string[] serverMsg = null; if (servers != null && servers.Length > 0) { serverc = new Json_ServerInfo[servers.Length]; for (int i = 0; i < servers.Length; i++) { serverMsg = servers[i].Split(','); if (serverMsg.Length != 4) { continue; } serverc [i] = new Json_ServerInfo(serverMsg[0], serverMsg[1], int.Parse(serverMsg[2]), serverMsg[3]); } } return(serverc.Where(t => t != null).ToArray()); }
/** 构建服务器信息 */ public string getServerInfo(Json_ServerInfo jsonServerInfo) { return(userName + "#" + jsonServerInfo.sid + "#" + jsonServerInfo.domainName + "#" + jsonServerInfo.port + "#" + jsonServerInfo.name + "#" + jsonServerInfo.payUrl + "#" + jsonServerInfo.isTestServer); }
public void saveLastServer(Json_ServerInfo _server) { this.lastServer = _server; }