Fixing carpet fake player incompatibility. Thanks @sug0
This commit is contained in:
parent
4c838cb477
commit
c71604bc8a
11
build.gradle
11
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 {
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue