Add ubot dev instance authentication + fixes to Hbot
This commit is contained in:
parent
30bb635411
commit
2a5c2c2718
4 changed files with 28 additions and 1 deletions
|
@ -25,6 +25,7 @@ public class Configuration {
|
||||||
public BotInfo hbot = new BotInfo("#", null);
|
public BotInfo hbot = new BotInfo("#", null);
|
||||||
public BotInfo sbot = new BotInfo(":", null);
|
public BotInfo sbot = new BotInfo(":", null);
|
||||||
public BotInfo ubot = new BotInfo("\"", null);
|
public BotInfo ubot = new BotInfo("\"", null);
|
||||||
|
public BotInfo ubotdev = new BotInfo("d\"", null);
|
||||||
public BotInfo chipmunk = new BotInfo("'", null);
|
public BotInfo chipmunk = new BotInfo("'", null);
|
||||||
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null);
|
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null);
|
||||||
public BotInfo kittycorp = new BotInfo("^", null);
|
public BotInfo kittycorp = new BotInfo("^", null);
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class ValidateCommand {
|
||||||
literal("validate")
|
literal("validate")
|
||||||
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))
|
.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("ubot").then(argument("command", greedyString()).executes(c -> ubot(getString(c, "command")))))
|
||||||
|
.then(literal("ubotdev").then(argument("command", greedyString()).executes(c -> ubotdev(getString(c, "command")))))
|
||||||
.then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(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("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(getString(c, "command")))))
|
||||||
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> {
|
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class BotValidationUtilities {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||||
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
String time = String.valueOf(System.currentTimeMillis() / 10000);
|
||||||
String input = prefix + command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getUuidAsString() + ";" + time + ";" + key;
|
String input = prefix + command.replaceAll("&[0-9a-fklmnor]", "") + ";" + client.player.getName() + ";" + time + ";" + key;
|
||||||
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||||
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
BigInteger bigInt = new BigInteger(1, Arrays.copyOfRange(hash, 0, 4));
|
||||||
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
String stringHash = bigInt.toString(Character.MAX_RADIX);
|
||||||
|
@ -66,6 +66,30 @@ public class BotValidationUtilities {
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int ubotdev (String command) throws RuntimeException {
|
||||||
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.ubotdev;
|
||||||
|
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 + ":" + client.player.getUuidAsString() + ":" + 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 {
|
public static int sbot (String command) throws RuntimeException {
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot;
|
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.sbot;
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"hbot": { "prefix": "#", "key": null },
|
"hbot": { "prefix": "#", "key": null },
|
||||||
"sbot": { "prefix": ":", "key": null },
|
"sbot": { "prefix": ":", "key": null },
|
||||||
"ubot": { "prefix": "\"", "key": null },
|
"ubot": { "prefix": "\"", "key": null },
|
||||||
|
"ubotdev": { "prefix": "\"", "key": null },
|
||||||
"chipmunk": { "prefix": "'", "key": null },
|
"chipmunk": { "prefix": "'", "key": null },
|
||||||
"kittycorp": { "prefix": "^", "key": null },
|
"kittycorp": { "prefix": "^", "key": null },
|
||||||
"testbot": { "prefix": "-", "webhookUrl": null }
|
"testbot": { "prefix": "-", "webhookUrl": null }
|
||||||
|
|
Loading…
Reference in a new issue