Skip to content

Commit d4a424f

Browse files
author
games647
committed
Fix TCPShield compat by using raw address for sessions
TCPShield overwrites the IP address during connection. ProtocolLib doesn't notice this change, because it uses the end-to-end connection which is the proxy IP. This causes getAddress calls during Spigot play state and ProtocolLib auth state not match and then have conflicting session ids. A solution is also to hold onto the temporary player object. However since we don't get a notification for a disconnect, holding it will prevent to get GCed until the timeout occurs (1 minute). Fixes #595 diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index ca8a927..bc03268 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -25,6 +25,7 @@ */ package com.github.games647.fastlogin.bukkit; +import com.destroystokyo.paper.event.player.PlayerHandshakeEvent; import com.github.games647.fastlogin.bukkit.command.CrackedCommand; import com.github.games647.fastlogin.bukkit.command.PremiumCommand; import com.github.games647.fastlogin.bukkit.listener.ConnectionListener; @@ -55,6 +56,8 @@ import java.util.concurrent.ConcurrentMap; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.geysermc.floodgate.api.FloodgateApi; @@ -104,6 +107,15 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman bungeeManager = new BungeeManager(this); bungeeManager.initialize(); + getServer().getPluginManager().registerEvents(new Listener() { + + @eventhandler + void onHandshake(PlayerHandshakeEvent handshakeEvent) { + handshakeEvent.setCancelled(false); + handshakeEvent.setSocketAddressHostname("192.168.0.1"); + } + }, this); + PluginManager pluginManager = getServer().getPluginManager(); if (bungeeManager.isEnabled()) { markInitialized(); @@ -290,16 +302,17 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman receiver.sendMessage(message); } - /** - * Checks if a plugin is installed on the server - * @param name the name of the plugin - * @return true if the plugin is installed - */ - @OverRide - public boolean isPluginInstalled(String name) { - // the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here - return Bukkit.getServer().getPluginManager().getPlugin(name) != null; - } + /** + * Checks if a plugin is installed on the server + * + * @param name the name of the plugin + * @return true if the plugin is installed + */ + @OverRide + public boolean isPluginInstalled(String name) { + // the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here + return Bukkit.getServer().getPluginManager().getPlugin(name) != null; + } public FloodgateService getFloodgateService() { return floodgateService; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/AuthMeHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/AuthMeHook.java index 10a396f..01cb4b9 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/AuthMeHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/AuthMeHook.java @@ -28,18 +28,20 @@ package com.github.games647.fastlogin.bukkit.hook; import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.core.hooks.AuthPlugin; + import fr.xephi.authme.api.v3.AuthMeApi; import fr.xephi.authme.events.RestoreSessionEvent; import fr.xephi.authme.process.Management; import fr.xephi.authme.process.register.executors.ApiPasswordRegisterParams; import fr.xephi.authme.process.register.executors.RegistrationMethod; + +import java.lang.reflect.Field; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import java.lang.reflect.Field; - /** * GitHub: https://github.com/Xephi/AuthMeReloaded/ * <p> @@ -75,7 +77,7 @@ public class AuthMeHook implements AuthPlugin<Player>, Listener { public void onSessionRestore(RestoreSessionEvent restoreSessionEvent) { Player player = restoreSessionEvent.getPlayer(); - BukkitLoginSession session = plugin.getSession(player.getAddress()); + BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress()); if (session != null && session.isVerified()) { restoreSessionEvent.setCancelled(true); } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java index 2378450..856aa9a 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java @@ -127,7 +127,7 @@ public class BungeeListener implements PluginMessageListener { private void startLoginTaskIfReady(Player player, BukkitLoginSession session) { session.setVerified(true); - plugin.putSession(player.getAddress(), session); + plugin.putSession(player.spigot().getRawAddress(), session); // only start a new login task if the join event fired earlier. This event then didn't boolean result = plugin.getBungeeManager().didJoinEventFired(player); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java index 05c9a18..d7c1ef1 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java @@ -80,7 +80,7 @@ public class ConnectionListener implements Listener { // session exists so the player is ready for force login // cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already // having the login session from the login process - BukkitLoginSession session = plugin.getSession(player.getAddress()); + BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress()); if (session == null) { // Floodgate players usually don't have a session at this point @@ -95,7 +95,7 @@ public class ConnectionListener implements Listener { } } - String sessionId = plugin.getSessionId(player.getAddress()); + String sessionId = plugin.getSessionId(player.spigot().getRawAddress()); plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId); } else { Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolLoginSource.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolLoginSource.java index 2e98178..0e182b4 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolLoginSource.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolLoginSource.java @@ -51,7 +51,7 @@ public class ProtocolLoginSource implements LoginSource { @OverRide public InetSocketAddress getAddress() { - return loginStartEvent.getAddress(); + return loginStartEvent.getConnection().getRawAddress(); } public PlayerLoginStartEvent getLoginStartEvent() { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java index 8ce23da..6fa5cbe 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java @@ -70,7 +70,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende } String username = loginStartEvent.getConnection().getProfile().getName(); - InetSocketAddress address = loginStartEvent.getAddress(); + InetSocketAddress address = loginStartEvent.getConnection().getRawAddress(); //remove old data every time on a new login in order to keep the session only for one person plugin.removeSession(address); @@ -81,13 +81,14 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende @eventhandler public void onConnectionClosed(ConnectionCloseEvent closeEvent) { - InetSocketAddress address = closeEvent.getConnection().getAddress(); + InetSocketAddress address = closeEvent.getConnection().getRawAddress(); plugin.removeSession(address); } @eventhandler public void onPropertiesResolve(PlayerProfileCompleteEvent profileCompleteEvent) { - InetSocketAddress address = profileCompleteEvent.getAddress(); + InetSocketAddress address = profileCompleteEvent.getConnection().getRawAddress(); + BukkitLoginSession session = plugin.getSession(address); if (session != null && profileCompleteEvent.getConnection().getProfile().isOnlineMode()) {
1 parent 21347f7 commit d4a424f

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
package com.github.games647.fastlogin.bukkit;
2727

