Bug fixes for global password.
This commit is contained in:
parent
322c3ad00b
commit
ff1b6749c6
|
@ -94,6 +94,7 @@ public class AuthCommand {
|
||||||
Entity sender = source.getEntity();
|
Entity sender = source.getEntity();
|
||||||
// Writing the global pass to config
|
// Writing the global pass to config
|
||||||
SimpleAuth.config.main.globalPassword = AuthHelper.hashPass(pass.toCharArray());
|
SimpleAuth.config.main.globalPassword = AuthHelper.hashPass(pass.toCharArray());
|
||||||
|
SimpleAuth.config.main.enableGlobalPassword = true;
|
||||||
SimpleAuth.config.save(new File("./mods/SimpleAuth/config.json"));
|
SimpleAuth.config.save(new File("./mods/SimpleAuth/config.json"));
|
||||||
|
|
||||||
if(sender != null)
|
if(sender != null)
|
||||||
|
|
|
@ -37,14 +37,16 @@ public class LoginCommand {
|
||||||
private static int login(ServerCommandSource source, String pass) throws CommandSyntaxException {
|
private static int login(ServerCommandSource source, String pass) throws CommandSyntaxException {
|
||||||
// Getting the player who send the command
|
// Getting the player who send the command
|
||||||
ServerPlayerEntity player = source.getPlayer();
|
ServerPlayerEntity player = source.getPlayer();
|
||||||
if(SimpleAuth.config.main.enableGlobalPassword && AuthHelper.checkPass("globalPass", pass.toCharArray())) {
|
if(SimpleAuth.isAuthenticated(player)) {
|
||||||
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if(SimpleAuth.isAuthenticated(player)) {
|
|
||||||
player.sendMessage(alreadyAuthenticated);
|
player.sendMessage(alreadyAuthenticated);
|
||||||
return 0;
|
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())) {
|
else if (AuthHelper.checkPass(player.getUuidAsString(), pass.toCharArray())) {
|
||||||
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
|
SimpleAuth.authenticatePlayer(player, successfullyAuthenticated);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class RegisterCommand {
|
||||||
private static Text alreadyRegistered = new LiteralText(SimpleAuth.config.lang.alreadyRegistered);
|
private static Text alreadyRegistered = new LiteralText(SimpleAuth.config.lang.alreadyRegistered);
|
||||||
private static Text registerSuccess = new LiteralText(SimpleAuth.config.lang.registerSuccess);
|
private static Text registerSuccess = new LiteralText(SimpleAuth.config.lang.registerSuccess);
|
||||||
private static Text matchPass = new LiteralText( SimpleAuth.config.lang.matchPassword);
|
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) {
|
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 {
|
private static int register(ServerCommandSource source, String pass1, String pass2) throws CommandSyntaxException {
|
||||||
ServerPlayerEntity player = source.getPlayer();
|
ServerPlayerEntity player = source.getPlayer();
|
||||||
if(SimpleAuth.config.main.enableGlobalPassword) {
|
if(SimpleAuth.config.main.enableGlobalPassword) {
|
||||||
player.sendMessage(globalPasswordRequired);
|
player.sendMessage(loginRequired);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(SimpleAuth.isAuthenticated(player)) {
|
else if(SimpleAuth.isAuthenticated(player)) {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
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.LiteralText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.TypedActionResult;
|
import net.minecraft.util.TypedActionResult;
|
||||||
|
@ -18,20 +20,25 @@ import java.util.TimerTask;
|
||||||
* and cancel them if they aren't authenticated
|
* and cancel them if they aren't authenticated
|
||||||
*/
|
*/
|
||||||
public class AuthEventHandler {
|
public class AuthEventHandler {
|
||||||
private static TranslatableText notAuthenticated = new TranslatableText(SimpleAuth.config.lang.notAuthenticated);
|
private static Text notAuthenticated() {
|
||||||
private static TranslatableText timeExpired = new TranslatableText(SimpleAuth.config.lang.timeExpired);
|
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;
|
private static int delay = SimpleAuth.config.main.delay;
|
||||||
|
|
||||||
// Player joining the server
|
// Player joining the server
|
||||||
public static void onPlayerJoin(ServerPlayerEntity player) {
|
public static void onPlayerJoin(ServerPlayerEntity player) {
|
||||||
SimpleAuth.deauthenticatedUsers.add(player);
|
SimpleAuth.deauthenticatedUsers.add(player);
|
||||||
CompoundTag tag = new CompoundTag();
|
/*CompoundTag tag = new CompoundTag();
|
||||||
tag.putInt("loginTries", 0);
|
tag.putInt("loginTries", 0);
|
||||||
player.writeCustomDataToTag(tag);
|
player.writeCustomDataToTag(tag);*/
|
||||||
// Player not authenticated
|
// Player not authenticated
|
||||||
// If clause actually not needed, since we add player to deauthenticated hashset above
|
// If clause actually not needed, since we add player to deauthenticated hashset above
|
||||||
if (!SimpleAuth.isAuthenticated(player)) {
|
if (!SimpleAuth.isAuthenticated(player)) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
// 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.main.playerInvulnerable);
|
player.setInvulnerable(SimpleAuth.config.main.playerInvulnerable);
|
||||||
player.setInvisible(SimpleAuth.config.main.playerInvisible);
|
player.setInvisible(SimpleAuth.config.main.playerInvisible);
|
||||||
|
@ -56,7 +63,7 @@ public class AuthEventHandler {
|
||||||
!msg.startsWith("/register") &&
|
!msg.startsWith("/register") &&
|
||||||
(!SimpleAuth.config.main.allowChat || msg.startsWith("/"))
|
(!SimpleAuth.config.main.allowChat || msg.startsWith("/"))
|
||||||
) {
|
) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
|
@ -72,7 +79,7 @@ public class AuthEventHandler {
|
||||||
// Using a block (right-click function)
|
// Using a block (right-click function)
|
||||||
public static ActionResult onUseBlock(PlayerEntity player) {
|
public static ActionResult onUseBlock(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockUse) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockUse) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
|
@ -81,7 +88,7 @@ public class AuthEventHandler {
|
||||||
// Punching a block
|
// Punching a block
|
||||||
public static ActionResult onAttackBlock(PlayerEntity player) {
|
public static ActionResult onAttackBlock(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockPunch) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowBlockPunch) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
|
@ -90,7 +97,7 @@ public class AuthEventHandler {
|
||||||
// Using an item
|
// Using an item
|
||||||
public static TypedActionResult<ItemStack> onUseItem(PlayerEntity player) {
|
public static TypedActionResult<ItemStack> onUseItem(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemUse) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemUse) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return TypedActionResult.fail(ItemStack.EMPTY);
|
return TypedActionResult.fail(ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +106,7 @@ public class AuthEventHandler {
|
||||||
// Dropping an item
|
// Dropping an item
|
||||||
public static ActionResult onDropItem(PlayerEntity player) {
|
public static ActionResult onDropItem(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemDrop) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowItemDrop) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
|
@ -107,7 +114,7 @@ public class AuthEventHandler {
|
||||||
// Attacking an entity
|
// Attacking an entity
|
||||||
public static ActionResult onAttackEntity(PlayerEntity player) {
|
public static ActionResult onAttackEntity(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityPunch) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityPunch) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +123,7 @@ public class AuthEventHandler {
|
||||||
// Interacting with entity
|
// Interacting with entity
|
||||||
public static ActionResult onUseEntity(PlayerEntity player) {
|
public static ActionResult onUseEntity(PlayerEntity player) {
|
||||||
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityInteract) {
|
if(!SimpleAuth.isAuthenticated((ServerPlayerEntity) player) && !SimpleAuth.config.main.allowEntityInteract) {
|
||||||
player.sendMessage(notAuthenticated);
|
player.sendMessage(notAuthenticated());
|
||||||
return ActionResult.FAIL;
|
return ActionResult.FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ 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 = "§4Your password was updated successfully!";
|
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 globalPasswordSet = "§aGlobal password was successfully set!";
|
||||||
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
|
public String notAuthenticated = "§cYou are not authenticated!\n§6Try with /login or /register.";
|
||||||
public String alreadyAuthenticated = "§4You are already authenticated.";
|
public String alreadyAuthenticated = "§4You are already authenticated.";
|
||||||
|
|
Loading…
Reference in New Issue