diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index 5b8842b4..55eb137b 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -25,7 +25,10 @@ package org.geysermc.platform.bukkit; +import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.Plugin; +import org.geysermc.common.FloodgateKeyLoader; import org.geysermc.common.IGeyserConfiguration; import java.io.File; @@ -45,6 +48,8 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { private Map userAuthInfo = new HashMap<>(); + private Path floodgateKey; + public GeyserBukkitConfiguration(File dataFolder, FileConfiguration config) { this.dataFolder = dataFolder; this.config = config; @@ -61,6 +66,11 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } } + public void loadFloodgate(GeyserBukkitPlugin plugin) { + Plugin floodgate = Bukkit.getPluginManager().getPlugin("floodgate-bukkit"); + floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")), floodgate, floodgate != null ? floodgate.getDataFolder().toPath() : null); + } + @Override public IBedrockConfiguration getBedrock() { return bedrockConfig; @@ -108,7 +118,7 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { @Override public Path getFloodgateKeyFile() { - return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); + return floodgateKey; } @Override diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java index fa58f66c..c4655bef 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitPlugin.java @@ -64,6 +64,9 @@ public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap { saveConfig(); this.geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode()); + + geyserConfig.loadFloodgate(this); + this.connector = GeyserConnector.start(PlatformType.BUKKIT, this); this.geyserCommandManager = new GeyserBukkitCommandManager(this, connector); diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index e0f6a6ef..c94d2723 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -25,8 +25,9 @@ package org.geysermc.platform.bungeecord; +import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.config.Configuration; - +import org.geysermc.common.FloodgateKeyLoader; import org.geysermc.common.IGeyserConfiguration; import java.io.File; @@ -46,6 +47,8 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { private Map userAuthInfo = new HashMap<>(); + private Path floodgateKey; + public GeyserBungeeConfiguration(File dataFolder, Configuration config) { this.dataFolder = dataFolder; this.config = config; @@ -62,6 +65,11 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } } + public void loadFloodgate(GeyserBungeePlugin plugin) { + Plugin floodgate = plugin.getProxy().getPluginManager().getPlugin("floodgate-bungee"); + floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")), floodgate, floodgate != null ? floodgate.getDataFolder().toPath() : null); + } + @Override public BungeeBedrockConfiguration getBedrock() { return bedrockConfig; @@ -109,7 +117,7 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { @Override public Path getFloodgateKeyFile() { - return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); + return floodgateKey; } @Override diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java index 4c595390..4c2e2580 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePlugin.java @@ -116,6 +116,9 @@ public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap { } this.geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode()); + + geyserConfig.loadFloodgate(this); + this.connector = GeyserConnector.start(PlatformType.BUNGEECORD, this); this.geyserCommandManager = new GeyserBungeeCommandManager(connector); diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java index 03f7cbee..33fd50fe 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java @@ -27,13 +27,18 @@ package org.geysermc.platform.velocity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.velocitypowered.api.plugin.PluginContainer; +import com.velocitypowered.api.proxy.ProxyServer; import lombok.Getter; import lombok.Setter; +import org.geysermc.common.FloodgateKeyLoader; import org.geysermc.common.IGeyserConfiguration; +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; +import java.util.Optional; @JsonIgnoreProperties(ignoreUnknown = true) @Getter @@ -67,9 +72,16 @@ public class GeyserVelocityConfiguration implements IGeyserConfiguration { private MetricsInfo metrics; + private Path floodgateKey; + + public void loadFloodgate(GeyserVelocityPlugin plugin, ProxyServer proxyServer, File dataFolder) { + Optional floodgate = proxyServer.getPluginManager().getPlugin("floodgate"); + floodgateKey = FloodgateKeyLoader.getKey(plugin.getGeyserLogger(), this, Paths.get(dataFolder.toString(), floodgateKeyFile.isEmpty() ? floodgateKeyFile : "public-key.pem"), floodgate.get(), Paths.get("plugins/floodgate/")); + } + @Override public Path getFloodgateKeyFile() { - return Paths.get(floodgateKeyFile); + return floodgateKey; } @Getter diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java index 38378f01..59647e1d 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPlugin.java @@ -54,7 +54,7 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { private Logger logger; @Inject - private ProxyServer server; + private ProxyServer proxyServer; @Inject private CommandManager commandManager; @@ -67,8 +67,9 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { @Override public void onEnable() { + File configDir = new File("plugins/" + GeyserConnector.NAME + "-Velocity/"); + try { - File configDir = new File("plugins/" + GeyserConnector.NAME + "-Velocity/"); if (!configDir.exists()) configDir.mkdir(); File configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString())); @@ -78,7 +79,7 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { ex.printStackTrace(); } - InetSocketAddress javaAddr = server.getBoundAddress(); + InetSocketAddress javaAddr = proxyServer.getBoundAddress(); // Don't change the ip if its listening on all interfaces // By default this should be 127.0.0.1 but may need to be changed in some circumstances @@ -89,6 +90,9 @@ public class GeyserVelocityPlugin implements IGeyserBootstrap { geyserConfig.getRemote().setPort(javaAddr.getPort()); this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode()); + + geyserConfig.loadFloodgate(this, proxyServer, configDir); + this.connector = GeyserConnector.start(PlatformType.VELOCITY, this); this.geyserCommandManager = new GeyserVelocityCommandManager(connector); diff --git a/common/src/main/java/org/geysermc/common/FloodgateKeyLoader.java b/common/src/main/java/org/geysermc/common/FloodgateKeyLoader.java new file mode 100644 index 00000000..9eb3275f --- /dev/null +++ b/common/src/main/java/org/geysermc/common/FloodgateKeyLoader.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019-2020 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + * + */ + +package org.geysermc.common; + +import org.geysermc.common.logger.IGeyserLogger; + +import java.nio.file.Files; +import java.nio.file.Path; + +public class FloodgateKeyLoader { + public static Path getKey(IGeyserLogger logger, IGeyserConfiguration config, Path floodgateKey, Object floodgate, Path floodgateFolder) { + if (!Files.exists(floodgateKey) && config.getRemote().getAuthType().equals("floodgate")) { + if (floodgate != null) { + Path autoKey = floodgateFolder.resolve("public-key.pem"); + if (Files.exists(autoKey)) { + logger.info("Auto-loaded floodgate key"); + floodgateKey = autoKey; + } else { + logger.error("Auth-type set to floodgate and the public key is missing!"); + } + } else { + logger.error("Auth-type set to floodgate but floodgate is not installed!"); + } + } + + return floodgateKey; + } +}