using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace Snxxz.UI { [XLua.Hotfix] [XLua.LuaCallCSharp] public class CrossServerLogin : Singleton { bool m_Busy = false; public bool busy { get { return m_Busy; } set { m_Busy = value; } } public bool reconnectBackGround { get; set; } Clock loginOverTimeClock; float lastLoginTime = 0f; int reLoginTimes = 0; public CrossServerOneVsOne oneVsOnePlayerData { get; private set; } LoginModel loginModel { get { return ModelCenter.Instance.GetModel(); } } public void Init() { SnxxzGame.Instance.AddApplicationOutAction(OnApplicationOut); } public void UnInit() { SnxxzGame.Instance.RemoveApplicationOutAction(OnApplicationOut); } public string ipBuf { get; private set; } public int portBuf { get; private set; } public int gamePortBuf { get; private set; } public string accountBuf { get; private set; } public string passwordBuf { get; private set; } public void UpdateCrossServerOneVsOneData(HC001_tagGCCrossRealmPKMatchOK matchOK,bool isClient) { oneVsOnePlayerData = new CrossServerOneVsOne() { isClient=isClient, roomId = matchOK.RoomID, waitForLoginCrossServer = true, validTimeLimited = Time.time + 30f, autoEnsureTime = Time.time + 3f, myName = matchOK.PlayerName, myJob = PlayerDatas.Instance.baseData.Job, myBornPoint = matchOK.Number, opponentName = matchOK.MatchPlayer[0].PlayerName, opponentJob = matchOK.MatchPlayer[0].Job, opponentMaxHp = (int)matchOK.MatchPlayer[0].MaxHP, opponentLevel = (int)matchOK.MatchPlayer[0].LV, opponentPlayerId = (int)matchOK.MatchPlayer[0].PlayerID, MaxProDef = (int)matchOK.MatchPlayer[0].MaxProDef, }; Clock.Create(DateTime.Now + new TimeSpan(3 * TimeSpan.TicksPerSecond), () => { if (oneVsOnePlayerData.waitForLoginCrossServer) { if (oneVsOnePlayerData.isClient) { ClientCrossServerOneVsOne.StartClientCrossServerOneVsOne(); } else { CrossServerOneVsOneLogin(); } } }); } public void CrossServerOneVsOneLogin() { var loginModel = ModelCenter.Instance.GetModel(); var account = loginModel.accountBuf; var ip = GameNetSystem.Instance.crossServerData.ip; var port = GameNetSystem.Instance.crossServerData.port; LoadingWin.isCrossServerOneVsOne = true; WindowCenter.Instance.Open(); SetWaitForLoginCrossServerState(false); AccountLogin(account, ip, port, false); } public void SetWaitForLoginCrossServerState(bool state) { oneVsOnePlayerData = oneVsOnePlayerData.SetWaitForLoginCrossServer(false); } public bool IsEnterCrossServerPreparing() { return oneVsOnePlayerData.IsCrossServerOneVsOneEntering(); } public void CrossServerBossLogin() { var loginModel = ModelCenter.Instance.GetModel(); var account = loginModel.accountBuf; var ip = GameNetSystem.Instance.crossServerData.ip; var port = GameNetSystem.Instance.crossServerData.port; WindowCenter.Instance.Open(); AccountLogin(account, ip, port, false); } public void AccountLogin(string account, string ip, int gamePort, bool reconnectBackGround) { if (Application.internetReachability == NetworkReachability.NotReachable) { ConfirmCancel.ShowPopConfirm( Language.Get("Mail101"), Language.Get("L1116"), () => { } ); return; } if (busy) { return; } reLoginTimes = 0; busy = true; try { this.reconnectBackGround = reconnectBackGround; accountBuf = account; ipBuf = ip; gamePortBuf = gamePort; StopLoginOverTimeProcess(); loginOverTimeClock = Clock.Create(DateTime.Now + new TimeSpan(30 * TimeSpan.TicksPerSecond), () => { busy = false; ReAccountLogin(); }); GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected); NetLinkWin.Show(); } catch (Exception ex) { Debug.Log(ex); busy = false; } } public void ReAccountLogin() { if (busy) { return; } busy = true; reLoginTimes++; if (reLoginTimes > 1) { ProcessLoginFailure(); return; } try { this.reconnectBackGround = true; StopLoginOverTimeProcess(); loginOverTimeClock = Clock.Create(DateTime.Now + new TimeSpan(30 * TimeSpan.TicksPerSecond), () => { busy = false; ReAccountLogin(); }); GameNetSystem.Instance.BeginConnectCrossServer(ipBuf, gamePortBuf, OnGameServerConnected); NetLinkWin.Show(); } catch (Exception ex) { Debug.Log(ex); busy = false; } } public void StopLoginOverTimeProcess() { if (loginOverTimeClock != null) { loginOverTimeClock.Stop(); } loginOverTimeClock = null; } private void OnGameServerConnected(bool ok) { if (ok) { var sendInfo = new C0123_tagCClientPackVersion(); sendInfo.Version = LoginModel.DwVersionNo; GameNetSystem.Instance.SendToCrossServer(sendInfo); } else { busy = false; } } public void AccessLogin(H0101_tagServerPrepared _serverInfo) { GameNetSystem.Instance.SendToCrossServer(loginModel.Get0101SendPackage(_serverInfo)); // 登录 NetLinkWin.Show(); } public void CheckClientVersion() { var sendInfo = new C010D_tagCClientVersion(); sendInfo.Version = "10.1000.1"; GameNetSystem.Instance.SendToCrossServer(sendInfo); NetLinkWin.Show(); } public void OnGetPlayerLoginInfo(byte _type) { NetLinkWin.Hide(); busy = false; if (Application.internetReachability == NetworkReachability.NotReachable) { ConfirmCancel.ShowPopConfirm( Language.Get("Mail101"), Language.Get("L1116"), () => { } ); return; } var tagCRoleLoginAsk = new C0108_tagCRoleLoginAsk(); tagCRoleLoginAsk.Type = (byte)_type;//进入游戏 tagCRoleLoginAsk.ClientID = SDKUtility.Instance.RegistrationID; GameNetSystem.Instance.SendToCrossServer(tagCRoleLoginAsk); NetLinkWin.Show(); } private void ProcessLoginFailure() { StopLoginOverTimeProcess(); busy = false; ExceptionCatcher.ReportException("登录跨服出现异常", StringUtility.Contact( "角色:", PlayerDatas.Instance.baseData.PlayerName, ";", "本机网络:", Application.internetReachability, ";", "Socket链接状态:", GameNetSystem.Instance.crossServerSocketConnected, ";", "0102记录:", StageLoadTimeOutCatcher.got0102Time.ToString()) ); var sendInfo = new CC003_tagCGForceQuitCrossState(); GameNetSystem.Instance.SendInfo(sendInfo); GameNetSystem.Instance.crossServerConnected_Loigc = false; Clock.Create(DateTime.Now + new TimeSpan(2 * TimeSpan.TicksPerSecond), () => { GameNetSystem.Instance.Reconnect(); }); } private void OnApplicationOut() { var sendInfo = new C0103_tagCPlayerLogOut(); sendInfo.Type = 1; GameNetSystem.Instance.SendToCrossServer(sendInfo); } } public struct CrossServerOneVsOne { public bool isClient; public int roomId; public bool waitForLoginCrossServer; public float autoEnsureTime; public float validTimeLimited; public string myName; public int myJob; public int myBornPoint;//1-左;2-右 public int opponentPlayerId; public string opponentName; public int opponentJob; public int opponentLevel; public int opponentMaxHp; public int MaxProDef;// 最大护盾 public CrossServerOneVsOne SetWaitForLoginCrossServer(bool waitForLoginCrossServer) { this.waitForLoginCrossServer = waitForLoginCrossServer; return this; } public bool IsCrossServerOneVsOneEntering() { return autoEnsureTime > Time.time; } } }