using System.Text.Json; using OMS.NET.DbClass; namespace OMS.NET.Instructs { /// /// 登录指令 /// public class LoginInstruct : Instruct { public LoginInstruct() { Type = "login"; } public override Task Handler(string wsid) { 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) { //只能原文比较,密文每次都不一样,涉及随机性填充 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}"); ResponseOrBroadcastInstructs.Add(new Instruct { Type = "broadcast", Class = "logIn", Data = new { userEmail = accountData.UserEmail, userName = accountData.UserName, headColor = accountData.HeadColor, userQq = accountData.UserQQ, }, IsBroadcast = true }); } else { ResponseOrBroadcastInstructs.Add(res1); } } }); } } }