Kaynağa Gözat

登录优化

guodong 3 yıl önce
ebeveyn
işleme
ca112645e2

+ 59 - 36
GameClient/Assets/Game/HotUpdate/Controller/ErrorCodeController.cs

@@ -11,46 +11,69 @@ namespace GFGGame
     {
         public static bool Handler(int errorCode)
         {
-            if (errorCode == ET.ErrorCode.ERR_Success)
+            switch(errorCode)
             {
-                return false;
-            }
-            else if (errorCode == ET.ErrorCode.ERR_NetWorkError)
-            {
-                Alert.Show("连接服务器失败:\n请检查网络和服务器状态")
-                .SetRightButton(true, "知道啦", (object data) =>
-                {
-                    Application.Quit();
-                });
-            }
-            else if (errorCode == ET.ErrorCode.ERR_ClientVersionError)
-            {
-                Alert.Show("版本已更新,请联系研发获取最新版本")
-                    .SetLeftButton(true, "知道了", (data) =>
+                case ET.ErrorCode.ERR_Success:
                     {
-                        Application.Quit();
-                    });
-            }
-            else if (errorCode == ET.ErrorCode.ERR_AntiAddiction)
-            {
-                string promptStr = "您属于未成年人,已被纳入防沉迷系统。每日22时至次日8时,本游戏将无法为未成年人用户提供游戏服务。";
-                Alert.Show(promptStr)
-                    .SetRightButton(true, "知道啦", (object data) =>
+                        return false;
+                    }
+                case ET.ErrorCode.ERR_NetWorkError:
+                    {
+                        Alert.Show("网络异常")
+                        .SetRightButton(true, "知道了", (object data) =>
+                        {
+                            Application.Quit();
+                        });
+                    }
+                    break;
+                case ET.ErrorCode.ERR_ClientVersionError:
+                    {
+                        Alert.Show("客户端版本错误,请联系研发获取最新版本!")
+                            .SetLeftButton(true, "知道了", (data) =>
+                            {
+                                Application.Quit();
+                            });
+                    }
+                    break;
+                case ET.ErrorCode.Err_LoginCountFull:
+                    {
+                        Alert.Show("游戏已爆满,请稍后再试!")
+                            .SetLeftButton(true, "知道了");
+                    }
+                    break;
+                case ET.ErrorCode.Err_ServerMaintain:
                     {
+                        Alert.Show("服务器维护中,请稍后再试!")
+                            .SetLeftButton(true, "知道了", (data) =>
+                            {
+                                Application.Quit();
+                            });
+                    }
+                    break;
+                case ET.ErrorCode.ERR_AntiAddiction:
+                    {
+                        string promptStr = "您属于未成年人,已被纳入防沉迷系统。每日22时至次日8时,本游戏将无法为未成年人用户提供游戏服务。";
+                        Alert.Show(promptStr)
+                            .SetRightButton(true, "知道啦", (object data) =>
+                            {
+
+                            });
+                    }
+                    break;
+                default:
+                    if (ErrorCodeCfgArray.Instance.GetCfg(errorCode) != null)
+                    {
+                        PromptController.Instance.ShowFloatTextPrompt(ErrorCodeCfgArray.Instance.GetCfg(errorCode).tips);
+                        ET.Log.Error("errorCode" + errorCode.ToString());
+                        return true;
+                    }
+                    else
+                    {
+                        PromptController.Instance.ShowFloatTextPrompt("errorCode " + errorCode.ToString());
+                        ET.Log.Error("errorCode" + errorCode.ToString());
+                        return true;
+                    }
 
-                    });
-            }
-            else if (ErrorCodeCfgArray.Instance.GetCfg(errorCode) != null)
-            {
-                PromptController.Instance.ShowFloatTextPrompt(ErrorCodeCfgArray.Instance.GetCfg(errorCode).tips);
-                ET.Log.Error("errorCode" + errorCode.ToString());
-                return true;
-            }
-            else
-            {
-                PromptController.Instance.ShowFloatTextPrompt("errorCode " + errorCode.ToString());
-                ET.Log.Error("errorCode" + errorCode.ToString());
-                return true;
             }
             return false;
         }

+ 14 - 11
GameClient/Assets/Game/HotUpdate/Controller/GameController.cs

