LoginController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. ViewManager.Show<LoginView>();
  13. }
  14. public static async ET.ETTask LoginTest(string account, bool cancelDelete = false)
  15. {
  16. ViewManager.Show<ModalStatusView>("登录中...");
  17. (int errorCode, long deleteTime) = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene,
  18. GameConfig.LoginAddress, account, cancelDelete);
  19. if (errorCode == ET.ErrorCode.ERR_Success)
  20. {
  21. GameGlobal.isVisitor = false;
  22. ViewManager.Hide<LoginInputView>();
  23. ViewManager.Hide<RegisterView>();
  24. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  25. GameGlobal.userId = accountInfoComponent.AccountId;
  26. GameGlobal.userAge = accountInfoComponent.Age;
  27. if (GameGlobal.isVisitor)
  28. {
  29. //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  30. }
  31. else
  32. {
  33. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
  34. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, "");
  35. }
  36. GameController.CheckSpecialAccount("sygfg");
  37. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  38. PlayerPrefs.Save();
  39. await OnLoginSuccess();
  40. }
  41. else
  42. {
  43. OnLoginFail(errorCode, account, deleteTime, null, false);
  44. }
  45. }
  46. public static async ET.ETTask Login(string account, string password, bool isMD5 = false,
  47. bool cancelDelete = false)
  48. {
  49. ViewManager.Show<ModalStatusView>("登录中...");
  50. (int errorCode, long deleteTime) = await ET.LoginHelper.Login(GameGlobal.zoneScene, GameConfig.LoginAddress,
  51. account, password, isMD5, cancelDelete);
  52. if (errorCode == ET.ErrorCode.ERR_Success)
  53. {
  54. GameGlobal.isVisitor = false;
  55. ViewManager.Hide<LoginInputView>();
  56. ViewManager.Hide<RegisterView>();
  57. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  58. GameGlobal.userId = accountInfoComponent.AccountId;
  59. GameGlobal.userAge = accountInfoComponent.Age;
  60. if (GameGlobal.isVisitor)
  61. {
  62. //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  63. }
  64. else
  65. {
  66. var passwordMD5 = password;
  67. //密码禁止明文传输
  68. if (!isMD5)
  69. {
  70. passwordMD5 = MD5Helper.stringMD5(password);
  71. }
  72. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
  73. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, passwordMD5);
  74. }
  75. GameController.CheckSpecialAccount(account);
  76. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  77. PlayerPrefs.Save();
  78. await OnLoginSuccess();
  79. }
  80. else
  81. {
  82. OnLoginFail(errorCode, account, deleteTime, password, isMD5);
  83. }
  84. }
  85. private static async ETTask OnLoginSuccess()
  86. {
  87. await GetServerInfos();
  88. ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  89. EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
  90. EventAgent.DispatchEvent(ConstMessage.LOGIN_SUCCESS);
  91. if (AntiAddictionController.CheckAntiAddictionWhenLogin())
  92. {
  93. ViewManager.Hide<ModalStatusView>();
  94. return;
  95. }
  96. await ReqNoticeInfo();
  97. ViewManager.Hide<ModalStatusView>();
  98. }
  99. private static void OnLoginFail(int errorCode, string account, long deleteTime, string password, bool isMD5)
  100. {
  101. ViewManager.Hide<ModalStatusView>();
  102. if (errorCode == ErrorCode.ERR_LoginIsLimit && deleteTime > 0)
  103. {
  104. //删除账号提示
  105. AlertSystem.Show("账号注销处理中,若确定登录将取消账号注销,是否确定登录游戏?")
  106. .SetLeftButton(true, "取消", (o) =>
  107. {
  108. GameController.QuitToLoginView(true);
  109. EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account);
  110. })
  111. .SetRightButton(true, "确定", (o) =>
  112. {
  113. if (string.IsNullOrEmpty(password))
  114. {
  115. LoginTest(account, true).Coroutine();
  116. }
  117. else
  118. {
  119. Login(account, password, isMD5, true).Coroutine();
  120. }
  121. });
  122. return;
  123. }
  124. if (ErrorCodeController.Handler(errorCode))
  125. {
  126. GameController.QuitToLoginView(true);
  127. }
  128. EventAgent.DispatchEvent(ConstMessage.LOGIN_FAIL, account);
  129. }
  130. private static async ETTask ReqNoticeInfo()
  131. {
  132. int result = await LoginHelper.ReqGetLatestNotice();
  133. if (result == ErrorCode.ERR_Success)
  134. {
  135. // NoticeInfo noticeInfo = NoticeDataManager.Instance.LastNoticeInfo;
  136. // // Debug.Log("noticeTime:" + noticeInfo.time + " currentTime:" + (TimeInfo.Instance.ServerNow() / 1000));
  137. //
  138. // long noticeTime =
  139. // TimeUtil.GetDayTimeBySec(noticeInfo.time, CommonDataManager.Tables.TblGlobalCfg.RefreshTime);
  140. // long currentTime =
  141. // TimeUtil.GetDayTimeBySec(TimeInfo.Instance.ServerNow(),
  142. // CommonDataManager.Tables.TblGlobalCfg.RefreshTime);
  143. // // Debug.Log("noticeTime:" + noticeTime + " currentTime:" + currentTime);
  144. // if ((currentTime - noticeTime) / 1000 / TimeUtil.SECOND_PER_DAY < 3)
  145. // {
  146. // ViewManager.Show<SystemNoticeView>(new object[]
  147. // {
  148. // NoticeDataManager.Instance.LastNoticeInfo.title,
  149. // NoticeDataManager.Instance.LastNoticeInfo.content
  150. // });
  151. // }
  152. }
  153. else
  154. {
  155. ErrorCodeController.Handler(result);
  156. }
  157. return;
  158. }
  159. public static async ETTask Register(string account, string password, string name, string identityNum,
  160. string code)
  161. {
  162. ViewManager.Show<ModalStatusView>("注册中...");
  163. int errorCode = await LoginHelper.Register(GameGlobal.zoneScene, GameConfig.LoginAddress, account, password,
  164. name, identityNum, code);
  165. if (errorCode == ErrorCode.ERR_Success)
  166. {
  167. Login(account, password).Coroutine();
  168. }
  169. else
  170. {
  171. ViewManager.Hide<ModalStatusView>();
  172. ErrorCodeController.Handler(errorCode);
  173. }
  174. }
  175. public static async ETTask GetServerInfos()
  176. {
  177. ViewManager.Show<ModalStatusView>("获取服务器列表...");
  178. int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene);
  179. if (errorCode != ErrorCode.ERR_Success)
  180. {
  181. ViewManager.Hide<ModalStatusView>();
  182. ErrorCodeController.Handler(errorCode);
  183. await ETTask.Create();
  184. return;
  185. }
  186. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  187. if (serverInfosComponent.ServerInfoList.Count <= 0)
  188. {
  189. AlertSystem.Show("服务器列表为空:\n请检查网络和服务器状态")
  190. .SetRightButton(true, "知道啦", (object data) => { Application.Quit(); });
  191. await ETTask.Create();
  192. return;
  193. }
  194. if (serverInfosComponent.CurrentServerId <= 0)
  195. {
  196. var serverInfo = serverInfosComponent.ServerInfoList[0];
  197. serverInfosComponent.CurrentServerId = int.Parse(serverInfo.Id.ToString());
  198. }
  199. }
  200. public static async ETTask GetRoles()
  201. {
  202. GameGlobal.OpenServerTime = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>().GetCurrentServerInfo()
  203. .OpenServerTime;
  204. ViewManager.Show<ModalStatusView>("获取角色信息...");
  205. int errorCode = await LoginHelper.GetRoles(GameGlobal.zoneScene);
  206. if (errorCode != ErrorCode.ERR_Success)
  207. {
  208. ErrorCodeController.Handler(errorCode);
  209. await ETTask.Create();
  210. }
  211. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  212. if (roleInfosComponent.RoleInfos != null && roleInfosComponent.RoleInfos.Count > 0)
  213. {
  214. var roleInfo = roleInfosComponent.RoleInfos[0];
  215. roleInfosComponent.CurrentRoleId = roleInfo.Id;
  216. await ReqEnterGame();
  217. }
  218. else
  219. {
  220. ViewManager.Hide<ModalStatusView>();
  221. //GameController.ShowCreateRole();不显示创角界面,在剧情中改名
  222. await ReqCreateRole();
  223. }
  224. }
  225. public static async ETTask<string> ReqRandomRoleName()
  226. {
  227. (int result, string name) = await LoginHelper.ReqRandomRoleName();
  228. if (result == ErrorCode.ERR_Success)
  229. {
  230. return name;
  231. }
  232. ErrorCodeController.Handler(result);
  233. return "";
  234. }
  235. public static async ETTask ReqCreateRole(string roleName = null)
  236. {
  237. if (string.IsNullOrEmpty(roleName))
  238. {
  239. roleName = await ReqRandomRoleName();
  240. }
  241. ViewManager.Show<ModalStatusView>("创建角色中...");
  242. int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName);
  243. if (errorCode != ErrorCode.ERR_Success)
  244. {
  245. ViewManager.Hide<ModalStatusView>();
  246. ErrorCodeController.Handler(errorCode);
  247. return;
  248. }
  249. ViewManager.Hide<CreateRoleView>();
  250. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  251. var roleInfo = roleInfosComponent.RoleInfos[0];
  252. roleInfosComponent.CurrentRoleId = roleInfo.Id;
  253. QDManager.OnCreateRole();
  254. await ReqEnterGame();
  255. }
  256. public static async ETTask ReqEnterGame()
  257. {
  258. //BuglyAgent.SetUserId(RoleDataManager.roleName + VersionController.Instance.PackageVersion);
  259. ViewManager.Show<ModalStatusView>("请求进入游戏...");
  260. int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene);
  261. if (errorCode != ErrorCode.ERR_Success)
  262. {
  263. ViewManager.Hide<ModalStatusView>();
  264. ErrorCodeController.Handler(errorCode);
  265. return;
  266. }
  267. errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
  268. if (errorCode != ErrorCode.ERR_Success)
  269. {
  270. ErrorCodeController.Handler(errorCode);
  271. return;
  272. }
  273. ViewManager.Hide<ModalStatusView>();
  274. ViewManager.Hide<LoginView>();
  275. ViewManager.Show<LoadingView>(0.01f);
  276. LoadingView.Instance.SetProgress(99);
  277. LoadingView.Instance.SetDesc("正在加载数据...");
  278. LogServerHelper.SendNodeLog((int)LogNode.StartEnterGame);
  279. await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
  280. AlertSystem.Hide();
  281. await GameController.PreEnterGameAsync();
  282. LogServerHelper.SendNodeLog((int)LogNode.OnEnterGame);
  283. }
  284. public static async ETTask ReqReConnectGate()
  285. {
  286. LogUtil.LogDev("ReqReConnectGate");
  287. ViewManager.Show<ModalStatusView>("重新连接中...");
  288. int errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
  289. if (errorCode != ErrorCode.ERR_Success)
  290. {
  291. string errMessage = "与服务器连接失败。";
  292. Log.Error($"Reconnect fail, errorCode {errorCode}!");
  293. if (errorCode == ErrorCode.ERR_TokenError)
  294. {
  295. errMessage = "登录已过期,请重新登录";
  296. AlertSystem.Show(errMessage)
  297. .SetRightButton(true, "好的", (object data) => { GameController.QuitToLoginView(false); });
  298. return;
  299. }
  300. else if (errorCode == ErrorCode.ERR_NetWorkError)
  301. {
  302. errMessage = "网络异常,与服务器连接失败。";
  303. }
  304. AlertSystem.Show(errMessage)
  305. .SetRightButton(true, "重新连接", (object data) => { ReqReConnectGate().Coroutine(); });
  306. return;
  307. }
  308. await GameGlobal.zoneScene.GetComponent<ObjectWait>().Wait<ET.WaitType.Wait_SceneChangeFinish>();
  309. EventAgent.DispatchEvent(ConstMessage.NUMERIC_CHANGE, NumericType.All);
  310. GameController.OnReconnected();
  311. AlertSystem.Hide();
  312. ViewManager.Hide<ModalStatusView>();
  313. GameController.CheckUpdateVersion();
  314. }
  315. //玩家账号信息登记
  316. public static async ETTask RegisterRoleInfo(string account, string password, string name, string identityNum,
  317. string code, string phoneNumber)
  318. {
  319. int errorCode =
  320. await LoginHelper.RegisterRoleInfo(GameGlobal.zoneScene, account, password, name, identityNum, code,
  321. phoneNumber);
  322. if (errorCode == ErrorCode.ERR_Success)
  323. {
  324. ViewManager.Hide<RoleInfoRegisterView>();
  325. }
  326. }
  327. }
  328. }