using System.Text.Json; using OMS.NET.DbClass; namespace OMS.NET.Instructs { /// /// 登录指令 /// public class LoginInstruct : Instruct { public LoginInstruct() { this.Type = "login"; } public override Task Handler(string wsid) { return Task.Run(() => { if (this.Data?.GetType() == typeof(JsonElement)) { string email = this.Data.GetProperty("email").GetString(); string password = this.Data.GetProperty("password").GetString(); if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { GlobalArea.Log.Warn("登录信息不能为空!"); return; } //能够获取到则说明客户端有发送数据过来 Instruct res1 = new LoginStatusInstuct { Data = false, IsResponse = true };//默认为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 this.ResponseOrBroadcastInstructs.Add(res1); GlobalArea.Log.Info($"{accountData.UserEmail}:登录成功"); GlobalArea.Login(wsid, accountData.UserEmail); GlobalArea.Log.Info($"当前登录用户数量: {GlobalArea.LoginUserCount}"); this.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 { this.ResponseOrBroadcastInstructs.Add(res1); } } } }); } } public class LoginStatusInstuct : Instruct { public LoginStatusInstuct() { this.Type = "loginStatus"; } } }