Mod should now be compatible with carpetmod /player cmd. Thanks for help, @sug0

This commit is contained in:
samo_lego 2020-04-19 16:44:35 +02:00
parent c71604bc8a
commit 8ba4879c6e
4 changed files with 14 additions and 27 deletions

View File

@ -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 {

View File

@ -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
archives_base_name = simpleauth

View File

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

View File

@ -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(
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;
@ -168,7 +172,7 @@ public class AuthEventHandler {
// Starting session
// Putting player to deauthenticated player map
deauthenticatePlayer(player);
// Setting that player was actually authenticated before leaving
PlayerCache playerCache = deauthenticatedUsers.get(player.getUuidAsString());
playerCache.wasAuthenticated = true;