mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 19:56:15 +00:00
refactor: remove ChomeNSAuth since we already have IP authentication
This commit is contained in:
parent
50db974497
commit
fd9a0ef0cb
2 changed files with 1 additions and 84 deletions
|
|
@ -59,7 +59,6 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
SongPlayer.INSTANCE.coreReady();
|
||||
RainbowName.INSTANCE.init();
|
||||
ChomeNSBotCommandSuggestions.INSTANCE.init();
|
||||
ChomeNSAuth.INSTANCE.init();
|
||||
CustomChat.INSTANCE.init();
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +93,8 @@ public class ClientPlayNetworkHandlerMixin {
|
|||
|
||||
try {
|
||||
final String suggestionId = message.getSiblings().getFirst().getString();
|
||||
final String authId = ((PlainTextContent) message.getContent()).string();
|
||||
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID) || authId.equals(ChomeNSAuth.INSTANCE.id)) {
|
||||
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID)) {
|
||||
ci.cancel();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
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 land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minecraft.text.PlainTextContent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextContent;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
public class ChomeNSAuth implements 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 text) {
|
||||
final String authKey = ChipmunkMod.CONFIG.bots.chomens.authKey;
|
||||
|
||||
if (authKey == null) return;
|
||||
|
||||
final TextContent message = text.getContent();
|
||||
|
||||
if (!(message instanceof PlainTextContent)) return;
|
||||
|
||||
final String id = ((PlainTextContent) message).string();
|
||||
|
||||
if (!id.equals(this.id)) return;
|
||||
|
||||
final List<Text> children = text.getSiblings();
|
||||
|
||||
if (children.size() != 2) return;
|
||||
|
||||
if (!(children.getFirst().getContent() instanceof PlainTextContent)) return;
|
||||
|
||||
final String hash = ((PlainTextContent) children.getFirst().getContent()).string();
|
||||
|
||||
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).getContent() instanceof PlainTextContent)) return;
|
||||
|
||||
final String selector = ((PlainTextContent) children.get(1).getContent()).string();
|
||||
|
||||
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);
|
||||
|
||||
System.out.println("Sending " + toSendString + " to " + selector);
|
||||
|
||||
CommandCore.INSTANCE.run("minecraft:tellraw " + selector + " " + toSendString);
|
||||
|
||||
CustomChat.INSTANCE.resetTotal();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue