Skip to content

Commit

Permalink
Change authorization method
Browse files Browse the repository at this point in the history
ref: #319
  • Loading branch information
Skidamek committed Feb 24, 2025
1 parent 9e9c124 commit 0cf2be2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/main/java/pl/skidam/automodpack/loader/GameCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.mojang.authlib.GameProfile;
import net.minecraft.util.UserCache;
import pl.skidam.automodpack.init.Common;
import pl.skidam.automodpack.modpack.GameHelpers;
import pl.skidam.automodpack_core.loader.GameCallService;

import java.net.SocketAddress;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

import static pl.skidam.automodpack_core.GlobalVariables.*;

Expand All @@ -29,10 +29,6 @@ public boolean canPlayerJoin(SocketAddress address, String id) {
return true;
}

AtomicBoolean canJoin = new AtomicBoolean(false);
GameProfile finalProfile = profile;
Common.server.submitAndJoin(() -> canJoin.set(Common.server.getPlayerManager().checkCanJoin(address, finalProfile) == null));

return canJoin.get();
return GameHelpers.isPlayerAuthorized(address, profile);
}
}
24 changes: 24 additions & 0 deletions src/main/java/pl/skidam/automodpack/modpack/GameHelpers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package pl.skidam.automodpack.modpack;

import com.mojang.authlib.GameProfile;

import java.net.SocketAddress;

import static pl.skidam.automodpack.init.Common.server;

public class GameHelpers {

// Simpler version of `PlayerManager.checkCanJoin`
public static boolean isPlayerAuthorized(SocketAddress address, GameProfile profile) {
var playerManager = server.getPlayerManager();
if (playerManager.getUserBanList().contains(profile)) {
return false;
} else if (!playerManager.isWhitelisted(profile)) {
return false;
} else if (playerManager.getIpBanList().isBanned(address)) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pl.skidam.automodpack.client.ui.versioned.VersionedText;
import pl.skidam.automodpack.init.Common;
import pl.skidam.automodpack.mixin.core.ServerLoginNetworkHandlerAccessor;
import pl.skidam.automodpack.modpack.GameHelpers;
import pl.skidam.automodpack.networking.content.DataPacket;
import pl.skidam.automodpack.networking.content.HandshakePacket;
import pl.skidam.automodpack.networking.PacketSender;
Expand All @@ -19,8 +20,6 @@
import pl.skidam.automodpack_core.auth.SecretsStore;
import pl.skidam.automodpack_core.utils.Ip;

import java.util.concurrent.atomic.AtomicBoolean;

import static pl.skidam.automodpack.networking.ModPackets.DATA;
import static pl.skidam.automodpack_core.GlobalVariables.*;

Expand All @@ -40,10 +39,7 @@ public static void receive(MinecraftServer server, ServerLoginNetworkHandler han
LOGGER.warn("Connection is not encrypted for player: {}", playerName);
}

AtomicBoolean canJoin = new AtomicBoolean(false);
server.submitAndJoin(() -> canJoin.set(server.getPlayerManager().checkCanJoin(connection.getAddress(), profile) == null));

if (!canJoin.get()) {
if (!GameHelpers.isPlayerAuthorized(connection.getAddress(), profile)) {
return;
}

Expand Down

0 comments on commit 0cf2be2

Please sign in to comment.