aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/elytrium/limboauth/handler
diff options
context:
space:
mode:
authorPetr Ilin <hevav@hevav.dev>2022-03-25 18:30:41 +0300
committerPetr Ilin <hevav@hevav.dev>2022-03-25 18:32:05 +0300
commit82424d4408abe364cdbc3d640829b550c88d93d5 (patch)
tree39656f3ba863a6bb933b18899eb29b1ba8efd84e /src/main/java/net/elytrium/limboauth/handler
parent2435294b7232923443ecda62d2c29aa119a289eb (diff)
downloadLimboAuth-82424d4408abe364cdbc3d640829b550c88d93d5.tar.gz
LimboAuth-82424d4408abe364cdbc3d640829b550c88d93d5.tar.bz2
LimboAuth-82424d4408abe364cdbc3d640829b550c88d93d5.zip
Ability to change auth commands "name"
Diffstat (limited to 'src/main/java/net/elytrium/limboauth/handler')
-rw-r--r--src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
index 03f9d5f..9a6ca8b 100644
--- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
+++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
@@ -115,10 +115,9 @@ public class AuthSessionHandler implements LimboSessionHandler {
public void onChat(String message) {
String[] args = message.split(" ");
if (args.length != 0 && this.checkArgsLength(args.length)) {
- switch (args[0]) {
- case "/reg":
- case "/register":
- case "/r": {
+ Command command = Command.parse(args[0]);
+ switch (command) {
+ case REGISTER: {
if (!this.totp && this.playerInfo == null) {
if (this.checkPasswordsRepeat(args) && this.checkPasswordLength(args[1]) && this.checkPasswordStrength(args[1])) {
this.register(args[1]);
@@ -139,9 +138,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
}
break;
}
- case "/log":
- case "/login":
- case "/l": {
+ case LOGIN: {
if (!this.totp && this.playerInfo != null) {
if (this.checkPassword(args[1])) {
this.loginOrTotp();
@@ -155,8 +152,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
}
break;
}
- case "/totp":
- case "/2fa": {
+ case TOTP: {
if (this.totp) {
if (verifier.isValidCode(this.playerInfo.getTotpToken(), args[1])) {
this.finishLogin();
@@ -168,6 +164,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
}
break;
}
+ case INVALID:
default: {
this.sendMessage(false);
}
@@ -423,4 +420,27 @@ public class AuthSessionHandler implements LimboSessionHandler {
public static String genHash(String password) {
return BCrypt.withDefaults().hashToString(Settings.IMP.MAIN.BCRYPT_COST, password.toCharArray());
}
+
+ private enum Command {
+ INVALID,
+ REGISTER,
+ LOGIN,
+ TOTP;
+
+ static Command parse(String command) {
+ if (Settings.IMP.MAIN.REGISTER_COMMAND.contains(command)) {
+ return Command.REGISTER;
+ }
+
+ if (Settings.IMP.MAIN.LOGIN_COMMAND.contains(command)) {
+ return Command.LOGIN;
+ }
+
+ if (Settings.IMP.MAIN.TOTP_COMMAND.contains(command)) {
+ return Command.TOTP;
+ }
+
+ return Command.INVALID;
+ }
+ }
}