From 21b389a99327d1dab925d81e25c2fc3e0eb20547 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 17 Jan 2025 22:28:46 +0100 Subject: [PATCH] Update Schematic Download and /webpw to new Website --- .../SQL/src/de/steamwar/sql/NodeDownload.java | 2 +- .../SQL/src/de/steamwar/sql/SteamwarUser.java | 7 ++-- .../core/events/PlayerJoinedEvent.java | 2 +- .../commands/PunishmentCommand.java | 2 +- .../commands/WebpasswordCommand.java | 35 +++++-------------- .../listeners/ConnectionListener.java | 3 +- 6 files changed, 18 insertions(+), 33 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java index b3792b63..030dbf38 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java @@ -35,7 +35,7 @@ import java.time.Instant; public class NodeDownload { private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - private static final String LINK_BASE = "https://steamwar.de/download.php?schem="; + private static final String LINK_BASE = "https://steamwar.de/schematic?code="; private static final Table table = new Table<>(NodeDownload.class); private static final Statement insert = table.insertFields("NodeId", "Link"); diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index d5b87b6e..9906d149 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -122,13 +122,12 @@ public class SteamwarUser { return byDiscord.select(discordId); } - public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer, BiConsumer nameUpdate) { + public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer) { SteamwarUser user = get(uuid); if (user != null) { if (!user.userName.equals(name)) { updateName.update(name, user.id); - nameUpdate.accept(user.userName, name); user.userName = name; } @@ -359,6 +358,10 @@ public class SteamwarUser { } } + public boolean hasPassword() { + return this.password == null; + } + private byte[] generateHash(String password, byte[] salt) throws InvalidKeySpecException { PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 512); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index 8936de9a..29b0ffd8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -35,7 +35,7 @@ public class PlayerJoinedEvent implements Listener{ @EventHandler(priority = EventPriority.LOWEST) private void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}, (oldName, newName) -> {}); + SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}); UserPerm.Prefix prefix = user.prefix(); if(prefix != UserPerm.emptyPrefix) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java index da847019..1dc8ebde 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java @@ -61,7 +61,7 @@ public class PunishmentCommand { return null; } - return SteamwarUser.getOrCreate(uuid, name, u -> {}, (o, n) -> {}); + return SteamwarUser.getOrCreate(uuid, name, u -> {}); } private static UUID getUUIDofOfflinePlayer(String playerName) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java index ff3370c8..3ab97ddf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -21,10 +21,9 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; +import de.steamwar.sql.SteamwarUser; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; public class WebpasswordCommand extends SWCommand { @@ -40,33 +39,15 @@ public class WebpasswordCommand extends SWCommand { return; } - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", sender.user().getUserName(), password); - pb.redirectErrorStream(true); - try { - Process regProcess = pb.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); - String errorLine; - if((errorLine = reader.readLine()) != null) { - if ("updated".equals(errorLine)) { - sender.system("WEB_UPDATED"); - return; - } else { - throw new SecurityException("Could not create webaccount " + errorLine); - } - } + SteamwarUser user = sender.user(); + boolean resetPW = user.hasPassword(); + user.setPassword(password); + + if (resetPW) { + sender.system("WEB_UPDATED"); + } else { sender.system("WEB_CREATED"); - } catch (IOException e) { - throw new SecurityException("Could not create webaccount", e); - } - } - - public static void changeUsername(String oldUsername, String newUsername){ - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/changename.php", oldUsername, newUsername); - try { - pb.start(); - } catch (IOException e) { - throw new SecurityException("Could not change username", e); } } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index c1a4b51d..95edeabb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -39,6 +39,7 @@ import net.kyori.adventure.text.event.ClickEvent; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.function.BiConsumer; public class ConnectionListener extends BasicListener { @@ -56,7 +57,7 @@ public class ConnectionListener extends BasicListener { if(!(subject instanceof Player player)) return perm -> Tristate.TRUE; - Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername).perms(); + Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer).perms(); if(perms.contains(UserPerm.ADMINISTRATION)) return perm -> Tristate.TRUE; else if(perms.contains(UserPerm.TEAM))