forked from sorceress/EasyAuth
Merge pull request #4 from samolego/new-uuid-2
Checking for online mode to decide on UUID password storage
This commit is contained in:
commit
12ceb906df
|
@ -2,7 +2,7 @@
|
|||
|
||||
![License](https://img.shields.io/badge/License-MIT-brightgreen)
|
||||
[![Curseforge downloads](http://cf.way2muchnoise.eu/full_simpleauth_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/simpleauth)
|
||||
![Java CI with Gradle](https://github.com/samolego/SimpleAuth/workflows/Java%20CI%20with%20Gradle/badge.svg)
|
||||
![Gradle Build](https://github.com/samolego/SimpleAuth/workflows/Gradle%20Build/badge.svg)
|
||||
|
||||
Requires Fabric API.
|
||||
|
||||
|
|
|
@ -21,7 +21,10 @@ import org.samo_lego.simpleauth.storage.PlayerCache;
|
|||
import org.samo_lego.simpleauth.storage.SimpleAuthDatabase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -46,6 +49,10 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
|
||||
// Getting game directory
|
||||
public static final File gameDirectory = FabricLoader.getInstance().getGameDirectory();
|
||||
|
||||
// Server properties
|
||||
public static Properties serverProp = new Properties();
|
||||
|
||||
// Mod config
|
||||
public static AuthConfig config;
|
||||
|
||||
|
@ -65,6 +72,12 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
|||
// Connecting to db
|
||||
db.openConnection();
|
||||
|
||||
try {
|
||||
serverProp.load(new FileReader(gameDirectory + "/server.properties"));
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("[SimpleAuth] Error while reading server properties: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
// Registering the commands
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> {
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.samo_lego.simpleauth.utils;
|
|||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
import static org.samo_lego.simpleauth.SimpleAuth.serverProp;
|
||||
|
||||
/**
|
||||
* Converts player uuid, to ensure player with "nAmE" and "NamE" get same uuid
|
||||
* Both players are not allowed to play, since mod mimics Mojang behaviour
|
||||
|
@ -9,21 +11,22 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
*/
|
||||
public class UuidConverter {
|
||||
|
||||
/** Converts player UUID to offline mode style.
|
||||
*
|
||||
* @param playername name of the player to get UUID for
|
||||
* @return converted UUID as string
|
||||
*/
|
||||
public static String convertUuid(String playername) {
|
||||
return PlayerEntity.getOfflinePlayerUuid(playername).toString();
|
||||
}
|
||||
private static final boolean isOnline = (boolean) serverProp.getOrDefault("online-mode", false);
|
||||
|
||||
/** Converts player UUID to offline mode style.
|
||||
/** Gets player UUID.
|
||||
*
|
||||
* @param player player to get UUID for
|
||||
* @return converted UUID as string
|
||||
*/
|
||||
public static String convertUuid(PlayerEntity player) {
|
||||
return convertUuid(player.getName().asString().toLowerCase());
|
||||
// If server is in online mode online-mode UUIDs should be used
|
||||
if(isOnline)
|
||||
return player.getUuidAsString();
|
||||
|
||||
/* Lower case is used for Player and PlAyEr to get same UUID
|
||||
Mimicking Mojang behaviour, where players cannot set their name to
|
||||
ExAmple if example is already taken.*/
|
||||
String playername = player.getName().asString().toLowerCase();
|
||||
return PlayerEntity.getOfflinePlayerUuid(playername).toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue