Adding `forceOfflineUuids` option, some minor fixes
This commit is contained in:
parent
0e369bf99f
commit
b0fe67669c
|
@ -36,7 +36,7 @@ import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;
|
||||||
|
|
||||||
public class SimpleAuth implements DedicatedServerModInitializer {
|
public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
|
|
||||||
public static SimpleAuthDatabase DB = new SimpleAuthDatabase();
|
public static final SimpleAuthDatabase DB = new SimpleAuthDatabase();
|
||||||
|
|
||||||
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
|
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
|
@ -45,19 +45,19 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
* It's cleared on server stop in order to save some interactions with database during runtime.
|
* It's cleared on server stop in order to save some interactions with database during runtime.
|
||||||
* Stores their data as {@link org.samo_lego.simpleauth.storage.PlayerCache PlayerCache} object.
|
* Stores their data as {@link org.samo_lego.simpleauth.storage.PlayerCache PlayerCache} object.
|
||||||
*/
|
*/
|
||||||
public static HashMap<String, PlayerCache> playerCacheMap = new HashMap<>();
|
public static final HashMap<String, PlayerCache> playerCacheMap = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HashSet of player names that have Mojang accounts.
|
* HashSet of player names that have Mojang accounts.
|
||||||
* If player is saved in here, they will be treated as online-mode ones.
|
* If player is saved in here, they will be treated as online-mode ones.
|
||||||
*/
|
*/
|
||||||
public static HashSet<String> mojangAccountNamesCache = new HashSet<>();
|
public static final HashSet<String> mojangAccountNamesCache = new HashSet<>();
|
||||||
|
|
||||||
// Getting game directory
|
// Getting game directory
|
||||||
public static final Path gameDirectory = FabricLoader.getInstance().getGameDir();
|
public static final Path gameDirectory = FabricLoader.getInstance().getGameDir();
|
||||||
|
|
||||||
// Server properties
|
// Server properties
|
||||||
public static Properties serverProp = new Properties();
|
public static final Properties serverProp = new Properties();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config of the SimpleAuth mod.
|
* Config of the SimpleAuth mod.
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class LogoutCommand {
|
||||||
private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException {
|
private static int logout(ServerCommandSource serverCommandSource) throws CommandSyntaxException {
|
||||||
ServerPlayerEntity player = serverCommandSource.getPlayer();
|
ServerPlayerEntity player = serverCommandSource.getPlayer();
|
||||||
|
|
||||||
if(mojangAccountNamesCache.contains(player.getGameProfile().getName().toLowerCase())) {
|
if(!mojangAccountNamesCache.contains(player.getGameProfile().getName().toLowerCase())) {
|
||||||
((PlayerAuth) player).setAuthenticated(false);
|
((PlayerAuth) player).setAuthenticated(false);
|
||||||
player.sendMessage(new LiteralText(config.lang.successfulLogout), false);
|
player.sendMessage(new LiteralText(config.lang.successfulLogout), false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ public class MixinPlayerAdvancementTracker {
|
||||||
|
|
||||||
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
@Inject(method = "load(Lnet/minecraft/server/ServerAdvancementLoader;)V", at = @At("HEAD"))
|
||||||
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
private void startMigratingOfflineAdvancements(ServerAdvancementLoader advancementLoader, CallbackInfo ci) {
|
||||||
System.out.println(this.advancementFile.isFile());
|
|
||||||
if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
if(config.experimental.premiumAutologin && ((PlayerAuth) this.owner).isUsingMojangAccount() && !this.advancementFile.isFile()) {
|
||||||
// Migrate
|
// Migrate
|
||||||
String playername = owner.getGameProfile().getName().toLowerCase();
|
String playername = owner.getGameProfile().getName().toLowerCase();
|
||||||
|
|
|
@ -21,13 +21,15 @@ import static org.samo_lego.simpleauth.SimpleAuth.*;
|
||||||
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
||||||
|
|
||||||
@Mixin(ServerLoginNetworkHandler.class)
|
@Mixin(ServerLoginNetworkHandler.class)
|
||||||
public class MixinServerLoginNetworkHandler {
|
public abstract class MixinServerLoginNetworkHandler {
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
private GameProfile profile;
|
private GameProfile profile;
|
||||||
@Shadow
|
@Shadow
|
||||||
private int loginTicks;
|
private int loginTicks;
|
||||||
|
|
||||||
|
@Shadow protected abstract GameProfile toOfflineProfile(GameProfile profile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fake state of current player.
|
* Fake state of current player.
|
||||||
*/
|
*/
|
||||||
|
@ -49,6 +51,13 @@ public class MixinServerLoginNetworkHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(method = "acceptPlayer()V", at = @At("HEAD"))
|
||||||
|
private void acceptPlayer(CallbackInfo ci) {
|
||||||
|
if(config.experimental.forceoOfflineUuids) {
|
||||||
|
this.profile = this.toOfflineProfile(this.profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the player has purchased an account.
|
* Checks whether the player has purchased an account.
|
||||||
* If so, server is presented as online, and continues as in normal-online mode.
|
* If so, server is presented as online, and continues as in normal-online mode.
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.serverProp;
|
import static org.samo_lego.simpleauth.SimpleAuth.serverProp;
|
||||||
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
import static org.samo_lego.simpleauth.utils.SimpleLogger.logError;
|
||||||
|
import static org.samo_lego.simpleauth.utils.SimpleLogger.logInfo;
|
||||||
|
|
||||||
public class AuthConfig {
|
public class AuthConfig {
|
||||||
private static final Gson gson = new GsonBuilder()
|
private static final Gson gson = new GsonBuilder()
|
||||||
|
@ -230,9 +231,15 @@ public class AuthConfig {
|
||||||
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)
|
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)
|
||||||
)) {
|
)) {
|
||||||
config = gson.fromJson(fileReader, AuthConfig.class);
|
config = gson.fromJson(fileReader, AuthConfig.class);
|
||||||
if(config.experimental.premiumAutologin && !Boolean.parseBoolean(serverProp.getProperty("online-mode"))) {
|
if(!Boolean.parseBoolean(serverProp.getProperty("online-mode"))) {
|
||||||
logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter.");
|
if(config.experimental.forceoOfflineUuids) {
|
||||||
config.experimental.premiumAutologin = false;
|
logInfo("Server is in offline mode, forceoOfflineUuids option is irrelevant. Setting it to false.");
|
||||||
|
config.experimental.forceoOfflineUuids = false;
|
||||||
|
}
|
||||||
|
if(config.experimental.premiumAutologin) {
|
||||||
|
logError("You cannot use server in offline mode and premiumAutologin! Disabling the latter.");
|
||||||
|
config.experimental.premiumAutologin = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("[SimpleAuth] Problem occurred when trying to load config: ", e);
|
throw new RuntimeException("[SimpleAuth] Problem occurred when trying to load config: ", e);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class PlayerCache {
|
||||||
public float pitch;
|
public float pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation();
|
public final PlayerCache.LastLocation lastLocation = new PlayerCache.LastLocation();
|
||||||
|
|
||||||
|
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
|
@ -64,6 +64,7 @@ public class SimpleAuthDatabase {
|
||||||
* @param data data to put inside database
|
* @param data data to put inside database
|
||||||
* @return true if operation was successful, otherwise false
|
* @return true if operation was successful, otherwise false
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public boolean registerUser(String uuid, String data) {
|
public boolean registerUser(String uuid, String data) {
|
||||||
try {
|
try {
|
||||||
if(!this.isUserRegistered(uuid)) {
|
if(!this.isUserRegistered(uuid)) {
|
||||||
|
@ -111,6 +112,7 @@ public class SimpleAuthDatabase {
|
||||||
* @param uuid uuid of the player to update data for
|
* @param uuid uuid of the player to update data for
|
||||||
* @param data data to put inside database
|
* @param data data to put inside database
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void updateUserData(String uuid, String data) {
|
public void updateUserData(String uuid, String data) {
|
||||||
try {
|
try {
|
||||||
levelDBStore.put(bytes("UUID:" + uuid), bytes("data:" + data));
|
levelDBStore.put(bytes("UUID:" + uuid), bytes("data:" + data));
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package org.samo_lego.simpleauth.utils;
|
package org.samo_lego.simpleauth.utils;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonNull;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import org.samo_lego.simpleauth.SimpleAuth;
|
|
||||||
import org.samo_lego.simpleauth.utils.hashing.HasherArgon2;
|
import org.samo_lego.simpleauth.utils.hashing.HasherArgon2;
|
||||||
import org.samo_lego.simpleauth.utils.hashing.HasherBCrypt;
|
import org.samo_lego.simpleauth.utils.hashing.HasherBCrypt;
|
||||||
|
|
||||||
|
@ -12,9 +7,6 @@ import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap;
|
import static org.samo_lego.simpleauth.SimpleAuth.playerCacheMap;
|
||||||
|
|
||||||
public class AuthHelper {
|
public class AuthHelper {
|
||||||
// Json parser
|
|
||||||
private static final JsonParser parser = new JsonParser();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks password of user
|
* Checks password of user
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue