diff --git a/Assets/_Scripts/Application/States/HomeState.cs b/Assets/_Scripts/Application/States/HomeState.cs index 9dcd462..fb4ac58 100644 --- a/Assets/_Scripts/Application/States/HomeState.cs +++ b/Assets/_Scripts/Application/States/HomeState.cs @@ -1,7 +1,10 @@ using CG.Framework; using CG.UTility; using System; +using System.Collections; +using System.IO; using UnityEngine; +using UnityEngine.Networking; /******************************************************************************** *Create By CG *Function ҳ״̬ @@ -17,10 +20,40 @@ namespace ZXK.LouDiXvMuNiu public override void EnterState() { UI_Manage.Instance.ShowPanel("HomePanel", Type.GetType("ZXK.LouDiXvMuNiu.HomePanel"), UIGroup.Main); + +#if UNITY_WEBGL + GameManager.Instance.StartCoroutine(LoadTimer()); +#else DateManager.UpdateTime(Tip, Tip, success: () => { + }); +#endif } + + IEnumerator LoadTimer() + { + string path = Path.Combine(Application.streamingAssetsPath, "Timer.txt"); + Debug.LogError(path); + using (UnityWebRequest request = new UnityWebRequest(path)) + { + request.downloadHandler = new DownloadHandlerBuffer(); + yield return request.SendWebRequest(); + if (string.IsNullOrEmpty(request.error)) + { + string datas = DecryptFileReader.ReadAndDecryptData(request.downloadHandler.data); + DateManager.UpdateTime(datas,Tip, Tip, success: () => + { + + }); + } + else + { + Debug.LogError(request.error); + } + } + } + public void Tip(string str) { PopUpMng.PopAlert("", str, "ȷ", () => diff --git a/Assets/_Scripts/NetWork/Encryption/DateManager.cs b/Assets/_Scripts/NetWork/Encryption/DateManager.cs index daeff58..49c46f7 100644 --- a/Assets/_Scripts/NetWork/Encryption/DateManager.cs +++ b/Assets/_Scripts/NetWork/Encryption/DateManager.cs @@ -8,10 +8,9 @@ public class DateManager public static string EndTimer = "2025-07-06 00:00:00";//结束时间 private static string RecordData; - private void Start() - { - // CreatTimer(); - } + + + /// /// 更新系统时间 @@ -58,6 +57,50 @@ public class DateManager } success?.Invoke(); } + /// + /// 更新系统时间 + /// + public static void UpdateTime(string datas, UnityAction error = null, UnityAction timeOut = null, UnityAction update = null, UnityAction success = null) + { + try + { + EndTimer = datas.Split('|')[0]; + RecordData = datas.Split('|')[1]; + //第一次获取获取系统时间 + DateTime currentDateTime = DateTime.Now; + string Data = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss"); + if (DateTime.TryParse(RecordData, out DateTime recordDateTime) && DateTime.TryParse(Data, out DateTime nowDateTime)) + { + if (recordDateTime > nowDateTime) + { + Debug.Log("仿真文件被损坏,请联系管理员进行修复"); + error?.Invoke("仿真文件被损坏,请联系管理员进行修复"); + } + else + { + //把上一次存储得系统时间更新到最新 + //string timer = "Timer.txt"; + //RecordData = Data; + //string strMerge = EndTimer + "|" + RecordData; + //EncryptFileCreator.EncryptAndSaveData(strMerge, timer); + update?.Invoke(); + } + } + } + catch (Exception e) + { + Debug.LogError($"数据出错: {e.Message}"); + error?.Invoke($"数据出错: {e.Message}"); + } + + if (JudgeExpire()) + { + Debug.Log("请联系管理员进行升级"); + timeOut?.Invoke("请联系管理员进行升级"); + return; + } + success?.Invoke(); + } /// /// 判断是否到期 diff --git a/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs index 1c6d60f..f8da5a9 100644 --- a/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs +++ b/Assets/_Scripts/NetWork/Encryption/DecryptFileReader.cs @@ -14,7 +14,12 @@ public class DecryptFileReader if (File.Exists(filePath)) return ""; // 读取加密文件 byte[] encryptedData = File.ReadAllBytes(fullPath); + return ReadAndDecryptData(encryptedData); + } + + public static string ReadAndDecryptData(byte[] encryptedData) + { // 创建AES解密器 using (Aes aesAlg = Aes.Create()) {