diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index e33fb4e..6c7c45a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -24,6 +24,7 @@ public class Configuration { public static class Bots { public BotInfo hbot = new BotInfo("#", null); public BotInfo sbot = new BotInfo(":", null); + public BotInfo ubot = new BotInfo("\"", null); public BotInfo chipmunk = new BotInfo("'", null); public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null); public BotInfo kittycorp = new BotInfo("^", 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..a24e859 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java @@ -15,6 +15,7 @@ public class ValidateCommand { dispatcher.register( literal("validate") .then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command"))))) + .then(literal("ubot").then(argument("command", greedyString()).executes(c -> ubot(getString(c, "command"))))) .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 -> { diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java index a5ebcb0..070659f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java @@ -42,6 +42,30 @@ public class BotValidationUtilities { return Command.SINGLE_SUCCESS; } + public static int ubot (String command) throws RuntimeException { + final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.ubot; + final MinecraftClient client = MinecraftClient.getInstance(); + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + final String prefix = info.prefix; + final String key = info.key; + if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + + try { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + String time = String.valueOf(System.currentTimeMillis() / 10000); + String input = "babyboom:" + key + ":" + command.replaceAll("&[0-9a-fklmnor]", "") + ":" + time; + byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); + String stringHash = Hexadecimal.encode(hash); + + Chat.sendChatMessage(prefix + command + " " + stringHash, true); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + + return Command.SINGLE_SUCCESS; + } + public static int sbot (String command) throws RuntimeException { final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot; final MinecraftClient client = MinecraftClient.getInstance(); diff --git a/src/main/resources/default_config.json b/src/main/resources/default_config.json index 42052ad..dd74894 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -14,7 +14,6 @@ "hbot": { "prefix": "#", "key": null }, "sbot": { "prefix": ":", "key": null }, "ubot": { "prefix": "\"", "key": null }, - "ubotdev": { "prefix": "\"", "key": null }, "chipmunk": { "prefix": "'", "key": null }, "kittycorp": { "prefix": "^", "key": null }, "testbot": { "prefix": "-", "webhookUrl": null }