Require authenticated Velocity forwarding before provisioning
This commit is contained in:
parent
b2036dfdc3
commit
840af6cb00
1 changed files with 26 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ package com.dunerealms.lobbyaccount;
|
|||
import static com.dunerealms.lobbyaccount.AccountJournal.Phase.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -18,6 +19,8 @@ import java.util.concurrent.TimeUnit;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
|
@ -42,6 +45,7 @@ public final class DuneLobbyAccount extends JavaPlugin implements Listener {
|
|||
try {
|
||||
Path root = getDataFolder().toPath().toAbsolutePath().normalize().getParent().getParent();
|
||||
if (!LOBBY.equals(root) || !LOBBY.equals(root.toRealPath())) throw new IOException("Invalid Lobby root");
|
||||
verifyForwarding(root);
|
||||
api = new LobbyAccountApi(TOKEN);
|
||||
api.verifyCredential();
|
||||
journal = new AccountJournal(getDataFolder().toPath().resolve("receipts"));
|
||||
|
|
@ -60,6 +64,28 @@ public final class DuneLobbyAccount extends JavaPlugin implements Listener {
|
|||
getServer().getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(this::attempt), 600, 600);
|
||||
}
|
||||
|
||||
private void verifyForwarding(Path root) throws IOException {
|
||||
Path config = root.resolve("config/paper-global.yml");
|
||||
Path spigot = root.resolve("spigot.yml");
|
||||
if (!"127.0.0.1".equals(getServer().getIp()) || !Files.isRegularFile(config) || !Files.isRegularFile(spigot))
|
||||
throw new IOException("Expected the local authenticated Lobby backend");
|
||||
var velocity = readConfig(config).getConfigurationSection("proxies.velocity");
|
||||
if (velocity == null || !velocity.getBoolean("enabled") || !velocity.getBoolean("online-mode")
|
||||
|| velocity.getString("secret", "").isBlank()
|
||||
|| readConfig(spigot).getBoolean("settings.bungeecord", true))
|
||||
throw new IOException("Expected authenticated Velocity forwarding");
|
||||
}
|
||||
|
||||
private static YamlConfiguration readConfig(Path path) throws IOException {
|
||||
var config = new YamlConfiguration();
|
||||
try {
|
||||
config.load(path.toFile());
|
||||
} catch (InvalidConfigurationException invalid) {
|
||||
throw new IOException("Invalid Lobby forwarding configuration");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override public void onDisable() {
|
||||
running = false;
|
||||
if (executor != null) executor.shutdownNow();
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff