fix: AreaGUIManager硬编码URL改为从插件配置读取

- AreaGUIManager删除用户组时通知PHP同步,URL和密钥之前写死为caoyuan.ypshidifu.cn
- 现在改为从webManager.getWebBaseUrl()和getSecretKey()读取,支持其他服主自定义web后端
- extractCodeFromInput增强支持#code=fragment形式(上一轮修复)
- verifyMinecraftAuthCode加debug日志便于排查
- deploy_sftp.py备份后缀改为.jar.old/.old.N(不以.jar结尾,避免MC加载冲突)
- .gitignore添加hs_err_pid*.log
This commit is contained in:
2026-07-17 19:40:01 +08:00
parent c568703996
commit f5a3dfbda5
5 changed files with 162 additions and 10 deletions
+4 -3
View File
@@ -1337,15 +1337,16 @@ public class AreaGUIManager implements Listener {
String groupName = names.get(raw);
if (p.hasPermission("sdf1.admin")) {
ugm.deleteGroupConfig(groupName);
// ★ 通知PHP同步
// ★ 通知PHP同步(从插件配置读取地址和密钥,不写死)
try {
java.net.URL url = new java.net.URL("https://caoyuan.ypshidifu.cn/plugin/api/land_api.php");
String landApiUrl = plugin.webManager.getWebBaseUrl() + "/api/land_api.php";
java.net.URL url = new java.net.URL(landApiUrl);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
String body = "action=delete_user_group&name=" + groupName + "&secret=sdf1_web_comm_2026_ypshidifu";
String body = "action=delete_user_group&name=" + groupName + "&secret=" + java.net.URLEncoder.encode(plugin.webManager.getSecretKey(), "UTF-8");
java.io.OutputStream os = conn.getOutputStream();
os.write(body.getBytes());
os.flush();
+18 -4
View File
@@ -1612,12 +1612,26 @@ public class Main extends JavaPlugin
input = input.trim();
// 如果包含code=参数,从中提取
if (input.contains("code=") || input.startsWith("http")) {
if (input.contains("code=") || input.startsWith("http") || input.contains("#")) {
try {
// 尝试解析URL中的query参数
// ★ 优先处理 #code= fragment形式(Microsoft公共客户端OAuth返回格式)
// URL如: https://login.live.com/oauth20_desktop.srf#code=M.C512_BAY.2_xxx
if (input.contains("#code=")) {
int hashIdx = input.indexOf("#code=");
String afterHash = input.substring(hashIdx + 6); // "#code=" 之后的内容
// code到下一个&或字符串结尾
int ampIdx = afterHash.indexOf('&');
String rawCode = ampIdx >= 0 ? afterHash.substring(0, ampIdx) : afterHash;
return java.net.URLDecoder.decode(rawCode, StandardCharsets.UTF_8);
}
// 尝试解析URL中的query参数 (?code=xxx)
int qIdx = input.indexOf('?');
if (qIdx >= 0) {
String query = input.substring(qIdx + 1);
// 去掉fragment部分
int hashQIdx = query.indexOf('#');
if (hashQIdx >= 0) query = query.substring(0, hashQIdx);
for (String param : query.split("&")) {
String[] kv = param.split("=", 2);
if (kv.length == 2 && kv[0].equals("code")) {
@@ -1626,11 +1640,11 @@ public class Main extends JavaPlugin
}
}
} catch (Exception e) {
// 解析失败,继续尝试其他方式
getLogger().warning("[正版验证] extractCodeFromInput解析异常: " + e.getMessage());
}
}
// 直接作为授权码返回
// 直接作为授权码返回(纯code)
return input;
}
+12 -2
View File
@@ -5162,7 +5162,14 @@ public class WebManager {
}
String sessionId = sessionData[0];
String secret = java.net.URLEncoder.encode(secretKey, StandardCharsets.UTF_8);
String secret = secretKey; // ★ 不再URLEncoder.encode,直接发送原始密钥
// ★ 调试日志:记录code提取结果
plugin.getLogger().info("[正版验证] /mscode 提交 - 玩家: " + playerName);
plugin.getLogger().info("[正版验证] sessionId: " + sessionId);
plugin.getLogger().info("[正版验证] code(前80字符): " + code.substring(0, Math.min(80, code.length())));
plugin.getLogger().info("[正版验证] code长度: " + code.length());
plugin.getLogger().info("[正版验证] secret: " + secret);
webExecutor.submit(() -> {
try {
@@ -5174,7 +5181,10 @@ public class WebManager {
postData.addProperty("code", code);
postData.addProperty("secret", secret);
String response = doPost(url, postData.toString());
String postBody = postData.toString();
plugin.getLogger().info("[正版验证] POST body(前200字符): " + postBody.substring(0, Math.min(200, postBody.length())));
String response = doPost(url, postBody);
if (response == null) {
player.sendMessage("§c无法连接Web后端");
return;