Cleanup
This commit is contained in:
parent
4db0578cf7
commit
cfce56df95
|
@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G
|
||||||
|
|
||||||
# Fabric properties
|
# Fabric properties
|
||||||
minecraft_version=1.16.1
|
minecraft_version=1.16.1
|
||||||
yarn_mappings=1.16.1+build.20
|
yarn_mappings=1.16.1+build.21
|
||||||
loader_version=0.8.9+build.203
|
loader_version=0.9.0+build.204
|
||||||
|
|
||||||
#Fabric api
|
#Fabric api
|
||||||
fabric_version=0.14.1+build.372-1.16
|
fabric_version=0.14.1+build.372-1.16
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.4.6
|
mod_version = 1.4.7
|
||||||
maven_group = org.samo_lego
|
maven_group = org.samo_lego
|
||||||
archives_base_name = simpleauth
|
archives_base_name = simpleauth
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ import java.util.HashMap;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static org.iq80.leveldb.impl.Iq80DBFactory.bytes;
|
import static org.iq80.leveldb.impl.Iq80DBFactory.bytes;
|
||||||
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
|
import static org.samo_lego.simpleauth.utils.CarpetHelper.isPlayerCarpetFake;
|
||||||
|
@ -43,7 +45,9 @@ import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||||
public class SimpleAuth implements DedicatedServerModInitializer {
|
public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
|
||||||
public static SimpleAuthDatabase db = new SimpleAuthDatabase();
|
public static SimpleAuthDatabase DB = new SimpleAuthDatabase();
|
||||||
|
|
||||||
|
public static final ExecutorService THREADPOOL = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
// HashMap of players that are not authenticated
|
// HashMap of players that are not authenticated
|
||||||
// Rather than storing all the authenticated players, we just store ones that are not authenticated
|
// Rather than storing all the authenticated players, we just store ones that are not authenticated
|
||||||
|
@ -73,13 +77,13 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
LOGGER.info("[SimpleAuth] This mod wouldn't exist without the awesome Fabric Community. TYSM guys!");
|
LOGGER.info("[SimpleAuth] This mod wouldn't exist without the awesome Fabric Community. TYSM guys!");
|
||||||
|
|
||||||
// Creating data directory (database and config files are stored there)
|
// Creating data directory (database and config files are stored there)
|
||||||
File file = new File(gameDirectory + "/mods/SimpleAuth/levelDBStore");
|
File file = new File(gameDirectory + "/mods/SimpleAuth/leveldbStore");
|
||||||
if (!file.exists() && !file.mkdirs())
|
if (!file.exists() && !file.mkdirs())
|
||||||
throw new RuntimeException("[SimpleAuth] Error creating directory!");
|
throw new RuntimeException("[SimpleAuth] Error creating directory!");
|
||||||
// Loading config
|
// Loading config
|
||||||
config = AuthConfig.load(new File(gameDirectory + "/mods/SimpleAuth/config.json"));
|
config = AuthConfig.load(new File(gameDirectory + "/mods/SimpleAuth/config.json"));
|
||||||
// Connecting to db
|
// Connecting to db
|
||||||
db.openConnection();
|
DB.openConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serverProp.load(new FileReader(gameDirectory + "/server.properties"));
|
serverProp.load(new FileReader(gameDirectory + "/server.properties"));
|
||||||
|
@ -118,7 +122,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
private void onStopServer() {
|
private void onStopServer() {
|
||||||
LOGGER.info("[SimpleAuth] Shutting down SimpleAuth.");
|
LOGGER.info("[SimpleAuth] Shutting down SimpleAuth.");
|
||||||
|
|
||||||
WriteBatch batch = db.getLevelDBStore().createWriteBatch();
|
WriteBatch batch = DB.getLevelDBStore().createWriteBatch();
|
||||||
// Writing coords of de-authenticated players to database
|
// Writing coords of de-authenticated players to database
|
||||||
deauthenticatedUsers.forEach((uuid, playerCache) -> {
|
deauthenticatedUsers.forEach((uuid, playerCache) -> {
|
||||||
JsonObject data = new JsonObject();
|
JsonObject data = new JsonObject();
|
||||||
|
@ -136,22 +140,26 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
// Writing and closing batch
|
// Writing and closing batch
|
||||||
db.getLevelDBStore().write(batch);
|
DB.getLevelDBStore().write(batch);
|
||||||
batch.close();
|
batch.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("[SimpleAuth] Error saving player data! " + e.getMessage());
|
LOGGER.error("[SimpleAuth] Error saving player data! " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Closing DB connection
|
// Closing DB connection
|
||||||
db.close();
|
DB.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting some config options
|
// Getting not authenticated text
|
||||||
private static Text notAuthenticated() {
|
private static LiteralText notAuthenticated(ServerPlayerEntity player) {
|
||||||
if(SimpleAuth.config.main.enableGlobalPassword) {
|
final PlayerCache cache = deauthenticatedUsers.get(convertUuid(player));
|
||||||
return new LiteralText(SimpleAuth.config.lang.loginRequired);
|
if(SimpleAuth.config.main.enableGlobalPassword || cache.isRegistered)
|
||||||
}
|
return new LiteralText(
|
||||||
return new LiteralText(SimpleAuth.config.lang.notAuthenticated);
|
SimpleAuth.config.lang.notAuthenticated + "\n" + SimpleAuth.config.lang.loginRequired
|
||||||
|
);
|
||||||
|
return new LiteralText(
|
||||||
|
SimpleAuth.config.lang.notAuthenticated+ "\n" + SimpleAuth.config.lang.registerRequired
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticates player and sends the message
|
// Authenticates player and sends the message
|
||||||
|
@ -185,7 +193,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
|
|
||||||
// De-authenticates player
|
// De-authenticates player
|
||||||
public static void deauthenticatePlayer(ServerPlayerEntity player) {
|
public static void deauthenticatePlayer(ServerPlayerEntity player) {
|
||||||
if(db.isClosed())
|
if(DB.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Marking player as not authenticated, (re)setting login tries to zero
|
// Marking player as not authenticated, (re)setting login tries to zero
|
||||||
|
@ -197,7 +205,7 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
teleportPlayer(player, true);
|
teleportPlayer(player, true);
|
||||||
|
|
||||||
// Player is now not authenticated
|
// Player is now not authenticated
|
||||||
player.sendMessage(notAuthenticated(), false);
|
player.sendMessage(notAuthenticated(player), false);
|
||||||
|
|
||||||
// Setting the player to be invisible to mobs and also invulnerable
|
// Setting the player to be invisible to mobs and also invulnerable
|
||||||
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
|
player.setInvulnerable(SimpleAuth.config.experimental.playerInvulnerable);
|
||||||
|
@ -206,7 +214,8 @@ public class SimpleAuth implements DedicatedServerModInitializer {
|
||||||
timer.schedule(new TimerTask() {
|
timer.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if(!SimpleAuth.isAuthenticated(player) && player.networkHandler.getConnection().isOpen()) // Kicking player if not authenticated
|
// Kicking player if not authenticated
|
||||||
|
if(!SimpleAuth.isAuthenticated(player) && player.networkHandler.getConnection().isOpen())
|
||||||
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
player.networkHandler.disconnect(new LiteralText(SimpleAuth.config.lang.timeExpired));
|
||||||
}
|
}
|
||||||
}, SimpleAuth.config.main.delay * 1000);
|
}, SimpleAuth.config.main.delay * 1000);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.THREADPOOL;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||||
|
|
||||||
|
@ -71,10 +72,10 @@ public class AccountCommand {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New thread to avoid lag spikes
|
// Different thread to avoid lag spikes
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
if (AuthHelper.checkPass(convertUuid(player), pass.toCharArray()) == 1) {
|
if (AuthHelper.checkPass(convertUuid(player), pass.toCharArray()) == 1) {
|
||||||
SimpleAuth.db.deleteUserData(convertUuid(player));
|
SimpleAuth.DB.deleteUserData(convertUuid(player));
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
new LiteralText(config.lang.accountDeleted),
|
new LiteralText(config.lang.accountDeleted),
|
||||||
false
|
false
|
||||||
|
@ -86,7 +87,7 @@ public class AccountCommand {
|
||||||
new LiteralText(config.lang.wrongPassword),
|
new LiteralText(config.lang.wrongPassword),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +103,8 @@ public class AccountCommand {
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// New thread to avoid lag spikes
|
// Different thread to avoid lag spikes
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
if (AuthHelper.checkPass(convertUuid(player), oldPass.toCharArray()) == 1) {
|
if (AuthHelper.checkPass(convertUuid(player), oldPass.toCharArray()) == 1) {
|
||||||
if (newPass.length() < config.main.minPasswordChars) {
|
if (newPass.length() < config.main.minPasswordChars) {
|
||||||
player.sendMessage(new LiteralText(
|
player.sendMessage(new LiteralText(
|
||||||
|
@ -122,7 +123,7 @@ public class AccountCommand {
|
||||||
String hash = AuthHelper.hashPass(newPass.toCharArray());
|
String hash = AuthHelper.hashPass(newPass.toCharArray());
|
||||||
playerdata.addProperty("password", hash);
|
playerdata.addProperty("password", hash);
|
||||||
|
|
||||||
SimpleAuth.db.updateUserData(convertUuid(player), playerdata.toString());
|
SimpleAuth.DB.updateUserData(convertUuid(player), playerdata.toString());
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
new LiteralText(config.lang.passwordUpdated),
|
new LiteralText(config.lang.passwordUpdated),
|
||||||
false
|
false
|
||||||
|
@ -133,7 +134,7 @@ public class AccountCommand {
|
||||||
new LiteralText(config.lang.wrongPassword),
|
new LiteralText(config.lang.wrongPassword),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
import static org.samo_lego.simpleauth.SimpleAuth.*;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.db;
|
|
||||||
|
|
||||||
public class AuthCommand {
|
public class AuthCommand {
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
@ -114,13 +113,13 @@ public class AuthCommand {
|
||||||
private static int setGlobalPassword(ServerCommandSource source, String pass) {
|
private static int setGlobalPassword(ServerCommandSource source, String pass) {
|
||||||
// Getting the player who send the command
|
// Getting the player who send the command
|
||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
// New thread to avoid lag spikes
|
// Different thread to avoid lag spikes
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
// Writing the global pass to config
|
// Writing the global pass to config
|
||||||
config.main.globalPassword = AuthHelper.hashPass(pass.toCharArray());
|
config.main.globalPassword = AuthHelper.hashPass(pass.toCharArray());
|
||||||
config.main.enableGlobalPassword = true;
|
config.main.enableGlobalPassword = true;
|
||||||
config.save(new File("./mods/SimpleAuth/config.json"));
|
config.save(new File("./mods/SimpleAuth/config.json"));
|
||||||
}).start();
|
});
|
||||||
|
|
||||||
if(sender != null)
|
if(sender != null)
|
||||||
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.globalPasswordSet), false);
|
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.globalPasswordSet), false);
|
||||||
|
@ -150,10 +149,10 @@ public class AuthCommand {
|
||||||
// Deleting (unregistering) user's account
|
// Deleting (unregistering) user's account
|
||||||
private static int removeAccount(ServerCommandSource source, String uuid) {
|
private static int removeAccount(ServerCommandSource source, String uuid) {
|
||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
db.deleteUserData(uuid);
|
DB.deleteUserData(uuid);
|
||||||
SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, null));
|
SimpleAuth.deauthenticatedUsers.put(uuid, new PlayerCache(uuid, null));
|
||||||
}).start();
|
});
|
||||||
|
|
||||||
if(sender != null)
|
if(sender != null)
|
||||||
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataDeleted), false);
|
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataDeleted), false);
|
||||||
|
@ -167,19 +166,19 @@ public class AuthCommand {
|
||||||
// Getting the player who send the command
|
// Getting the player who send the command
|
||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
|
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
// JSON object holding password (may hold some other info in the future)
|
// JSON object holding password (may hold some other info in the future)
|
||||||
JsonObject playerdata = new JsonObject();
|
JsonObject playerdata = new JsonObject();
|
||||||
String hash = AuthHelper.hashPass(password.toCharArray());
|
String hash = AuthHelper.hashPass(password.toCharArray());
|
||||||
playerdata.addProperty("password", hash);
|
playerdata.addProperty("password", hash);
|
||||||
|
|
||||||
if (db.registerUser(uuid, playerdata.toString())) {
|
if (DB.registerUser(uuid, playerdata.toString())) {
|
||||||
if (sender != null)
|
if (sender != null)
|
||||||
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
|
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
|
||||||
else
|
else
|
||||||
LOGGER.info(config.lang.userdataUpdated);
|
LOGGER.info(config.lang.userdataUpdated);
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,18 +187,18 @@ public class AuthCommand {
|
||||||
// Getting the player who send the command
|
// Getting the player who send the command
|
||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
|
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
// JSON object holding password (may hold some other info in the future)
|
// JSON object holding password (may hold some other info in the future)
|
||||||
JsonObject playerdata = new JsonObject();
|
JsonObject playerdata = new JsonObject();
|
||||||
String hash = AuthHelper.hashPass(password.toCharArray());
|
String hash = AuthHelper.hashPass(password.toCharArray());
|
||||||
playerdata.addProperty("password", hash);
|
playerdata.addProperty("password", hash);
|
||||||
|
|
||||||
db.updateUserData(uuid, playerdata.toString());
|
DB.updateUserData(uuid, playerdata.toString());
|
||||||
if (sender != null)
|
if (sender != null)
|
||||||
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
|
((PlayerEntity) sender).sendMessage(new LiteralText(config.lang.userdataUpdated), false);
|
||||||
else
|
else
|
||||||
LOGGER.info(config.lang.userdataUpdated);
|
LOGGER.info(config.lang.userdataUpdated);
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.THREADPOOL;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||||
|
|
||||||
|
@ -38,8 +39,8 @@ public class LoginCommand {
|
||||||
player.sendMessage(new LiteralText(config.lang.alreadyAuthenticated), false);
|
player.sendMessage(new LiteralText(config.lang.alreadyAuthenticated), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Putting rest of the command in new thread to avoid lag spikes
|
// Putting rest of the command in different thread to avoid lag spikes
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
int maxLoginTries = config.main.maxLoginTries;
|
int maxLoginTries = config.main.maxLoginTries;
|
||||||
int passwordResult = AuthHelper.checkPass(uuid, pass.toCharArray());
|
int passwordResult = AuthHelper.checkPass(uuid, pass.toCharArray());
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ public class LoginCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(passwordResult == -1) {
|
else if(passwordResult == -1) {
|
||||||
player.sendMessage(new LiteralText(config.lang.notRegistered), false);
|
player.sendMessage(new LiteralText(config.lang.registerRequired), false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Kicking the player out
|
// Kicking the player out
|
||||||
|
@ -64,7 +65,7 @@ public class LoginCommand {
|
||||||
player.sendMessage(new LiteralText(config.lang.wrongPassword), false);
|
player.sendMessage(new LiteralText(config.lang.wrongPassword), false);
|
||||||
// ++ the login tries
|
// ++ the login tries
|
||||||
SimpleAuth.deauthenticatedUsers.get(uuid).loginTries += 1;
|
SimpleAuth.deauthenticatedUsers.get(uuid).loginTries += 1;
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||||
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
import static com.mojang.brigadier.arguments.StringArgumentType.word;
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.THREADPOOL;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
import static org.samo_lego.simpleauth.utils.UuidConverter.convertUuid;
|
||||||
|
|
||||||
|
@ -48,8 +49,8 @@ public class RegisterCommand {
|
||||||
player.sendMessage(new LiteralText(config.lang.matchPassword), false);
|
player.sendMessage(new LiteralText(config.lang.matchPassword), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// New thread to avoid lag spikes
|
// Different thread to avoid lag spikes
|
||||||
new Thread(() -> {
|
THREADPOOL.submit(() -> {
|
||||||
if(pass1.length() < config.main.minPasswordChars) {
|
if(pass1.length() < config.main.minPasswordChars) {
|
||||||
player.sendMessage(new LiteralText(
|
player.sendMessage(new LiteralText(
|
||||||
String.format(config.lang.minPasswordChars, config.main.minPasswordChars)
|
String.format(config.lang.minPasswordChars, config.main.minPasswordChars)
|
||||||
|
@ -67,12 +68,12 @@ public class RegisterCommand {
|
||||||
JsonObject playerdata = new JsonObject();
|
JsonObject playerdata = new JsonObject();
|
||||||
playerdata.addProperty("password", hash);
|
playerdata.addProperty("password", hash);
|
||||||
|
|
||||||
if (SimpleAuth.db.registerUser(convertUuid(player), playerdata.toString())) {
|
if (SimpleAuth.DB.registerUser(convertUuid(player), playerdata.toString())) {
|
||||||
SimpleAuth.authenticatePlayer(player, new LiteralText(config.lang.registerSuccess));
|
SimpleAuth.authenticatePlayer(player, new LiteralText(config.lang.registerSuccess));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.sendMessage(new LiteralText(config.lang.alreadyRegistered), false);
|
player.sendMessage(new LiteralText(config.lang.alreadyRegistered), false);
|
||||||
}).start();
|
});
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class AuthEventHandler {
|
||||||
if(playerCache.isRegistered)
|
if(playerCache.isRegistered)
|
||||||
player.sendMessage(new LiteralText(config.lang.loginRequired), false);
|
player.sendMessage(new LiteralText(config.lang.loginRequired), false);
|
||||||
else
|
else
|
||||||
player.sendMessage(new LiteralText(config.lang.notRegistered), false);
|
player.sendMessage(new LiteralText(config.lang.registerRequired), false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
deauthenticatePlayer(player);
|
deauthenticatePlayer(player);
|
||||||
|
|
|
@ -68,24 +68,23 @@ public class AuthConfig {
|
||||||
public String wrongPassword = "§4Wrong password!";
|
public String wrongPassword = "§4Wrong password!";
|
||||||
public String matchPassword = "§6Passwords must match!";
|
public String matchPassword = "§6Passwords must match!";
|
||||||
public String passwordUpdated = "§aYour password was updated successfully!";
|
public String passwordUpdated = "§aYour password was updated successfully!";
|
||||||
public String loginRequired = "§cYou are not authenticated!\n§6Use /login to authenticate!";
|
public String loginRequired = "§6Use /login <password> to authenticate!";
|
||||||
public String loginTriesExceeded = "§4Too many login tries.";
|
public String loginTriesExceeded = "§4Too many login tries.";
|
||||||
public String globalPasswordSet = "§aGlobal password was successfully set!";
|
public String globalPasswordSet = "§aGlobal password was successfully set!";
|
||||||
public String cannotChangePassword = "§cYou cannot change password!";
|
public String cannotChangePassword = "§cYou cannot change password!";
|
||||||
public String cannotUnregister = "§cYou cannot unregister this account!";
|
public String cannotUnregister = "§cYou cannot unregister this account!";
|
||||||
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
|
public String notAuthenticated = "§cYou are not authenticated!";
|
||||||
public String alreadyAuthenticated = "§6You are already authenticated.";
|
public String alreadyAuthenticated = "§6You are already authenticated.";
|
||||||
public String successfullyAuthenticated = "§aYou are now authenticated.";
|
public String successfullyAuthenticated = "§aYou are now authenticated.";
|
||||||
public String successfulLogout = "§aLogged out successfully.";
|
public String successfulLogout = "§aLogged out successfully.";
|
||||||
public String timeExpired = "§cTime for authentication has expired.";
|
public String timeExpired = "§cTime for authentication has expired.";
|
||||||
public String notRegistered = "§6This account is not yet registered! Type `/register` first";
|
public String registerRequired = "§6Type /register <password> <password> to claim this account.";
|
||||||
public String alreadyRegistered = "§6This account name is already registered!";
|
public String alreadyRegistered = "§6This account name is already registered!";
|
||||||
public String registerSuccess = "§aYou are now authenticated.";
|
public String registerSuccess = "§aYou are now authenticated.";
|
||||||
public String userdataDeleted = "§aUserdata deleted.";
|
public String userdataDeleted = "§aUserdata deleted.";
|
||||||
public String userdataUpdated = "§aUserdata updated.";
|
public String userdataUpdated = "§aUserdata updated.";
|
||||||
public String accountDeleted = "§aYour account was successfully deleted!";
|
public String accountDeleted = "§aYour account was successfully deleted!";
|
||||||
public String configurationReloaded = "§aConfiguration file was reloaded successfully.";
|
public String configurationReloaded = "§aConfiguration file was reloaded successfully.";
|
||||||
public String successfulPortalRescue = "§aYou were rescued from nether portal successfully!";
|
|
||||||
public String maxPasswordChars = "§6Password can be at most %d characters long!";
|
public String maxPasswordChars = "§6Password can be at most %d characters long!";
|
||||||
public String minPasswordChars = "§6Password needs to be at least %d characters long!";
|
public String minPasswordChars = "§6Password needs to be at least %d characters long!";
|
||||||
public String disallowedUsername = "§6Invalid username characters! Allowed character regex: %s";
|
public String disallowedUsername = "§6Invalid username characters! Allowed character regex: %s";
|
||||||
|
@ -130,7 +129,9 @@ public class AuthConfig {
|
||||||
public static AuthConfig load(File file) {
|
public static AuthConfig load(File file) {
|
||||||
AuthConfig config;
|
AuthConfig config;
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try (FileReader fileReader = new FileReader(file)) {
|
try (BufferedReader fileReader = new BufferedReader(
|
||||||
|
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)
|
||||||
|
)) {
|
||||||
config = gson.fromJson(fileReader, AuthConfig.class);
|
config = gson.fromJson(fileReader, AuthConfig.class);
|
||||||
} 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);
|
||||||
|
|
|
@ -6,8 +6,8 @@ import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
import static org.samo_lego.simpleauth.SimpleAuth.DB;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
import static org.samo_lego.simpleauth.SimpleAuth.config;
|
||||||
import static org.samo_lego.simpleauth.SimpleAuth.db;
|
|
||||||
|
|
||||||
public class PlayerCache {
|
public class PlayerCache {
|
||||||
public boolean isRegistered;
|
public boolean isRegistered;
|
||||||
|
@ -29,7 +29,7 @@ public class PlayerCache {
|
||||||
|
|
||||||
|
|
||||||
public PlayerCache(String uuid, ServerPlayerEntity player) {
|
public PlayerCache(String uuid, ServerPlayerEntity player) {
|
||||||
if(db.isClosed())
|
if(DB.isClosed())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(player != null) {
|
if(player != null) {
|
||||||
|
@ -44,8 +44,8 @@ public class PlayerCache {
|
||||||
this.lastZ = player.getZ();
|
this.lastZ = player.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(db.isUserRegistered(uuid)) {
|
if(DB.isUserRegistered(uuid)) {
|
||||||
String data = db.getData(uuid);
|
String data = DB.getData(uuid);
|
||||||
|
|
||||||
// Getting (hashed) password
|
// Getting (hashed) password
|
||||||
JsonObject json = gson.fromJson(data, JsonObject.class);
|
JsonObject json = gson.fromJson(data, JsonObject.class);
|
||||||
|
@ -66,7 +66,7 @@ public class PlayerCache {
|
||||||
|
|
||||||
// Removing location data from DB
|
// Removing location data from DB
|
||||||
json.remove("lastLocation");
|
json.remove("lastLocation");
|
||||||
db.updateUserData(uuid, json.toString());
|
DB.updateUserData(uuid, json.toString());
|
||||||
}
|
}
|
||||||
} catch (JsonSyntaxException ignored) {
|
} catch (JsonSyntaxException ignored) {
|
||||||
// Player didn't have any coords in db to tp to
|
// Player didn't have any coords in db to tp to
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class AuthHelper {
|
||||||
hashed = SimpleAuth.deauthenticatedUsers.get(uuid).password;
|
hashed = SimpleAuth.deauthenticatedUsers.get(uuid).password;
|
||||||
// Hashed password from DB
|
// Hashed password from DB
|
||||||
else {
|
else {
|
||||||
JsonObject json = parser.parse(SimpleAuth.db.getData(uuid)).getAsJsonObject();
|
JsonObject json = parser.parse(SimpleAuth.DB.getData(uuid)).getAsJsonObject();
|
||||||
hashed = json.get("password").getAsString();
|
hashed = json.get("password").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue