diff --git a/build-number.txt b/build-number.txt index 7c43ea01..e39b4bbb 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -2672 \ No newline at end of file +2673 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/Bot.java b/src/main/java/me/chayapak1/chomens_bot/Bot.java index 2d2b3fb0..789c7271 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Bot.java +++ b/src/main/java/me/chayapak1/chomens_bot/Bot.java @@ -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); diff --git a/src/main/java/me/chayapak1/chomens_bot/Configuration.java b/src/main/java/me/chayapak1/chomens_bot/Configuration.java index 3ae51440..c405a385 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Configuration.java +++ b/src/main/java/me/chayapak1/chomens_bot/Configuration.java @@ -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; diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/FormatCheckerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/FormatCheckerPlugin.java deleted file mode 100644 index 9a00cccf..00000000 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/FormatCheckerPlugin.java +++ /dev/null @@ -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 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; - } -} diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 8327bbb4..b4137fc2 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -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