LoginController.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using ET;
  2. using UnityEngine;
  3. namespace GFGGame
  4. {
  5. public class LoginController
  6. {
  7. public static async ET.ETTask CheckVersion()
  8. {
  9. ViewManager.Show<ModalStatusView>("连接中...");
  10. int errorCode = 0;
  11. errorCode = await ET.LoginHelper.CheckVersion(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, GameConst.SERVER_VERSION);
  12. ViewManager.Hide<ModalStatusView>();
  13. if (errorCode != ET.ErrorCode.ERR_Success)
  14. {
  15. ErrorCodeController.Handler(errorCode);
  16. await ETTask.Create();
  17. }
  18. }
  19. public static async ET.ETTask Login(string account, string password, bool isMD5 = false)
  20. {
  21. ViewManager.Show<ModalStatusView>("登录中...");
  22. int errorCode = await ET.LoginHelper.Login(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, account, password, isMD5);
  23. ViewManager.Hide<ModalStatusView>();
  24. if (errorCode == ET.ErrorCode.ERR_Success)
  25. {
  26. GameGlobal.isVisitor = false;
  27. ViewManager.Hide<LoginInputView>();
  28. ViewManager.Hide<RegisterView>();
  29. AccountInfoComponent accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  30. GameGlobal.userId = accountInfoComponent.AccountId;
  31. GameGlobal.userAge = accountInfoComponent.Age;
  32. if (GameGlobal.isVisitor)
  33. {
  34. //PlayerPrefs.SetFloat(GameConst.VISITOR_ID_KEY, GameGlobal.userId);
  35. }
  36. else
  37. {
  38. var passwordMD5 = password;
  39. //密码禁止明文传输
  40. if (!isMD5)
  41. {
  42. passwordMD5 = MD5Helper.stringMD5(password);
  43. }
  44. PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
  45. PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, passwordMD5);
  46. }
  47. GameController.CheckSpecialAccount(account);
  48. LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
  49. PlayerPrefs.Save();
  50. GameProxy.ReqRoleInfo(GameGlobal.userId);
  51. }
  52. else
  53. {
  54. if(ErrorCodeController.Handler(errorCode))
  55. {
  56. ViewManager.Show<LoginInputView>();
  57. }
  58. }
  59. }
  60. public static async ETTask Register(string account, string password, string name, string identityNum, string code)
  61. {
  62. ViewManager.Show<ModalStatusView>("注册中...");
  63. int errorCode = await LoginHelper.Register(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, account, password, name, identityNum, code);
  64. ViewManager.Hide<ModalStatusView>();
  65. if (errorCode == ErrorCode.ERR_Success)
  66. {
  67. Login(account, password).Coroutine();
  68. }
  69. else
  70. {
  71. ErrorCodeController.Handler(errorCode);
  72. }
  73. }
  74. }
  75. }