NBot hashing (BROKEN !!!!!!!!)
This commit is contained in:
parent
2dd7443d4c
commit
fa7a41cecd
4 changed files with 50 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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")))))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 }
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue