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 37ba44f92..2213f90bb 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.connector.FloodgateKeyLoader; import org.geysermc.connector.GeyserConfiguration; import java.io.File; @@ -45,6 +48,8 @@ public class GeyserBukkitConfiguration implements GeyserConfiguration { 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 GeyserConfiguration { } } + 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 GeyserConfiguration { @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 e7beca799..d6bd31acd 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 @@ -67,6 +67,9 @@ public class GeyserBukkitPlugin extends JavaPlugin implements GeyserBootstrap { 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 85971d0f7..f8e401418 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.connector.FloodgateKeyLoader; import org.geysermc.connector.GeyserConfiguration; import java.io.File; @@ -46,6 +47,8 @@ public class GeyserBungeeConfiguration implements GeyserConfiguration { 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 GeyserConfiguration { } } + 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 GeyserConfiguration { @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 72f166c9d..bfd0cf49c 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 GeyserBootstrap { } 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 5f5098343..ff99f8ab1 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,15 +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.connector.FloodgateKeyLoader; import org.geysermc.connector.GeyserConfiguration; +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 @@ -72,9 +75,16 @@ public class GeyserVelocityConfiguration implements GeyserConfiguration { 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 f155fc823..bd8924133 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 GeyserBootstrap { private Logger logger; @Inject - private ProxyServer server; + private ProxyServer proxyServer; @Inject private CommandManager commandManager; @@ -67,8 +67,9 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { @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 GeyserBootstrap { 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 GeyserBootstrap { 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/connector/src/main/java/org/geysermc/connector/FloodgateKeyLoader.java b/connector/src/main/java/org/geysermc/connector/FloodgateKeyLoader.java new file mode 100644 index 000000000..0b631b2d2 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/FloodgateKeyLoader.java @@ -0,0 +1,50 @@ +/* + * 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.connector; + +import java.nio.file.Files; +import java.nio.file.Path; + +public class FloodgateKeyLoader { + public static Path getKey(GeyserLogger logger, GeyserConfiguration 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; + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java index d57b89487..0e329669b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaServerDeclareCommandsTranslator.java @@ -59,6 +59,7 @@ public class JavaServerDeclareCommandsTranslator extends PacketTranslator= 1) {