第65批修复:积分记录缺失/敏感词叠词绕过/规则开关同步覆盖/提示文案泄露
Check Source / check (push) Successful in 6s
Auto Release / build (push) Successful in 3m24s
Simple Test / test (push) Successful in 2s
Test Env / test (push) Successful in 3s

- CreditManager.addScore:新增 insertScoreRecord,每次积分变动写入 credit_records(source=game, status=approved),修复 PHP 端看不到违规扣分/登录恢复记录(#336)
- ChatFilterManager.checkSensitiveWords:归一化扩展反引号/中点号/波浪线 + 叠词压缩(ssbb→sb),修复 cm/s·b/ssbb 绕过(#339)
- CreditManager.syncCreditRulesFromPhp:enabled 以本地为准不从 PHP 覆盖,修复 PHP 端 chat_penalty 默认 enabled=0 覆盖 Java 端启用状态→后续违规不扣分(#341)
- Main.java 敏感词拦截:简化为单条中性消息,不泄露命中词/次数/处罚档位(#338)
- admin.php 规则列表:min_score=0 显示低于0分触发而非登录/聊天触发(#340)
This commit is contained in:
youpaishidifu
2026-10-30 18:03:08 +08:00
parent c1cf152e75
commit 9743040d9e
3 changed files with 77 additions and 17 deletions
@@ -1876,8 +1876,20 @@ public class ChatFilterManager {
if (msg == null || msg.isEmpty() || sensitiveWords.isEmpty()) if (msg == null || msg.isEmpty() || sensitiveWords.isEmpty())
return Collections.emptyList(); return Collections.emptyList();
String lower = msg.toLowerCase(); String lower = msg.toLowerCase();
// 归一化:去分隔符,用于捕获 "s.b"/"s b" 等变体 // ★ 第65批修复(#339):归一化扩展 + 叠词压缩
String normalized = lower.replaceAll("[\\s.\\-*_/\\\\]", ""); // 分隔符:空格、点号、连字符、星号、下划线、斜杠、反斜杠、反引号、中点号、波浪线
// "c`n`m" → "cnm", "s·b" → "sb", "s~b" → "sb"
String normalized = lower.replaceAll("[\\s.\\-*_/\\\\`·~]", "");
// ★ 叠词压缩:连续重复字母 → 单字母
// "ssbb" → "sb", "ccnnmm" → "cm", "sssb" → "sb"
// 逐字符扫描:同字母连续出现则跳过
StringBuilder compressed = new StringBuilder();
for (int i = 0; i < normalized.length(); i++) {
char c = normalized.charAt(i);
if (i > 0 && c == normalized.charAt(i - 1)) continue; // 跳过重复字母
compressed.append(c);
}
String compact = compressed.toString();
List<String> matched = new ArrayList<>(); List<String> matched = new ArrayList<>();
for (String sw : sensitiveWords) { for (String sw : sensitiveWords) {
if (sw.isEmpty()) continue; if (sw.isEmpty()) continue;
@@ -1886,14 +1898,15 @@ public class ChatFilterManager {
// 归一化后 "sb你" → "sb" 后跟中文(非 a-z)→ 匹配;"isbad" → "sb" 前后都是 a-z → 不匹配 // 归一化后 "sb你" → "sb" 后跟中文(非 a-z)→ 匹配;"isbad" → "sb" 前后都是 a-z → 不匹配
java.util.regex.Pattern p = java.util.regex.Pattern.compile( java.util.regex.Pattern p = java.util.regex.Pattern.compile(
"(?<![a-z])" + java.util.regex.Pattern.quote(sw) + "(?![a-z])"); "(?<![a-z])" + java.util.regex.Pattern.quote(sw) + "(?![a-z])");
if (p.matcher(normalized).find()) { if (p.matcher(normalized).find() || p.matcher(compact).find()) {
matched.add(sw); matched.add(sw);
} }
} else { } else {
// 长词或中文词:原文和归一化文本各查一次 // 长词或中文词:原文、归一化文本、压缩文本各查一次
// 原文查:保持原有行为("fuck you" 直接含 "fuck") // 原文查:保持原有行为("fuck you" 直接含 "fuck")
// 归一化查:捕获 "s.h.i.t" → "shit" 等分隔符变体 // 归一化查:捕获 "s.h.i.t" → "shit" 等分隔符变体
if (lower.contains(sw) || normalized.contains(sw)) { // 压缩查:捕获 "shhhiitt" → "shit" 等叠词变体
if (lower.contains(sw) || normalized.contains(sw) || compact.contains(sw)) {
matched.add(sw); matched.add(sw);
} }
} }
+55 -1
View File
@@ -266,6 +266,9 @@ public class CreditManager {
public void addScore(String playerName, double amount, String reason) { public void addScore(String playerName, double amount, String reason) {
double current = getScore(playerName); double current = getScore(playerName);
setScore(playerName, current + amount); setScore(playerName, current + amount);
// ★ 第65批修复(#336):每次积分变动都写入 credit_records,确保 PHP 端能看到完整记录
// 之前只有 UPDATE users 表,PHP 同步时查不到记录,导致违规扣分/登录恢复等记录缺失
insertScoreRecord(playerName, amount, reason);
plugin.getLogger().info("[信誉积分] " + playerName + " 积分变动: " plugin.getLogger().info("[信誉积分] " + playerName + " 积分变动: "
+ (amount > 0 ? "+" : "") + formatScore(amount) + " (" + reason + ")"); + (amount > 0 ? "+" : "") + formatScore(amount) + " (" + reason + ")");
// ★ 第64批修复(#335):积分变动后异步推送 PHP,避免 PHP 端长时间显示旧值 // ★ 第64批修复(#335):积分变动后异步推送 PHP,避免 PHP 端长时间显示旧值
@@ -273,6 +276,40 @@ public class CreditManager {
triggerCreditPushToPhpDebounced(); triggerCreditPushToPhpDebounced();
} }
/**
* ★ 第65批修复(#336):写入积分变动记录到 credit_records
* 自动触发的积分变动(违规扣分/登录恢复/管理员调整)都记录在此
* status='approved'(系统自动操作,无需审核)
* source='game'(来自游戏内,区别于 PHP 端上报)
*/
private void insertScoreRecord(String playerName, double amount, String reason) {
try {
// 根据 reason 推导 type(用于 PHP 端分类展示)
String type;
if (reason.contains("聊天违规")) {
type = "chat_penalty";
} else if (reason.contains("登录恢复")) {
type = "login_restore";
} else if (reason.contains("管理员") || reason.contains("调整")) {
type = "admin_adjust";
} else {
type = "system_adjust";
}
PreparedStatement ps = db.getConnection().prepareStatement(
"INSERT INTO credit_records (target_player, reporter_player, type, content, status, score_change, created_at, source) "
+ "VALUES (?, NULL, ?, ?, 'approved', ?, ?, 'game')");
ps.setString(1, playerName);
ps.setString(2, type);
ps.setString(3, reason);
ps.setDouble(4, amount);
ps.setString(5, java.time.LocalDateTime.now().toString());
ps.executeUpdate();
ps.close();
} catch (Exception e) {
plugin.getLogger().warning("[信誉积分] 写入积分记录失败: " + e.getMessage());
}
}
/** 兼容旧调用:int 版本的 addScore */ /** 兼容旧调用:int 版本的 addScore */
public void addScore(String playerName, int amount, String reason) { public void addScore(String playerName, int amount, String reason) {
addScore(playerName, (double) amount, reason); addScore(playerName, (double) amount, reason);
@@ -2217,6 +2254,23 @@ public class CreditManager {
String description = rule.has("description") ? rule.get("description").getAsString() : ""; String description = rule.has("description") ? rule.get("description").getAsString() : "";
// ★ 按 rule_name 匹配(UNIQUE 列),id 跨库不一致不能用作匹配键 // ★ 按 rule_name 匹配(UNIQUE 列),id 跨库不一致不能用作匹配键
// ★ 第65批修复(#341):enabled 以本地为准,不从 PHP 覆盖
// 原因:PHP 端 chat_penalty 默认 enabled=0,管理员在 Java 端 GUI 启用后,
// PHP 同步时把 enabled=0 写回 → 规则被禁用 → 后续违规不再扣分
// → 参数(阈值/限额/倍数/amount/描述)跨端同步,开关各端独立管理
int localEnabled = rule.has("enabled") ? rule.get("enabled").getAsInt() : 0;
// 先查本地当前 enabled 值
int localEnabledNow = 0;
try {
PreparedStatement qs = db.getConnection().prepareStatement(
"SELECT enabled FROM credit_rules WHERE rule_name = ?");
qs.setString(1, ruleName);
ResultSet qrs = qs.executeQuery();
if (qrs.next()) localEnabledNow = qrs.getInt("enabled");
qs.close();
} catch (Exception ignored) {}
// 本地有记录 → 保留本地 enabled;本地无记录 → 用 PHP 的 enabled
int useEnabled = localEnabledNow != 0 ? localEnabledNow : localEnabled;
PreparedStatement ps = db.getConnection().prepareStatement( PreparedStatement ps = db.getConnection().prepareStatement(
"UPDATE credit_rules SET min_score = ?, max_score = ?, " "UPDATE credit_rules SET min_score = ?, max_score = ?, "
+ "restriction_type = ?, enabled = ?, description = ?, limit_amount = ?, multiplier = ?, amount = ? " + "restriction_type = ?, enabled = ?, description = ?, limit_amount = ?, multiplier = ?, amount = ? "
@@ -2224,7 +2278,7 @@ public class CreditManager {
ps.setInt(1, minScore); ps.setInt(1, minScore);
ps.setInt(2, maxScore); ps.setInt(2, maxScore);
ps.setString(3, restrictionType); ps.setString(3, restrictionType);
ps.setInt(4, enabled); ps.setInt(4, useEnabled);
ps.setString(5, description); ps.setString(5, description);
ps.setDouble(6, limitAmount); ps.setDouble(6, limitAmount);
ps.setDouble(7, multiplier); ps.setDouble(7, multiplier);
+4 -11
View File
@@ -6534,17 +6534,10 @@ public class Main extends JavaPlugin
} }
chatFilter.incrementViolation(p.getName()); chatFilter.incrementViolation(p.getName());
int sc = chatFilter.getViolationCount(p.getName()); int sc = chatFilter.getViolationCount(p.getName());
// ★ 2026-10-08:命中必须给发送者明确反馈——此前 warn 档完全静默、 // ★ 第65批修复(#338):最小信息泄露——不告诉玩家命中的敏感词、
// 自回显又与正常聊天一模一样 →观感「中文敏感词没过滤」 // 累计次数、处罚档位。只告知消息被拦截,避免被用作绕过探测工具。
getLogger().info("[Sdf1_chat] " + p.getName() + " 命中敏感词(" getLogger().info("[Sdf1_chat] " + p.getName() + " 命中敏感词,累计违规 " + sc + " 次,消息已拦截");
+ ms.get(0) + "),累计违规 " + sc + " 次,消息已拦截"); p.sendMessage("§c§l[聊天过滤] §7你的消息包含违规内容,已被拦截");
p.sendMessage("§c§l[聊天过滤] §7消息包含违规词 §f" + ms.get(0)
+ " §7已被拦截,§8本次为第 " + sc + " 次违规");
String punishHint = chatFilter.nextPunishHint(sc);
if (punishHint != null) {
// ★ 只报处罚档位,不报「第N次」——与上一行的次数并列易被读成跳号
p.sendMessage("§8再次违规将处罚: §e" + punishHint);
}
String swReason = "说出敏感词(" String swReason = "说出敏感词("
+ ms.get(0) + ")"; + ms.get(0) + ")";
String ptype = chatFilter.applyPunishment( String ptype = chatFilter.applyPunishment(