diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index ada19a8..8acf323 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -27,6 +27,7 @@ public class Configuration { public BotInfo chipmunk = new BotInfo("'", null); public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null); public BotInfo fnfboyfriend = new BotInfo("~", null); + public BotInfo nbot = 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 2030015..9923ea1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java @@ -23,6 +23,7 @@ public class ValidateCommand { return chomens(getString(c, "command")); }))) .then(literal("fnfboyfriend").then(argument("command", greedyString()).executes(c -> fnfboyfriend(getString(c, "command"))))) + .then(literal("nbot").then(argument("command", greedyString()).executes(c -> nbot(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 aa79138..12343b3 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/BotValidationUtilities.java @@ -11,6 +11,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import java.math.BigInteger; +import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -122,7 +123,9 @@ public class BotValidationUtilities { String[] arguments = command.split(" "); long currentTime = System.currentTimeMillis() / 1000; - String input = currentTime + ChipmunkMod.CONFIG.bots.fnfboyfriend.key; + final String key = ChipmunkMod.CONFIG.bots.fnfboyfriend.key; + if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?"); + String input = currentTime + key; MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(input.getBytes()); StringBuilder hexString = new StringBuilder(); @@ -144,6 +147,49 @@ public class BotValidationUtilities { return Command.SINGLE_SUCCESS; } + // !!! broken (for now) + public static int nbot (String command) throws RuntimeException { + final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.nbot; + + final MinecraftClient client = MinecraftClient.getInstance(); + + 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 { + String[] arguments = command.split(" "); + + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + String time = String.valueOf(System.currentTimeMillis() / 5_000); + String input = arguments[0].replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key; + + md.update(input.getBytes(StandardCharsets.UTF_8)); + + byte[] hash = md.digest(); + + long bigInt = ByteBuffer.wrap(new byte[] {0, 0, hash[0], hash[1], hash[2], hash[3], hash[4], hash[5]}).getLong(); + + String stringHash = Long.toUnsignedString(bigInt, 36).substring(0, 6); + + final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length); + + final String toSend = prefix + + arguments[0] + + " " + + stringHash + + " " + + String.join(" ", restArguments); + + Chat.sendChatMessage(toSend, true); + } 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 86bff87..85762f0 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -16,6 +16,7 @@ "chipmunk": { "prefix": "'", "key": null }, "chomens": { "prefix": "*", "key": null, "authKey": null, "formatKey": null }, "fnfboyfriend": { "prefix": "~", "key": null }, + "nbot": { "prefix": "?", "key": null }, "kittycorp": { "prefix": "^", "key": null }, "testbot": { "prefix": "-", "webhookUrl": null } },