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..d4bed21c 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -29,7 +29,6 @@ import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.sql.Timestamp; import java.util.*; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.logging.Level; import java.util.stream.Collectors; @@ -122,13 +121,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 +357,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..d19dedd0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -21,10 +21,7 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; +import de.steamwar.sql.SteamwarUser; public class WebpasswordCommand extends SWCommand { @@ -40,33 +37,11 @@ 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(); - sender.system("WEB_CREATED"); - } catch (IOException e) { - throw new SecurityException("Could not create webaccount", e); - } - } + user.setPassword(password); - 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); - } + sender.system(resetPW ? "WEB_UPDATED" : "WEB_CREATED"); } } 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))