diff --git a/UserClass/AsyncTcpClient.cs b/UserClass/AsyncTcpClient.cs index d7efa62..f640414 100644 --- a/UserClass/AsyncTcpClient.cs +++ b/UserClass/AsyncTcpClient.cs @@ -5,9 +5,11 @@ using System.Collections.Generic; using System.Data; using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; using TouchSocket.Core; using TouchSocket.Sockets; using static SunlightAggregationManager.UserClass.AsyncTcpServer; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace SunlightAggregationManager.UserClass { @@ -105,13 +107,22 @@ namespace SunlightAggregationManager.UserClass //行为 Dictionary myDict = new Dictionary(); //myDict.Add("LinkID", client.Id); + + //AES解密 + string dataAES = AES.AesDecrypt(deserializedPerson!.Terminal, deserializedPerson.Dat); + Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]COMMAND[" + + Regex.Replace(dataAES, @"\\u[0-9A-Fa-f]{4}", match => + { return Regex.Unescape(match.Value); }) + "]"); + + //记录 myDict.Add("LastLoginIP", deserializedPerson?.IP ?? client.IP); myDict.Add("LastActionTime", DateTime.Now); - myDict.Add("Note", deserializedPerson?.Dat ?? "unknown"); - MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + deserializedPerson?.User + "'", myDict); + myDict.Add("Note", dataAES ?? "unknown"); - Console.WriteLine("[Log on]User[" + deserializedPerson?.User + "]Note[" + (deserializedPerson?.Dat ?? "unknown") + "]"); - CommandC(deserializedPerson?.Dat ?? "NOT", deserializedPerson!); + MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + + deserializedPerson?.User + "'", myDict); + + CommandC(dataAES ?? "NOT", deserializedPerson!); } else {//停用账号关闭连接 @@ -194,7 +205,7 @@ namespace SunlightAggregationManager.UserClass string Command = "", ret = ""; Dictionary data_ = new Dictionary(); - var deserialized = JsonSerializer.Deserialize>( AES.AesDecrypt(person.Terminal, dat))!; + var deserialized = JsonSerializer.Deserialize>(dat)!; if (deserialized.TryGetValue("Command", out var val) && val != null) Command = val.ToString()!; if (Command == "Log")//回复请求的信息 { @@ -385,6 +396,10 @@ namespace SunlightAggregationManager.UserClass ret = JsonSerializer.Serialize(data_); } //加密回传 + /*Console.WriteLine("[Log on]User[" + person?.User + "]REPLY[" + + Regex.Replace(ret, @"\\u[0-9A-Fa-f]{4}", match => + { return Regex.Unescape(match.Value); }) + "]");*/ + person!.Dat =AES.AesEncipher( person.Terminal, ret); var jsdat = JsonSerializer.Serialize(person); await tcpClient.SendAsync(jsdat);