From f8d2c3e46bb6ef68bb1dcd07a26ad53621e59da7 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 17 Oct 2023 08:55:11 +0100 Subject: [PATCH] Disable authentication client-side if in dev mode --- .../minecraft/mapsync/common/MapSyncMod.java | 2 +- .../mapsync/common/net/SyncClient.java | 26 ++++++++++++------- .../mapsync/fabric/FabricMapSyncMod.java | 2 +- .../mapsync/forge/ForgeMapSyncMod.java | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mod/common/src/main/java/gjum/minecraft/mapsync/common/MapSyncMod.java b/mod/common/src/main/java/gjum/minecraft/mapsync/common/MapSyncMod.java index 1813dfe3..ce47224e 100644 --- a/mod/common/src/main/java/gjum/minecraft/mapsync/common/MapSyncMod.java +++ b/mod/common/src/main/java/gjum/minecraft/mapsync/common/MapSyncMod.java @@ -68,7 +68,7 @@ public MapSyncMod() { */ public abstract String getVersion(); - protected abstract boolean isDevMode(); + public abstract boolean isDevMode(); public abstract void registerKeyBinding(KeyMapping mapping); diff --git a/mod/common/src/main/java/gjum/minecraft/mapsync/common/net/SyncClient.java b/mod/common/src/main/java/gjum/minecraft/mapsync/common/net/SyncClient.java index 40d84312..5c3f9d55 100644 --- a/mod/common/src/main/java/gjum/minecraft/mapsync/common/net/SyncClient.java +++ b/mod/common/src/main/java/gjum/minecraft/mapsync/common/net/SyncClient.java @@ -1,6 +1,7 @@ package gjum.minecraft.mapsync.common.net; import com.mojang.authlib.exceptions.AuthenticationException; +import gjum.minecraft.mapsync.common.MapSyncMod; import gjum.minecraft.mapsync.common.data.ChunkTile; import gjum.minecraft.mapsync.common.net.encryption.EncryptionDecoder; import gjum.minecraft.mapsync.common.net.encryption.EncryptionEncoder; @@ -245,16 +246,21 @@ void setUpEncryption(ChannelHandlerContext ctx, ClientboundEncryptionRequestPack byte[] sharedSecret = new byte[16]; ThreadLocalRandom.current().nextBytes(sharedSecret); - // note that this is different from minecraft (we get no negative hashes) - final String shaHex = HexFormat.of().formatHex(Hasher.sha1() - .update(sharedSecret) - .update(packet.publicKey.getEncoded()) - .generateHash() - ); - - User session = Minecraft.getInstance().getUser(); - Minecraft.getInstance().getMinecraftSessionService().joinServer( - session.getGameProfile(), session.getAccessToken(), shaHex); + if (!MapSyncMod.getMod().isDevMode()) { + // note that this is different from minecraft (we get no negative hashes) + final String shaHex = HexFormat.of().formatHex(Hasher.sha1() + .update(sharedSecret) + .update(packet.publicKey.getEncoded()) + .generateHash() + ); + + final User session = Minecraft.getInstance().getUser(); + Minecraft.getInstance().getMinecraftSessionService().joinServer( + session.getGameProfile(), + session.getAccessToken(), + shaHex + ); + } try { ctx.channel().writeAndFlush(new ServerboundEncryptionResponsePacket( diff --git a/mod/fabric/src/main/java/gjum/minecraft/mapsync/fabric/FabricMapSyncMod.java b/mod/fabric/src/main/java/gjum/minecraft/mapsync/fabric/FabricMapSyncMod.java index d1c48710..2562d224 100644 --- a/mod/fabric/src/main/java/gjum/minecraft/mapsync/fabric/FabricMapSyncMod.java +++ b/mod/fabric/src/main/java/gjum/minecraft/mapsync/fabric/FabricMapSyncMod.java @@ -26,7 +26,7 @@ public String getVersion() { } @Override - protected boolean isDevMode() { + public boolean isDevMode() { return FabricLoader.getInstance().isDevelopmentEnvironment(); } diff --git a/mod/forge/src/main/java/gjum/minecraft/mapsync/forge/ForgeMapSyncMod.java b/mod/forge/src/main/java/gjum/minecraft/mapsync/forge/ForgeMapSyncMod.java index 2d06cc62..9e09e0c3 100644 --- a/mod/forge/src/main/java/gjum/minecraft/mapsync/forge/ForgeMapSyncMod.java +++ b/mod/forge/src/main/java/gjum/minecraft/mapsync/forge/ForgeMapSyncMod.java @@ -24,7 +24,7 @@ public String getVersion() { } @Override - protected boolean isDevMode() { + public boolean isDevMode() { return !FMLLoader.isProduction(); }