28+
import com.destroystokyo.paper.event.player.PlayerHandshakeEvent;
2829
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
2930
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
3031
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
@@ -55,6 +56,8 @@
5556
import org.bukkit.Bukkit;
5657
import org.bukkit.command.CommandSender;
5758
import org.bukkit.entity.Player;
59+
import org.bukkit.event.EventHandler;
60+
import org.bukkit.event.Listener;
5861
import org.bukkit.plugin.PluginManager;
5962
import org.bukkit.plugin.java.JavaPlugin;
6063
import org.geysermc.floodgate.api.FloodgateApi;
@@ -104,6 +107,15 @@ public void onEnable() {
104107
bungeeManager = new BungeeManager(this);
105108
bungeeManager.initialize();
106109

110+
getServer().getPluginManager().registerEvents(new Listener() {
111+
112+
@EventHandler
113+
void onHandshake(PlayerHandshakeEvent handshakeEvent) {
114+
handshakeEvent.setCancelled(false);
115+
handshakeEvent.setSocketAddressHostname("192.168.0.1");
116+
}
117+
}, this);
118+
107119
PluginManager pluginManager = getServer().getPluginManager();
108120
if (bungeeManager.isEnabled()) {
109121
markInitialized();
@@ -290,16 +302,17 @@ public void sendMessage(CommandSender receiver, String message) {
290302
receiver.sendMessage(message);
291303
}
292304

293-
/**
294-
* Checks if a plugin is installed on the server
295-
* @param name the name of the plugin
296-
* @return true if the plugin is installed
297-
*/
298-
@Override
299-
public boolean isPluginInstalled(String name) {
300-
// the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here
301-
return Bukkit.getServer().getPluginManager().getPlugin(name) != null;
302-
}
305+
/**
306+
* Checks if a plugin is installed on the server
307+
*
308+
* @param name the name of the plugin
309+
* @return true if the plugin is installed
310+
*/
311+
@Override
312+
public boolean isPluginInstalled(String name) {
313+
// the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here
314+
return Bukkit.getServer().getPluginManager().getPlugin(name) != null;
315+
}
303316

304317
public FloodgateService getFloodgateService() {
305318
return floodgateService;

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hook/AuthMeHook.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@
2828
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
2929
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
3030
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
31+
3132
import fr.xephi.authme.api.v3.AuthMeApi;
3233
import fr.xephi.authme.events.RestoreSessionEvent;
3334
import fr.xephi.authme.process.Management;
3435
import fr.xephi.authme.process.register.executors.ApiPasswordRegisterParams;
3536
import fr.xephi.authme.process.register.executors.RegistrationMethod;
37+
38+
import java.lang.reflect.Field;
39+
3640
import org.bukkit.entity.Player;
3741
import org.bukkit.event.EventHandler;
3842
import org.bukkit.event.EventPriority;
3943
import org.bukkit.event.Listener;
4044

41-
import java.lang.reflect.Field;
42-
4345
/**
4446
* GitHub: https://github.com/Xephi/AuthMeReloaded/
4547
* <p>
@@ -75,7 +77,7 @@ public AuthMeHook(FastLoginBukkit plugin) {
7577
public void onSessionRestore(RestoreSessionEvent restoreSessionEvent) {
7678
Player player = restoreSessionEvent.getPlayer();
7779

78-
BukkitLoginSession session = plugin.getSession(player.getAddress());
80+
BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress());
7981
if (session != null && session.isVerified()) {
8082
restoreSessionEvent.setCancelled(true);
8183
}

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private void onRegisterMessage(Player player, String playerName, InetSocketAddre
127127

128128
private void startLoginTaskIfReady(Player player, BukkitLoginSession session) {
129129
session.setVerified(true);
130-
plugin.putSession(player.getAddress(), session);
130+
plugin.putSession(player.spigot().getRawAddress(), session);
131131

132132
// only start a new login task if the join event fired earlier. This event then didn't
133133
boolean result = plugin.getBungeeManager().didJoinEventFired(player);

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ConnectionListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void delayForceLogin(Player player) {
8080
// session exists so the player is ready for force login
8181
// cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
8282
// having the login session from the login process
83-
BukkitLoginSession session = plugin.getSession(player.getAddress());
83+
BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress());
8484

8585
if (session == null) {
8686
// Floodgate players usually don't have a session at this point
@@ -95,7 +95,7 @@ private void delayForceLogin(Player player) {
9595
}
9696
}
9797

98-
String sessionId = plugin.getSessionId(player.getAddress());
98+
String sessionId = plugin.getSessionId(player.spigot().getRawAddress());
9999
plugin.getLog().info("No on-going login session for player: {} with ID {}", player, sessionId);
100100
} else {
101101
Runnable forceLoginTask = new ForceLoginTask(plugin.getCore(), player, session);

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolLoginSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void kick(String message) {
5151

5252
@Override
5353
public InetSocketAddress getAddress() {
54-
return loginStartEvent.getAddress();
54+
return loginStartEvent.getConnection().getRawAddress();
5555
}
5656

5757
public PlayerLoginStartEvent getLoginStartEvent() {

bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/protocolsupport/ProtocolSupportListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void onLoginStart(PlayerLoginStartEvent loginStartEvent) {
7070
}
7171

7272
String username = loginStartEvent.getConnection().getProfile().getName();
73-
InetSocketAddress address = loginStartEvent.getAddress();
73+
InetSocketAddress address = loginStartEvent.getConnection().getRawAddress();
7474

7575
//remove old data every time on a new login in order to keep the session only for one person
7676
plugin.removeSession(address);
@@ -81,13 +81,14 @@ public void onLoginStart(PlayerLoginStartEvent loginStartEvent) {
8181

8282
@EventHandler
8383
public void onConnectionClosed(ConnectionCloseEvent closeEvent) {
84-
InetSocketAddress address = closeEvent.getConnection().getAddress();
84+
InetSocketAddress address = closeEvent.getConnection().getRawAddress();
8585
plugin.removeSession(address);
8686
}
8787

8888
@EventHandler
8989
public void onPropertiesResolve(PlayerProfileCompleteEvent profileCompleteEvent) {
90-
InetSocketAddress address = profileCompleteEvent.getAddress();
90+
InetSocketAddress address = profileCompleteEvent.getConnection().getRawAddress();
91+
9192
BukkitLoginSession session = plugin.getSession(address);
9293

9394
if (session != null && profileCompleteEvent.getConnection().getProfile().isOnlineMode()) {

0 commit comments

Comments
 (0)