Sfoglia il codice sorgente

Merge branch 'master' of http://git.gfggame.com:3000/gfg/client

# Conflicts:
#	GameClient/Assets/ResIn/Config/excelConfig.sqlite.bytes
zhaoyang 3 anni fa
parent
commit
cb4c1e0b50

+ 12 - 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 && PlayerPrefs.HasKey(GameConst.PASSWORD_LAST_LOGIN_KEY))
+                {
+                    if(doLogin)
+                    {
+                        LoginController.LoginTest(account).Coroutine();
+                    }
+                    return true;
+                }
             }
             return false;
         }
@@ -133,6 +141,8 @@ namespace GFGGame
             StudioDataManager.Instance.Clear();
             StorageDataManager.Instance.Clear();
             RechargeDataManager.Instance.Clear();
+            GameGlobal.zoneScene.GetComponent<SessionComponent>()?.Disconnect();
+            GameGlobal.zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
             if (logout)
             {
                 Logout();

+ 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.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>("登录中...");
@@ -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>();
             }
         }
 

+ 7 - 2
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/Account/A2C_DisconnectHandler.cs

@@ -10,6 +10,8 @@ namespace ET
     {
         protected override async ETTask Run(Session session, A2C_Disconnect message)
         {
+            session?.GetComponent<DisConnectedCompnent>()?.CancelAlert();
+            session.Dispose();
             switch(message.Error)
             {
                 case ErrorCode.ERR_loginTimeOut:
@@ -20,8 +22,11 @@ namespace ET
                         });
                     break;
                 case ErrorCode.ERR_loginByOther:
-                case ErrorCode.ERR_OtherAccountLogin:
-                    Alert.Show("账号已在其他地方登录!");
+                    Alert.Show("账号已在其他地方登录!")
+                        .SetLeftButton(true, "返回登录", (obj) =>
+                        {
+                            GameController.QuitToLoginView(true);
+                        });
                     break;
                 default:
                     Alert.Show("您已被迫下线!");

+ 14 - 6
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/DisConnected/DisConnectedCompnentSystem.cs

@@ -6,20 +6,28 @@ using GFGGame;
 
 namespace ET
 {
+
     public class DisConnectedCompnentDestroy : DestroySystem<DisConnectedCompnent>
     {
         public override void Destroy(DisConnectedCompnent self)
         {
-            Alert.Show("服务器连接已断开!")
-                .SetLeftButton(true, "返回登录",(obj) =>
-                {
-                    GameController.QuitToLoginView(false);
-                });
+            if(self.showAlert)
+            {
+                Alert.Show("服务器连接已断开!")
+                    .SetLeftButton(true, "返回登录", (obj) =>
+                    {
+                        GameController.QuitToLoginView(false);
+                    });
+            }
+            self.showAlert = true;
         }
     }
 
     public static class DisConnectedCompnentSystem
     {
-        
+        public static void CancelAlert(this DisConnectedCompnent self)
+        {
+            self.showAlert = false;
+        }
     }
 }

+ 38 - 5
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,18 +82,24 @@ 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>();
             }
             zoneScene.GetComponent<SessionComponent>().Session = accountSession;
-            zoneScene.GetComponent<SessionComponent>().Session.AddComponent<PingComponent>();
+            accountSession.AddComponent<PingComponent>();
+            accountSession.AddComponent<DisConnectedCompnent>();
             AccountInfoComponent accountInfoComponent = zoneScene.GetComponent<AccountInfoComponent>();
             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)
@@ -118,7 +151,7 @@ namespace ET
             {
                 return a2C_GetServerInfos.Error;
             }
-
+            zoneScene.GetComponent<ServerInfosComponent>()?.ServerInfoList?.Clear();
             foreach (var serverInfoProto in a2C_GetServerInfos.ServerInfosList)
             {
                 ServerInfo serverInfo = zoneScene.GetComponent<ServerInfosComponent>().AddChild<ServerInfo>();
@@ -259,7 +292,7 @@ namespace ET
 
             zoneScene.GetComponent<AccountInfoComponent>().RealmKey = a2C_GetRealmKey.RealmKey;
             zoneScene.GetComponent<AccountInfoComponent>().RealmAddress = a2C_GetRealmKey.RealmAddress;
-            zoneScene.GetComponent<SessionComponent>().Session.Dispose();
+            zoneScene.GetComponent<SessionComponent>().Disconnect();
 
             await ETTask.CompletedTask;
             return ErrorCode.ERR_Success;

+ 9 - 0
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/Session/SessionComponentSystem.cs

@@ -7,4 +7,13 @@
 			self.Session.Dispose();
 		}
 	}
+
+	public static class SessionComponentComponent
+    {
+		public static void Disconnect(this SessionComponent self)
+        {
+			self.Session?.GetComponent<DisConnectedCompnent>()?.CancelAlert();
+			self.Session?.Dispose();
+		}
+    }
 }

+ 1 - 1
GameClient/Assets/Game/HotUpdate/ETCodes/Model/App/DisConnected/DisConnectedCompnent.cs

@@ -8,6 +8,6 @@ namespace ET
 {
     public class DisConnectedCompnent : Entity, IAwake, IDestroy
     {
-
+        public bool showAlert = true;
     }
 }

+ 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()

+ 6 - 3
GameClient/Assets/Game/HotUpdate/Views/Login/LoginView.cs

@@ -67,6 +67,11 @@ namespace GFGGame
 
             ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
             UpdateServer(recentlyServerInfo);
+            //尝试自动登录
+            if (serverInfosComponent.ServerInfoList.Count <= 0)
+            {
+                OnClickBtnStart();
+            }
         }
 
         protected override void OnHide()
@@ -122,9 +127,7 @@ namespace GFGGame
 
         private void OnClickBtnLogout()
         {
-            _ui.m_btnLogout.visible = false;
-            GameController.Logout();
-            ViewManager.Show<LoginInputView>();
+            GameController.QuitToLoginView(true);
         }
     }
 }

+ 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;

+ 1 - 1
GameClient/ProjectSettings/ProjectSettings.asset

@@ -172,7 +172,7 @@ PlayerSettings:
     tvOS: 0
   overrideDefaultApplicationIdentifier: 1
   AndroidBundleVersionCode: 1
-  AndroidMinSdkVersion: 19
+  AndroidMinSdkVersion: 21
   AndroidTargetSdkVersion: 0
   AndroidPreferredInstallLocation: 1
   aotOptions: