VFP系统

This commit is contained in:
2025-07-16 22:52:09 +08:00
parent 7d0f231547
commit 10f29f76b6
5 changed files with 96 additions and 2 deletions

View File

@ -15,6 +15,7 @@ using EXiled_NebulaMist_CP_NG_hint.Helper;
using EXiled_NebulaMist_CP_NG_hint.Items;
using EXiled_NebulaMist_CP_NG_hint.Role;
using EXiled_NebulaMist_CP_NG_hint.SQL;
using NorthwoodLib;
using Org.BouncyCastle.Math.EC;
using RoundRestarting;
using System;
@ -43,13 +44,106 @@ namespace EXiled_NebulaMist_CP_NG_hint
public static Plugin Instance666 { get; private set; }
//设定注册表的字符串变量
string hwid = ReadRegistryString(@"Software\Nebulamist", "Hwid");
string kami = ReadRegistryString(@"Software\Nebulamist", "Kami");
private static string ReadRegistryString(string path, string key)
{
try
{
// 打开 HKEY_LOCAL_MACHINE 下指定子项
using (var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path))
{
// 获取对应键的值并转为字符串
return regKey?.GetValue(key)?.ToString();
}
}
catch (Exception ex)
{
Log.Error($"读取注册表 [{path}\\{key}] 失败: {ex.Message}");
return null;
}
}
private bool ValidateLicense(string hwid, string kami)
{
try
{
using (var client = new System.Net.Http.HttpClient())
{
// 拼接完整的 GET 请求 URL
string url = $"http://127.0.0.1:5678/login?kami={kami}&hwid={hwid}";
// 发起同步 GET 请求(也可以改为异步)
var response = client.GetAsync(url).Result;
var jsonString = response.Content.ReadAsStringAsync().Result;
// 输出原始返回,便于调试
Log.Info($"VFP API 原始响应: {jsonString}");
// 使用 System.Text.Json 解析 JSON 字符串
using (var doc = System.Text.Json.JsonDocument.Parse(jsonString))
{
// 获取 success 字段
if (doc.RootElement.TryGetProperty("success", out var successElement))
{
bool isSuccess = successElement.GetBoolean();
// 获取 message 字段(可选)
string message = doc.RootElement.GetProperty("message").GetString();
Log.Info($"VFP 验证结果:{isSuccess},消息:{message}");
return isSuccess;
}
else
{
Log.Warn("VFP API 响应中没有 'success' 字段!");
return false;
}
}
}
}
catch (Exception ex)
{
Log.Error("调用 VFP 验证 API 出现异常: " + ex.Message);
return false;
}
}
//注册
public override void OnEnabled()
{
base.OnEnabled(); // 调用基类 OnEnabled确保插件生命周期正常
// 检查是否成功读取
if (string.IsNullOrEmpty(hwid) || string.IsNullOrEmpty(kami))
{
Log.Error("注册表中未找到 HWID 或 KAMI插件不会启用");
return;
}
Log.Info($"读取注册表成功hwid = {hwid}, kami = {kami}");
// 调用 API 进行验证
if (!ValidateLicense(hwid, kami))
{
Log.Error("VFP 验证失败,插件不会启用!");
return;
}
Log.Info("VFP 验证成功,开始初始化插件功能...");
Log.Info("===!连接SQL数据库中!===");
Mysql.InitSql();
if (!Mysql.IsSql)