Made debug mode better + fixed the anti-spam (I think)
This commit is contained in:
@@ -261,10 +261,10 @@ public class Action {
|
||||
.setColor(action.getEmbedColor());
|
||||
webhook.addEmbed(embed);
|
||||
try {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
ServerUtils.sendDebugMessage("ActionBuilder: Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage("ActionBuilder: Epic webhook failure!!!");
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class FilterAction {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException ex) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!");
|
||||
Sentinel.log.info(ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WebhookSender {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage("Epic webhook failure!!!");
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,25 +16,25 @@ public class ChatEvent implements Listener {
|
||||
@EventHandler
|
||||
public static void onChat(AsyncPlayerChatEvent e) {
|
||||
if (e.isCancelled()) return;
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Chat event detected!"));
|
||||
ServerUtils.sendDebugMessage("ChatEvent: Chat event detected!");
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiunicode.bypass")) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for unicode"));
|
||||
ServerUtils.sendDebugMessage("ChatEvent: Permission bypass failed, checking for unicode");
|
||||
if (Config.antiUnicode) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing unicode check!"));
|
||||
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing unicode check!"));
|
||||
AntiUnicode.handleAntiUnicode(e);
|
||||
}
|
||||
}
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiswear.bypass")) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for swears"));
|
||||
ServerUtils.sendDebugMessage("ChatEvent: Permission bypass failed, checking for swears");
|
||||
if (Config.antiSwearEnabled) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing swear check!"));
|
||||
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing swear check!"));
|
||||
ProfanityFilter.handleProfanityFilter(e);
|
||||
}
|
||||
}
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antispam.bypass")) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for spam"));
|
||||
ServerUtils.sendDebugMessage(("ChatEvent: Permission bypass failed, checking for spam"));
|
||||
if (Config.antiSpamEnabled) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing spam check!"));
|
||||
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing spam check!"));
|
||||
AntiSpam.handleAntiSpam(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ public class CommandEvent implements Listener {
|
||||
private void onCommand(PlayerCommandPreprocessEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String command = e.getMessage().substring(1).split(" ")[0];
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking command"));
|
||||
ServerUtils.sendDebugMessage("CommandEvent: Checking command");
|
||||
if (Sentinel.isDangerousCommand(command)) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix( "Command is dangerous"));
|
||||
ServerUtils.sendDebugMessage("CommandEvent: Command is dangerous");
|
||||
if (!Sentinel.isTrusted(p)) {
|
||||
e.setCancelled(true);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Command is canceled"));
|
||||
ServerUtils.sendDebugMessage("CommandEvent: Command is canceled");
|
||||
Action a = new Action.Builder()
|
||||
.setAction(ActionType.DANGEROUS_COMMAND)
|
||||
.setEvent(e)
|
||||
@@ -38,12 +38,12 @@ public class CommandEvent implements Listener {
|
||||
}
|
||||
}
|
||||
if (Config.blockSpecific) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking command for specific"));
|
||||
ServerUtils.sendDebugMessage("CommandEvent: Checking command for specific");
|
||||
if (command.contains(":")) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking is specific"));
|
||||
ServerUtils.sendDebugMessage("CommandEvent: Checking is specific");
|
||||
if (!Sentinel.isTrusted(p)) {
|
||||
e.setCancelled(true);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Command is canceled"));
|
||||
ServerUtils.sendDebugMessage(("CommandEvent: Command is canceled"));
|
||||
Action a = new Action.Builder()
|
||||
.setAction(ActionType.SPECIFIC_COMMAND)
|
||||
.setEvent(e)
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.FilterAction;
|
||||
import io.github.thetrouper.sentinel.server.util.GPTUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -19,23 +20,34 @@ public class AntiSpam {
|
||||
heatMap = new HashMap<>();
|
||||
lastMessageMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public static void handleAntiSpam(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
|
||||
if (!lastMessageMap.containsKey(p)) {
|
||||
lastMessageMap.put(p,"/* Placeholder Message from Sentinel */");
|
||||
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " did not have a previous message, setting to placeholder!");
|
||||
}
|
||||
if (!heatMap.containsKey(p)) {
|
||||
heatMap.put(p,0);
|
||||
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " did not have a heat, setting it to 0!");
|
||||
}
|
||||
|
||||
if (lastMessageMap.containsKey(p)) {
|
||||
String lastMessage = lastMessageMap.get(p);
|
||||
double similarity = GPTUtils.calcSim(message, lastMessage);
|
||||
if (similarity > 0.25) heatMap.put(p, heatMap.get(p) + Config.lowGain);
|
||||
if (similarity > 0.5) heatMap.put(p, heatMap.get(p) + Config.mediumGain);
|
||||
if (similarity > 0.9) heatMap.put(p, heatMap.get(p) + Config.highGain);
|
||||
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " has a heat of " + heatMap.get(p) + "/" + Config.punishHeat + ". Current Message: \"" + message + "\" Last message: \"" + lastMessage + "\"");
|
||||
if (similarity > 90) {
|
||||
heatMap.put(p, heatMap.get(p) + Config.highGain);
|
||||
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 90% for " + p.getName() + ". Adding " + Config.highGain);
|
||||
} else if (similarity > 50) {
|
||||
heatMap.put(p, heatMap.get(p) + Config.mediumGain);
|
||||
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 50% for " + p.getName() + ". Adding " + Config.mediumGain);
|
||||
} else if (similarity > 25) {
|
||||
heatMap.put(p, heatMap.get(p) + Config.lowGain);
|
||||
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 25% for " + p.getName() + ". Adding " + Config.lowGain);
|
||||
}
|
||||
}
|
||||
|
||||
if (heatMap.get(p) > Config.punishHeat) {
|
||||
@@ -59,6 +71,7 @@ public class AntiSpam {
|
||||
heat = heat - Config.heatDecay;
|
||||
heatMap.put(p, Math.max(0, heat));
|
||||
}
|
||||
//ServerUtils.sendDebugMessage("AntiSpam: Decaying heat for " + p.getName() + ": " + heatMap.get(p));
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -194,11 +194,11 @@ public class ProfanityFilter {
|
||||
public static String checkSeverity(String text) {
|
||||
// 1:
|
||||
String lowercasedText = text.toLowerCase();
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Lowercased: " + lowercasedText));
|
||||
ServerUtils.sendDebugMessage("ProfanityFilter: Lowercased: " + lowercasedText);
|
||||
|
||||
// 2:
|
||||
String cleanedText = removeFalsePositives(lowercasedText);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Removed False positives: " + cleanedText));
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed False positives: " + cleanedText));
|
||||
|
||||
// 3:
|
||||
if (containsSwears(cleanedText)) return "low";
|
||||
@@ -206,7 +206,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 4:
|
||||
String convertedText = convertLeetSpeakCharacters(cleanedText);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Leet Converted: " + convertedText));
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Leet Converted: " + convertedText));
|
||||
|
||||
// 5:
|
||||
if (containsSwears(convertedText)) return "medium-low";
|
||||
@@ -214,7 +214,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 6:
|
||||
String strippedText = stripSpecialCharacters(convertedText);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Specials Removed: " + strippedText));
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Specials Removed: " + strippedText));
|
||||
|
||||
// 7:
|
||||
if (containsSwears(strippedText)) return "medium";
|
||||
@@ -222,7 +222,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 8:
|
||||
String simplifiedText = simplifyRepeatingLetters(strippedText);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Removed Repeating: " + simplifiedText));
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed Repeating: " + simplifiedText));
|
||||
|
||||
// 9:
|
||||
if (containsSwears(simplifiedText)) return "medium-high";
|
||||
@@ -230,7 +230,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 10:
|
||||
String finalText = removePeriodsAndSpaces(simplifiedText);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Remove Punctuation: " + finalText));
|
||||
ServerUtils.sendDebugMessage(("ProfanityFilter: Remove Punctuation: " + finalText));
|
||||
|
||||
// 11:
|
||||
if (containsSwears(finalText)) return "high";
|
||||
@@ -244,14 +244,14 @@ public class ProfanityFilter {
|
||||
return containsSwears(text) || containsSlurs(text);
|
||||
}
|
||||
private static boolean containsSwears(String text) {
|
||||
ServerUtils.sendDebugMessage("Debug: [AntiSwear] Checking for swears");
|
||||
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for swears");
|
||||
for (String swear : swearBlacklist) {
|
||||
if (text.contains(swear)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static boolean containsSlurs(String text) {
|
||||
ServerUtils.sendDebugMessage("Debug: [AntiSwear] Checking for slurs");
|
||||
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for slurs");
|
||||
for (String slur : slurs) {
|
||||
if (text.contains(slur)) return true;
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ public class ReportFalsePositives {
|
||||
public static String generateReport(AsyncPlayerChatEvent e) {
|
||||
final long reportLong = Randomizer.generateID();
|
||||
final String reportID = Long.toString(reportLong);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Generating chat filter report"));
|
||||
ServerUtils.sendDebugMessage("FP Report: Generating chat filter report");
|
||||
reportMap.put(reportID,e);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Generated chat filter report. ID:" + reportID + " Message: \"" + reportMap.get(reportID).getMessage() + "\" Expires in 60 seconds"));
|
||||
ServerUtils.sendDebugMessage(("FP Report: Generated chat filter report. ID:" + reportID + " Message: \"" + reportMap.get(reportID).getMessage() + "\" Expires in 60 seconds"));
|
||||
Bukkit.getScheduler().runTaskLater(Sentinel.getInstance(),()->{
|
||||
reportMap.remove(reportID);
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Chat filter Report expired. ID: " + reportID));
|
||||
ServerUtils.sendDebugMessage("FP Report: Chat filter Report expired. ID: " + reportID);
|
||||
},60000);
|
||||
return reportID;
|
||||
}
|
||||
@@ -75,10 +75,10 @@ public class ReportFalsePositives {
|
||||
.setThumbnail("https://crafatar.com/avatars/" + player.getUniqueId() + "?size=64&&overlay");
|
||||
webhook.addEmbed(embed);
|
||||
try {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
ServerUtils.sendDebugMessage("FP Report: Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage("FP Report: Epic webhook failure!!!");
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ public class ServerUtils {
|
||||
}
|
||||
public static void sendDebugMessage(String message) {
|
||||
if (SentinelCommand.debugmode) {
|
||||
Sentinel.log.info(message);
|
||||
String log = "[Sentinel] [DEBUG]: " + message;
|
||||
Sentinel.log.info(log);
|
||||
for (Player trustedPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (Sentinel.isTrusted(trustedPlayer)) {
|
||||
trustedPlayer.sendMessage(message);
|
||||
trustedPlayer.sendMessage("§d§lSentinel §7[§bDEBUG§7] §8» §7" + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user