Hardcoded rn, planning to add language file in the future.
This commit is contained in:
samo_lego 2019-12-02 17:41:22 +01:00
parent 4187a855fb
commit 8054602a23
9 changed files with 29 additions and 46 deletions

View File

@ -23,10 +23,14 @@ dependencies {
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Argon2 library for password hashing // Argon2 library for password hashing
compile 'de.mkammerer:argon2-jvm:2.6' implementation 'de.mkammerer:argon2-jvm:2.6'
include 'de.mkammerer:argon2-jvm:2.6'
// JDBC SQLite Driver // JDBC SQLite Driver
compile group:'org.xerial', name:'sqlite-jdbc', version:'3.8.11.2' include group:'org.xerial', name:'sqlite-jdbc', version:'3.8.11.2'
// JNA lib
include 'net.java.dev.jna:jna:5.5.0'
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them. // You may need to force-disable transitiveness on them.

View File

@ -54,7 +54,6 @@ public class SimpleAuth implements DedicatedServerModInitializer {
PlayerJoinServerCallback.EVENT.register(AuthEventHandler::onPlayerJoin); PlayerJoinServerCallback.EVENT.register(AuthEventHandler::onPlayerJoin);
PlayerLeaveServerCallback.EVENT.register(AuthEventHandler::onPlayerLeave); PlayerLeaveServerCallback.EVENT.register(AuthEventHandler::onPlayerLeave);
DropItemCallback.EVENT.register(AuthEventHandler::onDropItem); DropItemCallback.EVENT.register(AuthEventHandler::onDropItem);
//todo
OnChatCallback.EVENT.register(AuthEventHandler::onPlayerChat); OnChatCallback.EVENT.register(AuthEventHandler::onPlayerChat);
OnPlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove); OnPlayerMoveCallback.EVENT.register(AuthEventHandler::onPlayerMove);
// From Fabric API // From Fabric API

View File

@ -1,32 +1,24 @@
package org.samo_lego.simpleauth.commands; package org.samo_lego.simpleauth.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.SimpleAuth;
import org.samo_lego.simpleauth.utils.AuthHelper; import org.samo_lego.simpleauth.utils.AuthHelper;
import static com.mojang.brigadier.arguments.StringArgumentType.*; import static com.mojang.brigadier.arguments.StringArgumentType.getString;
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.authenticatedUsers;
import static org.samo_lego.simpleauth.SimpleAuth.isAuthenticated;
public class AuthCommand { public class AuthCommand {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
private static TranslatableText userdataDeleted = new TranslatableText("command.simpleauth.userdataDeleted"); private static TranslatableText userdataDeleted = new TranslatableText("§aUserdata deleted.");
private static TranslatableText userdataUpdated = new TranslatableText("command.simpleauth.userdataUpdated"); private static TranslatableText userdataUpdated = new TranslatableText("§aUserdata updated.");
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
// Registering the "/auth" command // Registering the "/auth" command

View File

@ -16,10 +16,10 @@ import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
public class ChangepwCommand { public class ChangepwCommand {
private static TranslatableText enterNewPassword = new TranslatableText("command.simpleauth.passwordNew"); private static TranslatableText enterNewPassword = new TranslatableText("§4You need to enter new password!");
private static TranslatableText enterPassword = new TranslatableText("command.simpleauth.password"); private static TranslatableText enterPassword = new TranslatableText("§6You need to enter your password!");
private static TranslatableText wrongPassword = new TranslatableText("command.simpleauth.wrongPassword"); private static TranslatableText wrongPassword = new TranslatableText("§4Wrong password!");
private static TranslatableText passwordUpdated = new TranslatableText("command.simpleauth.passwordUpdated"); private static TranslatableText passwordUpdated = new TranslatableText("§4Your password was updated successfully!");
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
// Registering the "/changepw" command // Registering the "/changepw" command

View File

@ -2,9 +2,6 @@ package org.samo_lego.simpleauth.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@ -19,10 +16,10 @@ import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
public class LoginCommand { public class LoginCommand {
private static TranslatableText enterPassword = new TranslatableText("command.simpleauth.password"); private static TranslatableText enterPassword = new TranslatableText("§6You need to enter your password!");
private static TranslatableText wrongPassword = new TranslatableText("command.simpleauth.wrongPassword"); private static TranslatableText wrongPassword = new TranslatableText("§4Wrong password!");
private static TranslatableText alreadyAuthenticated = new TranslatableText("command.simpleauth.alreadyAuthenticated"); private static TranslatableText alreadyAuthenticated = new TranslatableText("§4You are already authenticated.");
private static Text text = new LiteralText("You have entered login command"); private static Text text = new LiteralText("§aYou are now authenticated.");
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
// Registering the "/login" command // Registering the "/login" command

View File

@ -2,8 +2,6 @@ package org.samo_lego.simpleauth.commands;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@ -11,8 +9,6 @@ import net.minecraft.text.TranslatableText;
import org.samo_lego.simpleauth.SimpleAuth; import org.samo_lego.simpleauth.SimpleAuth;
import org.samo_lego.simpleauth.utils.AuthHelper; import org.samo_lego.simpleauth.utils.AuthHelper;
import java.util.Objects;
import static com.mojang.brigadier.arguments.StringArgumentType.getString; 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;
@ -20,11 +16,11 @@ import static net.minecraft.server.command.CommandManager.literal;
public class RegisterCommand { public class RegisterCommand {
private static TranslatableText pleaseRegister = new TranslatableText("§4Type /register <password> <password> to login."); private static TranslatableText enterPassword = new TranslatableText("§6You need to enter your password!");
private static TranslatableText enterPassword = new TranslatableText("command.simpleauth.passwordTwice"); private static TranslatableText alreadyAuthenticated = new TranslatableText("§4You are already authenticated.");
private static TranslatableText alreadyAuthenticated = new TranslatableText("command.simpleauth.alreadyAuthenticated"); private static TranslatableText alreadyRegistered = new TranslatableText("§6This account name is already registered!");
private static TranslatableText alreadyRegistered = new TranslatableText("command.simpleauth.alreadyRegistered"); private static TranslatableText registerSuccess = new TranslatableText("§aYou are now authenticated.");
private static TranslatableText registerSuccess = new TranslatableText("command.simpleauth.registerSuccess"); private static TranslatableText matchPass = new TranslatableText( "§6Passwords must match!");
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
@ -59,9 +55,7 @@ public class RegisterCommand {
player.sendMessage(alreadyRegistered); player.sendMessage(alreadyRegistered);
return 0; return 0;
} }
player.sendMessage( player.sendMessage(matchPass);
new LiteralText(source.getName() + ", passwords must match!")
);
return 0; return 0;
} }
} }

View File

@ -16,9 +16,9 @@ import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
public class UnregisterCommand { public class UnregisterCommand {
private static TranslatableText enterPassword = new TranslatableText("command.simpleauth.password"); private static TranslatableText enterPassword = new TranslatableText("§6You need to enter your password!");
private static TranslatableText wrongPassword = new TranslatableText("command.simpleauth.wrongPassword"); private static TranslatableText wrongPassword = new TranslatableText("§4Wrong password!");
private static TranslatableText accountDeleted = new TranslatableText("command.simpleauth.accountDeleted"); private static TranslatableText accountDeleted = new TranslatableText("§4Your account was successfully deleted!");
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
// Registering the "/unregister" command // Registering the "/unregister" command

View File

@ -1,10 +1,7 @@
package org.samo_lego.simpleauth.event; package org.samo_lego.simpleauth.event;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.client.network.packet.InventoryS2CPacket;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketEncoder;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.ChatMessageC2SPacket; import net.minecraft.server.network.packet.ChatMessageC2SPacket;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
@ -17,7 +14,7 @@ import org.samo_lego.simpleauth.SimpleAuth;
* and cancels them if they aren't authenticated * and cancels them if they aren't authenticated
*/ */
public class AuthEventHandler { public class AuthEventHandler {
private static TranslatableText notAuthenticated = new TranslatableText("command.simpleauth.notAuthenticated"); private static TranslatableText notAuthenticated = new TranslatableText("§4You are not authenticated!\nTry with /login or /register.");
// Player joining the server // Player joining the server
public static void onPlayerJoin(ServerPlayerEntity player) { public static void onPlayerJoin(ServerPlayerEntity player) {

View File

@ -19,7 +19,7 @@ public class AuthHelper {
// Verify password // Verify password
return argon2.verify(hashed, pass); return argon2.verify(hashed, pass);
} catch(Error e) { } catch(Error e) {
LOGGER.error("SimpleAut error: " + e); LOGGER.error("[SimpleAuth] error: " + e);
} finally { } finally {
// Wipe confidential data // Wipe confidential data
argon2.wipeArray(pass); argon2.wipeArray(pass);