Browse Source

登录优化

guodong 3 years ago
parent
commit
b22aca9c99

+ 10 - 2
GameClient/Assets/Game/HotUpdate/Controller/GameController.cs

@@ -37,9 +37,9 @@ namespace GFGGame
                     return true;
                 }
             }
-            else if (account != null && account.Length > 0)
+            else if (!string.IsNullOrEmpty(account))
             {
-                if (password != null && password.Length > 0)
+                if (!string.IsNullOrEmpty(password))
                 {
                     if (doLogin)
                     {
@@ -47,6 +47,14 @@ namespace GFGGame
                     }
                     return true;
                 }
+                else if(LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
+                {
+                    if(doLogin)
+                    {
+                        LoginController.LoginTest(account).Coroutine();
+                    }
+                    return true;
+                }
             }
             return false;
         }

+ 62 - 16
GameClient/Assets/Game/HotUpdate/Controller/LoginController.cs

@@ -19,6 +19,42 @@ namespace GFGGame
             }
         }
 
+
+        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.DeleteKey(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>("登录中...");
@@ -50,26 +86,36 @@ namespace GFGGame
                 GameController.CheckSpecialAccount(account);
                 LocalCache.SetBool(GameConst.LAST_LOGIN_IS_VISITOR_KEY, GameGlobal.isVisitor);
                 PlayerPrefs.Save();
-                await GetServerInfos();
-                ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
-
-                if (serverInfosComponent.ServerInfoList.Count > 1)
-                {
-                    ViewManager.Hide<ModalStatusView>();
-                    EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
-                }
-                else
-                {
-                    await GetRoles();
-                }
+                await OnLoginSuccess();
             }
             else
             {
+                OnLoginFail(errorCode);
+            }
+        }
+
+        private static async ETTask OnLoginSuccess()
+        {
+            await GetServerInfos();
+            ServerInfosComponent serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
+
+            if (serverInfosComponent.ServerInfoList.Count > 1)
+            {
                 ViewManager.Hide<ModalStatusView>();
-                if (ErrorCodeController.Handler(errorCode))
-                {
-                    ViewManager.Show<LoginInputView>();
-                }
+                EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE, serverInfosComponent.CurrentServerId);
+            }
+            else
+            {
+                await GetRoles();
+            }
+        }
+
+        private static void OnLoginFail(int errorCode)
+        {
+            ViewManager.Hide<ModalStatusView>();
+            if (ErrorCodeController.Handler(errorCode))
+            {
+                ViewManager.Show<LoginInputView>();
             }
         }
 

+ 34 - 2
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/Login/LoginHelper.cs

@@ -28,6 +28,33 @@ namespace ET
             return ErrorCode.ERR_Success;
         }
 
+        public static async ETTask<int> LoginTest(Scene zoneScene, string address, string account)
+        {
+            A2C_LoginAccount a2CLoginAccount = null;
+            Session accountSession = null;
+            try
+            {
+                accountSession = zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(address));
+                
+                a2CLoginAccount = (A2C_LoginAccount)await accountSession.Call(new C2A_LoginTest() { Account = account });
+            }
+            catch (Exception e)
+            {
+                accountSession?.Dispose();
+                Log.Error(e.ToString());
+                return ErrorCode.ERR_NetWorkError;
+            }
+
+            if (a2CLoginAccount.Error != ErrorCode.ERR_Success)
+            {
+                accountSession?.Dispose();
+                return a2CLoginAccount.Error;
+            }
+            OnLoginSuccess(zoneScene, a2CLoginAccount, accountSession);
+
+            return ErrorCode.ERR_Success;
+        }
+
         public static async ETTask<int> Login(Scene zoneScene, string address, string account, string password, bool isMD5)
         {
             A2C_LoginAccount a2CLoginAccount = null;
@@ -55,6 +82,13 @@ namespace ET
                 accountSession?.Dispose();
                 return a2CLoginAccount.Error;
             }
+            OnLoginSuccess(zoneScene, a2CLoginAccount, accountSession);
+
+            return ErrorCode.ERR_Success;
+        }
+
+        public static void OnLoginSuccess(Scene zoneScene, A2C_LoginAccount a2CLoginAccount, Session accountSession)
+        {
             if (zoneScene.GetComponent<SessionComponent>() == null)
             {
                 zoneScene.AddComponent<SessionComponent>();
@@ -65,8 +99,6 @@ namespace ET
             accountInfoComponent.Token = a2CLoginAccount.Token;
             accountInfoComponent.AccountId = a2CLoginAccount.AccountId;
             accountInfoComponent.Age = a2CLoginAccount.Age;
-
-            return ErrorCode.ERR_Success;
         }
 
         public static async ETTask<int> Register(Scene zoneScene, string address, string account, string password, string name, string identityNum, string code)

+ 19 - 1
GameClient/Assets/Game/HotUpdate/Views/Login/LoginInputView.cs

@@ -43,7 +43,25 @@ namespace GFGGame
 
         private void OnClickBtnSure()
         {
-            LoginController.Login(_ui.m_inputAccount.text, _ui.m_inputPassword.text).Coroutine();
+            var account = _ui.m_inputAccount.text;
+            var password = _ui.m_inputPassword.text;
+            if (string.IsNullOrEmpty(account))
+            {
+                PromptController.Instance.ShowFloatTextPrompt("请输入账号");
+                return;
+            }
+            if (!string.IsNullOrEmpty(password))
+            {
+                LoginController.Login(account, password).Coroutine();
+            }
+            else if(LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
+            {
+                LoginController.LoginTest(account).Coroutine();
+            }
+            else
+            {
+                PromptController.Instance.ShowFloatTextPrompt("请输入密码");
+            }
         }
 
         private void OnClickBtnCancel()

+ 2 - 2
GameClient/Assets/Game/HotUpdate/Views/Login/RegisterView.cs

@@ -80,12 +80,12 @@ namespace GFGGame
             string passwordSure = _ui.m_inputPassword2.text;
             string realName = _ui.m_inputName.text;
             string idNumberStr = _ui.m_inputIDNumber.text;
-            if (account.Length <= 0)
+            if (string.IsNullOrEmpty(account))
             {
                 PromptController.Instance.ShowFloatTextPrompt("请输入账号");
                 return;
             }
-            if (password.Length <= 0)
+            if (string.IsNullOrEmpty(password))
             {
                 PromptController.Instance.ShowFloatTextPrompt("请输入密码");
                 return;