Fixing carpet fake player incompatibility. Thanks @sug0

This commit is contained in:
samo_lego 2020-04-19 13:38:41 +02:00
parent 4c838cb477
commit c71604bc8a
5 changed files with 45 additions and 5 deletions

View File

@ -3,6 +3,13 @@ plugins {
id 'maven-publish' id 'maven-publish'
} }
repositories {
// Carpet mod
maven {
url 'https://masa.dy.fi/maven'
}
}
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -36,8 +43,8 @@ dependencies {
// JNA lib // JNA lib
include 'net.java.dev.jna:jna:5.5.0' include 'net.java.dev.jna:jna:5.5.0'
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // carpetMod
// You may need to force-disable transitiveness on them. modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
} }
processResources { processResources {

View File

@ -13,3 +13,6 @@ fabric_version=0.5.10+build.320-1.16
mod_version = 1.4.0 mod_version = 1.4.0
maven_group = org.samo_lego maven_group = org.samo_lego
archives_base_name = simpleauth archives_base_name = simpleauth
# Dependencies
carpet_core_version = 1.3.19+v200415

View File

@ -25,11 +25,16 @@ import java.util.HashMap;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
public class SimpleAuth implements DedicatedServerModInitializer { public class SimpleAuth implements DedicatedServerModInitializer {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
public static SimpleAuthDatabase db = new SimpleAuthDatabase(); public static SimpleAuthDatabase db = new SimpleAuthDatabase();
// If server is running carpetmod
public static boolean isUsingCarpet;
// HashMap of players that are not authenticated // HashMap of players that are not authenticated
// Rather than storing all the authenticated players, we just store ones 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 // 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 // Connecting to db
db.openConnection(); db.openConnection();
// Checking if carpetmod is loaded
isUsingCarpet = FabricLoader.getInstance().isModLoaded("carpet");
// Registering the commands // Registering the commands
CommandRegistry.INSTANCE.register(false, dispatcher -> { CommandRegistry.INSTANCE.register(false, dispatcher -> {
@ -114,7 +122,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
// De-authenticates player // De-authenticates player
public static void deauthenticatePlayer(ServerPlayerEntity player) { public static void deauthenticatePlayer(ServerPlayerEntity player) {
if(db.isClosed()) if(db.isClosed() || isPlayerFake(player))
return; return;
// Marking player as not authenticated, (re)setting login tries to zero // Marking player as not authenticated, (re)setting login tries to zero
String uuid = player.getUuidAsString(); String uuid = player.getUuidAsString();
@ -134,4 +142,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
} }
}, SimpleAuth.config.main.delay * 1000); }, 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;
}
} }

View File

@ -51,7 +51,7 @@ public class AuthEventHandler {
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(incomingPlayerUsername); 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 // Player needs to be kicked, since there's already a player with that name
// playing on the server // playing on the server
return new LiteralText( return new LiteralText(
@ -158,7 +158,11 @@ public class AuthEventHandler {
} }
public static void onPlayerLeave(ServerPlayerEntity player) { public static void onPlayerLeave(ServerPlayerEntity player) {
if(!isAuthenticated(player) || config.main.sessionTimeoutTime == -1) if(
!isAuthenticated(player) ||
config.main.sessionTimeoutTime == -1 ||
isPlayerFake(player)
)
return; return;
// Starting session // Starting session

View File

@ -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;
}
}