Detect if a player is connecting through Floodgate

The Floodgate API requires UUID which is inaccessible at the level
FastLogion operates on.
A workaround for this is to check if the currently connecting player is
also a part of the Geyser server's online players list.
*TODO: Check for Java and Bedrock name conflicts with multiple
configurations.*
This commit is contained in:
Smart123s
2021-03-19 08:58:29 +01:00
parent 176781d55a
commit e03e67b8fa
2 changed files with 31 additions and 0 deletions

View File

@ -98,6 +98,12 @@
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Floodgate -->
<repository>
<id>nukkitx-snapshot</id>
<url>https://repo.nukkitx.com/maven-snapshots/</url>
</repository>
</repositories>
<dependencies>
@ -213,6 +219,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.2.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--No maven repository :(-->
<dependency>

View File

@ -12,6 +12,9 @@ import java.security.KeyPair;
import java.security.SecureRandom;
import org.bukkit.entity.Player;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.network.session.GeyserSession;
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
import static com.comphenix.protocol.PacketType.Login.Client.START;
@ -87,6 +90,21 @@ public class ProtocolLibListener extends PacketAdapter {
String username = packet.getGameProfiles().read(0).getName();
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
// check if the player is connecting through Geyser
if (GeyserConnector.getInstance().getDefaultAuthType() == AuthType.FLOODGATE) {
// the Floodgate API requires UUID, which is inaccessible at this state
// workaround: iterate over Geyser's player's usernames
for (GeyserSession geyserPlayer : GeyserConnector.getInstance().getPlayers()) {
if (geyserPlayer.getName().equals(username)) {
plugin.getLog().info(
"Player {} is connecting throught Geyser Floodgate. FastLogin will not check this player.",
username);
// TODO: auto login (WHEN?)
return;
}
}
}
packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic());
plugin.getScheduler().runAsync(nameCheckTask);