custom chat format checker
to stop yfd impostering
This commit is contained in:
parent
375bde4895
commit
36afeba760
7 changed files with 87 additions and 16 deletions
|
@ -78,6 +78,7 @@ public class Bot {
|
|||
public WorldPlugin world;
|
||||
public AuthPlugin auth;
|
||||
public ScreensharePlugin screenshare;
|
||||
public FormatCheckerPlugin formatChecker;
|
||||
|
||||
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
|
||||
this.host = botOption.host;
|
||||
|
@ -127,6 +128,7 @@ public class Bot {
|
|||
this.world = new WorldPlugin(this);
|
||||
this.auth = new AuthPlugin(this);
|
||||
// this.screenshare = new ScreensharePlugin(this);
|
||||
this.formatChecker = new FormatCheckerPlugin(this);
|
||||
|
||||
for (Listener listener : listeners) listener.loadedPlugins();
|
||||
|
||||
|
|
|
@ -27,14 +27,20 @@ public class Configuration {
|
|||
|
||||
public String ownerName = "chayapak"; // mabe mabe
|
||||
|
||||
public ImposterFormatChecker imposterFormatChecker = new ImposterFormatChecker();
|
||||
|
||||
public OwnerAuthentication ownerAuthentication = new OwnerAuthentication();
|
||||
|
||||
public List<String> trusted = new ArrayList<>();
|
||||
public SelfCare selfCare = new SelfCare();
|
||||
public Eval eval = new Eval();
|
||||
|
||||
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 String key = "";
|
||||
|
@ -137,10 +143,6 @@ public class Configuration {
|
|||
public boolean username = true;
|
||||
}
|
||||
|
||||
public static class Eval {
|
||||
public String address = "ws://localhost:3069";
|
||||
}
|
||||
|
||||
public static class BotOption {
|
||||
public String host;
|
||||
public int port;
|
||||
|
|
|
@ -34,8 +34,8 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
|||
bot.players.addListener(this);
|
||||
bot.chat.addListener(new ChatPlugin.Listener() {
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {
|
||||
AuthPlugin.this.systemMessageReceived(component, isCommandSuggestions, isAuth);
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
AuthPlugin.this.systemMessageReceived(component, isCommandSuggestions, isAuth, isImposterFormat);
|
||||
}
|
||||
});
|
||||
bot.executor.scheduleAtFixedRate(this::check, 0, 1, TimeUnit.SECONDS);
|
||||
|
@ -83,9 +83,9 @@ public class AuthPlugin extends PlayersPlugin.Listener {
|
|||
started = false;
|
||||
}
|
||||
|
||||
private void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth) {
|
||||
private void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat) {
|
||||
try {
|
||||
if (isCommandSuggestions || !isAuth) return;
|
||||
if (isCommandSuggestions || !isAuth || !isImposterFormat) return;
|
||||
|
||||
final List<Component> children = component.children();
|
||||
|
||||
|
|
|
@ -100,12 +100,14 @@ public class ChatPlugin extends Bot.Listener {
|
|||
else if (id.equals(bot.auth.id)) isAuth = true;
|
||||
}
|
||||
|
||||
final boolean isImposterFormat = bot.formatChecker.isImposterFormat(component);
|
||||
|
||||
final String string = ComponentUtilities.stringify(component);
|
||||
final String ansi = ComponentUtilities.stringifyAnsi(component);
|
||||
|
||||
for (Listener listener : listeners) {
|
||||
if (!isCommandSuggestions && !isAuth) listener.systemMessageReceived(component, string, ansi);
|
||||
listener.systemMessageReceived(component, isCommandSuggestions, isAuth, string, ansi);
|
||||
if (!isCommandSuggestions && !isAuth && !isImposterFormat) listener.systemMessageReceived(component, string, ansi);
|
||||
listener.systemMessageReceived(component, isCommandSuggestions, isAuth, isImposterFormat, string, ansi);
|
||||
|
||||
if (playerMessage != null) listener.playerMessageReceived(playerMessage);
|
||||
}
|
||||
|
@ -365,6 +367,6 @@ public class ChatPlugin extends Bot.Listener {
|
|||
public static class Listener {
|
||||
public void playerMessageReceived (PlayerMessage message) {}
|
||||
public void systemMessageReceived (Component component, String string, String ansi) {}
|
||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {}
|
||||
public void systemMessageReceived (Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class CommandSuggestionPlugin extends ChatPlugin.Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, String string, String ansi) {
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
if (!isCommandSuggestions) return;
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class FormatCheckerPlugin extends ChatPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public FormatCheckerPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.chat.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemMessageReceived(Component component, boolean isCommandSuggestions, boolean isAuth, boolean isImposterFormat, String string, String ansi) {
|
||||
if (!isImposterFormat) return;
|
||||
|
||||
bot.chat.tellraw(Component.text("fake chomens custom chat .,.,.,.,"));
|
||||
}
|
||||
|
||||
public boolean isImposterFormat (Component component) {
|
||||
if (!(component instanceof TranslatableComponent format)) return false;
|
||||
|
||||
final List<Component> args = format.args();
|
||||
if (args.size() < 3 || !format.key().equals("[%s] %s › %s")) return false;
|
||||
|
||||
final Component nameComponent = format.args().get(1);
|
||||
|
||||
if (!(nameComponent instanceof TextComponent)) return false;
|
||||
|
||||
final String name = ((TextComponent) nameComponent).content();
|
||||
|
||||
if (!name.equals(bot.config.ownerName)) return false;
|
||||
|
||||
final Component prefix = format.args().get(0);
|
||||
|
||||
if (!(prefix instanceof TranslatableComponent translatablePrefix)) return true;
|
||||
|
||||
final Component userHash = translatablePrefix.args().get(0);
|
||||
|
||||
if (userHash == null) return true;
|
||||
|
||||
if (!(userHash instanceof TextComponent userHashComponent)) return true;
|
||||
|
||||
final long time = System.currentTimeMillis() / 10_000;
|
||||
|
||||
final String key = bot.config.imposterFormatChecker.key;
|
||||
|
||||
final String hash = Hashing.sha256()
|
||||
// very pro hash input
|
||||
.hashString(key + key + time + time, StandardCharsets.UTF_8)
|
||||
.toString()
|
||||
.substring(0, 8);
|
||||
|
||||
return !hash.equals(userHashComponent.content());
|
||||
}
|
||||
}
|
|
@ -51,6 +51,10 @@ colorPalette:
|
|||
|
||||
ownerName: 'chayapak' # currently this is only used in the console
|
||||
|
||||
imposterFormatChecker:
|
||||
enabled: false
|
||||
key: ''
|
||||
|
||||
ownerAuthentication:
|
||||
enabled: false
|
||||
key: ''
|
||||
|
@ -106,9 +110,6 @@ selfCare:
|
|||
prefix: '&8[&eChomeNS Bot&8]'
|
||||
username: true # MIGHT cause problem(s) if set to false (not tested,.,.)
|
||||
|
||||
eval:
|
||||
address: 'ws://localhost:3069'
|
||||
|
||||
bots:
|
||||
# username - optional, if not specified it will just use a random username
|
||||
# creayun - defaults to false
|
||||
|
|
Loading…
Reference in a new issue