Require authenticated Velocity forwarding before provisioning
All checks were successful
Lobby Account Provisioning Build / lobby-account (push) Successful in 55s
DuneRealms Plugin CI / plugins (push) Successful in 3m5s

This commit is contained in:
unimatrixgit 2026-12-02 11:37:06 +01:00
commit 840af6cb00

View file

@ -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();