@2026-07-05 00:30 Java修复: 1) N+1验证码核心修复-回答错误不再永久放行,玩家需持续答对才能验证通过 2) 验证码过期后仍需重新验证(不自动放行) 3) URL正则扩展支持_.混合格式如123_ypshidifu.cn 4) GUI验证码跳过聊天答案 5) 编译成功

This commit is contained in:
2026-07-05 00:35:11 +08:00
parent 8b147b2531
commit f18e7485c7
2 changed files with 21 additions and 13 deletions
@@ -124,10 +124,9 @@ public class ChatFilterManager {
verificationData.remove(name);
return VerificationResult.VERIFIED;
}
// 验证码是否过期
// 验证码是否过期 — 过期后自动放行,不无限卡玩家
if (vd.isExpired()) {
verificationData.remove(name);
// 过期后不再要求验证(避免玩家反复被卡)
verifiedPlayers.add(name);
return VerificationResult.VERIFIED;
}
@@ -397,17 +396,14 @@ public class ChatFilterManager {
if (ans == expected) {
vd.completed = true;
verificationData.remove(playerName);
verifiedPlayers.add(playerName); // 永久记录
verifiedPlayers.add(playerName); // 永久记录 - 验证通过
return VerificationResult.VERIFIED;
} else {
// ★ 关键修复:回答错误也永久放行,防止无限重试
verificationData.remove(playerName);
verifiedPlayers.add(playerName);
// ★ 回答错误 → 不清除验证码也不加入verifiedPlayers,让玩家重新答题
return VerificationResult.FAILED;
}
} catch (NumberFormatException e) {
verificationData.remove(playerName);
verifiedPlayers.add(playerName);
// 非数字答案 → 同样不放行,重新答题
return VerificationResult.FAILED;
}
}
@@ -537,7 +533,10 @@ public class ChatFilterManager {
+ "(?:[a-zA-Z0-9\\-]*"
+ "[a-zA-Z0-9])?\\.)+"
+ "[a-zA-Z]{2,})"
+ "(?:/\\S*)?");
+ "(?:/\\S*)?"
+ "|(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\\-]*[a-zA-Z0-9])?)[_.]"
+ "[a-zA-Z0-9](?:[a-zA-Z0-9\\-]*[a-zA-Z0-9])?)*[_.]"
+ "[a-zA-Z]{2,}");
private static final Pattern DOT_VARIANTS =
Pattern.compile(
"[\uff0e\u3002\u2025\u2026\u00b7]");
+13 -4
View File
@@ -2634,33 +2634,42 @@ public class Main extends JavaPlugin
// ★ 首次触发验证码 → 缓存消息, 拦截
chatFilter.cachePendingMessage(p.getName(), msg);
chatFilter.generateMathVerification(p.getName());
p.sendMessage("§e[验证码] 请先回答验证码才能发言");
e.setCancelled(true);
return;
}
if (vr == ChatFilterManager.VerificationResult.PENDING) {
// 验证进行中:当前聊天框输入就是答案
// ★ 如果是GUI验证码,跳过聊天答案
ChatFilterManager.VerificationData vd = chatFilter.verificationData.get(p.getName());
if (vd != null && vd.type == ChatFilterManager.VerificationType.GUI) {
// GUI验证码,聊天输入不算答案,拦截
e.setCancelled(true);
return;
}
ChatFilterManager.VerificationResult checkResult = chatFilter.checkAnswer(p.getName(), msg);
if (checkResult == ChatFilterManager.VerificationResult.VERIFIED) {
// ★ 答对了 → 释放所有缓存消息(N-1条) + 当前消息(第N条)
// ★ 答对了 → 释放所有缓存消息 + 当前消息
chatFilter.broadcastCachedMessages(p.getName());
Bukkit.broadcastMessage(p.getDisplayName() + ": " + msg);
p.sendMessage("§a§l[验证码] §a验证通过!");
e.setCancelled(true);
return;
} else if (checkResult == ChatFilterManager.VerificationResult.FAILED) {
// ★ 答错了 → 清除缓存(不泄露) + 重新出题
// ★ 答错了 → 清除缓存 + 重新出题(不加入verifiedPlayers)
chatFilter.clearPendingMessages(p.getName());
chatFilter.generateMathVerification(p.getName());
p.sendMessage("§c§l[验证码] §c回答错误,请重新回答");
e.setCancelled(true);
return;
}
// PENDING → GUI验证码,忽略聊天输入,消息保持缓存
// PENDING → 未识别的答案类型,拦截
e.setCancelled(true);
return;
}
// VERIFIED → 正常放行聊天
// VERIFIED → 正常放行聊天(但先检查URL)
}
// ===== 冻结检查 =====