using ET; using UnityEngine; namespace GFGGame { public class LoginController { public static string ageTipsTitle = "适龄提示说明"; public static string ageTips = "1)本游戏是一款角色扮演类游戏,适用于年满16周岁及以上的用户,建议未成年人在家长监护下使用游戏产品。\n2)本游戏基于架空的故事背景和幻想世界观,剧情简单且积极向上,没有基于真实历史和现实事件的改编内容游戏玩法以收集不同服装进行搭配展开,有较为简单的竞技和对抗玩法,游戏中有基于文字的陌生人社交系统。\n3)本游戏中有用户实名认证系统,认证为未成年人的用户将接受以下管理:游戏中部分玩法和道具需要付费。未满8周岁的用户不能付费; 8周岁以上未满16周岁的未成年人用户,单次充值金额不得超过50元人民币,每月充值金额累计不得超过200元人民币; 16周岁以上的未成年人用户,单次充值金额不得超过100元人民币,每月充值金额累计不得超过400元人民币。\n4)本游戏以服装收集及搭配为主要玩法,有助于玩家开阔眼界、进一步提升审美能力。游戏中很多服装融入了中华传统元素,可以有助于中华传统文化的传播,体验中国的古典美。"; public static void ShowLogin() { LauncherView.Instance.Close(); ViewManager.Show(); } public static async ET.ETTask LoginTest(string account) { ViewManager.Show("登录中..."); int errorCode = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene, GameConfig.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, GameConfig.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); EventAgent.DispatchEvent(ConstMessage.LOGIN_SUCCESS); if (AntiAddictionController.CheckAntiAddictionWhenLogin()) { ViewManager.Hide(); return; } await ReqNoticeInfo(); ViewManager.Hide(); } private static async ETTask ReqNoticeInfo() { int result = await LoginHelper.ReqGetLatestNotice(); if (result == ErrorCode.ERR_Success) { NoticeInfo noticeInfo = NoticeDataManager.Instance.LastNoticeInfo; Debug.Log("noticeTime:" + noticeInfo.time + " currentTime:" + (TimeInfo.Instance.ServerNow() / 1000)); long noticeTime = TimeUtil.GetDayTimeBySec(noticeInfo.time * 1000, GlobalCfgArray.globalCfg.refreshTime); long currentTime = TimeUtil.GetDayTimeBySec(TimeInfo.Instance.ServerNow(), GlobalCfgArray.globalCfg.refreshTime); Debug.Log("noticeTime:" + noticeTime + " currentTime:" + currentTime); if ((currentTime - noticeTime) / 1000 / TimeUtil.SECOND_PER_DAY < 3) { ViewManager.Show(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content }); } } else { ErrorCodeController.Handler(result); } return; } private static void OnLoginFail(int errorCode) { ViewManager.Hide(); if (ErrorCodeController.Handler(errorCode)) { GameController.QuitToLoginView(true); } EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL); } public static void Logout() { GameGlobal.zoneScene.GetComponent().AccountSession?.Dispose(); GameGlobal.zoneScene.GetComponent().GateSession?.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, GameConfig.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() { ViewManager.Show("获取服务器列表..."); int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); await ETTask.Create(); return; } var serverInfosComponent = GameGlobal.zoneScene.GetComponent(); if (serverInfosComponent.ServerInfoList.Count <= 0) { AlertSystem.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() { ViewManager.Show("获取角色信息..."); 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() { ViewManager.Show("请求进入游戏..."); int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); return; } ViewManager.Hide(); ViewManager.Hide(); ViewManager.Show(); LoadingView.Instance.SetProgress(99); LoadingView.Instance.SetDesc("正在进入游戏"); LogServerHelperHttp.SendNodeLog((int)LogNode.StartEnterGame); 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); } public static async ETTask ReqReConnectGate() { ViewManager.Show("重新连接中..."); int errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { if(errorCode != ErrorCode.ERR_SessionStateError && errorCode != ErrorCode.ERR_NetWorkError) { Log.Error($"Reconnect fail, errorCode {errorCode}!"); } AlertSystem.Show("重新连接失败,游戏或已更新,请重新进入游戏获得最佳体验。") .SetRightButton(true, "好的", (object data) => { Application.Quit(); }); return; } EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE, NumericType.All); //重连成功请求邮件和公告等离线后会变更的数据 NoticeSProxy.ReqSystemNoticeList().Coroutine(); MailSProxy.ReqMailCount().Coroutine(); FriendSProxy.ReqAllFriendInfos().Coroutine(); PoemGallerySProxy.ReqGalleryTheme().Coroutine(); ViewManager.Hide(); } } }