diff --git a/Instructs/LoginInstruct.cs b/Instructs/LoginInstruct.cs index c344d74..3ccaffc 100644 --- a/Instructs/LoginInstruct.cs +++ b/Instructs/LoginInstruct.cs @@ -19,30 +19,29 @@ namespace OMS.NET.Instructs return Task.Run(() => { if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查 - string email = Data.GetProperty("email").GetString(); - string password = Data.GetProperty("password").GetString(); - if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) - { - GlobalArea.Log.Warn("登录信息不能为空!"); - return; - } - //能够获取到则说明客户端有发送数据过来 - Instruct res1 = new() - { - IsResponse = true, - Type = "loginStatus", - Data = false - };//默认为false - //Console.WriteLine($"已获取到{email}:{password},解密测试{GlobalArea.DecryptFromBase64String(password)}"); - AccountData? accountData = AccountData.Get(email); - GlobalArea.AddLoginAccountData(accountData); - if (accountData != null) + try { + string email = Data.GetProperty("email").GetString(); + string password = Data.GetProperty("password").GetString(); + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("登录信息不能为空"); + } + //能够获取到则说明客户端有发送数据过来 + Instruct res1 = new() + { + IsResponse = true, + Type = "loginStatus", + Data = false + };//默认为false + //Console.WriteLine($"已获取到{email}:{password},解密测试{GlobalArea.DecryptFromBase64String(password)}"); + AccountData accountData = AccountData.Get(email) ?? throw new Exception($"数据库中不包含用户{email}"); + GlobalArea.AddLoginAccountData(accountData); + ResponseOrBroadcastInstructs.Add(res1); //只能原文比较,密文每次都不一样,涉及随机性填充 if (accountData.Password == GlobalArea.DecryptFromBase64String(password)) { res1.Data = true;//登录成功则修改为true - ResponseOrBroadcastInstructs.Add(res1); GlobalArea.Log.Info($"{accountData.UserEmail}:登录成功"); GlobalArea.Login(wsid, accountData.UserEmail); GlobalArea.Log.Info($"当前登录用户数量: {GlobalArea.LoginUserCount}"); @@ -60,10 +59,11 @@ namespace OMS.NET.Instructs IsBroadcast = true }); } - else - { - ResponseOrBroadcastInstructs.Add(res1); - } + + } + catch (Exception ex) + { + GlobalArea.Log.Warn($"处理{Type}广播指令出错:" + ex.Message); } }); }