Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Auto load floodgate key if floodgate installed and set authtype (#454)
* Added floodgate key auto loading for Bukkit * Added floodgate key auto loading for Bungee * Added floodgate key auto loading for Velocity and fixed key location * Moved key loading to common
Dieser Commit ist enthalten in:
Ursprung
692e46146c
Commit
9c6ac1b41c
@ -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<String, BukkitUserAuthenticationInfo> 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
|
||||
|
@ -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);
|
||||
|
@ -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<String, BungeeUserAuthenticationInfo> 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
|
||||
|
@ -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);
|
||||
|
@ -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<PluginContainer> 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
|
||||
|
@ -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);
|
||||
|
52
common/src/main/java/org/geysermc/common/FloodgateKeyLoader.java
Normale Datei
52
common/src/main/java/org/geysermc/common/FloodgateKeyLoader.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren