refactor: remove ChomeNSAuth

it's merged to ChomeNS Mod :D
This commit is contained in:
Chayapak Supasakul 2025-04-08 10:04:34 +07:00
parent 4d536c5a24
commit 657ae684ff
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
2 changed files with 0 additions and 118 deletions

View file

@ -14,7 +14,6 @@ import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket; import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.text.PlainTextContent;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableTextContent; import net.minecraft.text.TranslatableTextContent;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
@ -45,7 +44,6 @@ public class ClientPlayNetworkHandlerMixin {
CommandCore.INSTANCE.init(); CommandCore.INSTANCE.init();
SongPlayer.INSTANCE.coreReady(); SongPlayer.INSTANCE.coreReady();
RainbowName.INSTANCE.init(); RainbowName.INSTANCE.init();
ChomeNSAuth.INSTANCE.init();
ChomeNSBotCommandSuggestions.INSTANCE.init(); ChomeNSBotCommandSuggestions.INSTANCE.init();
CustomChat.INSTANCE.init(); CustomChat.INSTANCE.init();
} }
@ -89,16 +87,8 @@ public class ClientPlayNetworkHandlerMixin {
if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID)) { if (suggestionId.equals(ChomeNSBotCommandSuggestions.ID)) {
ci.cancel(); ci.cancel();
return;
} }
} }
if (
message.getContent() instanceof PlainTextContent plainTextContent &&
plainTextContent.string().equals(ChomeNSAuth.ID)
) {
ci.cancel();
}
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }

View file

@ -1,108 +0,0 @@
package land.chipmunk.chipmunkmod.modules;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import net.fabricmc.loader.api.FabricLoader;
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 javax.crypto.Cipher;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.List;
public class ChomeNSAuth implements Listener {
public static ChomeNSAuth INSTANCE = new ChomeNSAuth();
public static PublicKey PUBLIC_KEY;
private static final Path PUBLIC_KEY_PATH = FabricLoader.getInstance()
.getGameDir()
.resolve("data")
.resolve("chipmunkmod")
.resolve("chomens_auth")
.resolve("public.key");
private static final String BEGIN_PUBLIC_KEY = "-----BEGIN CHOMENS BOT PUBLIC KEY-----";
private static final String END_PUBLIC_KEY = "-----END CHOMENS BOT PUBLIC KEY-----";
public static final String ID = "chomens_bot_verify";
static {
try {
if (Files.exists(PUBLIC_KEY_PATH)) {
final String publicKeyString = new String(Files.readAllBytes(PUBLIC_KEY_PATH))
.replace(BEGIN_PUBLIC_KEY + "\n", "")
.replace("\n" + END_PUBLIC_KEY, "")
.replace("\n", "")
.trim();
final byte[] publicKeyBytes = Base64.getDecoder().decode(publicKeyString);
final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PUBLIC_KEY = keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyBytes));
}
} catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException | IllegalArgumentException ignored) {}
}
public ChomeNSAuth () {
ListenerManager.addListener(this);
}
public void init () {}
@Override
public void chatMessageReceived (Text message) {
if (PUBLIC_KEY == null) return;
if (message.getContent() == null || !(message.getContent() instanceof PlainTextContent idTextContent)) return;
final String id = idTextContent.string();
if (!id.equals(ID)) return;
final List<Text> children = message.getSiblings();
if (children.size() != 1) return;
if (!(children.getFirst().getContent() instanceof PlainTextContent selectorTextContent)) return;
final String selector = selectorTextContent.string();
try {
final String encrypted = encrypt(ID.getBytes(StandardCharsets.UTF_8));
final Component component = Component
.text(ID)
.append(Component.text(encrypted));
CommandCore.INSTANCE.run(
String.format(
"tellraw %s %s",
selector,
GsonComponentSerializer.gson()
.serialize(component)
)
);
} catch (Exception ignored) {}
}
public String encrypt (byte[] data) throws Exception {
final Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, PUBLIC_KEY);
final byte[] encryptedBytes = cipher.doFinal(data);
return Base64.getEncoder().encodeToString(encryptedBytes);
}
}