diff --git a/build.gradle b/build.gradle index 8b89ebe..41d3e58 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,13 @@ plugins { id 'maven-publish' } +repositories { + // Carpet mod + maven { + url 'https://masa.dy.fi/maven' + } +} + sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -36,8 +43,8 @@ dependencies { // JNA lib include 'net.java.dev.jna:jna:5.5.0' - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. + // carpetMod + modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 4b62c74..2b4f1c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,6 @@ fabric_version=0.5.10+build.320-1.16 mod_version = 1.4.0 maven_group = org.samo_lego archives_base_name = simpleauth + +# Dependencies +carpet_core_version = 1.3.19+v200415 \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java index 4d4b55a..63b63c0 100644 --- a/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java +++ b/src/main/java/org/samo_lego/simpleauth/SimpleAuth.java @@ -25,11 +25,16 @@ import java.util.HashMap; import java.util.Timer; import java.util.TimerTask; +import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake; + public class SimpleAuth implements DedicatedServerModInitializer { private static final Logger LOGGER = LogManager.getLogger(); public static SimpleAuthDatabase db = new SimpleAuthDatabase(); + // If server is running carpetmod + public static boolean isUsingCarpet; + // HashMap of players that are not authenticated // Rather than storing all the authenticated players, we just store ones that are not authenticated // It stores some data as well, e.g. login tries and user password @@ -61,6 +66,9 @@ public class SimpleAuth implements DedicatedServerModInitializer { // Connecting to db db.openConnection(); + // Checking if carpetmod is loaded + isUsingCarpet = FabricLoader.getInstance().isModLoaded("carpet"); + // Registering the commands CommandRegistry.INSTANCE.register(false, dispatcher -> { @@ -114,7 +122,7 @@ public class SimpleAuth implements DedicatedServerModInitializer { // De-authenticates player public static void deauthenticatePlayer(ServerPlayerEntity player) { - if(db.isClosed()) + if(db.isClosed() || isPlayerFake(player)) return; // Marking player as not authenticated, (re)setting login tries to zero String uuid = player.getUuidAsString(); @@ -134,4 +142,10 @@ public class SimpleAuth implements DedicatedServerModInitializer { } }, SimpleAuth.config.main.delay * 1000); } + + // Checking is player is a fake (carpetmod) player + public static boolean isPlayerFake(PlayerEntity player) { + // We ask CarpetHelper class since it has the imports needed + return isUsingCarpet ? isPlayerCarpetFake(player) : false; + } } \ No newline at end of file diff --git a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java index ef9ad9f..4b653c8 100644 --- a/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java +++ b/src/main/java/org/samo_lego/simpleauth/event/AuthEventHandler.java @@ -51,7 +51,7 @@ public class AuthEventHandler { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(incomingPlayerUsername); - if(onlinePlayer != null && config.experimental.disableAnotherLocationKick) { + if((onlinePlayer != null && !isPlayerFake(onlinePlayer)) && config.experimental.disableAnotherLocationKick) { // Player needs to be kicked, since there's already a player with that name // playing on the server return new LiteralText( @@ -158,7 +158,11 @@ public class AuthEventHandler { } public static void onPlayerLeave(ServerPlayerEntity player) { - if(!isAuthenticated(player) || config.main.sessionTimeoutTime == -1) + if( + !isAuthenticated(player) || + config.main.sessionTimeoutTime == -1 || + isPlayerFake(player) + ) return; // Starting session diff --git a/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java b/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java new file mode 100644 index 0000000..808fe5c --- /dev/null +++ b/src/main/java/org/samo_lego/simpleauth/utils/CarpetHelper.java @@ -0,0 +1,12 @@ +package org.samo_lego.simpleauth.utils; + +import carpet.patches.EntityPlayerMPFake; +import net.minecraft.entity.player.PlayerEntity; + +public class CarpetHelper { + // Checking if player is actually a fake one + // This is in its own class since we need carpet classes + public static boolean isPlayerCarpetFake(PlayerEntity player) { + return player instanceof EntityPlayerMPFake; + } +}