From 951d4e35c18ffc10e08791e81aea1f2db689bb46 Mon Sep 17 00:00:00 2001 From: Chayapak Supasakul Date: Mon, 21 Oct 2024 10:22:53 +0700 Subject: [PATCH] Support FNFBoyfriendBot Validation --- .../chipmunk/chipmunkmod/Configuration.java | 1 + .../chipmunkmod/commands/ValidateCommand.java | 3 +- .../util/BotValidationUtilities.java | 29 +++++++++++++++++++ src/main/resources/default_config.json | 1 + 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index e33fb4e..ada19a8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -26,6 +26,7 @@ public class Configuration { public BotInfo sbot = new BotInfo(":", null); public BotInfo chipmunk = new BotInfo("'", null); public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null); + public BotInfo fnfboyfriend = new BotInfo("~", null); public BotInfo kittycorp = new BotInfo("^", null); public TestBotInfo testbot = new TestBotInfo("-", null); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java index 806f4cf..2030015 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java @@ -18,10 +18,11 @@ public class ValidateCommand { .then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(getString(c, "command"))))) // .then(literal("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(getString(c, "command"))))) .then(literal("chomens").then(argument("command", greedyString()).executes(c -> { - c.getSource().sendFeedback(Text.literal("Warning: Manual ChomeNS Bot validation is deprecated")); + c.getSource().sendFeedback(Text.literal("Warning: Manual ChomeNS Bot validation is deprecated. Please use the completions from typing the bot's prefix.")); return chomens(getString(c, "command")); }))) + .then(literal("fnfboyfriend").then(argument("command", greedyString()).executes(c -> fnfboyfriend(getString(c, "command"))))) .then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(getString(c, "command"))))) ); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java index a5ebcb0..808cca7 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java @@ -115,6 +115,35 @@ public class BotValidationUtilities { return Command.SINGLE_SUCCESS; } + public static int fnfboyfriend (String command) { + try { + final String prefix = ChipmunkMod.CONFIG.bots.fnfboyfriend.prefix; + + String[] arguments = command.split(" "); + + long currentTime = System.currentTimeMillis() / 1000; + String input = currentTime + ChipmunkMod.CONFIG.bots.fnfboyfriend.key; + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] hash = digest.digest(input.getBytes()); + StringBuilder hexString = new StringBuilder(); + for (byte b : hash) { + String hex = Integer.toHexString(0xff & b); + if (hex.length() == 1) hexString.append('0'); + hexString.append(hex); + } + + final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length); + + final String result = hexString.substring(0, 16); + + Chat.sendChatMessage(prefix + arguments[0] + " " + result + " " + String.join(" ", restArguments)); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + + return Command.SINGLE_SUCCESS; + } + public static int kittycorp (String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp; final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); diff --git a/src/main/resources/default_config.json b/src/main/resources/default_config.json index 3ce37ff..86bff87 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -15,6 +15,7 @@ "sbot": { "prefix": ":", "key": null }, "chipmunk": { "prefix": "'", "key": null }, "chomens": { "prefix": "*", "key": null, "authKey": null, "formatKey": null }, + "fnfboyfriend": { "prefix": "~", "key": null }, "kittycorp": { "prefix": "^", "key": null }, "testbot": { "prefix": "-", "webhookUrl": null } },