From fd8270741428dffdd46d156e8c6e2cef4052b404 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 23 Feb 2025 17:27:29 +0100 Subject: [PATCH] Update `webpassword` command and clean up deprecated logic --- .../steamwar/messages/BungeeCore.properties | 1 - .../messages/BungeeCore_de.properties | 1 - .../commands/WebpasswordCommand.java | 21 ++++++++++--------- .../velocitycore/listeners/ChatListener.java | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index 2315ed12..c9527253 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -543,7 +543,6 @@ WEB_USAGE=§8/§7webpassword §8[§epassword§8] WEB_UPDATED=§7Your password was updated. WEB_CREATED=§7Your webaccount was created. WEB_PASSWORD_LENGTH=§cYour password is shorter than 8 characters. -WEB_RESET_URL=§7You can reset your Password here: §ehttps://steamwar.de/reset-password?token={0} #ChatListener CHAT_LIXFEL_ACTION_BAR=§4§lTechnical problems? diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index cbbb3e2e..c50cf682 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -518,7 +518,6 @@ WEB_USAGE=§8/§7webpassword §8[§ePasswort§8] WEB_UPDATED=§7Dein Passwort wurde aktualisiert. WEB_CREATED=§7Dein Webaccount wurde erstellt. WEB_PASSWORD_LENGTH=§cDein Passwort ist kürzer als 8 Zeichen. -WEB_RESET_URL=§7Hier kannst du dein Passwort zurücksetzen: §ehttps://steamwar.de/passwort-setzen?token={0} #ChatListener CHAT_LIXFEL_ACTION_BAR=§4§lTechnische Probleme? diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java index 6115f47f..d19dedd0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -22,11 +22,6 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.Token; - -import java.net.URLEncoder; -import java.net.http.HttpClient; -import java.nio.charset.StandardCharsets; public class WebpasswordCommand extends SWCommand { @@ -34,13 +29,19 @@ public class WebpasswordCommand extends SWCommand { super("webpassword", "webpw", "web"); } - private static final HttpClient client = HttpClient.newHttpClient(); @Register(description = "WEB_USAGE") - public void genericCommand(Chatter sender) { - SteamwarUser user = sender.user(); + public void genericCommand(Chatter sender, String password) { + if(password.length() < 8) { + sender.system("WEB_PASSWORD_LENGTH"); + return; + } - String token = Token.createToken("PT" + user.getUserName(), user); - sender.system("WEB_RESET_URL", URLEncoder.encode(token, StandardCharsets.UTF_8)); + SteamwarUser user = sender.user(); + boolean resetPW = user.hasPassword(); + + user.setPassword(password); + + sender.system(resetPW ? "WEB_UPDATED" : "WEB_CREATED"); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java index daccaa9f..17137bf5 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ChatListener.java @@ -54,7 +54,7 @@ public class ChatListener extends BasicListener { private static final List rankedModes = ArenaMode.getAllModes().stream().filter(ArenaMode::isRanked).map(ArenaMode::getSchemTypeOrInternalName).toList(); - private static final Set noLogCommands = Set.of("webpw", "webpassword"); + private static final Set noLogCommands = Set.of("webpw", "webpassword", "web"); @Subscribe(order = PostOrder.FIRST) public void fixCommands(CommandExecuteEvent e) {