Skip to content

Commit 46239c9

Browse files
committed
Use InboundConnection as session keys for Velocity
Related #1286
1 parent 083068b commit 46239c9

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

core/src/main/java/com/github/games647/fastlogin/core/scheduler/AsyncScheduler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public class AsyncScheduler extends AbstractAsyncScheduler {
4242

4343
public AsyncScheduler(Logger logger, Executor processingPool) {
4444
super(logger, processingPool);
45-
logger.info("Using legacy platform scheduler for using an older Java version");
45+
logger.info("Using legacy platform scheduler for using an older Java version. "
46+
+ "Upgrade Java to 21+ for improved performance");
4647
}
4748

4849
@Override

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,6 +46,7 @@
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;
4950
import com.velocitypowered.api.proxy.Player;
5051
import com.velocitypowered.api.proxy.ProxyServer;
5152
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
@@ -57,7 +58,6 @@
5758
import org.slf4j.Logger;
5859

5960
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<InetSocketAddress, VelocityLoginSession> session = new MapMaker().weakKeys().makeMap();
78+
private final ConcurrentMap<InboundConnection, 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<InetSocketAddress, VelocityLoginSession> getSession() {
178+
public ConcurrentMap<InboundConnection, VelocityLoginSession> getSession() {
179179
return session;
180180
}
181181

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,8 @@ public void kick(String message) {
6666
public InetSocketAddress getAddress() {
6767
return connection.getRemoteAddress();
6868
}
69+
70+
public InboundConnection getConnection() {
71+
return connection;
72+
}
6973
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ 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().getRemoteAddress());
122+
LoginSession session = plugin.getSession().get(event.getConnection());
123123
if (session == null) {
124-
plugin.getLog().warn("No active login session found for player {}", event.getUsername());
124+
plugin.getLog().error("No active login session found for onlinemode player {}", event.getUsername());
125125
return;
126126
}
127127

@@ -173,7 +173,7 @@ public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
173173
}
174174
}
175175

176-
VelocityLoginSession session = plugin.getSession().get(player.getRemoteAddress());
176+
VelocityLoginSession session = plugin.getSession().get(player);
177177
if (session == null) {
178178
plugin.getLog().info("No active login session found on server connect for {}", player);
179179
return;
@@ -192,6 +192,8 @@ public void onServerConnected(ServerConnectedEvent serverConnectedEvent) {
192192
public void onDisconnect(DisconnectEvent disconnectEvent) {
193193
Player player = disconnectEvent.getPlayer();
194194
plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
195+
196+
plugin.getSession().remove(player);
195197
}
196198

197199
/**

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.getRemoteAddress());
130+
VelocityLoginSession loginSession = plugin.getSession().get(forPlayer);
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: 3 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.getRemoteAddress());
61+
plugin.getSession().remove(connection);
6262
super.onLogin(username, new VelocityLoginSource(connection, preLoginEvent));
6363
}
6464

@@ -82,7 +82,7 @@ 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.getAddress(), session);
85+
plugin.getSession().put(source.getConnection(), session);
8686

8787
String ip = source.getAddress().getAddress().getHostAddress();
8888
plugin.getCore().addLoginAttempt(ip, username);
@@ -91,6 +91,6 @@ public void requestPremiumLogin(VelocityLoginSource source, StoredProfile profil
9191
@Override
9292
public void startCrackedSession(VelocityLoginSource source, StoredProfile profile, String username) {
9393
VelocityLoginSession session = new VelocityLoginSession(username, false, profile);
94-
plugin.getSession().put(source.getAddress(), session);
94+
plugin.getSession().put(source.getConnection(), session);
9595
}
9696
}

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.getRemoteAddress(), session);
55+
core.getPlugin().getSession().put(player, 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)