Bug fixes for global password.

This commit is contained in:
samo_lego 2020-02-17 19:21:52 +01:00
parent 322c3ad00b
commit ff1b6749c6
5 changed files with 30 additions and 20 deletions

View File

@ -94,6 +94,7 @@ public class AuthCommand {
Entity sender = source.getEntity();
// Writing the global pass to config
SimpleAuth.config.main.globalPassword = AuthHelper.hashPass(pass.toCharArray());
SimpleAuth.config.main.enableGlobalPassword = true;
SimpleAuth.config.save(new File("./mods/SimpleAuth/config.json"));
if(sender != null)

View File

@ -37,14 +37,16 @@ public class LoginCommand {
private static int login(ServerCommandSource source, String pass) throws CommandSyntaxException {
// Getting the player who send the command
ServerPlayerEntity player = source.getPlayer();
if(SimpleAuth.config.main.enableGlobalPassword && AuthHelper.checkPass("globalPass", pass.toCharArray())) {
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
return 1;
}
else if(SimpleAuth.isAuthenticated(player)) {
if(SimpleAuth.isAuthenticated(player)) {
player.sendMessage(alreadyAuthenticated);
return 0;
}
else if(SimpleAuth.config.main.enableGlobalPassword) {
if (AuthHelper.checkPass("globalPass", pass.toCharArray())) {
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
return 1;
}
}
else if (AuthHelper.checkPass(player.getUuidAsString(), pass.toCharArray())) {
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
return 1;

View File

@ -22,7 +22,7 @@ public class RegisterCommand {
private static Text alreadyRegistered = new LiteralText(SimpleAuth.config.lang.alreadyRegistered);
private static Text registerSuccess = new LiteralText(SimpleAuth.config.lang.registerSuccess);
private static Text matchPass = new LiteralText( SimpleAuth.config.lang.matchPassword);
private static Text globalPasswordRequired = new LiteralText( SimpleAuth.config.lang.globalPasswordRequired);
private static Text loginRequired = new LiteralText(SimpleAuth.config.lang.loginRequired);
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
@ -42,7 +42,7 @@ public class RegisterCommand {
private static int register(ServerCommandSource source, String pass1, String pass2) throws CommandSyntaxException {
ServerPlayerEntity player = source.getPlayer();
if(SimpleAuth.config.main.enableGlobalPassword) {
player.sendMessage(globalPasswordRequired);
player.sendMessage(loginRequired);
return 0;
}
else if(SimpleAuth.isAuthenticated(player)) {

View File

@ -5,6 +5,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.packet.ChatMessageC2SPacket;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.TypedActionResult;
@ -18,20 +20,25 @@ import java.util.TimerTask;
* and cancel them if they aren't authenticated
*/
public class AuthEventHandler {
private static TranslatableText notAuthenticated = new TranslatableText(SimpleAuth.config.lang.notAuthenticated);
private static TranslatableText timeExpired = new TranslatableText(SimpleAuth.config.lang.timeExpired);
private static Text notAuthenticated() {
if(SimpleAuth.config.main.enableGlobalPassword) {
return new LiteralText(SimpleAuth.config.lang.loginRequired);
}
return new LiteralText(SimpleAuth.config.lang.notAuthenticated);
}
private static Text timeExpired = new LiteralText(SimpleAuth.config.lang.timeExpired);
private static int delay = SimpleAuth.config.main.delay;
// Player joining the server
public static void onPlayerJoin(ServerPlayerEntity player) {
SimpleAuth.deauthenticatedUsers.add(player);
CompoundTag tag = new CompoundTag();
/*CompoundTag tag = new CompoundTag();
tag.putInt("loginTries", 0);
player.writeCustomDataToTag(tag);
player.writeCustomDataToTag(tag);*/
// Player not authenticated
// If clause actually not needed, since we add player to deauthenticated hashset above
if (!SimpleAuth.isAuthenticated(player)) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
// Setting the player to be invisible to mobs and also invulnerable
player.setInvulnerable(SimpleAuth.config.main.playerInvulnerable);
player.setInvisible(SimpleAuth.config.main.playerInvisible);
@ -56,7 +63,7 @@ public class AuthEventHandler {
!msg.startsWith("/register") &&
(!SimpleAuth.config.main.allowChat || msg.startsWith("/"))
) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}
return ActionResult.PASS;
@ -72,7 +79,7 @@ public class AuthEventHandler {
// Using a block (right-click function)
public static ActionResult onUseBlock(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockUse) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}
return ActionResult.PASS;
@ -81,7 +88,7 @@ public class AuthEventHandler {
// Punching a block
public static ActionResult onAttackBlock(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockPunch) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}
return ActionResult.PASS;
@ -90,7 +97,7 @@ public class AuthEventHandler {
// Using an item
public static TypedActionResult<ItemStack> onUseItem(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemUse) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return TypedActionResult.fail(ItemStack.EMPTY);
}
@ -99,7 +106,7 @@ public class AuthEventHandler {
// Dropping an item
public static ActionResult onDropItem(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemDrop) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}
return ActionResult.PASS;
@ -107,7 +114,7 @@ public class AuthEventHandler {
// Attacking an entity
public static ActionResult onAttackEntity(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityPunch) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}
@ -116,7 +123,7 @@ public class AuthEventHandler {
// Interacting with entity
public static ActionResult onUseEntity(PlayerEntity player) {
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityInteract) {
player.sendMessage(notAuthenticated);
player.sendMessage(notAuthenticated());
return ActionResult.FAIL;
}

View File

@ -66,7 +66,7 @@ public class AuthConfig {
public String wrongPassword = "§4Wrong password!";
public String matchPassword = "§6Passwords must match!";
public String passwordUpdated = "§4Your password was updated successfully!";
public String globalPasswordRequired = "§4Use /login <global password> to authenticate!";
public String loginRequired = "§cYou are not authenticated!\n§6Use /login to authenticate!";
public String globalPasswordSet = "§aGlobal password was successfully set!";
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
public String alreadyAuthenticated = "§4You are already authenticated.";