Skip to content

Commit 4550562

Browse files
committed
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
1 parent 2308d98 commit 4550562

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

bukkit/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@
354354
<version>v3.0.0</version>
355355
<scope>provided</scope>
356356
<optional>true</optional>
357+
358+
<!-- Exclude dependencies to prevent potential version conflicts-->
359+
<exclusions>
360+
<exclusion>
361+
<groupId>*</groupId>
362+
<artifactId>*</artifactId>
363+
</exclusion>
364+
</exclusions>
357365
</dependency>
358366

359367
<!--No maven repository :(-->

velocity/src/main/java/com/github/games647/fastlogin/velocity/FastLoginVelocity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
4747
import com.velocitypowered.api.plugin.Plugin;
4848
import com.velocitypowered.api.plugin.annotation.DataDirectory;
49-
import com.velocitypowered.api.proxy.InboundConnection;
5049
import com.velocitypowered.api.proxy.Player;
5150
import com.velocitypowered.api.proxy.ProxyServer;
5251
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
@@ -58,6 +57,7 @@
5857
import org.slf4j.Logger;
5958

6059
import java.io.IOException;
60+
import java.net.InetSocketAddress;
6161
import java.nio.charset.StandardCharsets;
6262
import java.nio.file.Files;
6363
import java.nio.file.Path;
@@ -75,7 +75,7 @@ public class FastLoginVelocity implements PlatformPlugin<CommandSource> {
7575
private final ProxyServer server;
7676
private final Path dataDirectory;
7777
private final Logger logger;
78-
private final ConcurrentMap<InboundConnection, VelocityLoginSession> session = new MapMaker().weakKeys().makeMap();
78+
private final ConcurrentMap<InetSocketAddress, VelocityLoginSession> session = new MapMaker().weakKeys().makeMap();
7979
private static final String PROXY_ID_FILE = "proxyId.txt";
8080

8181
private FastLoginCore<Player, CommandSource, FastLoginVelocity> core;
@@ -175,7 +175,7 @@ public FastLoginCore<Player, CommandSource, FastLoginVelocity> getCore() {
175175
return core;
176176
}
177177

178-
public ConcurrentMap<InboundConnection, VelocityLoginSession> getSession() {
178+
public ConcurrentMap<InetSocketAddress, VelocityLoginSession> getSession() {
179179
return session;
180180
}
181181

velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/ConnectListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public EventTask onPreLogin(PreLoginEvent preLoginEvent) {
119119
@Subscribe
120120
public void onGameProfileRequest(GameProfileRequestEvent event) {
121121
if (event.isOnlineMode()) {
122-
LoginSession session = plugin.getSession().get(event.getConnection());
122+
LoginSession session = plugin.getSession().get(event.getConnection().getRemoteAddress());
123123
if (session == null) {
124124
plugin.getLog().error("No active login session found for onlinemode player {}", event.getUsername());
125125
return;
@@ -173,7 +173,7 @@ public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
173173
}
174174
}
175175

176-
VelocityLoginSession session = plugin.getSession().get(player);
176+
VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress());
177177
if (session == null) {
178178
plugin.getLog().info("No active login session found on server connect for {}", player);
179179
return;
@@ -193,7 +193,7 @@ public void onDisconnect(DisconnectEvent disconnectEvent) {
193193
Player player = disconnectEvent.getPlayer();
194194
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
195195

196-
plugin.getSession().remove(player);
196+
plugin.getSession().remove(player.getRemoteAddress());
197197
}
198198

199199
/**

velocity/src/main/java/com/github/games647/fastlogin/velocity/listener/PluginMessageListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void onSuccessMessage(Player forPlayer) {
127127
if (shouldPersist) {
128128
//bukkit module successfully received and force logged in the user
129129
//update only on success to prevent corrupt data
130-
VelocityLoginSession loginSession = plugin.getSession().get(forPlayer);
130+
VelocityLoginSession loginSession = plugin.getSession().get(forPlayer.getRemoteAddress());
131131
StoredProfile playerProfile = loginSession.getProfile();
132132
loginSession.setRegistered(true);
133133
if (!loginSession.isAlreadySaved()) {

velocity/src/main/java/com/github/games647/fastlogin/velocity/task/AsyncPremiumCheck.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public AsyncPremiumCheck(FastLoginVelocity plugin, InboundConnection connection,
5858

5959
@Override
6060
public void run() {
61-
plugin.getSession().remove(connection);
61+
plugin.getSession().remove(connection.getRemoteAddress());
6262
super.onLogin(username, new VelocityLoginSource(connection, preLoginEvent));
6363
}
6464

@@ -82,7 +82,8 @@ public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profil
8282
String username, boolean registered) {
8383
source.enableOnlinemode();
8484
VelocityLoginSession session = new VelocityLoginSession(username, registered, profile);
85-
plugin.getSession().put(source.getConnection(), session);
85+
plugin.getLog().error("Putting session: {}", source.getConnection());
86+
plugin.getSession().put(source.getConnection().getRemoteAddress(), session);
8687

8788
String ip = source.getAddress().getAddress().getHostAddress();
8889
plugin.getCore().addLoginAttempt(ip, username);
@@ -91,6 +92,6 @@ public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profil
9192
@Override
9293
public void startCrackedSession(VelocityLoginSource source, StoredProfile profile, String username) {
9394
VelocityLoginSession session = new VelocityLoginSession(username, false, profile);
94-
plugin.getSession().put(source.getConnection(), session);
95+
plugin.getSession().put(source.getConnection().getRemoteAddress(), session);
9596
}
9697
}

velocity/src/main/java/com/github/games647/fastlogin/velocity/task/FloodgateAuthTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public FloodgateAuthTask(FastLoginCore<Player, CommandSource, FastLoginVelocity>
5252
@Override
5353
protected void startLogin() {
5454
VelocityLoginSession session = new VelocityLoginSession(player.getUsername(), isRegistered, profile);
55-
core.getPlugin().getSession().put(player, session);
55+
core.getPlugin().getSession().put(player.getRemoteAddress(), session);
5656

5757
// enable auto login based on the value of 'autoLoginFloodgate' in config.yml
5858
boolean forcedOnlineMode = autoLoginFloodgate.equals("true")

0 commit comments

Comments
 (0)