Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable authentication client-side if in dev mode #94

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public MapSyncMod() {
*/
public abstract String getVersion();

protected abstract boolean isDevMode();
public abstract boolean isDevMode();

public abstract void registerKeyBinding(KeyMapping mapping);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public String getVersion() {
}

@Override
protected boolean isDevMode() {
public boolean isDevMode() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public String getVersion() {
}

@Override
protected boolean isDevMode() {
public boolean isDevMode() {
return !FMLLoader.isProduction();
}

Expand Down