Update Schematic Download and /webpw to new Website
This commit is contained in:
@ -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<NodeDownload> table = new Table<>(NodeDownload.class);
|
||||
private static final Statement insert = table.insertFields("NodeId", "Link");
|
||||
|
||||
@ -122,13 +122,12 @@ public class SteamwarUser {
|
||||
return byDiscord.select(discordId);
|
||||
}
|
||||
|
||||
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> newPlayer, BiConsumer<String, String> nameUpdate) {
|
||||
public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer<UUID> 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);
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<UserPerm> perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername).perms();
|
||||
Set<UserPerm> 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))
|
||||
|
||||
Reference in New Issue
Block a user