forked from TuxCoding/FastLogin
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
This commit is contained in:
@ -26,6 +26,7 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
package com.github.games647.fastlogin.bukkit;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.destroystokyo.paper.event.player.PlayerHandshakeEvent;
|
||||||
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
|
import com.github.games647.fastlogin.bukkit.command.CrackedCommand;
|
||||||
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
|
import com.github.games647.fastlogin.bukkit.command.PremiumCommand;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
|
import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
|
||||||
@ -56,6 +57,8 @@ import java.util.concurrent.ConcurrentMap;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.geysermc.floodgate.api.FloodgateApi;
|
import org.geysermc.floodgate.api.FloodgateApi;
|
||||||
@ -105,6 +108,15 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
bungeeManager = new BungeeManager(this);
|
bungeeManager = new BungeeManager(this);
|
||||||
bungeeManager.initialize();
|
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();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
if (bungeeManager.isEnabled()) {
|
if (bungeeManager.isEnabled()) {
|
||||||
markInitialized();
|
markInitialized();
|
||||||
|
@ -77,7 +77,7 @@ public class AuthMeHook implements AuthPlugin<Player>, Listener {
|
|||||||
public void onSessionRestore(RestoreSessionEvent restoreSessionEvent) {
|
public void onSessionRestore(RestoreSessionEvent restoreSessionEvent) {
|
||||||
Player player = restoreSessionEvent.getPlayer();
|
Player player = restoreSessionEvent.getPlayer();
|
||||||
|
|
||||||
BukkitLoginSession session = plugin.getSession(player.getAddress());
|
BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress());
|
||||||
if (session != null && session.isVerified()) {
|
if (session != null && session.isVerified()) {
|
||||||
restoreSessionEvent.setCancelled(true);
|
restoreSessionEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public class BungeeListener implements PluginMessageListener {
|
|||||||
|
|
||||||
private void startLoginTaskIfReady(Player player, BukkitLoginSession session) {
|
private void startLoginTaskIfReady(Player player, BukkitLoginSession session) {
|
||||||
session.setVerified(true);
|
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
|
// only start a new login task if the join event fired earlier. This event then didn't
|
||||||
boolean result = plugin.getBungeeManager().didJoinEventFired(player);
|
boolean result = plugin.getBungeeManager().didJoinEventFired(player);
|
||||||
|
@ -80,7 +80,7 @@ public class ConnectionListener implements Listener {
|
|||||||
// session exists so the player is ready for force login
|
// session exists so the player is ready for force login
|
||||||
// cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
|
// cases: Paper (firing BungeeCord message before PlayerJoinEvent) or not running BungeeCord and already
|
||||||
// having the login session from the login process
|
// having the login session from the login process
|
||||||
BukkitLoginSession session = plugin.getSession(player.getAddress());
|
BukkitLoginSession session = plugin.getSession(player.spigot().getRawAddress());
|
||||||
|
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
// Floodgate players usually don't have a session at this point
|
// 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);
|
plugin.getLog().info("No on-going login session for player: {} with ID {}. ", player, sessionId);
|
||||||
plugin.getLog().info("Setups using Minecraft proxies will start delayed "
|
plugin.getLog().info("Setups using Minecraft proxies will start delayed "
|
||||||
+ "when the command from the proxy is received");
|
+ "when the command from the proxy is received");
|
||||||
|
@ -51,7 +51,7 @@ public class ProtocolLoginSource implements LoginSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getAddress() {
|
public InetSocketAddress getAddress() {
|
||||||
return loginStartEvent.getAddress();
|
return loginStartEvent.getConnection().getRawAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerLoginStartEvent getLoginStartEvent() {
|
public PlayerLoginStartEvent getLoginStartEvent() {
|
||||||
|
@ -66,7 +66,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
|||||||
}
|
}
|
||||||
|
|
||||||
String username = loginStartEvent.getConnection().getProfile().getName();
|
String username = loginStartEvent.getConnection().getProfile().getName();
|
||||||
InetSocketAddress address = loginStartEvent.getAddress();
|
InetSocketAddress address = loginStartEvent.getConnection().getRawAddress();
|
||||||
plugin.getLog().info("Incoming login request for {} from {}", username, address);
|
plugin.getLog().info("Incoming login request for {} from {}", username, address);
|
||||||
|
|
||||||
Action action = antiBotService.onIncomingConnection(address, username);
|
Action action = antiBotService.onIncomingConnection(address, username);
|
||||||
@ -91,13 +91,14 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onConnectionClosed(ConnectionCloseEvent closeEvent) {
|
public void onConnectionClosed(ConnectionCloseEvent closeEvent) {
|
||||||
InetSocketAddress address = closeEvent.getConnection().getAddress();
|
InetSocketAddress address = closeEvent.getConnection().getRawAddress();
|
||||||
plugin.removeSession(address);
|
plugin.removeSession(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPropertiesResolve(PlayerProfileCompleteEvent profileCompleteEvent) {
|
public void onPropertiesResolve(PlayerProfileCompleteEvent profileCompleteEvent) {
|
||||||
InetSocketAddress address = profileCompleteEvent.getAddress();
|
InetSocketAddress address = profileCompleteEvent.getConnection().getRawAddress();
|
||||||
|
|
||||||
BukkitLoginSession session = plugin.getSession(address);
|
BukkitLoginSession session = plugin.getSession(address);
|
||||||
|
|
||||||
if (session != null && profileCompleteEvent.getConnection().getProfile().isOnlineMode()) {
|
if (session != null && profileCompleteEvent.getConnection().getProfile().isOnlineMode()) {
|
||||||
|
Reference in New Issue
Block a user