diff --git a/src/main/java/de/gnmyt/mcdash/entities/ServerConfiguration.java b/src/main/java/de/gnmyt/mcdash/entities/ServerConfiguration.java index 8dab4e0..51dfca2 100644 --- a/src/main/java/de/gnmyt/mcdash/entities/ServerConfiguration.java +++ b/src/main/java/de/gnmyt/mcdash/entities/ServerConfiguration.java @@ -1,12 +1,13 @@ package de.gnmyt.mcdash.entities; -import com.google.gson.Gson; +import at.favre.lib.crypto.bcrypt.BCrypt; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; import de.gnmyt.mcdash.api.Logger; import org.apache.commons.io.FileUtils; import java.io.File; +import java.io.IOException; import java.util.HashMap; public class ServerConfiguration { @@ -34,6 +35,9 @@ public class ServerConfiguration { @Expose(serialize = true, deserialize = true) private boolean autoStart; + @Expose(serialize = true, deserialize = true) + private String proxyKey; + /** * Loads a server configuration from a file * @@ -131,6 +135,14 @@ public class ServerConfiguration { return memory; } + /** + * Gets the proxy key of the server + * @return The proxy key of the server + */ + public String getProxyKey() { + return proxyKey; + } + /** * Gets the auto start of the server * @return The auto start of the server @@ -198,6 +210,26 @@ public class ServerConfiguration { save(); } + /** + * Sets the proxy key of the server + * @param proxyKey The new proxy key of the server + */ + public void setProxyKey(String proxyKey) { + File pluginsFolder = new File(file.getParentFile(), "plugins"); + File accounts = new File(pluginsFolder, "MinecraftDashboard/accounts.yml"); + if (accounts.exists()) accounts.delete(); + + try { + String hashedKey = "PROXY: " + BCrypt.withDefaults().hashToString(10, proxyKey.toCharArray()); + FileUtils.writeStringToFile(accounts, "accounts:\n " + hashedKey, "UTF-8"); + } catch (IOException e) { + LOG.error("An error occurred while setting up the plugin: " + e.getMessage()); + } + + this.proxyKey = proxyKey; + save(); + } + /** * Creates a new server configuration * @return The created server configuration