A Lot of Untested Code
Dieser Commit ist enthalten in:
Ursprung
d307fb90cf
Commit
c64008f2f2
@ -33,7 +33,7 @@ dependencies {
|
||||
compileOnly project(":common")
|
||||
|
||||
// Used to Override 'private final'
|
||||
implementation 'org.jooq:joor:0.9.14'
|
||||
compileOnly 'org.jooq:joor:0.9.14'
|
||||
include 'org.jooq:joor:0.9.14'
|
||||
}
|
||||
|
||||
@ -45,3 +45,7 @@ processResources {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/altauth.accesswidener")
|
||||
}
|
||||
|
@ -4,10 +4,12 @@
|
||||
"package": "de.chaoscaot.altauth.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"client.LoginRequestMixin"
|
||||
"LoginRequestMixin",
|
||||
"ConnectScreenMixin"
|
||||
],
|
||||
"server": [
|
||||
"server.ServerIdMixin"
|
||||
"ServerIdMixin",
|
||||
"MinecraftServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
5
fabric/src/altauth.accesswidener
Normale Datei
5
fabric/src/altauth.accesswidener
Normale Datei
@ -0,0 +1,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;
|
@ -4,17 +4,18 @@ package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class AltAuthFabric implements ModInitializer {
|
||||
public class AltAuth {
|
||||
|
||||
private AltAuth() {}
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
public static ServerAddress address;
|
||||
|
||||
}
|
||||
public static boolean trustOnce = false;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class AltAuthClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||
|
||||
public class AltAuthServer implements DedicatedServerModInitializer {
|
||||
@Override
|
||||
public void onInitializeServer() {
|
||||
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class AltAuthServerConfig {
|
||||
|
||||
private static final String CONFIG_FILE_NAME = "altauth.json";
|
||||
|
||||
public static AltAuthServerConfig INSTANCE;
|
||||
|
||||
static {
|
||||
if(!new File(FabricLoader.getInstance().getConfigDir().toFile(), CONFIG_FILE_NAME).exists()) {
|
||||
INSTANCE = new AltAuthServerConfig();
|
||||
} else {
|
||||
try {
|
||||
INSTANCE = AltAuthFabric.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), AltAuthServerConfig.class);
|
||||
if(INSTANCE.serverUrl.length() > 20) {
|
||||
AltAuthFabric.LOGGER.error("AltauthServer: AltAuthServerConfig: ServerUrl is too long. Max length is 20 characters");
|
||||
INSTANCE.serverUrl = "";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
AltAuthFabric.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while loading config", e);
|
||||
AltAuthFabric.LOGGER.info("Reset Config...");
|
||||
INSTANCE = new AltAuthServerConfig();
|
||||
INSTANCE.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String serverUrl = "EnterNameHere";
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuthFabric.GSON.toJson(this));
|
||||
} catch (IOException e) {
|
||||
AltAuthFabric.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while saving config", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +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.gui.screen.WarningScreen;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ApproveServerScreen extends WarningScreen {
|
||||
private static final Text TITLE = Text.of("Approve Server");
|
||||
private static final Text MESSAGE = Text.of("Do you want to approve this server?");
|
||||
private static final Text NARRATOR_MESSAGE = Text.of("Do you want to approve this server?");
|
||||
|
||||
public ApproveServerScreen(String serverAddress) {
|
||||
super(TITLE, MESSAGE, NARRATOR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initButtons(int yOffset) {
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
@ -10,22 +11,22 @@ import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AltAuthClientConfig {
|
||||
public class ClientConfig {
|
||||
|
||||
private static final String CONFIG_FILE_NAME = "altauth.client.json";
|
||||
|
||||
public static AltAuthClientConfig INSTANCE;
|
||||
public static ClientConfig INSTANCE;
|
||||
|
||||
static {
|
||||
if(!new File(FabricLoader.getInstance().getConfigDir().toFile(), CONFIG_FILE_NAME).exists()) {
|
||||
INSTANCE = new AltAuthClientConfig();
|
||||
INSTANCE = new ClientConfig();
|
||||
} else {
|
||||
try {
|
||||
INSTANCE = AltAuthFabric.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), AltAuthClientConfig.class);
|
||||
} catch (IOException e) {
|
||||
AltAuthFabric.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while loading config", e);
|
||||
AltAuthFabric.LOGGER.info("Reset Config...");
|
||||
INSTANCE = new AltAuthClientConfig();
|
||||
INSTANCE = AltAuth.GSON.fromJson(Files.readString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME)), ClientConfig.class);
|
||||
} catch (IOException | JsonSyntaxException e) {
|
||||
AltAuth.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while loading config", e);
|
||||
AltAuth.LOGGER.info("Reset Config...");
|
||||
INSTANCE = new ClientConfig();
|
||||
INSTANCE.save();
|
||||
}
|
||||
}
|
||||
@ -36,9 +37,9 @@ public class AltAuthClientConfig {
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuthFabric.GSON.toJson(this));
|
||||
Files.writeString(FabricLoader.getInstance().getConfigDir().resolve(CONFIG_FILE_NAME), AltAuth.GSON.toJson(this));
|
||||
} catch (IOException e) {
|
||||
AltAuthFabric.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while saving config", e);
|
||||
AltAuth.LOGGER.error("AltauthClient: AltAuthClientConfig: Error while saving config", e);
|
||||
}
|
||||
}
|
||||
}
|
49
fabric/src/de/chaoscaot/altauth/fabric/ServerConfig.java
Normale Datei
49
fabric/src/de/chaoscaot/altauth/fabric/ServerConfig.java
Normale Datei
@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package de.chaoscaot.altauth.fabric;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class ServerConfig {
|
||||
|
||||
private static final String CONFIG_FILE_NAME = "altauth.json";
|
||||
|
||||
public static ServerConfig INSTANCE;
|
||||
|
||||
static {
|
||||
if(!new File(FabricLoader.getInstance().getConfigDir().toFile(), CONFIG_FILE_NAME).exists()) {
|
||||
INSTANCE = new ServerConfig();
|
||||
} else {
|
||||
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");
|
||||
INSTANCE.serverUrl = "";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
AltAuth.LOGGER.error("AltauthServer: AltAuthServerConfig: Error while loading config", e);
|
||||
AltAuth.LOGGER.info("Reset Config...");
|
||||
INSTANCE = new ServerConfig();
|
||||
INSTANCE.save();
|
||||
} catch (JsonSyntaxException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String serverUrl = "EnterNameHere";
|
||||
|
||||
public void save() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
49
fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java
Normale Datei
49
fabric/src/de/chaoscaot/altauth/fabric/TrustServerScreen.java
Normale Datei
@ -0,0 +1,49 @@
|
||||
// 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);
|
||||
}));
|
||||
}
|
||||
}
|
19
fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java
Normale Datei
19
fabric/src/de/chaoscaot/altauth/fabric/mixin/ConnectScreenMixin.java
Normale Datei
@ -0,0 +1,19 @@
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(ConnectScreen.class)
|
||||
public class ConnectScreenMixin {
|
||||
|
||||
@ModifyArg(method = "connect(Lnet/minecraft/client/gui/screen/Screen;Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ConnectScreen;connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;)V"), index = 1)
|
||||
private static ServerAddress copyServerAddress(ServerAddress address) {
|
||||
AltAuth.address = address;
|
||||
return address;
|
||||
}
|
||||
}
|
@ -3,11 +3,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 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.DisconnectedScreen;
|
||||
import net.minecraft.client.network.ClientLoginNetworkHandler;
|
||||
import net.minecraft.network.packet.s2c.login.LoginHelloS2CPacket;
|
||||
import net.minecraft.text.Text;
|
||||
import org.joor.Reflect;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@ -29,8 +35,20 @@ public class LoginRequestMixin {
|
||||
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");
|
||||
Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url);
|
||||
} else {
|
||||
if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) {
|
||||
cs.connectingCancelled = true;
|
||||
if( cs.connection != null) {
|
||||
cs.connection.disconnect(Text.translatable("connect.aborted"));
|
||||
}
|
||||
|
||||
MinecraftClient.getInstance().setScreen(new TrustServerScreen(packet.getServerId(), cs.parent));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("AltauthClient: LoginRequestMixin: Server is running on mojang");
|
||||
URL url = new URL(YggdrasilEnvironment.PROD.getEnvironment().getSessionHost() + "/session/minecraft/join");
|
||||
@ -38,7 +56,9 @@ public class LoginRequestMixin {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) {
|
||||
MinecraftClient.getInstance().setScreen(new DisconnectedScreen(cs.parent, Text.of("AltAuth error"), Text.of(e.getMessage())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package de.chaoscaot.altauth.fabric.mixin;
|
||||
|
||||
import de.chaoscaot.altauth.fabric.AltAuth;
|
||||
import de.chaoscaot.altauth.fabric.ServerConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ApiServices;
|
||||
import org.joor.Reflect;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
@Environment(EnvType.SERVER)
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin {
|
||||
|
||||
@Shadow
|
||||
protected ApiServices apiServices;
|
||||
|
||||
@Redirect(method = "<init>", at = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;apiServices:Lnet/minecraft/util/ApiServices;", opcode = Opcodes.PUTFIELD))
|
||||
private void apiServiceMixin(MinecraftServer instance, ApiServices value) {
|
||||
apiServices = value;
|
||||
|
||||
try {
|
||||
URL url = new URL("https://" + ServerConfig.INSTANCE.serverUrl + "/session/minecraft/join");
|
||||
Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url);
|
||||
} catch (MalformedURLException e) {
|
||||
AltAuth.LOGGER.error("Malformed URL: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
package de.chaoscaot.altauth.fabric.mixin;
|
||||
|
||||
import de.chaoscaot.altauth.fabric.AltAuthServerConfig;
|
||||
import de.chaoscaot.altauth.fabric.ServerConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
@ -17,6 +17,6 @@ public class ServerIdMixin {
|
||||
|
||||
@Redirect(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;writeString(Ljava/lang/String;)Lnet/minecraft/network/PacketByteBuf;"))
|
||||
public PacketByteBuf writeString(PacketByteBuf packetByteBuf, String string) {
|
||||
return packetByteBuf.writeString(AltAuthServerConfig.INSTANCE.serverUrl);
|
||||
return packetByteBuf.writeString(ServerConfig.INSTANCE.serverUrl);
|
||||
}
|
||||
}
|
||||
|
@ -8,22 +8,12 @@
|
||||
"contact": {},
|
||||
"license": "MIT",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"de.chaoscaot.altauth.fabric.AltAuth"
|
||||
],
|
||||
"client": [
|
||||
"de.chaoscaot.altauth.fabric.AltAuthClient"
|
||||
],
|
||||
"server": [
|
||||
"de.chaoscaot.altauth.fabric.AltAuthServer"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"alt-auth.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.13.3",
|
||||
"minecraft": ">=1.18.2"
|
||||
}
|
||||
},
|
||||
"accessWidener": "altauth.accesswidener"
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren