refactor: remove imposter format checker since it's pretty much useless these days, and it's also disabled in the main instance
This commit is contained in:
@@ -1 +1 @@
|
||||
2672
|
||||
2673
|
||||
@@ -110,7 +110,6 @@ public class Bot extends SessionAdapter {
|
||||
public final ChomeNSModIntegrationPlugin chomeNSMod;
|
||||
public final AuthPlugin auth;
|
||||
public final ScreensharePlugin screenshare = null;
|
||||
public final FormatCheckerPlugin formatChecker;
|
||||
public final ClearChatNameAnnouncerPlugin clearChatNameAnnouncer;
|
||||
public final WhitelistPlugin whitelist;
|
||||
public final PlayersDatabasePlugin playersDatabase;
|
||||
@@ -167,7 +166,6 @@ public class Bot extends SessionAdapter {
|
||||
this.chomeNSMod = new ChomeNSModIntegrationPlugin(this);
|
||||
this.auth = new AuthPlugin(this);
|
||||
// this.screenshare = new ScreensharePlugin(this);
|
||||
this.formatChecker = new FormatCheckerPlugin(this);
|
||||
this.clearChatNameAnnouncer = new ClearChatNameAnnouncerPlugin(this);
|
||||
this.whitelist = new WhitelistPlugin(this);
|
||||
this.playersDatabase = new PlayersDatabasePlugin(this);
|
||||
|
||||
@@ -36,8 +36,6 @@ public class Configuration {
|
||||
|
||||
public String consoleChatFormat = "{\"translate\":\"chat.type.text\",\"with\":[\"OWNER_NAME\",\"MESSAGE\"]}";
|
||||
|
||||
public ImposterFormatChecker imposterFormatChecker = new ImposterFormatChecker();
|
||||
|
||||
public OwnerAuthentication ownerAuthentication = new OwnerAuthentication();
|
||||
|
||||
public boolean announceClearChatUsername = false;
|
||||
@@ -47,11 +45,6 @@ public class Configuration {
|
||||
|
||||
public BotOption[] bots = new BotOption[] {};
|
||||
|
||||
public static class ImposterFormatChecker {
|
||||
public boolean enabled = false;
|
||||
public String key;
|
||||
}
|
||||
|
||||
public static class OwnerAuthentication {
|
||||
public boolean enabled = false;
|
||||
public int timeout = 10 * 1000;
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package me.chayapak1.chomens_bot.plugins;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.Main;
|
||||
import me.chayapak1.chomens_bot.data.player.PlayerEntry;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class FormatCheckerPlugin implements ChatPlugin.Listener, PlayersPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private int totalFormat = 0;
|
||||
|
||||
public FormatCheckerPlugin (final Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.chat.addListener(this);
|
||||
bot.players.addListener(this);
|
||||
}
|
||||
|
||||
private void reset (final PlayerEntry entry) {
|
||||
if (!entry.profile.getName().equals(bot.config.ownerName)) return;
|
||||
|
||||
totalFormat = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerJoined (final PlayerEntry target) {
|
||||
reset(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerLeft (final PlayerEntry target) {
|
||||
reset(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean systemMessageReceived (final Component component, final String string, final String ansi) {
|
||||
if (!isImposterFormat(component)) return true;
|
||||
|
||||
bot.chat.tellraw(Component.text("Possible fake ChomeNS custom chat").style(Style.style(TextDecoration.ITALIC)).color(NamedTextColor.GRAY));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isImposterFormat (final Component component) {
|
||||
if (!bot.config.imposterFormatChecker.enabled) return false;
|
||||
|
||||
if (!(component instanceof final TranslatableComponent format)) return false;
|
||||
|
||||
final List<TranslationArgument> args = format.arguments();
|
||||
if (args.size() < 3 || !format.key().equals("[%s] %s › %s")) return false;
|
||||
|
||||
final Object nameComponent = format.arguments().get(1).value();
|
||||
|
||||
if (!(nameComponent instanceof TextComponent)) return false;
|
||||
|
||||
final String name = ((TextComponent) nameComponent).content();
|
||||
|
||||
if (!name.equals(bot.config.ownerName)) return false;
|
||||
|
||||
final Object prefix = format.arguments().getFirst().value();
|
||||
|
||||
if (
|
||||
((prefix instanceof final TextComponent text) && text.content().equals(bot.username + " Console")) || // ohio
|
||||
(Main.discord != null && prefix.equals(Main.discord.messagePrefix))
|
||||
) return false;
|
||||
|
||||
if (!(prefix instanceof final TranslatableComponent translatablePrefix)) return true;
|
||||
|
||||
final Object userHash = translatablePrefix.arguments().getFirst().value();
|
||||
|
||||
if (!(userHash instanceof final TextComponent userHashComponent)) return true;
|
||||
|
||||
final String key = bot.config.imposterFormatChecker.key;
|
||||
|
||||
final String hash = Hashing.sha256()
|
||||
// very pro hash input
|
||||
.hashString(key + totalFormat, StandardCharsets.UTF_8)
|
||||
.toString()
|
||||
.substring(0, 8);
|
||||
|
||||
final boolean correct = hash.equals(userHashComponent.content());
|
||||
|
||||
if (correct) totalFormat++;
|
||||
|
||||
return !correct;
|
||||
}
|
||||
}
|
||||
@@ -82,10 +82,6 @@ ownerName: 'XxChange_mexX'
|
||||
|
||||
consoleChatFormat: '{"translate":"chat.type.text","with":["OWNER_NAME","MESSAGE"]}'
|
||||
|
||||
imposterFormatChecker:
|
||||
enabled: false
|
||||
key: ''
|
||||
|
||||
ownerAuthentication:
|
||||
enabled: false
|
||||
timeout: 10000 # 10 seconds - 10 * 1000
|
||||
|
||||
Reference in New Issue
Block a user