123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- 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<LoginView>();
- }
- public static async ET.ETTask LoginTest(string account)
- {
- ViewManager.Show<ModalStatusView>("登录中...");
- int errorCode = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene, GameConfig.LoginAddress, account);
- if (errorCode == ET.ErrorCode.ERR_Success)
- {
- GameGlobal.isVisitor = false;
- ViewManager.Hide<LoginInputView>();
- ViewManager.Hide<RegisterView>();
- AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
- 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);
- }
- }
- public static async ET.ETTask Login(string account, string password, bool isMD5 = false)
- {
- ViewManager.Show<ModalStatusView>("登录中...");
- int errorCode = await ET.LoginHelper.Login(GameGlobal.zoneScene, GameConfig.LoginAddress, account, password, isMD5);
- if (errorCode == ET.ErrorCode.ERR_Success)
- {
- GameGlobal.isVisitor = false;
- ViewManager.Hide<LoginInputView>();
- ViewManager.Hide<RegisterView>();
- AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
- 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);
- }
- }
- private static async ETTask OnLoginSuccess()
- {
- await GetServerInfos();
- ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
- EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
- EventAgent.DispatchEvent(ConstMessage.LOGIN_SUCCESS);
- if (AntiAddictionController.CheckAntiAddictionWhenLogin())
- {
- ViewManager.Hide<ModalStatusView>();
- return;
- }
- await ReqNoticeInfo();
- ViewManager.Hide<ModalStatusView>();
- }
- 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<SystemNoticeView>(new object[] { NoticeDataManager.Instance.LastNoticeInfo.title, NoticeDataManager.Instance.LastNoticeInfo.content });
- }
- }
- else
- {
- ErrorCodeController.Handler(result);
- }
- return;
- }
- private static void OnLoginFail(int errorCode, string account)
- {
- ViewManager.Hide<ModalStatusView>();
- if (ErrorCodeController.Handler(errorCode))
- {
- GameController.QuitToLoginView(true);
- }
- EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account);
- }
- public static async ETTask Register(string account, string password, string name, string identityNum, string code)
- {
- ViewManager.Show<ModalStatusView>("注册中...");
- 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<ModalStatusView>();
- ErrorCodeController.Handler(errorCode);
- }
- }
- public static async ETTask GetServerInfos()
- {
- ViewManager.Show<ModalStatusView>("获取服务器列表...");
- int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene);
- if (errorCode != ErrorCode.ERR_Success)
- {
- ViewManager.Hide<ModalStatusView>();
- ErrorCodeController.Handler(errorCode);
- await ETTask.Create();
- return;
- }
- var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
- 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<ServerInfosComponent>().GetCurrentServerInfo().OpenServerTime;
- ViewManager.Show<ModalStatusView>("获取角色信息...");
- int errorCode = await LoginHelper.GetRoles(GameGlobal.zoneScene);
- if (errorCode != ErrorCode.ERR_Success)
- {
- ErrorCodeController.Handler(errorCode);
- await ETTask.Create();
- }
- var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
- if (roleInfosComponent.RoleInfos != null && roleInfosComponent.RoleInfos.Count > 0)
- {
- var roleInfo = roleInfosComponent.RoleInfos[0];
- roleInfosComponent.CurrentRoleId = roleInfo.Id;
- await ReqEnterGame();
- }
- else
- {
- ViewManager.Hide<ModalStatusView>();
- //GameController.ShowCreateRole();不显示创角界面,在剧情中改名
- await ReqCreateRole();
- }
- }
- public static async ETTask<string> 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<ModalStatusView>("创建角色中...");
- int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName);
- if (errorCode != ErrorCode.ERR_Success)
- {
- ViewManager.Hide<ModalStatusView>();
- ErrorCodeController.Handler(errorCode);
- return;
- }
- ViewManager.Hide<CreateRoleView>();
- var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
- 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<ModalStatusView>("请求进入游戏...");
- int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene);
- if (errorCode != ErrorCode.ERR_Success)
- {
- ViewManager.Hide<ModalStatusView>();
- ErrorCodeController.Handler(errorCode);
- return;
- }
- errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
- if (errorCode != ErrorCode.ERR_Success)
- {
- ErrorCodeController.Handler(errorCode);
- return;
- }
- ViewManager.Hide<ModalStatusView>();
- ViewManager.Hide<LoginView>();
- ViewManager.Show<LoadingView>(0.01f);
- LoadingView.Instance.SetProgress(99);
- LoadingView.Instance.SetDesc("正在加载数据...");
- LogServerHelper.SendNodeLog((int)LogNode.StartEnterGame);
- await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
- AlertSystem.hide();
- await GameController.PreEnterGameAsync();
- LogServerHelper.SendNodeLog((int)LogNode.OnEnterGame);
- }
- public static async ETTask ReqReConnectGate()
- {
- LogUtil.LogDev("ReqReConnectGate");
- ViewManager.Show<ModalStatusView>("重新连接中...");
- 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;
- }
- await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
- EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE, NumericType.All);
- GameController.OnReconnected();
- AlertSystem.hide();
- ViewManager.Hide<ModalStatusView>();
- }
- }
- }
|