XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension.NetCore.ServerInteractive

规范名称

0351bf8
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

23 个文件 +148 -140
Modified XFEExtension.NetCore.ServerInteractive/Models/RequesterModels/ClientRequestResult.cs +3 -3
@@ -21,12 +21,12 @@ public class ClientRequestResult<T> : IRequestResult<T>
21 21 /// <summary>
22 22 /// 转换为指定泛型
23 23 /// </summary>
24 /// <typeparam name="F">指定泛型</typeparam>
24 /// <typeparam name="TF">指定泛型</typeparam>
25 25 /// <returns></returns>
26 public ClientRequestResult<F> TryConvertTo<F>() => new()
26 public ClientRequestResult<TF> TryConvertTo<TF>() => new()
27 27 {
28 28 Message = Message,
29 29 StatusCode = StatusCode,
30 Result = Result is not null ? (F)(object)Result : default!
30 Result = Result is not null ? (TF)(object)Result : default!
31 31 };
32 32 }
Modified XFEExtension.NetCore.ServerInteractive/Models/ServerModels/ServerCoreReturnArgs.cs +1 -1
@@ -24,7 +24,7 @@ public class ServerCoreReturnArgs : Exception
24 24 /// <summary>
25 25 /// 是否已经处理完成
26 26 /// </summary>
27 public bool Handled { get; set; } = false;
27 public bool Handled { get; set; }
28 28 /// <summary>
29 29 /// 状态码
30 30 /// </summary>
Modified XFEExtension.NetCore.ServerInteractive/Models/UserModels/UserLoginModel.cs +1 -1
@@ -8,7 +8,7 @@ public class UserLoginModel
8 8 /// <summary>
9 9 /// 用户ID
10 10 /// </summary>
11 public string UID { get; set; } = string.Empty;
11 public string Uid { get; set; } = string.Empty;
12 12 /// <summary>
13 13 /// 上一次登录IP
14 14 /// </summary>
Modified XFEExtension.NetCore.ServerInteractive/Profiles/ServerBaseProfile.cs +7 -7
@@ -9,19 +9,19 @@ public partial class ServerBaseProfile : XFEProfile
9 9 /// 服务器入口点
10 10 /// </summary>
11 11 [ProfileProperty]
12 private string entryPoint = "api";
12 private string _entryPoint = "api";
13 13 /// <summary>
14 14 /// 封禁的IP地址列表
15 15 /// </summary>
16 16 [ProfileProperty]
17 [ProfilePropertyAddGet("Current.bannedIPAddressList.CurrentProfile = Current")]
18 [ProfilePropertyAddGet("return Current.bannedIPAddressList")]
19 private ProfileList<IPAddressInfo> bannedIPAddressList = [];
17 [ProfilePropertyAddGet("Current._bannedIPAddressList.CurrentProfile = Current")]
18 [ProfilePropertyAddGet("return Current._bannedIPAddressList")]
19 private ProfileList<IPAddressInfo> _bannedIPAddressList = [];
20 20 /// <summary>
21 21 /// 服务器上次绑定的IP地址字典
22 22 /// </summary>
23 23 [ProfileProperty]
24 [ProfilePropertyAddGet("Current.serverLastBindingAddressDictionary.CurrentProfile = Current")]
25 [ProfilePropertyAddGet("return Current.serverLastBindingAddressDictionary")]
26 private ProfileDictionary<string, string> serverLastBindingAddressDictionary = [];
24 [ProfilePropertyAddGet("Current._serverLastBindingAddressDictionary.CurrentProfile = Current")]
25 [ProfilePropertyAddGet("return Current._serverLastBindingAddressDictionary")]
26 private ProfileDictionary<string, string> _serverLastBindingAddressDictionary = [];
27 27 }
Modified XFEExtension.NetCore.ServerInteractive/Utilities/DataTable/XFEDataTableManagerBuilder.cs +8 -8
@@ -14,8 +14,8 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.DataTable;
14 14 [CreateImpl]
15 15 public abstract class XFEDataTableManagerBuilder
16 16 {
17 readonly List<IXFEDataTable> dataTableList = [];
18 readonly JsonSerializerOptions userJsonSerializerOptions = new();
17 private readonly List<IXFEDataTable> _dataTableList = [];
18 private readonly JsonSerializerOptions _userJsonSerializerOptions = new();
19 19 /// <summary>
20 20 /// 执行语句列表
21 21 /// </summary>
@@ -28,7 +28,7 @@ public abstract class XFEDataTableManagerBuilder
28 28 public static XFEDataTableManagerBuilder CreateBuilder()
29 29 {
30 30 var builder = new XFEDataTableManagerBuilderImpl();
31 builder.userJsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
31 builder._userJsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
32 32 return builder;
33 33 }
34 34
@@ -40,7 +40,7 @@ public abstract class XFEDataTableManagerBuilder
40 40 /// <returns></returns>
41 41 public XFEDataTableManagerBuilder AddTable<T>(XFEDataTable<T> xFEDataTable) where T : IIDModel
42 42 {
43 dataTableList.Add(xFEDataTable);
43 _dataTableList.Add(xFEDataTable);
44 44 ExecuteList.AddRange([$"get_{xFEDataTable.TableNameInRequest}", $"add_{xFEDataTable.TableNameInRequest}", $"change_{xFEDataTable.TableNameInRequest}", $"remove_{xFEDataTable.TableNameInRequest}"]);
45 45 return this;
46 46 }
@@ -49,7 +49,7 @@ public abstract class XFEDataTableManagerBuilder
49 49 /// 添加数据表
50 50 /// </summary>
51 51 /// <typeparam name="T">数据类型</typeparam>
52 /// <typeparam name="P">配置文件类型</typeparam>
52 /// <typeparam name="TP">配置文件类型</typeparam>
53 53 /// <param name="tabelShowName">表格数据的显示名称(如:订单、用户等)</param>
54 54 /// <param name="addPermissionLevel">增加数据所需的最小权限</param>
55 55 /// <param name="removePermissionLevel">删除数据所需的最小权限</param>
@@ -57,14 +57,14 @@ public abstract class XFEDataTableManagerBuilder
57 57 /// <param name="getPermissionLevel">获取数据所需的最小权限</param>
58 58 /// <param name="jsonSerializerOptions">JSON转换器</param>
59 59 /// <returns></returns>
60 public XFEDataTableManagerBuilder AddTable<T, P>(string tabelShowName, int addPermissionLevel, int removePermissionLevel, int changePermissionLevel, int getPermissionLevel, JsonSerializerOptions? jsonSerializerOptions = null) where T : IIDModel where P : XFEProfile => AddTable<T>(new XFEDataTable<T>(typeof(P))
60 public XFEDataTableManagerBuilder AddTable<T, TP>(string tabelShowName, int addPermissionLevel, int removePermissionLevel, int changePermissionLevel, int getPermissionLevel, JsonSerializerOptions? jsonSerializerOptions = null) where T : IIDModel where TP : XFEProfile => AddTable<T>(new XFEDataTable<T>(typeof(TP))
61 61 {
62 62 TableShowName = tabelShowName,
63 63 AddPermissionLevel = addPermissionLevel,
64 64 RemovePermissionLevel = removePermissionLevel,
65 65 ChangePermissionLevel = changePermissionLevel,
66 66 GetPermissionLevel = getPermissionLevel,
67 UserJsonSerializerOptions = userJsonSerializerOptions,
67 UserJsonSerializerOptions = _userJsonSerializerOptions,
68 68 JsonSerializerOptions = jsonSerializerOptions
69 69 });
70 70
@@ -77,7 +77,7 @@ public abstract class XFEDataTableManagerBuilder
77 77 public XFEDataTableManager Build(Func<IEnumerable<IUserInfo>> getUsersFunction, Func<IEnumerable<EncryptedUserLoginModel>> getEncryptedUserLoginModelFunction)
78 78 {
79 79 var xFEDataTableManager = new XFEDataTableManagerImpl();
80 foreach (var table in dataTableList)
80 foreach (var table in _dataTableList)
81 81 {
82 82 table.GetEncryptedUserLoginModelFunction = getEncryptedUserLoginModelFunction;
83 83 table.GetUsersFunction = getUsersFunction;
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Extensions/XFEClientRequesterBuilderExtensions.cs +3 -3
@@ -12,9 +12,9 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Extensions;
12 12 /// </summary>
13 13 public static class XFEClientRequesterBuilderExtensions
14 14 {
15 readonly static JsonSerializerOptions jsonSerializerOptions = new();
15 private readonly static JsonSerializerOptions JsonSerializerOptions = new();
16 16
17 static XFEClientRequesterBuilderExtensions() => jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
17 static XFEClientRequesterBuilderExtensions() => JsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
18 18
19 19 /// <summary>
20 20 /// 添加连接检查请求
@@ -55,7 +55,7 @@ public static class XFEClientRequesterBuilderExtensions
55 55 execute = "get_bannedIpList",
56 56 session,
57 57 computerInfo
58 }, static response => JsonSerializer.Deserialize<List<IPAddressInfo>>(response, jsonSerializerOptions)!).AddRequest("add_bannedIp", static (session, computerInfo, parameters) => new
58 }, static response => JsonSerializer.Deserialize<List<IPAddressInfo>>(response, JsonSerializerOptions)!).AddRequest("add_bannedIp", static (session, computerInfo, parameters) => new
59 59 {
60 60 execute = "add_bannedIp",
61 61 session,
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/AESHelper.cs +2 -2
@@ -5,7 +5,7 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
5 5 /// <summary>
6 6 /// AES加密帮助
7 7 /// </summary>
8 public static class AESHelper
8 public static class AesHelper
9 9 {
10 10 /// <summary>
11 11 /// 生成随机密钥
@@ -22,7 +22,7 @@ public static class AESHelper
22 22 /// 生成随机向量
23 23 /// </summary>
24 24 /// <returns></returns>
25 public static string GenerateRandomIV()
25 public static string GenerateRandomIv()
26 26 {
27 27 byte[] iv = new byte[16];
28 28 RandomNumberGenerator.Fill(iv);
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/DeviceHelper.cs +7 -7
@@ -12,7 +12,7 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Helpers;
12 12 [SupportedOSPlatform("windows")]
13 13 public static class DeviceHelper
14 14 {
15 static string GetMacAddress()
15 private static string GetMacAddress()
16 16 {
17 17 try
18 18 {
@@ -31,27 +31,27 @@ public static class DeviceHelper
31 31 }
32 32 }
33 33
34 static string GetCpuId()
34 private static string GetCpuId()
35 35 {
36 36 return GetWmiProperty("Win32_Processor", "ProcessorId");
37 37 }
38 38
39 static string GetBoardSerial()
39 private static string GetBoardSerial()
40 40 {
41 41 return GetWmiProperty("Win32_BaseBoard", "SerialNumber");
42 42 }
43 43
44 static string GetBiosSerial()
44 private static string GetBiosSerial()
45 45 {
46 46 return GetWmiProperty("Win32_BIOS", "SerialNumber");
47 47 }
48 48
49 static string GetDiskSerial()
49 private static string GetDiskSerial()
50 50 {
51 51 return GetWmiProperty("Win32_PhysicalMedia", "SerialNumber");
52 52 }
53 53
54 static string GetWmiProperty(string wmiClass, string wmiProperty)
54 private static string GetWmiProperty(string wmiClass, string wmiProperty)
55 55 {
56 56 try
57 57 {
@@ -65,7 +65,7 @@ public static class DeviceHelper
65 65 return "N/A";
66 66 }
67 67
68 static string GetSha256Hash(string input)
68 private static string GetSha256Hash(string input)
69 69 {
70 70 var hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(input));
71 71 var sb = new StringBuilder();
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Helpers/UserHelper.cs +5 -5
@@ -36,14 +36,14 @@ public static class UserHelper
36 36 user = null;
37 37 session = Regex.Unescape(session);
38 38 var split = session.Split('|');
39 if (encryptedUserLoginModels.FirstOrDefault(user => user.UserLoginModel.UID == split[0]) is not EncryptedUserLoginModel encryptedUserLoginModel)
39 if (encryptedUserLoginModels.FirstOrDefault(user => user.UserLoginModel.Uid == split[0]) is not EncryptedUserLoginModel encryptedUserLoginModel)
40 40 return UserOperateResult.LoginExpired;
41 41 if (encryptedUserLoginModel.UserLoginModel.ComputerInfo != computerInfo) return UserOperateResult.LoginExpired;
42 if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, split[1]) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.UID != targetUserLoginModel.UID)
42 if (Decrypt<UserLoginModel>(encryptedUserLoginModel.Key, split[1]) is not UserLoginModel targetUserLoginModel || encryptedUserLoginModel.UserLoginModel.Uid != targetUserLoginModel.Uid)
43 43 return UserOperateResult.UserNotFound;
44 44 if (encryptedUserLoginModel.UserLoginModel.EndDateTime < DateTime.Now || (encryptedUserLoginModel.UserLoginModel.LastIPAddress != ipAddress && !((encryptedUserLoginModel.UserLoginModel.LastIPAddress == "127.0.0.1" || encryptedUserLoginModel.UserLoginModel.LastIPAddress == "::1") && (ipAddress == "127.0.0.1" || ipAddress == "::1"))))
45 45 return UserOperateResult.LoginExpired;
46 if (GetUser(targetUserLoginModel.UID, userInfoList) is not IUserInfo userInfo)
46 if (GetUser(targetUserLoginModel.Uid, userInfoList) is not IUserInfo userInfo)
47 47 return UserOperateResult.UserNotFound;
48 48 if (!userInfo.Enable)
49 49 return UserOperateResult.UserDisabled;
@@ -291,7 +291,7 @@ public static class UserHelper
291 291 /// <param name="key"></param>
292 292 /// <param name="model"></param>
293 293 /// <returns></returns>
294 public static string Encrypt<T>(string key, T model) where T : class => AESHelper.Encrypt(JsonSerializer.Serialize(model), key);
294 public static string Encrypt<T>(string key, T model) where T : class => AesHelper.Encrypt(JsonSerializer.Serialize(model), key);
295 295
296 296 /// <summary>
297 297 /// 解密用户登录模型
@@ -299,5 +299,5 @@ public static class UserHelper
299 299 /// <param name="key"></param>
300 300 /// <param name="encryptedModel"></param>
301 301 /// <returns></returns>
302 public static T Decrypt<T>(string key, string encryptedModel) where T : class, new() => JsonSerializer.Deserialize<T>(AESHelper.Decrypt(encryptedModel, key)) ?? new();
302 public static T Decrypt<T>(string key, string encryptedModel) where T : class, new() => JsonSerializer.Deserialize<T>(AesHelper.Decrypt(encryptedModel, key)) ?? new();
303 303 }
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Requester/Serviecs/LoginRequestService.cs +3 -3
@@ -11,16 +11,16 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Requester.Serviecs;
11 11 /// </summary>
12 12 public class LoginRequestService<T> : XFERequestServiceBase where T : IUserFaceInfo
13 13 {
14 readonly JsonSerializerOptions jsonSerializerOptions = new();
14 private readonly JsonSerializerOptions _jsonSerializerOptions = new();
15 15 /// <summary>
16 16 /// 登录请求服务
17 17 /// </summary>
18 public LoginRequestService() => jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
18 public LoginRequestService() => _jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
19 19
20 20 /// <inheritdoc/>
21 21 public override object AnalyzeResponse(string response)
22 22 {
23 var result = JsonSerializer.Deserialize<UserLoginResult<T>>(response, jsonSerializerOptions);
23 var result = JsonSerializer.Deserialize<UserLoginResult<T>>(response, _jsonSerializerOptions);
24 24 XFEClientRequester.Session = result!.Session;
25 25 return result;
26 26 }
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Requester/Serviecs/ReloginRequestService.cs +3 -3
@@ -10,13 +10,13 @@ namespace XFEExtension.NetCore.ServerInteractive.Utilities.Requester.Serviecs;
10 10 /// </summary>
11 11 public class ReloginRequestService<T> : XFERequestServiceBase where T : IUserFaceInfo
12 12 {
13 readonly JsonSerializerOptions jsonSerializerOptions = new();
13 private readonly JsonSerializerOptions _jsonSerializerOptions = new();
14 14 /// <summary>
15 15 /// 登录校验请求服务
16 16 /// </summary>
17 public ReloginRequestService() => jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
17 public ReloginRequestService() => _jsonSerializerOptions.Converters.Add(new JsonDateTimeConverter());
18 18 /// <inheritdoc/>
19 public override object AnalyzeResponse(string response) => JsonSerializer.Deserialize<T>(response, jsonSerializerOptions)!;
19 public override object AnalyzeResponse(string response) => JsonSerializer.Deserialize<T>(response, _jsonSerializerOptions)!;
20 20
21 21 /// <inheritdoc/>
22 22 public override object PostRequest(string execute, params object[] parameters) => new
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Requester/XFEClientRequester.cs +0 -1
@@ -106,6 +106,5 @@ public abstract class XFEClientRequester : IRequesterBase
106 106 result.StatusCode = HttpStatusCode.InternalServerError;
107 107 return result;
108 108 }
109 throw new XFERequesterException("请求的方法未注册");
110 109 }
111 110 }
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Requester/XFEClientRequesterBuilder.cs +31 -22
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/DailyCounterService.cs +6 -6
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserLoginAutoCleanService.cs +1 -1
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserLoginService.cs +3 -3
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/CoreService/UserReloginService.cs +3 -3
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/ServerService/ServerExceptionProcessService.cs +2 -2
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/Services/ServerService/ServerIpInitializer.cs +2 -2
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/XFEServer.cs +6 -6
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/XFEServerBuilder.cs +13 -13
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/XFEServerCore.cs +10 -10
Modified XFEExtension.NetCore.ServerInteractive/Utilities/Server/XFEServerCoreBuilder.cs +28 -28