Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bungeeguard-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
</parent>

<artifactId>bungeeguard-backend</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bungeeguard-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
</parent>

<artifactId>bungeeguard-bungee</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bungeeguard-spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
</parent>

<artifactId>bungeeguard-spigot</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>

<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
Expand All @@ -57,7 +61,7 @@ public void onEnable() {
saveDefaultConfig();
this.tokenStore = new TokenStore(this);
this.tokenStore.load();
FloodgateHandshakeIntegration.register(getLogger());
registerFloodgateIntegrationWhenAvailable();

if (hasSpigotConfigMethod() && !isBungeeEnabled()) {
getLogger().severe("*-----------------------------------------------------------*");
Expand Down Expand Up @@ -107,6 +111,26 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ExtraProtectionListener(logger), this);
}

private void registerFloodgateIntegrationWhenAvailable() {
if (FloodgateHandshakeIntegration.register(getLogger())) {
return;
}

getLogger().info("Floodgate is not enabled yet; waiting for Floodgate/EduFloodgate before registering the Bedrock/Education token bypass.");
Listener enableListener = new Listener() {
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
if (!FloodgateHandshakeIntegration.isFloodgatePlugin(event.getPlugin())) {
return;
}
if (FloodgateHandshakeIntegration.register(event.getPlugin(), getLogger())) {
HandlerList.unregisterAll(this);
}
}
};
getServer().getPluginManager().registerEvents(enableListener, this);
}

@Override
public void onDisable() {
FloodgateHandshakeIntegration.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -37,10 +39,40 @@ public final class FloodgateHandshakeIntegration {
private FloodgateHandshakeIntegration() {
}

/** Register a Floodgate handshake callback if Floodgate is installed and exposes its 2.x API. */
/**
* Detect Floodgate / EduFloodgate without assuming the plugin's declared casing or name.
* The API class is the strongest signal; the name check also lets the enable-event listener
* recognize the plugin before testing whether its API has finished initializing.
*/
public static boolean isFloodgatePlugin(Plugin candidate) {
if (candidate == null) {
return false;
}
String name = candidate.getDescription().getName();
if (name != null && name.toLowerCase(Locale.ROOT).contains("floodgate")) {
return true;
}
try {
candidate.getClass().getClassLoader().loadClass("org.geysermc.floodgate.api.InstanceHolder");
return true;
} catch (ClassNotFoundException | LinkageError ignored) {
return false;
}
}

/** Register Floodgate's callback if a compatible, enabled instance is already available. */
public static synchronized boolean register(Logger logger) {
Plugin floodgate = Bukkit.getPluginManager().getPlugin("floodgate");
if (floodgate == null || !floodgate.isEnabled()) {
for (Plugin candidate : Bukkit.getPluginManager().getPlugins()) {
if (candidate.isEnabled() && isFloodgatePlugin(candidate)) {
return register(candidate, logger);
}
}
return false;
}

/** Register a callback against the exact Floodgate plugin that has just enabled. */
public static synchronized boolean register(Plugin floodgate, Logger logger) {
if (floodgate == null || !floodgate.isEnabled() || !isFloodgatePlugin(floodgate)) {
return false;
}
if (handlerId >= 0) {
Expand Down Expand Up @@ -88,7 +120,9 @@ public static synchronized boolean register(Logger logger) {
private static void handleValidatedFloodgateHandshake(Object data, Logger logger) {
try {
boolean isFloodgatePlayer = Boolean.TRUE.equals(data.getClass().getMethod("isFloodgatePlayer").invoke(data));
if (!isFloodgatePlayer) {
if (!isFloodgatePlayer || !hasExpectedFloodgateDataLength(data)) {
// Floodgate also calls custom handlers for decrypt / malformed-data failures.
// Only valid payload lengths may mint a BungeeGuard bypass marker.
return;
}

Expand Down Expand Up @@ -121,6 +155,24 @@ private static void handleValidatedFloodgateHandshake(Object data, Logger logger
}
}

private static boolean hasExpectedFloodgateDataLength(Object handshakeData) throws ReflectiveOperationException {
Object bedrockData = handshakeData.getClass().getMethod("getBedrockData").invoke(handshakeData);
if (bedrockData == null) {
return false;
}

Method getDataLength = bedrockData.getClass().getMethod("getDataLength");
int actualLength = ((Number) getDataLength.invoke(bedrockData)).intValue();

// EXPECTED_LENGTH is an implementation constant in Floodgate's BedrockData class rather
// than part of the public API. Read it reflectively to avoid a compile-time dependency;
// fail closed if a future Floodgate version removes or changes this validation contract.
Field expectedLengthField = bedrockData.getClass().getDeclaredField("EXPECTED_LENGTH");
expectedLengthField.setAccessible(true);
int expectedLength = expectedLengthField.getInt(null);
return actualLength == expectedLength;
}

static String insertMarkerAfterHostname(String hostname, String marker) {
if (hostname == null || marker == null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion bungeeguard-sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
</parent>

<artifactId>bungeeguard-sponge</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bungeeguard-universal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
</parent>

<artifactId>bungeeguard-universal</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>

<build>
<defaultGoal>clean package</defaultGoal>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>
<packaging>pom</packaging>

<modules>
Expand Down
Loading