From acd392b8916b2b38b76184fcd307ec21c6eed0f7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 25 Sep 2022 16:03:41 +0200 Subject: [PATCH] Features, People, Features! --- fabric/build.gradle | 4 +- fabric/src/altauth.accesswidener | 1 + fabric/src/assets/altauth/lang/de_de.json | 7 ++- fabric/src/assets/altauth/lang/en_us.json | 7 ++- .../de/chaoscaot/altauth/fabric/AltAuth.java | 2 + .../altauth/fabric/TrustServerScreen.java | 48 +++++++++++++++++++ .../altauth/fabric/config/ClientConfig.java | 1 + .../fabric/config/ModMenuIntegration.java | 6 ++- .../altauth/fabric/config/ServerConfig.java | 6 +-- .../fabric/mixin/ConnectScreenMixin.java | 2 + .../fabric/mixin/LoginRequestMixin.java | 17 ++----- .../fabric/mixin/MinecraftServerMixin.java | 2 + 12 files changed, 80 insertions(+), 23 deletions(-) create mode 100644 fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java diff --git a/fabric/build.gradle b/fabric/build.gradle index e052731..c377f4b 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -42,9 +42,7 @@ processResources { filteringCharset "UTF-8" filesMatching("fabric.mod.json") { - expand "version": project.version - expand "minecraftVersion": project.minecraft_version - expand "loaderVersion": project.loader_version + expand "version": project.version, "minecraftVersion": project.minecraft_version, "loaderVersion": project.loader_version } } diff --git a/fabric/src/altauth.accesswidener b/fabric/src/altauth.accesswidener index 1f38ed9..bc3dd67 100644 --- a/fabric/src/altauth.accesswidener +++ b/fabric/src/altauth.accesswidener @@ -1,3 +1,4 @@ +# SPDX-License-Identifier: MIT 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; diff --git a/fabric/src/assets/altauth/lang/de_de.json b/fabric/src/assets/altauth/lang/de_de.json index af6cab7..c892646 100644 --- a/fabric/src/assets/altauth/lang/de_de.json +++ b/fabric/src/assets/altauth/lang/de_de.json @@ -1,10 +1,13 @@ { "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.confirm.text": "Willst du\n'%s'\nals Authentication Server vertrauen?\n\n§4§lACHTUNG: §rJemand bösartiges kann mit den gesendeten Information sich als dich für bis zu Zwei Tage auf §4§lJEDEN§r Server ausgeben!\n\nWenn du dir nicht sicher bist, klicke auf 'Abbrechen'.", + "gui.altauth.confirm.force_mojang": "Mojang Authentifizierung erzwingen", + "gui.altauth.confirm.once": "Einmal vertrauen", "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" + "config.altauth.servers": "Vertraute AltAuth Server", + "config.altauth.disabled": "Mojang Authentifizierung benutzen" } \ 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 index 04f9ee2..f0c5d3e 100644 --- a/fabric/src/assets/altauth/lang/en_us.json +++ b/fabric/src/assets/altauth/lang/en_us.json @@ -1,10 +1,13 @@ { "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.confirm.text": "Do you want to trust\n'%s'\nas an Authentication server?\n\n§4§lWARNING: §rA Malicious actor can use the info send to this server to impersonate you on §4§lANY§r server for up to two days!\n\nMake sure that you trust this Server!", + "gui.altauth.confirm.force_mojang": "Use Mojang Authentication", + "gui.altauth.confirm.once": "Trust Once", "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" + "config.altauth.servers": "Trusted AltAuth Servers", + "config.altauth.disabled": "Forced Mojang Authentication" } \ 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 1dd01ea..99f7625 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/AltAuth.java @@ -16,4 +16,6 @@ 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 new file mode 100644 index 0000000..44c5eda --- /dev/null +++ b/fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: MIT + +package de.chaoscaot.altauth.fabric; + +import de.chaoscaot.altauth.fabric.config.ClientConfig; +import net.minecraft.client.gui.screen.ConfirmScreen; +import net.minecraft.client.gui.screen.ConnectScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.Text; + +public class TrustServerScreen extends ConfirmScreen { + private static final Text FORCE_MOJANG = Text.translatable("gui.altauth.confirm.force_mojang"); + private static final Text TRUST_ONCE = Text.translatable("gui.altauth.confirm.once"); + + private final String server; + private final Screen parent; + + public TrustServerScreen(String server, Screen parent) { + super(t -> {}, Text.translatable("gui.altauth.confirm.title", AltAuth.address.getAddress(), server), Text.translatable("gui.altauth.confirm.text", server), ScreenTexts.YES, ScreenTexts.CANCEL); + this.server = server; + this.parent = parent; + } + + @Override + protected void addButtons(int y) { + this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, y, 150, 20, this.yesText, (button) -> { + ClientConfig.INSTANCE.allowedServers.add(server); + ClientConfig.INSTANCE.save(); + + ConnectScreen.connect(parent, client, AltAuth.address, null); + })); + this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, y, 150, 20, FORCE_MOJANG, (button) -> { + ClientConfig.INSTANCE.forcedMojang.add(AltAuth.address.getAddress()); + ClientConfig.INSTANCE.save(); + + ConnectScreen.connect(parent, client, AltAuth.address, null); + })); + this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, y + 25, 150, 20, TRUST_ONCE, (button) -> { + AltAuth.trustOnce = true; + ConnectScreen.connect(parent, client, AltAuth.address, null); + })); + this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, y + 25, 150, 20, this.noText, (button) -> { + client.setScreen(parent); + })); + } +} diff --git a/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java index 11c7d59..919441e 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ClientConfig.java @@ -38,6 +38,7 @@ public class ClientConfig { public boolean enabled = true; public List allowedServers = new ArrayList<>(); + public List forcedMojang = new ArrayList<>(); public void save() { try { diff --git a/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java index faaafd1..dbf8231 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ModMenuIntegration.java @@ -9,7 +9,6 @@ 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; @@ -36,6 +35,11 @@ public class ModMenuIntegration implements ModMenuApi { .setDefaultValue(new ArrayList<>()) .setSaveConsumer(list -> ClientConfig.INSTANCE.allowedServers = list) .build()); + general.addEntry(entryBuilder.startStrList(Text.translatable("config.altauth.disabled"), ClientConfig.INSTANCE.forcedMojang) + .setDefaultValue(new ArrayList<>()) + .setSaveConsumer(list -> ClientConfig.INSTANCE.forcedMojang = list) + .build()); + return builder.build(); }; } diff --git a/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java b/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java index 4ea39aa..4337654 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/config/ServerConfig.java @@ -26,11 +26,11 @@ public class ServerConfig { try { INSTANCE = AltAuth.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), ServerConfig.class); if(INSTANCE.serverUrl.length() > 20) { - AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: ServerUrl is too long. Max length is 20 characters"); + AltAuth.LOGGER.error("AltauthServer: ServerUrl is too long. Max length is 20 characters"); INSTANCE.serverUrl = ""; } } catch (IOException e) { - AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while loading config", e); + AltAuth.LOGGER.error("AltauthServer: Error while loading config", e); AltAuth.LOGGER.info("Reset Config..."); INSTANCE = new ServerConfig(); INSTANCE.save(); @@ -47,7 +47,7 @@ public class ServerConfig { try { Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuth.GSON.toJson(this)); } catch (IOException e) { - AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while saving config", e); + AltAuth.LOGGER.error("AltauthServer: Error while saving config", e); } } } diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java index 3689719..3b94b5c 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + package de.chaoscaot.altauth.fabric.mixin; import de.chaoscaot.altauth.fabric.AltAuth; diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java index 3b15149..5ce2708 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/LoginRequestMixin.java @@ -4,6 +4,7 @@ package de.chaoscaot.altauth.fabric.mixin; import com.mojang.authlib.yggdrasil.YggdrasilEnvironment; import de.chaoscaot.altauth.fabric.AltAuth; +import de.chaoscaot.altauth.fabric.TrustServerScreen; import de.chaoscaot.altauth.fabric.config.ClientConfig; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -37,9 +38,10 @@ public class LoginRequestMixin { public void onHello(LoginHelloS2CPacket packet, CallbackInfo ci) { String server = packet.getServerId(); try { - if(packet.getServerId().contains(".")) { + if(server.contains(".") && !ClientConfig.INSTANCE.forcedMojang.contains(AltAuth.address.getAddress()) && ClientConfig.INSTANCE.enabled) { LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on a custom: {}", server); - if(ClientConfig.INSTANCE.allowedServers.contains(server)) { + if(ClientConfig.INSTANCE.allowedServers.contains(server) || AltAuth.trustOnce) { + AltAuth.trustOnce = false; if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) { cs.status = Text.translatable("gui.altauth.connecting", server); } @@ -53,16 +55,7 @@ public class LoginRequestMixin { cs.connection.disconnect(Text.translatable("connect.aborted")); } - 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))); + MinecraftClient.getInstance().execute(() -> client.setScreen(new TrustServerScreen(server, cs.parent))); } } } else { diff --git a/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java b/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java index 41a0c82..b36df24 100644 --- a/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java +++ b/fabric/src/de/chaoscaot/altauth/fabric/mixin/MinecraftServerMixin.java @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + package de.chaoscaot.altauth.fabric.mixin; import de.chaoscaot.altauth.fabric.AltAuth;