Skip to content

Commit

Permalink
Feature: Detect incorrect proxy setups (GeyserMC#4941)
Browse files Browse the repository at this point in the history
* Feature: Detect & warn about incorrect proxy setups on Spigot platforms

* Properly disable Geyser if we failed to load
  • Loading branch information
onebeastchris authored Aug 10, 2024
1 parent 41e65b0 commit d3ea651
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
private IGeyserPingPassthrough geyserBungeePingPassthrough;
private GeyserImpl geyser;

// We can't disable the plugin; hence we need to keep track of it manually
private boolean disabled;

@Override
public void onLoad() {
onGeyserInitialize();
Expand All @@ -98,7 +95,6 @@ public void onGeyserInitialize() {
}

if (!this.loadConfig()) {
disabled = true;
return;
}
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
Expand All @@ -112,7 +108,7 @@ public void onGeyserInitialize() {

@Override
public void onEnable() {
if (disabled) {
if (geyser == null) {
return; // Config did not load properly!
}
// Big hack - Bungee does not provide us an event to listen to, so schedule a repeating
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public void onGeyserInitialize() {
}

public void onGeyserEnable() {
// "Disabling" a mod isn't possible; so if we fail to initialize we need to manually stop here
if (geyser == null) {
return;
}

if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public void onGeyserInitialize() {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server.message", "1.13.2"));
geyserLogger.error("");
geyserLogger.error("*********************************************");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

Expand All @@ -131,7 +130,6 @@ public void onGeyserInitialize() {
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_server_type.message", "Paper"));
geyserLogger.error("");
geyserLogger.error("*********************************************");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
}
Expand All @@ -144,10 +142,25 @@ public void onGeyserInitialize() {
geyserLogger.error("This version of Spigot is using an outdated version of netty. Please use Paper instead!");
geyserLogger.error("");
geyserLogger.error("*********************************************");
Bukkit.getPluginManager().disablePlugin(this);
return;
}

try {
// Check spigot config for BungeeCord mode
if (Bukkit.getServer().spigot().getConfig().getBoolean("settings.bungeecord")) {
warnInvalidProxySetups("BungeeCord");
return;
}

// Now: Check for velocity mode - deliberately after checking bungeecord because this is a paper only option
if (Bukkit.getServer().spigot().getPaperConfig().getBoolean("proxies.velocity.enabled")) {
warnInvalidProxySetups("Velocity");
return;
}
} catch (NoSuchMethodError e) {
// no-op
}

if (!loadConfig()) {
return;
}
Expand All @@ -162,6 +175,11 @@ public void onGeyserInitialize() {

@Override
public void onEnable() {
// Disabling the plugin in onLoad() is not supported; we need to manually stop here
if (geyser == null) {
return;
}

// Create command manager early so we can add Geyser extension commands
var sourceConverter = new CommandSourceConverter<>(
CommandSender.class,
Expand Down Expand Up @@ -458,4 +476,13 @@ private boolean loadConfig() {

return true;
}

private void warnInvalidProxySetups(String platform) {
geyserLogger.error("*********************************************");
geyserLogger.error("");
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.unsupported_proxy_backend", platform));
geyserLogger.error(GeyserLocale.getLocaleStringLog("geyser.bootstrap.setup_guide", "https://geysermc.org/wiki/geyser/setup/"));
geyserLogger.error("");
geyserLogger.error("*********************************************");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public void onGeyserInitialize() {

@Override
public void onGeyserEnable() {
// If e.g. the config failed to load, GeyserImpl was not loaded and we cannot start
if (geyser == null) {
return;
}
if (GeyserImpl.getInstance().isReloading()) {
if (!loadConfig()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public void onGeyserInitialize() {

@Override
public void onGeyserEnable() {
// If e.g. the config failed to load, GeyserImpl was not loaded and we cannot start
if (geyser == null) {
return;
}
boolean reloading = geyser.isReloading();
if (reloading) {
if (!this.loadConfig()) {
Expand Down

0 comments on commit d3ea651

Please sign in to comment.