forked from ChomeNS/chipmunkmod
chomens auth i forgor to commit
i made this since yesterday and modified it a bit today few hours ago but forgor to commit 💀
This commit is contained in:
parent
4e07c1083a
commit
d987be251f
5 changed files with 95 additions and 4 deletions
|
@ -25,11 +25,23 @@ 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 chipmunk = new BotInfo("'", null);
|
public BotInfo chipmunk = new BotInfo("'", null);
|
||||||
public BotInfo chomens = new BotInfo("*", null);
|
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null);
|
||||||
public BotInfo kittycorp = new BotInfo("^", null);
|
public BotInfo kittycorp = new BotInfo("^", null);
|
||||||
public TestBotInfo testbot = new TestBotInfo("-", null);
|
public TestBotInfo testbot = new TestBotInfo("-", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ChomeNSBotInfo {
|
||||||
|
public String prefix;
|
||||||
|
public String key;
|
||||||
|
public String authKey;
|
||||||
|
|
||||||
|
public ChomeNSBotInfo (String prefix, String key, String authKey) {
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.key = key;
|
||||||
|
this.authKey = authKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestBotInfo {
|
public static class TestBotInfo {
|
||||||
public String prefix;
|
public String prefix;
|
||||||
public String webhookUrl;
|
public String webhookUrl;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
SongPlayer.INSTANCE.coreReady();
|
SongPlayer.INSTANCE.coreReady();
|
||||||
RainbowName.INSTANCE.init();
|
RainbowName.INSTANCE.init();
|
||||||
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
||||||
|
ChomeNSAuth.INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
|
||||||
|
@ -78,7 +79,10 @@ public class ClientPlayNetworkHandlerMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (((TextComponent) message.asComponent().children().get(0)).content().equals(ChomeNSBotCommandSuggestions.ID)) {
|
final TextComponent suggestionId = ((TextComponent) message.asComponent().children().get(0));
|
||||||
|
final TextComponent authId = (TextComponent) message.asComponent();
|
||||||
|
|
||||||
|
if (suggestionId.content().equals(ChomeNSBotCommandSuggestions.ID) || authId.content().equals(ChomeNSAuth.INSTANCE.id)) {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package land.chipmunk.chipmunkmod.modules;
|
||||||
|
|
||||||
|
import com.google.common.hash.Hashing;
|
||||||
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.Listener;
|
||||||
|
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ChomeNSAuth extends Listener {
|
||||||
|
public static final ChomeNSAuth INSTANCE = new ChomeNSAuth();
|
||||||
|
|
||||||
|
public final String id = "chomens_bot_verify";
|
||||||
|
|
||||||
|
public ChomeNSAuth () {
|
||||||
|
ListenerManager.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init () {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void chatMessageReceived(Text message) {
|
||||||
|
final String authKey = ChipmunkMod.CONFIG.bots.chomens.authKey;
|
||||||
|
|
||||||
|
if (authKey == null) return;
|
||||||
|
|
||||||
|
final Component component = message.asComponent();
|
||||||
|
|
||||||
|
if (!(component instanceof TextComponent)) return;
|
||||||
|
|
||||||
|
final String id = ((TextComponent) component).content();
|
||||||
|
|
||||||
|
if (!id.equals(this.id)) return;
|
||||||
|
|
||||||
|
final List<Component> children = component.children();
|
||||||
|
|
||||||
|
if (children.size() != 2) return;
|
||||||
|
|
||||||
|
if (!(children.get(0) instanceof TextComponent)) return;
|
||||||
|
|
||||||
|
final String hash = ((TextComponent) children.get(0)).content();
|
||||||
|
|
||||||
|
final long time = System.currentTimeMillis() / 10_000;
|
||||||
|
|
||||||
|
final String actual = Hashing.sha256()
|
||||||
|
// very pro hash input
|
||||||
|
.hashString(authKey + time, StandardCharsets.UTF_8)
|
||||||
|
.toString()
|
||||||
|
.substring(0, 8);
|
||||||
|
|
||||||
|
if (!hash.equals(actual)) return;
|
||||||
|
|
||||||
|
if (!(children.get(1) instanceof TextComponent)) return;
|
||||||
|
|
||||||
|
final String selector = ((TextComponent) children.get(1)).content();
|
||||||
|
|
||||||
|
final String toSendHash = Hashing.sha256()
|
||||||
|
// very pro hash input
|
||||||
|
.hashString(authKey + authKey + time + time, StandardCharsets.UTF_8)
|
||||||
|
.toString()
|
||||||
|
.substring(0, 8);
|
||||||
|
|
||||||
|
final Component toSend = Component.text(id)
|
||||||
|
.append(Component.text(toSendHash));
|
||||||
|
|
||||||
|
final String toSendString = GsonComponentSerializer.gson().serialize(toSend);
|
||||||
|
|
||||||
|
CommandCore.INSTANCE.run("tellraw " + selector + " " + toSendString);
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,7 +65,7 @@ public class BotValidationUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int chomens (String command) throws RuntimeException {
|
public static int chomens (String command) throws RuntimeException {
|
||||||
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.chomens;
|
final Configuration.ChomeNSBotInfo info = ChipmunkMod.CONFIG.bots.chomens;
|
||||||
|
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"hbot": { "prefix": "#", "key": null },
|
"hbot": { "prefix": "#", "key": null },
|
||||||
"sbot": { "prefix": ":", "key": null },
|
"sbot": { "prefix": ":", "key": null },
|
||||||
"chipmunk": { "prefix": "'", "key": null },
|
"chipmunk": { "prefix": "'", "key": null },
|
||||||
"chomens": { "prefix": "*", "key": null },
|
"chomens": { "prefix": "*", "key": null, "authKey": null },
|
||||||
"kittycorp": { "prefix": "^", "key": null },
|
"kittycorp": { "prefix": "^", "key": null },
|
||||||
"testbot": { "prefix": "-", "webhookUrl": null }
|
"testbot": { "prefix": "-", "webhookUrl": null }
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue