From 886a0b795f11c3d1fe81a15188dbe4f24a0fd781 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 25 Sep 2022 12:15:31 +0200 Subject: [PATCH] =?UTF-8?q?More=20of=20that=20some=E2=84=A2=20tested=20cod?= =?UTF-8?q?e=20and=20contact=20infos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fabric/src/altauth.accesswidener | 3 +- fabric/src/assets/altauth/lang/de_de.json | 10 ++++ fabric/src/assets/altauth/lang/en_us.json | 10 ++++ .../de/chaoscaot/altauth/fabric/AltAuth.java | 2 - .../altauth/fabric/TrustServerScreen.java | 49 ------------------- .../fabric/{ => config}/ClientConfig.java | 6 ++- .../fabric/config/ModMenuIntegration.java | 42 ++++++++++++++++ .../fabric/{ => config}/ServerConfig.java | 6 ++- .../fabric/mixin/ConnectScreenMixin.java | 1 - .../fabric/mixin/LoginRequestMixin.java | 41 +++++++++++----- .../fabric/mixin/MinecraftServerMixin.java | 2 +- .../altauth/fabric/mixin/ServerIdMixin.java | 2 +- fabric/src/fabric.mod.json | 24 +++++++-- 13 files changed, 123 insertions(+), 75 deletions(-) create mode 100644 fabric/src/assets/altauth/lang/de_de.json create mode 100644 fabric/src/assets/altauth/lang/en_us.json delete mode 100644 fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java rename fabric/src/de/chaoscaot/altauth/fabric/{ => config}/ClientConfig.java (88%) create mode 100644 fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java rename fabric/src/de/chaoscaot/altauth/fabric/{ => config}/ServerConfig.java (90%) diff --git a/fabric/src/altauth.accesswidener b/fabric/src/altauth.accesswidener index 10f26bd..1f38ed9 100644 --- a/fabric/src/altauth.accesswidener +++ b/fabric/src/altauth.accesswidener @@ -2,4 +2,5 @@ accessWidener v1 named mutable field net/minecraft/server/MinecraftServer apiServices Lnet/minecraft/util/ApiServices; accessible field net/minecraft/client/gui/screen/ConnectScreen connection Lnet/minecraft/network/ClientConnection; accessible field net/minecraft/client/gui/screen/ConnectScreen connectingCancelled Z -accessible field net/minecraft/client/gui/screen/ConnectScreen parent Lnet/minecraft/client/gui/screen/Screen; \ No newline at end of file +accessible field net/minecraft/client/gui/screen/ConnectScreen parent Lnet/minecraft/client/gui/screen/Screen; +accessible field net/minecraft/client/gui/screen/ConnectScreen status Lnet/minecraft/text/Text; \ No newline at end of file diff --git a/fabric/src/assets/altauth/lang/de_de.json b/fabric/src/assets/altauth/lang/de_de.json new file mode 100644 index 0000000..af6cab7 --- /dev/null +++ b/fabric/src/assets/altauth/lang/de_de.json @@ -0,0 +1,10 @@ +{ + "gui.altauth.confirm.title": "%s §rmöchte '%s' als AltAuth server nutzen", + "gui.altauth.confirm.text": "Willst du\n'%s'\nals Authentication Server vertrauen?\n\n§4§lACHTUNG: §rDieser Server ist nicht von Mojang und kann unsicher sein!\nJemand bösartiges kann mit den gesendeten Information sich in deinen Minecraft Account einloggen und ihn auf §4§lJEDEM§r Server benutzen!\n\nWenn du dir nicht sicher bist, klicke auf 'Abbrechen'.", + "gui.altauth.connecting": "Verbinden mit AltAuth '%s'...", + "gui.altauth.error": "AltAuth Fehler!", + "config.altauth.title": "AltAuth Client Config", + "config.altauth.general": "Allgemein", + "config.altauth.enabled": "AltAuth Benutzen", + "config.altauth.servers": "Vertraute AltAuth Server" +} \ No newline at end of file diff --git a/fabric/src/assets/altauth/lang/en_us.json b/fabric/src/assets/altauth/lang/en_us.json new file mode 100644 index 0000000..04f9ee2 --- /dev/null +++ b/fabric/src/assets/altauth/lang/en_us.json @@ -0,0 +1,10 @@ +{ + "gui.altauth.confirm.title": "%s wants to use '%s' as AltAuth Server", + "gui.altauth.confirm.text": "Do you want to trust\n'%s'\nas an Authentication server?\n\n§4§lWARNING: §rThe Authentication server is not provided by Mojang and can be unsafe!\nA Malicious actor can use the info send to this Server to login and use your Minecraft Account on §4§lANY§r server!\n\nMake sure that you trust this Server!", + "gui.altauth.connecting": "Connecting with AltAuth '%s'...", + "gui.altauth.error": "AltAuth error", + "config.altauth.title": "AltAuth Client Config", + "config.altauth.general": "General", + "config.altauth.enabled": "AltAuth Enabled", + "config.altauth.servers": "Trusted AltAuth Servers" +} \ No newline at end of file diff --git a/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java b/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java index 99f7625..1dd01ea 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java @@ -16,6 +16,4 @@ public class AltAuth { public static final Logger LOGGER = LogManager.getLogger(); public static ServerAddress address; - - public static boolean trustOnce = false; } diff --git a/fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java b/fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java deleted file mode 100644 index 7d799e7..0000000 --- a/fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: MIT - -package de.chaoscaot.altauth.fabric; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ConnectScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.WarningScreen; -import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.network.ServerAddress; -import net.minecraft.text.Text; - -@Environment(EnvType.CLIENT) -public class TrustServerScreen extends WarningScreen { - private static final Text MESSAGE = Text.of("Do you want to trust this server?"); - - private final String serverId; - private final Screen parent; - - public TrustServerScreen(String serverAddress, Screen parent) { - super(Text.of("Trust '" + serverAddress + "'"), MESSAGE, Text.of("Do you want to Trust '" + serverAddress + "'?")); - this.serverId = serverAddress; - this.parent = null; - } - - @Override - protected void initButtons(int yOffset) { - // Yes, Once, Cancel - - addDrawableChild(new ButtonWidget(width / 2 - 155, height / 6 + 96 + yOffset, 150, 20, Text.of("Yes"), (buttonWidget) -> { - ClientConfig.INSTANCE.allowedServers.add(serverId); - ClientConfig.INSTANCE.save(); - - ConnectScreen.connect(parent, client, AltAuth.address, null); - })); - - addDrawableChild(new ButtonWidget(width / 2 - 155 + 160, height / 6 + 96 + yOffset + 30, 150, 20, Text.of("Once"), (buttonWidget) -> { - AltAuth.trustOnce = true; - - ConnectScreen.connect(parent, client, AltAuth.address, null); - })); - - addDrawableChild(new ButtonWidget(width / 2 - 155 + 160, height / 6 + 96 + yOffset + 60, 150, 20, Text.of("Cancel"), (buttonWidget) -> { - client.setScreen(parent); - })); - } -} diff --git a/fabric/src/de/chaoscaot/altauth/fabric/ClientConfig.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java similarity index 88% rename from fabric/src/de/chaoscaot/altauth/fabric/ClientConfig.java rename to fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java index 21a0fde..11c7d59 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/ClientConfig.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java @@ -1,8 +1,11 @@ // SPDX-License-Identifier: MIT -package de.chaoscaot.altauth.fabric; +package de.chaoscaot.altauth.fabric.config; import com.google.gson.JsonSyntaxException; +import de.chaoscaot.altauth.fabric.AltAuth; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import java.io.File; @@ -11,6 +14,7 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +@Environment(EnvType.CLIENT) public class ClientConfig { private static final String CONFIG_FILE_NAME = "altauth.client.json"; diff --git a/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java new file mode 100644 index 0000000..faaafd1 --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: MIT + +package de.chaoscaot.altauth.fabric.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.shedaniel.clothconfig2.api.ConfigBuilder; +import me.shedaniel.clothconfig2.api.ConfigCategory; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.Text; + +import java.util.ArrayList; + +@Environment(EnvType.CLIENT) +public class ModMenuIntegration implements ModMenuApi { + + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> { + ConfigBuilder builder = ConfigBuilder.create() + .setParentScreen(parent) + .setTitle(Text.translatable("config.altauth.title")); + + builder.setSavingRunnable(ClientConfig.INSTANCE::save); + ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + ConfigCategory general = builder.getOrCreateCategory(Text.translatable("config.altauth.general")); + general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("config.altauth.enabled"), ClientConfig.INSTANCE.enabled) + .setDefaultValue(true) + .setSaveConsumer(value -> ClientConfig.INSTANCE.enabled = value) + .build()); + + general.addEntry(entryBuilder.startStrList(Text.translatable("config.altauth.servers"), ClientConfig.INSTANCE.allowedServers) + .setDefaultValue(new ArrayList<>()) + .setSaveConsumer(list -> ClientConfig.INSTANCE.allowedServers = list) + .build()); + return builder.build(); + }; + } +} diff --git a/fabric/src/de/chaoscaot/altauth/fabric/ServerConfig.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java similarity index 90% rename from fabric/src/de/chaoscaot/altauth/fabric/ServerConfig.java rename to fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java index e9902f7..4ea39aa 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/ServerConfig.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java @@ -1,14 +1,18 @@ // SPDX-License-Identifier: MIT -package de.chaoscaot.altauth.fabric; +package de.chaoscaot.altauth.fabric.config; import com.google.gson.JsonSyntaxException; +import de.chaoscaot.altauth.fabric.AltAuth; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; import java.io.File; import java.io.IOException; import java.nio.file.Files; +@Environment(EnvType.SERVER) public class ServerConfig { private static final String CONFIG_FILE_NAME = "altauth.json"; diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java index c92350d..3689719 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java @@ -1,7 +1,6 @@ package de.chaoscaot.altauth.fabric.mixin; import de.chaoscaot.altauth.fabric.AltAuth; -import de.chaoscaot.altauth.fabric.TrustServerScreen; import net.minecraft.client.gui.screen.ConnectScreen; import net.minecraft.client.network.ServerAddress; import org.spongepowered.asm.mixin.Mixin; diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java index 6fb45b8..02dacae 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java @@ -2,17 +2,17 @@ package de.chaoscaot.altauth.fabric.mixin; -import com.mojang.authlib.yggdrasil.YggdrasilEnvironment; import de.chaoscaot.altauth.fabric.AltAuth; -import de.chaoscaot.altauth.fabric.ClientConfig; -import de.chaoscaot.altauth.fabric.TrustServerScreen; +import de.chaoscaot.altauth.fabric.config.ClientConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.screen.ConnectScreen; import net.minecraft.client.gui.screen.DisconnectedScreen; import net.minecraft.client.network.ClientLoginNetworkHandler; import net.minecraft.network.packet.s2c.login.LoginHelloS2CPacket; +import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; import org.joor.Reflect; import org.slf4j.Logger; @@ -30,34 +30,49 @@ import java.net.URL; public class LoginRequestMixin { @Shadow @Final private static Logger LOGGER; - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/login/LoginHelloS2CPacket;getServerId()Ljava/lang/String;"), method = "onHello") + @Shadow @Final private MinecraftClient client; + + @Inject(at = @At("HEAD"), method = "onHello", cancellable = true) public void onHello(LoginHelloS2CPacket packet, CallbackInfo ci) { + String server = "chaoscaot.de";//packet.getServerId(); try { - if(packet.getServerId().contains(".")) { - LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on a custom: {}", packet.getServerId()); - if(ClientConfig.INSTANCE.allowedServers.contains(packet.getServerId()) || AltAuth.trustOnce) { - AltAuth.trustOnce = false; - URL url = new URL("https://" + packet.getServerId() + "/session/minecraft/join"); + //if(packet.getServerId().contains(".")) { + LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on a custom: {}", server); + if(ClientConfig.INSTANCE.allowedServers.contains(server)) { + if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) { + cs.status = Text.translatable("gui.altauth.connecting", server); + } + URL url = new URL("https://" + server + "/session/minecraft/join"); Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url); } else { if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) { + ci.cancel(); cs.connectingCancelled = true; if( cs.connection != null) { cs.connection.disconnect(Text.translatable("connect.aborted")); } - MinecraftClient.getInstance().setScreen(new TrustServerScreen(packet.getServerId(), cs.parent)); + MinecraftClient.getInstance().execute(() -> MinecraftClient.getInstance().setScreen(new ConfirmScreen(t -> { + if(t) { + ClientConfig.INSTANCE.allowedServers.add(server); + ClientConfig.INSTANCE.save(); + + ConnectScreen.connect(cs.parent, client, AltAuth.address, null); + } else { + client.setScreen(cs.parent); + } + }, Text.translatable("gui.altauth.confirm.title", AltAuth.address.getAddress(), server), Text.translatable("gui.altauth.confirm.text", server), ScreenTexts.YES, ScreenTexts.CANCEL))); } } - } else { + /*} else { LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on mojang"); URL url = new URL(YggdrasilEnvironment.PROD.getEnvironment().getSessionHost() + "/session/minecraft/join"); Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url); - } + }*/ } catch (Exception e) { e.printStackTrace(); if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) { - MinecraftClient.getInstance().setScreen(new DisconnectedScreen(cs.parent, Text.of("AltAuth error"), Text.of(e.getMessage()))); + client.execute(() -> MinecraftClient.getInstance().setScreen(new DisconnectedScreen(cs.parent, Text.translatable("gui.altauth.error"), Text.of(e.getMessage())))); } } } diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java index 28f0f02..41a0c82 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java @@ -1,7 +1,7 @@ package de.chaoscaot.altauth.fabric.mixin; import de.chaoscaot.altauth.fabric.AltAuth; -import de.chaoscaot.altauth.fabric.ServerConfig; +import de.chaoscaot.altauth.fabric.config.ServerConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ServerIdMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ServerIdMixin.java index e880ba9..97bc7ae 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ServerIdMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ServerIdMixin.java @@ -2,7 +2,7 @@ package de.chaoscaot.altauth.fabric.mixin; -import de.chaoscaot.altauth.fabric.ServerConfig; +import de.chaoscaot.altauth.fabric.config.ServerConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.network.PacketByteBuf; diff --git a/fabric/src/fabric.mod.json b/fabric/src/fabric.mod.json index 14c31bb..0d04a6e 100644 --- a/fabric/src/fabric.mod.json +++ b/fabric/src/fabric.mod.json @@ -1,11 +1,16 @@ { "schemaVersion": 1, - "id": "alt-auth-client", + "id": "altauth", "version": "${version}", "name": "AltAuth", - "description": "Use AltAuth", - "authors": [], - "contact": {}, + "description": "AltAuth in your Game", + "authors": ["Chaoscaot ", "Lixfel"], + "contact": { + "email": "chaoscaot@zohomail.eu", + "sources": "https://steamwar.de/devlabs/Lixfel/AltAuth", + "homepage": "https://steamwar.de/devlabs/Lixfel/AltAuth", + "issues": "https://steamwar.de/devlabs/Lixfel/AltAuth/issues" + }, "license": "MIT", "environment": "*", "mixins": [ @@ -15,5 +20,14 @@ "fabricloader": ">=0.13.3", "minecraft": ">=1.18.2" }, - "accessWidener": "altauth.accesswidener" + "recommends": { + "modmenu": "*", + "cloth-config": "*" + }, + "accessWidener": "altauth.accesswidener", + "entrypoints": { + "modmenu": [ + "de.chaoscaot.altauth.fabric.config.ModMenuIntegration" + ] + } }