@@ -1,13 +1,14 @@
 using FairyGUI;
 using UnityEngine;
 using ET;
+using LitJson;
 
 namespace GFGGame
 {
     public class GameController
     {
 
-        public static async ETTask Init()
+        public static void Start()
         {
             //界面
             ViewManager.Init();
@@ -21,19 +22,21 @@ namespace GFGGame
             SqliteController.Instance.Init(false, ResPathUtil.SQLITE_FILE_PATH);
             //全局点击效果
             ViewGlobal.CreatClickEffect();
-            GameGlobal.GetGameCfg();
+            //获取游戏配置
+            GetGameCfg();
         }
 
-        public static async ETTask Start()
+        /// <summary>
+        /// 获取游戏配置
+        /// </summary>
+        public static void GetGameCfg()
         {
-            await LoginController.CheckVersion();
-            CheckShowLoginView();
-        }
-
-        private static void CheckShowLoginView()
-        {
-            LauncherView.Instance.Close();
-            ViewManager.Show<LoginView>();
+            var url = LauncherConfig.cfgUrl.Replace("{cfgName}", GameGlobal.cfgName);
+            HttpTool.Instance.Get(url, (string data) => {
+                GameGlobal.InitData(data);
+                //显示登录
+                LoginController.ShowLogin();
+            });
         }
 
         public static bool CheckLoginCache(bool doLogin)

+ 3 - 12
GameClient/Assets/Game/HotUpdate/Controller/LoginController.cs

@@ -5,21 +5,12 @@ namespace GFGGame
 {
     public class LoginController
     {
-
-        public static async ETTask CheckVersion()
+        public static void ShowLogin()
         {
-            ViewManager.Show<ModalStatusView>("连接中...");
-            int errorCode = 0;
-            errorCode = await LoginHelper.CheckVersion(GameGlobal.zoneScene, ET.ConstValue.LoginAddress, GameConst.SERVER_VERSION);
-            ViewManager.Hide<ModalStatusView>();
-            if (errorCode != ErrorCode.ERR_Success)
-            {
-                ErrorCodeController.Handler(errorCode);
-                return;
-            }
+            LauncherView.Instance.Close();
+            ViewManager.Show<LoginView>();
         }
 
-
         public static async ET.ETTask LoginTest(string account)
         {
             ViewManager.Show<ModalStatusView>("登录中...");

+ 13 - 6
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/Account/A2C_DisconnectHandler.cs

@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using GFGGame;
+using GFGGame;
 
 namespace ET
 {
@@ -29,7 +25,18 @@ namespace ET
                         });
                     break;
                 default:
-                    Alert.Show("您已被迫下线!");
+                    if(string.IsNullOrEmpty(message.Message))
+                    {
+                        Alert.Show(message.Message)
+                        .SetLeftButton(true, "返回登录", (obj) =>
+                        {
+                            GameController.QuitToLoginView(true);
+                        });
+                    }
+                    else
+                    {
+                        Alert.Show("您已被迫下线!");
+                    }
                     break;
             }
             await ETTask.CompletedTask;

+ 9 - 27
GameClient/Assets/Game/HotUpdate/ETCodes/Hotfix/App/Login/LoginHelper.cs

@@ -5,31 +5,6 @@ namespace ET
 {
     public static class LoginHelper
     {
-        public static async ETTask<int> CheckVersion(Scene zoneScene, string address, string version)
-        {
-            A2C_CheckVersion a2C_GetVersion = null;
-            Session session = null;
-            try
-            {
-                session = zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(address));
-                a2C_GetVersion = (A2C_CheckVersion)await session.Call(new C2A_CheckVersion() { Version = version });
-            }
-            catch (Exception e)
-            {
-                Log.Error(e.ToString());
-                return ErrorCode.ERR_NetWorkError;
-            }
-            finally
-            {
-                session?.Dispose();
-            }
-            if (a2C_GetVersion.Error != ErrorCode.ERR_Success)
-            {
-                return a2C_GetVersion.Error;
-            }
-            return ErrorCode.ERR_Success;
-        }
-
         public static async ETTask<int> LoginTest(Scene zoneScene, string address, string account)
         {
             A2C_LoginAccount a2CLoginAccount = null;
@@ -38,7 +13,10 @@ namespace ET
             {
                 accountSession = zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(address));
 
-                a2CLoginAccount = (A2C_LoginAccount)await accountSession.Call(new C2A_LoginTest() { Account = account });
+                a2CLoginAccount = (A2C_LoginAccount)await accountSession.Call(new C2A_LoginTest() { 
+                    Account = account, 
+                    Version = GameConst.SERVER_VERSION 
+                });
             }
             catch (Exception e)
             {
@@ -70,7 +48,11 @@ namespace ET
                 {
                     passwordMD5 = MD5Helper.stringMD5(password);
                 }
-                a2CLoginAccount = (A2C_LoginAccount)await accountSession.Call(new C2A_LoginAccount() { Account = account, Password = passwordMD5 });
+                a2CLoginAccount = (A2C_LoginAccount)await accountSession.Call(new C2A_LoginAccount() { 
+                    Account = account, 
+                    Password = passwordMD5, 
+                    Version = GameConst.SERVER_VERSION 
+                });
             }
             catch (Exception e)
             {

+ 2 - 16
GameClient/Assets/Game/HotUpdate/GameGlobal.cs

@@ -46,25 +46,11 @@ namespace GFGGame
             }
         }
 
-        /// <summary>
-        /// 获取游戏配置
-        /// </summary>
-        public static void GetGameCfg()
+        public static void InitData(string json)
         {
-            var url = LauncherConfig.cfgUrl.Replace("{cfgName}", cfgName);
-            HttpTool.Instance.Get(url, (string data) => {
-                ResultHandler(data);
-            });
-        }
-
-
-        private static void ResultHandler(string data)
-        {
-            var result = JsonMapper.ToObject<Result>(data);
+            var result = JsonMapper.ToObject<Result>(json);
             loginApiUrl = result.loginApiUrl;
             ConstValue.LoginAddress = loginApiUrl;
-            //开始游戏
-            GameController.Start().Coroutine();
         }
 
         private struct Result

+ 1 - 1
GameClient/Assets/Game/HotUpdate/HotUpdateEntry.cs

@@ -27,7 +27,7 @@ namespace GFGGame.HotUpdate
             {
                 Log.Error(e);
             }
-            GameController.Init().Coroutine();
+            GameController.Start();
         }
 
     }

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Sqlite/SqliteController.cs

@@ -24,7 +24,7 @@ namespace GFGGame
 #if !UNITY_EDITOR && UNITY_ANDROID
             connectionPath =  "uri=file:" + dbPath;
 #endif
-            Debug.Log($"connectionPath {connectionPath}");
+            //Debug.Log($"connectionPath {connectionPath}");
             if(resPath != null)
             {
                 CheckSqlFile(dbPath, resPath);

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/ViewManager.cs

@@ -150,7 +150,7 @@ namespace GFGGame
                 if (!view.isShowing)
                 {
                     view.Show();
-                    Debug.Log("当前打开:" + name);
+                    //Debug.Log("当前打开:" + name);
                 }
                 else
                 {

+ 1 - 13
GameClient/Assets/Game/Launcher/HotUpdateProxy/HotUpdateCodeLoader.cs

@@ -24,27 +24,20 @@ namespace GFGGame
         IEnumerator StartLoadAssemblyHotfix()
         {
             LogServerHelperHttp.SendNodeLog((int)LogNode.StartLoadGameDll);
-            Debug.LogFormat("ILRuntimeLauncher StartLoadAssemblyHotfix");
+            //ET.Log.Debug("ILRuntimeLauncher StartLoadAssemblyHotfix");
             yield return new WaitForSeconds(0.1f);
             var dllPath = "Assets/Res/Code/Game.HotUpdate.dll.bytes";
             var asset = GFGAsset.Load<TextAsset>(dllPath);
             byte[] assBytes = asset.bytes;
-            //Debug.LogFormat("assBytes != null {0}", assBytes != null);
-            //Debug.LogFormat("assBytes.Length {0}", assBytes.Length);
-            //yield return new WaitForSeconds(0.1f);
             var pdbPath = "Assets/Res/Code/Game.HotUpdate.pdb.bytes";
             asset = GFGAsset.Load<TextAsset>(pdbPath);
             byte[] pdbBytes = asset.bytes;
-            //Debug.LogFormat("pdbBytes != null {0}", pdbBytes != null);
-            //Debug.LogFormat("pdbBytes.Length {0}", pdbBytes.Length);
             if (LauncherConfig.ILRuntimeMode)
             {
-                Debug.LogFormat("Assembly Mode ILRuntime");
                 ILRuntimeLauncher.Instance.LoadAssembly(assBytes, pdbBytes);
             }
             else
             {
-                Debug.LogFormat("Assembly Mode Jit");
                 StartCoroutine(LoadAssemblyJustInTime(assBytes, pdbBytes));
             }
             GFGAsset.Release(dllPath);
@@ -53,15 +46,10 @@ namespace GFGGame
 
         IEnumerator LoadAssemblyJustInTime(byte[] assBytes, byte[] pdbBytes)
         {
-            //yield return new WaitForSeconds(0.1f);
             //mono模式
             var assembly = Assembly.Load(assBytes, pdbBytes);
             this.allTypes = assembly.GetTypes();
-            //Debug.LogFormat("assembly != null {0}", assembly != null);
-            //yield return new WaitForSeconds(0.1f);
             System.Type type = assembly.GetType("GFGGame.HotUpdate.HotUpdateEntry");
-            //Debug.LogFormat("type != null {0}", type != null);
-            //yield return new WaitForSeconds(0.1f);
             type.GetMethod("Start").Invoke(type, null);
             yield break;
         }

+ 3 - 3
GameClient/Assets/Game/Launcher/Net/Http/HttpTool.cs

@@ -33,7 +33,7 @@ namespace GFGGame
         public IEnumerator GetRequest(string url, Action<string> callback, bool showWrong)
         {
             var key = url;
-            ET.Log.Debug("get url : " + key);
+            //ET.Log.Debug("get url : " + key);
             using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
             {
                 webRequest.timeout = LauncherConfig.HTTP_GET_TIME_OUT;
@@ -77,7 +77,7 @@ namespace GFGGame
         private IEnumerator PostRequest(string url, string body, Action<string> callback, string contentType, bool showWrong)
         {
             var key = url + ":" + body;
-            ET.Log.Debug(string.Format($"post {key}", url, body));
+            //ET.Log.Debug(string.Format($"post {key}", url, body));
             using (UnityWebRequest webRequest = new UnityWebRequest(url, "POST"))
             {
                 byte[] bodyRaw = Encoding.UTF8.GetBytes(body);
@@ -122,7 +122,7 @@ namespace GFGGame
             }
             else
             {
-                ET.Log.Debug("from server " + webRequest.downloadHandler.text + "\nby " + tag);
+                //ET.Log.Debug("from server " + webRequest.downloadHandler.text + "\nby " + tag);
                 paramCallback = webRequest.downloadHandler.text;
                 //paramCallback = System.Text.Encoding.UTF8.GetString(webRequest.downloadHandler.data, 3, webRequest.downloadHandler.data.Length - 3);
                 callback?.Invoke(paramCallback);

+ 1 - 0
GameClient/Assets/Game/Launcher/Version/VersionController.cs

@@ -19,6 +19,7 @@ namespace GFGGame
         public IEnumerator InitVersion()
         {
             LauncherView.Instance.SetDesc("正在校验资源版本...");
+            VEngine.Logger.Loggable = false;
             EncryptHelper.resKey = LauncherConfig.resKey;
             Versions.DownloadURL = LauncherConfig.CDN_ROOT;
             var operation = Versions.InitializeAsync(LauncherConfig.CDN_ROOT);

+ 2 - 2
GameClient/Assets/Game/Launcher/Xasset/GFGAsset.cs

@@ -9,7 +9,7 @@ namespace GFGGame
     {
         public static T Load<T>(string path) where T:Object
         {
-            VEngine.Logger.I($"GFGAsset.Load {path} {Random.Range(0, int.MaxValue)}");
+            //VEngine.Logger.I($"GFGAsset.Load {path} {Random.Range(0, int.MaxValue)}");
             T t = null;
             if (path.Contains("Asset"))
             {
@@ -28,7 +28,7 @@ namespace GFGGame
 
         public static void Release(string path)
         {
-            VEngine.Logger.I($"GFGAsset.Release {path} {Random.Range(0, int.MaxValue)}");
+            //VEngine.Logger.I($"GFGAsset.Release {path} {Random.Range(0, int.MaxValue)}");
             if (path.Contains("Asset"))
             {
                 Asset asset;