forked from sorceress/EasyAuth
Mod should now be compatible with carpetmod /player cmd. Thanks for help, @sug0
This commit is contained in:
parent
c71604bc8a
commit
8ba4879c6e
|
@ -3,12 +3,6 @@ plugins {
|
|||
id 'maven-publish'
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Carpet mod
|
||||
maven {
|
||||
url 'https://masa.dy.fi/maven'
|
||||
}
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
@ -42,9 +36,6 @@ dependencies {
|
|||
|
||||
// JNA lib
|
||||
include 'net.java.dev.jna:jna:5.5.0'
|
||||
|
||||
// carpetMod
|
||||
modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
|
|
@ -10,9 +10,6 @@ loader_version=0.8.2+build.194
|
|||
fabric_version=0.5.10+build.320-1.16
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.4.0
|
||||
mod_version = 1.4.1
|
||||
maven_group = org.samo_lego
|
||||
archives_base_name = simpleauth
|
||||
|
||||
# Dependencies
|
||||
carpet_core_version = 1.3.19+v200415
|
|
@ -32,9 +32,6 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
|
||||
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
|
||||
|
@ -42,7 +39,8 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
|
||||
// Boolean for easier checking if player is authenticated
|
||||
public static boolean isAuthenticated(ServerPlayerEntity player) {
|
||||
return !deauthenticatedUsers.containsKey(player.getUuidAsString());
|
||||
String uuid = player.getUuidAsString();
|
||||
return !deauthenticatedUsers.containsKey(uuid) || deauthenticatedUsers.get(uuid).wasAuthenticated;
|
||||
}
|
||||
|
||||
// Getting game directory
|
||||
|
@ -66,9 +64,6 @@ 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 -> {
|
||||
|
@ -122,7 +117,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
|
||||
// De-authenticates player
|
||||
public static void deauthenticatePlayer(ServerPlayerEntity player) {
|
||||
if(db.isClosed() || isPlayerFake(player))
|
||||
if(db.isClosed())
|
||||
return;
|
||||
// Marking player as not authenticated, (re)setting login tries to zero
|
||||
String uuid = player.getUuidAsString();
|
||||
|
@ -146,6 +141,6 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
// 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;
|
||||
return FabricLoader.getInstance().isModLoaded("carpet") && isPlayerCarpetFake(player);
|
||||
}
|
||||
}
|
|
@ -72,14 +72,18 @@ public class AuthEventHandler {
|
|||
|
||||
// Player joining the server
|
||||
public static void onPlayerJoin(ServerPlayerEntity player) {
|
||||
// If player is fake auth is not needed
|
||||
if(isPlayerFake(player))
|
||||
return;
|
||||
// Checking if session is still valid
|
||||
String uuid = player.getUuidAsString();
|
||||
PlayerCache playerCache = deauthenticatedUsers.getOrDefault(uuid, null);
|
||||
|
||||
if (
|
||||
playerCache != null &&
|
||||
playerCache.lastIp.equals(player.getIp()) &&
|
||||
playerCache.wasAuthenticated &&
|
||||
playerCache.validUntil >= System.currentTimeMillis()
|
||||
playerCache.validUntil >= System.currentTimeMillis() &&
|
||||
playerCache.lastIp.equals(player.getIp())
|
||||
) {
|
||||
deauthenticatedUsers.remove(uuid); // Makes player authenticated
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue