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() { ViewManager.Show(); } public static async ET.ETTask LoginTest(string account, bool cancelDelete = false) { ViewManager.Show("登录中..."); (int errorCode, long deleteTime) = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene, GameConfig.LoginAddress, account, cancelDelete); 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, account, deleteTime, null, false); } } public static async ET.ETTask Login(string account, string password, bool isMD5 = false, bool cancelDelete = false) { ViewManager.Show("登录中..."); (int errorCode, long deleteTime) = await ET.LoginHelper.Login(GameGlobal.zoneScene, GameConfig.LoginAddress, account, password, isMD5, cancelDelete); 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, account, deleteTime, password, isMD5); } } 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 void OnLoginFail(int errorCode, string account, long deleteTime, string password, bool isMD5) { ViewManager.Hide(); if (errorCode == ErrorCode.ERR_LoginIsLimit && deleteTime > 0) { //删除账号提示 AlertSystem.Show("账号注销处理中,若确定登录将取消账号注销,是否确定登录游戏?") .SetLeftButton(true, "取消", (o) => { GameController.QuitToLoginView(true); EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account); }) .SetRightButton(true, "确定", (o) => { if (string.IsNullOrEmpty(password)) { LoginTest(account, true).Coroutine(); } else { Login(account, password, isMD5, true).Coroutine(); } }); return; } if (ErrorCodeController.Handler(errorCode)) { GameController.QuitToLoginView(true); } EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account); } 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, 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; } 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() { GameGlobal.OpenServerTime = GameGlobal.zoneScene.GetComponent().GetCurrentServerInfo() .OpenServerTime; 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 { ViewManager.Hide(); //GameController.ShowCreateRole();不显示创角界面,在剧情中改名 await ReqCreateRole(); } } public static async ETTask ReqRandomRoleName() { (int result, string name) = await LoginHelper.ReqRandomRoleName(); if (result == ErrorCode.ERR_Success) { return name; } ErrorCodeController.Handler(result); return ""; } public static async ETTask ReqCreateRole(string roleName = null) { if (string.IsNullOrEmpty(roleName)) { roleName = await ReqRandomRoleName(); } ViewManager.Show("创建角色中..."); int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName); if (errorCode != ErrorCode.ERR_Success) { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); return; } ViewManager.Hide(); var roleInfosComponent = GameGlobal.zoneScene.GetComponent(); var roleInfo = roleInfosComponent.RoleInfos[0]; roleInfosComponent.CurrentRoleId = roleInfo.Id; QDManager.OnCreateRole(); await ReqEnterGame(); } public static async ETTask ReqEnterGame() { BuglyAgent.SetUserId(RoleDataManager.roleName + VersionController.Instance.PackageVersion); ViewManager.Show("请求进入游戏..."); int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ViewManager.Hide(); ErrorCodeController.Handler(errorCode); return; } errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { ErrorCodeController.Handler(errorCode); return; } ViewManager.Hide(); ViewManager.Hide(); ViewManager.Show(0.01f); LoadingView.Instance.SetProgress(99); LoadingView.Instance.SetDesc("正在加载数据..."); LogServerHelper.SendNodeLog((int)LogNode.StartEnterGame); await GameGlobal.zoneScene.GetComponent().Wait(); AlertSystem.Hide(); await GameController.PreEnterGameAsync(); LogServerHelper.SendNodeLog((int)LogNode.OnEnterGame); } public static async ETTask ReqReConnectGate() { LogUtil.LogDev("ReqReConnectGate"); ViewManager.Show("重新连接中..."); int errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene); if (errorCode != ErrorCode.ERR_Success) { string errMessage = "与服务器连接失败。"; Log.Error($"Reconnect fail, errorCode {errorCode}!"); if (errorCode == ErrorCode.ERR_TokenError) { errMessage = "登录已过期,请重新登录"; AlertSystem.Show(errMessage) .SetRightButton(true, "好的", (object data) => { GameController.QuitToLoginView(false); }); return; } else if (errorCode == ErrorCode.ERR_NetWorkError) { errMessage = "网络异常,与服务器连接失败。"; } AlertSystem.Show(errMessage) .SetRightButton(true, "重新连接", (object data) => { ReqReConnectGate().Coroutine(); }); return; } await GameGlobal.zoneScene.GetComponent().Wait(); EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE, NumericType.All); GameController.OnReconnected(); AlertSystem.Hide(); ViewManager.Hide(); GameController.CheckUpdateVersion(); } //玩家账号信息登记 public static async ETTask RegisterRoleInfo(string account, string password, string name, string identityNum, string code, string phoneNumber) { int errorCode = await LoginHelper.RegisterRoleInfo(GameGlobal.zoneScene, account, password, name, identityNum, code, phoneNumber); if (errorCode == ErrorCode.ERR_Success) { ViewManager.Hide(); } } } }