Working Fabric Server & Clientus

Dieser Commit ist enthalten in:
Chaoscaot 2022-10-01 11:56:17 +02:00
Ursprung 77ae329d6e
Commit 7080792d52
4 geänderte Dateien mit 35 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,8 @@
], ],
"server": [ "server": [
"ServerIdMixin", "ServerIdMixin",
"MinecraftServerMixin" "MinecraftServerMixin",
"ServerLoginNetworkHandlerNetworkMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1

Datei anzeigen

@ -48,10 +48,10 @@ public class LoginRequestMixin {
} else { } else {
if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) { if(MinecraftClient.getInstance().currentScreen instanceof ConnectScreen cs) {
ci.cancel(); ci.cancel();
/*cs.connectingCancelled = true; cs.connectingCancelled = true;
if( cs.connection != null) { if( cs.connection != null) {
cs.connection.disconnect(Text.translatable("connect.aborted")); cs.connection.disconnect(Text.translatable("connect.aborted"));
}*/ }
MinecraftClient.getInstance().execute(() -> client.setScreen(new TrustServerScreen(server, cs.parent))); MinecraftClient.getInstance().execute(() -> client.setScreen(new TrustServerScreen(server, cs.parent)));
} }

Datei anzeigen

@ -2,39 +2,41 @@
package de.chaoscaot.altauth.fabric.mixin; package de.chaoscaot.altauth.fabric.mixin;
import com.mojang.datafixers.DataFixer;
import de.chaoscaot.altauth.fabric.AltAuth; import de.chaoscaot.altauth.fabric.AltAuth;
import de.chaoscaot.altauth.fabric.config.ServerConfig; import de.chaoscaot.altauth.fabric.config.ServerConfig;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient; import net.minecraft.resource.ResourcePackManager;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.SaveLoader;
import net.minecraft.server.WorldGenerationProgressListenerFactory;
import net.minecraft.util.ApiServices; import net.minecraft.util.ApiServices;
import net.minecraft.world.level.storage.LevelStorage;
import org.joor.Reflect; import org.joor.Reflect;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL; import java.net.URL;
@Environment(EnvType.SERVER) @Environment(EnvType.SERVER)
@Mixin(MinecraftServer.class) @Mixin(MinecraftServer.class)
public class MinecraftServerMixin { public class MinecraftServerMixin {
@Shadow @Inject(method = "<init>", at = @At(value = "TAIL"))
protected ApiServices apiServices; private void apiServiceMixin(Thread serverThread, LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, Proxy proxy, DataFixer dataFixer, ApiServices apiServices, WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory, CallbackInfo ci) {
@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 { try {
URL url = new URL("https://" + ServerConfig.INSTANCE.serverUrl + "/session/minecraft/join"); URL url = new URL("https://" + ServerConfig.INSTANCE.serverUrl + "/session/minecraft/hasJoined");
Reflect.on(MinecraftClient.getInstance().getSessionService()).set("joinUrl", url); Reflect.on(apiServices.sessionService()).set("checkUrl", url);
URL joinUrl = new URL("https://" + ServerConfig.INSTANCE.serverUrl + "/session/minecraft/join");
Reflect.on(apiServices.sessionService()).set("joinUrl", joinUrl);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
AltAuth.LOGGER.error("Malformed URL: {}", e.getMessage()); AltAuth.LOGGER.error("Malformed URL: {}", e.getMessage());
} }
ServerConfig.INSTANCE.save();
} }
} }

Datei anzeigen

@ -0,0 +1,16 @@
package de.chaoscaot.altauth.fabric.mixin;
import de.chaoscaot.altauth.fabric.config.ServerConfig;
import net.minecraft.server.network.ServerLoginNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(ServerLoginNetworkHandler.class)
public class ServerLoginNetworkHandlerNetworkMixin {
@ModifyArg(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/encryption/NetworkEncryptionUtils;computeServerId(Ljava/lang/String;Ljava/security/PublicKey;Ljavax/crypto/SecretKey;)[B"), index = 0)
private String onKey(String serverId) {
return ServerConfig.INSTANCE.serverUrl;
}
}