From 4550562465f02167454e07eafe705283927580e3 Mon Sep 17 00:00:00 2001
From: TuxCoding <1957196+TuxCoding@users.noreply.github.com>
Date: Mon, 2 Jun 2025 18:23:33 +0200
Subject: [PATCH] Fix finding the correct login sessions in Velocity
Velocity uses different objects during each login phase.
Therefore, keys are no persistent. Only an internal variable
is shared and exposed with `getConnection()`, but this method
is not available in the API. We use `InetSocketAddress` objects
until there is a better method for identifying sessions.
Related #1297
---
bukkit/pom.xml | 8 ++++++++
.../games647/fastlogin/velocity/FastLoginVelocity.java | 6 +++---
.../fastlogin/velocity/listener/ConnectListener.java | 6 +++---
.../velocity/listener/PluginMessageListener.java | 2 +-
.../fastlogin/velocity/task/AsyncPremiumCheck.java | 7 ++++---
.../fastlogin/velocity/task/FloodgateAuthTask.java | 2 +-
6 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index fcef5991..3d3a0efc 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -354,6 +354,14 @@
v3.0.0
provided
true
+
+
+
+
+ *
+ *
+
+
diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
index cb009dfe..26217b83 100644
--- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
+++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java
@@ -46,7 +46,6 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
-import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
@@ -58,6 +57,7 @@ import org.geysermc.geyser.GeyserImpl;
import org.slf4j.Logger;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -75,7 +75,7 @@ public class FastLoginVelocity implements PlatformPlugin {
private final ProxyServer server;
private final Path dataDirectory;
private final Logger logger;
- private final ConcurrentMap session = new MapMaker().weakKeys().makeMap();
+ private final ConcurrentMap session = new MapMaker().weakKeys().makeMap();
private static final String PROXY_ID_FILE = "proxyId.txt";
private FastLoginCore core;
@@ -175,7 +175,7 @@ public class FastLoginVelocity implements PlatformPlugin {
return core;
}
- public ConcurrentMap getSession() {
+ public ConcurrentMap getSession() {
return session;
}
diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java
index da49a41f..4247a33c 100644
--- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java
+++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java
@@ -119,7 +119,7 @@ public class ConnectListener {
@Subscribe
public void onGameProfileRequest(GameProfileRequestEvent event) {
if (event.isOnlineMode()) {
- LoginSession session = plugin.getSession().get(event.getConnection());
+ LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress());
if (session == null) {
plugin.getLog().error("No active login session found for onlinemode player {}", event.getUsername());
return;
@@ -173,7 +173,7 @@ public class ConnectListener {
}
}
- VelocityLoginSession session = plugin.getSession().get(player);
+ VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress());
if (session == null) {
plugin.getLog().info("No active login session found on server connect for {}", player);
return;
@@ -193,7 +193,7 @@ public class ConnectListener {
Player player = disconnectEvent.getPlayer();
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
- plugin.getSession().remove(player);
+ plugin.getSession().remove(player.getRemoteAddress());
}
/**
diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java
index 03afd899..64041fbf 100644
--- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java
+++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java
@@ -127,7 +127,7 @@ public class PluginMessageListener {
if (shouldPersist) {
//bukkit module successfully received and force logged in the user
//update only on success to prevent corrupt data
- VelocityLoginSession loginSession = plugin.getSession().get(forPlayer);
+ VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress());
StoredProfile playerProfile = loginSession.getProfile();
loginSession.setRegistered(true);
if (!loginSession.isAlreadySaved()) {
diff --git a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java
index 878f6068..9bf97003 100644
--- a/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java
+++ b/velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java
@@ -58,7 +58,7 @@ public class AsyncPremiumCheck extends JoinManagement