| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 | 
							- using ET;
 
- using UnityEngine;
 
- namespace GFGGame
 
- {
 
-     public class LoginController
 
-     {
 
-         public static async ET.ETTask CheckVersion()
 
-         {
 
-             ViewManager.Show<ModalStatusView>("连接中...");
 
-             int errorCode = 0;
 
-             errorCode = await ET.LoginHelper.CheckVersion(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, GameConst.SERVER_VERSION);
 
-             ViewManager.Hide<ModalStatusView>();
 
-             if (errorCode != ET.ErrorCode.ERR_Success)
 
-             {
 
-                 ErrorCodeController.Handler(errorCode);
 
-                 await ETTask.Create();
 
-             }
 
-         }
 
-         public static async ET.ETTask LoginTest(string account)
 
-         {
 
-             ViewManager.Show<ModalStatusView>("登录中...");
 
-             int errorCode = await ET.LoginHelper.LoginTest(GameGlobal.zoneScene, ET.ConstValue.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);
 
-             }
 
-         }
 
-         public static async ET.ETTask Login(string account, string password, bool isMD5 = false)
 
-         {
 
-             ViewManager.Show<ModalStatusView>("登录中...");
 
-             int errorCode = await ET.LoginHelper.Login(GameGlobal.zoneScene, ET.ConstValue.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);
 
-             }
 
-         }
 
-         private static async ETTask OnLoginSuccess()
 
-         {
 
-             await GetServerInfos();
 
-             ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
 
-             ViewManager.Hide<ModalStatusView>();
 
-             EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
 
-         }
 
-         private static void OnLoginFail(int errorCode)
 
-         {
 
-             ViewManager.Hide<ModalStatusView>();
 
-             if (ErrorCodeController.Handler(errorCode))
 
-             {
 
-                 ViewManager.Show<LoginInputView>();
 
-             }
 
-         }
 
-         public static void Logout()
 
-         {
 
-             GameGlobal.zoneScene.GetComponent<SessionComponent>().Session?.Dispose();
 
-         }
 
-         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, ET.ConstValue.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()
 
-         {
 
-             int errorCode = await LoginHelper.GetServerInfos(GameGlobal.zoneScene);
 
-             if (errorCode != ErrorCode.ERR_Success)
 
-             {
 
-                 ErrorCodeController.Handler(errorCode);
 
-                 await ETTask.Create();
 
-                 return;
 
-             }
 
-             var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
 
-             if (serverInfosComponent.ServerInfoList.Count <= 0)
 
-             {
 
-                 Alert.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()
 
-         {
 
-             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
 
-             {
 
-                 GameGlobal.isFirstEntry = true;
 
-                 ViewManager.Hide<ModalStatusView>();
 
-                 GameController.ShowCreateRole();
 
-             }
 
-         }
 
-         public static async ETTask ReqCreateRole(string roleName)
 
-         {
 
-             ViewManager.Show<ModalStatusView>("创建角色中...");
 
-             int errorCode = await ET.LoginHelper.CreateRole(GameGlobal.zoneScene, roleName);
 
-             if (errorCode != ErrorCode.ERR_Success)
 
-             {
 
-                 ViewManager.Hide<ModalStatusView>();
 
-                 ErrorCodeController.Handler(errorCode);
 
-                 return;
 
-             }
 
-             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();
 
-             }
 
-             ViewManager.Hide(ViewName.CREATE_ROLE_VIEW);
 
-         }
 
-         public static async ETTask ReqEnterGame()
 
-         {
 
-             int errorCode = await LoginHelper.GetRealmKey(GameGlobal.zoneScene);
 
-             if (errorCode != ErrorCode.ERR_Success)
 
-             {
 
-                 ErrorCodeController.Handler(errorCode);
 
-                 return;
 
-             }
 
-             errorCode = await LoginHelper.EnterGame(GameGlobal.zoneScene);
 
-             if (errorCode != ErrorCode.ERR_Success)
 
-             {
 
-                 ErrorCodeController.Handler(errorCode);
 
-                 return;
 
-             }
 
-             await GameController.PreEnterGameAsync();
 
-             ViewManager.Hide<ModalStatusView>();
 
-         }
 
-     }
 
- }
 
 
  |