using ET; using UnityEngine; namespace GFGGame { public class LoginController { public static async ETTask CheckVersion() { ViewManager.Show("连接中..."); int errorCode = 0; errorCode = await LoginHelper.CheckVersion(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, GameConst.SERVER_VERSION); ViewManager.Hide(); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); return; } } public static async ET.ETTask LoginTest(string account) { ViewManager.Show("登录中..."); int errorCode = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, account); if (errorCode == ET.ErrorCode.ERR_Success) { GameGlobal.isVisitor = false; ViewManager.Hide(); ViewManager.Hide(); AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent(); GameGlobal.userId = accountInfoComponent.AccountId; GameGlobal.userAge = accountInfoComponent.Age; if (GameGlobal.isVisitor) { //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId); } else { PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account); PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, ""); } GameController.CheckSpecialAccount("sygfg"); LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor); PlayerPrefs.Save(); await OnLoginSuccess(); } else { OnLoginFail(errorCode); } } public static async ET.ETTask Login(string account, string password, bool isMD5 = false) { ViewManager.Show("登录中..."); int errorCode = await ET.LoginHelper.Login(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, account, password, isMD5); if (errorCode == ET.ErrorCode.ERR_Success) { GameGlobal.isVisitor = false; ViewManager.Hide(); ViewManager.Hide(); AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent(); GameGlobal.userId = accountInfoComponent.AccountId; GameGlobal.userAge = accountInfoComponent.Age; if (GameGlobal.isVisitor) { //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId); } else { var passwordMD5 = password; //密码禁止明文传输 if (!isMD5) { passwordMD5 = MD5Helper.stringMD5(password); } PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account); PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, passwordMD5); } GameController.CheckSpecialAccount(account); LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor); PlayerPrefs.Save(); await OnLoginSuccess(); } else { OnLoginFail(errorCode); } } private static async ETTask OnLoginSuccess() { await GetServerInfos(); ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent(); EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId); await ReqNoticeInfo(); ViewManager.Hide(); } private static async ETTask ReqNoticeInfo() { bool result = await LoginHelper.ReqGetLatestNotice(); if (result) { NoticeInfo noticeInfo = NoticeDataManager.Instance.LastNoticeInfo; Debug.Log("noticeTime:" + noticeInfo.time + " currentTime:" + (TimeInfo.Instance.ServerNow() / 1000)); int noticeTime = TimeUtil.GetDayTimeBySec(noticeInfo.time * 1000, GlobalCfgArray.globalCfg.refreshTime); int currentTime = TimeUtil.GetDayTimeBySec(TimeInfo.Instance.ServerNow(), GlobalCfgArray.globalCfg.refreshTime); Debug.Log("noticeTime:" + noticeTime + " currentTime:" + currentTime); if ((currentTime - noticeTime) / TimeUtil.SECOND_PER_DAY < 3) { ViewManager.Show(); } } return; } private static void OnLoginFail(int errorCode) { ViewManager.Hide(); if (ErrorCodeController.Handler(errorCode)) { ViewManager.Show(); } } public static void Logout() { GameGlobal.zoneScene.GetComponent().AccountSession?.Dispose(); GameGlobal.zoneScene.GetComponent().Session?.Dispose(); } public static async ETTask Register(string account, string password, string name, string identityNum, string code) { ViewManager.Show("注册中..."); int errorCode = await LoginHelper.Register(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, account, password, name, identityNum, code); if (errorCode == ErrorCode.ERR_Success) { Login(account, password).Coroutine(); } else { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); } } public static async ETTask GetServerInfos() { int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); await ETTask.Create(); return; } var serverInfosComponent = GameGlobal.zoneScene.GetComponent(); if (serverInfosComponent.ServerInfoList.Count <= 0) { Alert.Show("服务器列表为空:\n请检查网络和服务器状态") .SetRightButton(true, "知道啦", (object data) => { Application.Quit(); }); await ETTask.Create(); return; } if (serverInfosComponent.CurrentServerId <= 0) { var serverInfo = serverInfosComponent.ServerInfoList[0]; serverInfosComponent.CurrentServerId = int.Parse(serverInfo.Id.ToString()); } } public static async ETTask GetRoles() { int errorCode = await LoginHelper.GetRoles(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); await ETTask.Create(); } var roleInfosComponent = GameGlobal.zoneScene.GetComponent(); if (roleInfosComponent.RoleInfos != null && roleInfosComponent.RoleInfos.Count > 0) { var roleInfo = roleInfosComponent.RoleInfos[0]; roleInfosComponent.CurrentRoleId = roleInfo.Id; await ReqEnterGame(); } else { GameGlobal.isFirstEntry = true; ViewManager.Hide(); GameController.ShowCreateRole(); } } public static async ETTask ReqCreateRole(string roleName) { ViewManager.Show("创建角色中..."); int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName); if (errorCode != ErrorCode.ERR_Success) { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); return; } ViewManager.Hide(ViewName.CREATE_ROLE_VIEW); var roleInfosComponent = GameGlobal.zoneScene.GetComponent(); var roleInfo = roleInfosComponent.RoleInfos[0]; roleInfosComponent.CurrentRoleId = roleInfo.Id; await ReqEnterGame(); } public static async ETTask ReqEnterGame() { LogServerHelperHttp.SendNodeLog((int)LogNode.StartEnterGame); int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); return; } errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); return; } await GameController.PreEnterGameAsync(); ViewManager.Hide(); LogServerHelperHttp.SendNodeLog((int)LogNode.OnEnterGame); } } }