瀏覽代碼

Merge remote-tracking branch 'remotes/origin/master' into GFG

hexiaojie 18 小時之前
父節點
當前提交
07609987e8

+ 3 - 1
GameClient/Assets/Game/HotUpdate/AccountData/AccountManager.cs

@@ -12,7 +12,9 @@ namespace GFGGame
         private List<AccountData> _cachedAccounts = new List<AccountData>();
 
         // 单例实例
-        private static readonly Lazy<AccountManager> _instance = new Lazy<AccountManager>(() => new AccountManager());
+        private static readonly SimpleLazy<AccountManager> _instance =
+            new SimpleLazy<AccountManager>(() => new AccountManager());
+
         public static AccountManager Instance => _instance.Value;
 
         // 私有构造函数,防止外部实例化

+ 2 - 52
GameClient/Assets/Game/HotUpdate/AccountData/AesEncryption.cs

@@ -7,64 +7,14 @@ namespace GFGGame
 {
     public static class AesEncryption
     {
-        // !!!重要警告!!!
-        // 硬编码在客户端的密钥并不安全,容易被反编译获取。
-        // 这只能防止简单的窥探,无法抵御专业黑客。
-        // 对于极度敏感的信息,请考虑其他方案(如服务端令牌验证)。
-        private static readonly string Key = "45418100000000000000000000000000"; // 必须恰好是32字节
-        private static readonly string IV = "1234567890123456"; // 必须恰好是16字节
-
         public static string Encrypt(string plainText)
         {
-            using (Aes aesAlg = Aes.Create())
-            {
-                aesAlg.Key = Encoding.UTF8.GetBytes(Key);
-                aesAlg.IV = Encoding.UTF8.GetBytes(IV);
-
-                ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
-                using (MemoryStream msEncrypt = new MemoryStream())
-                {
-                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
-                    {
-                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
-                        {
-                            swEncrypt.Write(plainText);
-                        }
-                    }
-
-                    return Convert.ToBase64String(msEncrypt.ToArray());
-                }
-            }
+            return plainText;
         }
 
         public static string Decrypt(string cipherText)
         {
-            try
-            {
-                byte[] buffer = Convert.FromBase64String(cipherText);
-                using (Aes aesAlg = Aes.Create())
-                {
-                    aesAlg.Key = Encoding.UTF8.GetBytes(Key);
-                    aesAlg.IV = Encoding.UTF8.GetBytes(IV);
-
-                    ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
-                    using (MemoryStream msDecrypt = new MemoryStream(buffer))
-                    {
-                        using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
-                        {
-                            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
-                            {
-                                return srDecrypt.ReadToEnd();
-                            }
-                        }
-                    }
-                }
-            }
-            catch
-            {
-                // 解密失败(可能数据被篡改或密钥错误)
-                return null;
-            }
+            return cipherText;
         }
     }
 }

+ 41 - 0
GameClient/Assets/Game/HotUpdate/AccountData/SimpleLazy.cs

@@ -0,0 +1,41 @@
+using System;
+
+namespace GFGGame
+{
+    // 替代 System.Lazy<T> 的简单实现
+    // 替代 System.Lazy<T> 的简易实现
+    public class SimpleLazy<T>
+    {
+        private readonly Func<T> _initializer;
+        private T _value;
+        private bool _isInitialized;
+        private readonly object _lock = new object();
+
+        public SimpleLazy(Func<T> initializer)
+        {
+            _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer));
+        }
+
+        public T Value
+        {
+            get
+            {
+                if (!_isInitialized)
+                {
+                    lock (_lock)
+                    {
+                        if (!_isInitialized)
+                        {
+                            _value = _initializer();
+                            _isInitialized = true;
+                        }
+                    }
+                }
+
+                return _value;
+            }
+        }
+
+        public bool IsValueCreated => _isInitialized;
+    }
+}

+ 3 - 0
GameClient/Assets/Game/HotUpdate/AccountData/SimpleLazy.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 40e26eb0a8bc478ab48e59a32f853dff
+timeCreated: 1761164883

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Controller/GameController.cs

@@ -101,7 +101,7 @@ namespace GFGGame
                 {
                     if (doLogin)
                     {
-                        LoginController.Login(account, password, true).Coroutine();
+                        LoginController.Login(account, password).Coroutine();
                     }
                     return true;
                 }

+ 6 - 1
GameClient/Assets/Game/HotUpdate/Controller/LoginController.cs

@@ -55,6 +55,11 @@ namespace GFGGame
         public static async ET.ETTask Login(string account, string password, bool isMD5 = false,
             bool cancelDelete = false)
         {
+            if (password.Length > 20)
+            {
+                isMD5 = true;
+            }
+
             ViewManager.Show<ModalStatusView>("登录中...");
             (int errorCode, long deleteTime) = await ET.LoginHelper.Login(GameGlobal.zoneScene, GameConfig.LoginAddress,
                 account, password, isMD5, cancelDelete);
@@ -81,7 +86,7 @@ namespace GFGGame
                     }
 
                     PlayerPrefs.SetString(GameConst.ACCOUNT_LAST_LOGIN_KEY, account);
-                    PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, passwordMD5);
+                    PlayerPrefs.SetString(GameConst.PASSWORD_LAST_LOGIN_KEY, password);
                 }
 
                 GameController.CheckSpecialAccount(account);