LoginController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using ET;
  2. using UnityEngine;
  3. namespace GFGGame
  4. {
  5. public class LoginController
  6. {
  7. public static string ageTipsTitle = "适龄提示说明";
  8. public static string ageTips =
  9. "1)本游戏是一款角色扮演类游戏,适用于年满16周岁及以上的用户,建议未成年人在家长监护下使用游戏产品。\n2)本游戏基于架空的故事背景和幻想世界观,剧情简单且积极向上,没有基于真实历史和现实事件的改编内容游戏玩法以收集不同服装进行搭配展开,有较为简单的竞技和对抗玩法,游戏中有基于文字的陌生人社交系统。\n3)本游戏中有用户实名认证系统,认证为未成年人的用户将接受以下管理:游戏中部分玩法和道具需要付费。未满8周岁的用户不能付费; 8周岁以上未满16周岁的未成年人用户,单次充值金额不得超过50元人民币,每月充值金额累计不得超过200元人民币; 16周岁以上的未成年人用户,单次充值金额不得超过100元人民币,每月充值金额累计不得超过400元人民币。\n4)本游戏以服装收集及搭配为主要玩法,有助于玩家开阔眼界、进一步提升审美能力。游戏中很多服装融入了中华传统元素,可以有助于中华传统文化的传播,体验中国的古典美。";
  10. public static void ShowLogin()
  11. {
  12. Debug.Log($"ShowLogin");
  13. ViewManager.Show<LoginView>();
  14. }
  15. public static async ET.ETTask LoginTest(string account, bool cancelDelete = false)
  16. {
  17. ViewManager.Show<ModalStatusView>("登录中...");
  18. (int errorCode, long deleteTime) = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene,
  19. GameConfig.LoginAddress, account, cancelDelete);
  20. if (errorCode == ET.ErrorCode.ERR_Success)
  21. {
  22. GameGlobal.isVisitor = false;
  23. ViewManager.Hide<LoginInputView>();
  24. ViewManager.Hide<RegisterView>();
  25. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  26. GameGlobal.userId = accountInfoComponent.AccountId;
  27. GameGlobal.userAge = accountInfoComponent.Age;
  28. if (GameGlobal.isVisitor)
  29. {
  30. //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  31. }
  32. else
  33. {
  34. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
  35. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, "");
  36. }
  37. GameController.CheckSpecialAccount("sygfg");
  38. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  39. PlayerPrefs.Save();
  40. await OnLoginSuccess();
  41. }
  42. else
  43. {
  44. OnLoginFail(errorCode, account, deleteTime, null, false);
  45. }
  46. }
  47. public static async ET.ETTask Login(string account, string password, bool isMD5 = false,
  48. bool cancelDelete = false)
  49. {
  50. ViewManager.Show<ModalStatusView>("登录中...");
  51. (int errorCode, long deleteTime) = await ET.LoginHelper.Login(GameGlobal.zoneScene, GameConfig.LoginAddress,
  52. account, password, isMD5, cancelDelete);
  53. if (errorCode == ET.ErrorCode.ERR_Success)
  54. {
  55. GameGlobal.isVisitor = false;
  56. ViewManager.Hide<LoginInputView>();
  57. ViewManager.Hide<RegisterView>();
  58. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  59. GameGlobal.userId = accountInfoComponent.AccountId;
  60. GameGlobal.userAge = accountInfoComponent.Age;
  61. if (GameGlobal.isVisitor)
  62. {
  63. //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  64. }
  65. else
  66. {
  67. var passwordMD5 = password;
  68. //密码禁止明文传输
  69. if (!isMD5)
  70. {
  71. passwordMD5 = MD5Helper.stringMD5(password);
  72. }
  73. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
  74. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, passwordMD5);
  75. }
  76. GameController.CheckSpecialAccount(account);
  77. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  78. PlayerPrefs.Save();
  79. await OnLoginSuccess();
  80. }
  81. else
  82. {
  83. OnLoginFail(errorCode, account, deleteTime, password, isMD5);
  84. }
  85. }
  86. private static async ETTask OnLoginSuccess()
  87. {
  88. await GetServerInfos();
  89. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  90. EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
  91. EventAgent.DispatchEvent(ConstMessage.LOGIN_SUCCESS);
  92. if (AntiAddictionController.CheckAntiAddictionWhenLogin())
  93. {
  94. ViewManager.Hide<ModalStatusView>();
  95. return;
  96. }
  97. await ReqNoticeInfo();
  98. ViewManager.Hide<ModalStatusView>();
  99. }
  100. private static void OnLoginFail(int errorCode, string account, long deleteTime, string password, bool isMD5)
  101. {
  102. ViewManager.Hide<ModalStatusView>();
  103. if (errorCode == ErrorCode.ERR_LoginIsLimit && deleteTime > 0)
  104. {
  105. //删除账号提示
  106. AlertSystem.Show("账号注销处理中,若确定登录将取消账号注销,是否确定登录游戏?")
  107. .SetLeftButton(true, "取消", (o) =>
  108. {
  109. GameController.QuitToLoginView(true);
  110. EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account);
  111. })
  112. .SetRightButton(true, "确定", (o) =>
  113. {
  114. if (string.IsNullOrEmpty(password))
  115. {
  116. LoginTest(account, true).Coroutine();
  117. }
  118. else
  119. {
  120. Login(account, password, isMD5, true).Coroutine();
  121. }
  122. });
  123. return;
  124. }
  125. if (ErrorCodeController.Handler(errorCode))
  126. {
  127. GameController.QuitToLoginView(true);
  128. }
  129. EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account);
  130. }
  131. private static async ETTask ReqNoticeInfo()
  132. {
  133. int result = await LoginHelper.ReqGetLatestNotice();
  134. if (result == ErrorCode.ERR_Success)
  135. {
  136. // NoticeInfo noticeInfo = NoticeDataManager.Instance.LastNoticeInfo;
  137. // // Debug.Log("noticeTime:" + noticeInfo.time + " currentTime:" + (TimeInfo.Instance.ServerNow() / 1000));
  138. //
  139. // long noticeTime =
  140. // TimeUtil.GetDayTimeBySec(noticeInfo.time, CommonDataManager.Tables.TblGlobalCfg.RefreshTime);
  141. // long currentTime =
  142. // TimeUtil.GetDayTimeBySec(TimeInfo.Instance.ServerNow(),
  143. // CommonDataManager.Tables.TblGlobalCfg.RefreshTime);
  144. // // Debug.Log("noticeTime:" + noticeTime + " currentTime:" + currentTime);
  145. // if ((currentTime - noticeTime) / 1000 / TimeUtil.SECOND_PER_DAY < 3)
  146. // {
  147. // ViewManager.Show<SystemNoticeView>(new object[]
  148. // {
  149. // NoticeDataManager.Instance.LastNoticeInfo.title,
  150. // NoticeDataManager.Instance.LastNoticeInfo.content
  151. // });
  152. // }
  153. }
  154. else
  155. {
  156. ErrorCodeController.Handler(result);
  157. }
  158. return;
  159. }
  160. public static async ETTask Register(string account, string password, string name, string identityNum,
  161. string code)
  162. {
  163. ViewManager.Show<ModalStatusView>("注册中...");
  164. int errorCode = await LoginHelper.Register(GameGlobal.zoneScene, GameConfig.LoginAddress, account, password,
  165. name, identityNum, code);
  166. if (errorCode == ErrorCode.ERR_Success)
  167. {
  168. Login(account, password).Coroutine();
  169. }
  170. else
  171. {
  172. ViewManager.Hide<ModalStatusView>();
  173. ErrorCodeController.Handler(errorCode);
  174. }
  175. }
  176. public static async ETTask GetServerInfos()
  177. {
  178. ViewManager.Show<ModalStatusView>("获取服务器列表...");
  179. int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene);
  180. if (errorCode != ErrorCode.ERR_Success)
  181. {
  182. ViewManager.Hide<ModalStatusView>();
  183. ErrorCodeController.Handler(errorCode);
  184. await ETTask.Create();
  185. return;
  186. }
  187. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  188. if (serverInfosComponent.ServerInfoList.Count <= 0)
  189. {
  190. AlertSystem.Show("服务器列表为空:\n请检查网络和服务器状态")
  191. .SetRightButton(true, "知道啦", (object data) => { Application.Quit(); });
  192. await ETTask.Create();
  193. return;
  194. }
  195. if (serverInfosComponent.CurrentServerId <= 0)
  196. {
  197. var serverInfo = serverInfosComponent.ServerInfoList[0];
  198. serverInfosComponent.CurrentServerId = int.Parse(serverInfo.Id.ToString());
  199. }
  200. }
  201. public static async ETTask GetRoles()
  202. {
  203. GameGlobal.OpenServerTime = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>().GetCurrentServerInfo()
  204. .OpenServerTime;
  205. ViewManager.Show<ModalStatusView>("获取角色信息...");
  206. int errorCode = await LoginHelper.GetRoles(GameGlobal.zoneScene);
  207. if (errorCode != ErrorCode.ERR_Success)
  208. {
  209. ErrorCodeController.Handler(errorCode);
  210. await ETTask.Create();
  211. }
  212. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  213. if (roleInfosComponent.RoleInfos != null && roleInfosComponent.RoleInfos.Count > 0)
  214. {
  215. var roleInfo = roleInfosComponent.RoleInfos[0];
  216. roleInfosComponent.CurrentRoleId = roleInfo.Id;
  217. await ReqEnterGame();
  218. }
  219. else
  220. {
  221. ViewManager.Hide<ModalStatusView>();
  222. //GameController.ShowCreateRole();不显示创角界面,在剧情中改名
  223. await ReqCreateRole();
  224. }
  225. }
  226. public static async ETTask<string> ReqRandomRoleName()
  227. {
  228. (int result, string name) = await LoginHelper.ReqRandomRoleName();
  229. if (result == ErrorCode.ERR_Success)
  230. {
  231. return name;
  232. }
  233. ErrorCodeController.Handler(result);
  234. return "";
  235. }
  236. public static async ETTask ReqCreateRole(string roleName = null)
  237. {
  238. if (string.IsNullOrEmpty(roleName))
  239. {
  240. roleName = await ReqRandomRoleName();
  241. }
  242. ViewManager.Show<ModalStatusView>("创建角色中...");
  243. int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName);
  244. if (errorCode != ErrorCode.ERR_Success)
  245. {
  246. ViewManager.Hide<ModalStatusView>();
  247. ErrorCodeController.Handler(errorCode);
  248. return;
  249. }
  250. ViewManager.Hide<CreateRoleView>();
  251. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  252. var roleInfo = roleInfosComponent.RoleInfos[0];
  253. roleInfosComponent.CurrentRoleId = roleInfo.Id;
  254. QDManager.OnCreateRole();
  255. await ReqEnterGame();
  256. }
  257. public static async ETTask ReqEnterGame()
  258. {
  259. //BuglyAgent.SetUserId(RoleDataManager.roleName + VersionController.Instance.PackageVersion);
  260. ViewManager.Show<ModalStatusView>("请求进入游戏...");
  261. int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene);
  262. if (errorCode != ErrorCode.ERR_Success)
  263. {
  264. ViewManager.Hide<ModalStatusView>();
  265. ErrorCodeController.Handler(errorCode);
  266. return;
  267. }
  268. CommonDataManager.InitAllAsync(async () =>
  269. {
  270. errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
  271. if (errorCode != ErrorCode.ERR_Success)
  272. {
  273. ErrorCodeController.Handler(errorCode);
  274. return;
  275. }
  276. ViewManager.Hide<ModalStatusView>();
  277. ViewManager.Hide<LoginView>();
  278. ViewManager.Show<LoadingView>(0.01f);
  279. LoadingView.Instance.SetProgress(99);
  280. LoadingView.Instance.SetDesc("正在加载数据...");
  281. LogServerHelper.SendNodeLog((int)LogNode.StartEnterGame);
  282. await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
  283. AlertSystem.Hide();
  284. await GameController.PreEnterGameAsync();
  285. LogServerHelper.SendNodeLog((int)LogNode.OnEnterGame);
  286. });
  287. }
  288. public static async ETTask ReqReConnectGate()
  289. {
  290. LogUtil.LogDev("ReqReConnectGate");
  291. ViewManager.Show<ModalStatusView>("重新连接中...");
  292. int errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
  293. if (errorCode != ErrorCode.ERR_Success)
  294. {
  295. string errMessage = "与服务器连接失败。";
  296. Log.Error($"Reconnect fail, errorCode {errorCode}!");
  297. if (errorCode == ErrorCode.ERR_TokenError)
  298. {
  299. errMessage = "登录已过期,请重新登录";
  300. AlertSystem.Show(errMessage)
  301. .SetRightButton(true, "好的", (object data) => { GameController.QuitToLoginView(false); });
  302. return;
  303. }
  304. else if (errorCode == ErrorCode.ERR_NetWorkError)
  305. {
  306. errMessage = "网络异常,与服务器连接失败。";
  307. }
  308. AlertSystem.Show(errMessage)
  309. .SetRightButton(true, "重新连接", (object data) => { ReqReConnectGate().Coroutine(); });
  310. return;
  311. }
  312. await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
  313. EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE, NumericType.All);
  314. GameController.OnReconnected();
  315. AlertSystem.Hide();
  316. ViewManager.Hide<ModalStatusView>();
  317. GameController.CheckUpdateVersion();
  318. }
  319. //玩家账号信息登记
  320. public static async ETTask RegisterRoleInfo(string account, string password, string name, string identityNum,
  321. string code, string phoneNumber)
  322. {
  323. int errorCode =
  324. await LoginHelper.RegisterRoleInfo(GameGlobal.zoneScene, account, password, name, identityNum, code,
  325. phoneNumber);
  326. if (errorCode == ErrorCode.ERR_Success)
  327. {
  328. ViewManager.Hide<RoleInfoRegisterView>();
  329. }
  330. }
  331. }
  332. }