Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4302e4de8 | ||
|
|
e859a1c95a | ||
|
|
a1e9b84b47 | ||
|
|
af998585e9 | ||
|
|
62b18b0842 | ||
|
|
8c0d98fda4 | ||
|
|
a6dc0865f7 | ||
|
|
7907d8f731 | ||
|
|
32142f9961 | ||
|
|
f8d32f5e96 | ||
|
|
f8da84de07 | ||
|
|
cafc278c32 | ||
|
|
e958718bcb | ||
|
|
031c2ed091 | ||
|
|
faf7568c81 | ||
|
|
812f5c353f |
No files matched your search
@@ -6,12 +6,12 @@ It also parses passed IP addresses so the server is aware of the real player IP
|
||||
|
||||
### Compatibility
|
||||
|
||||
TCPShield is compatible with Paper, Spigot / CraftBukkit, BungeeCord and Velocity.
|
||||
TCPShield is compatible with Spigot / CraftBukkit, BungeeCord and Velocity.
|
||||
|
||||
When using Spigot / CraftBukkit, [ProtocolLib](https://github.com/aadnk/ProtocolLib) needs to be installed. This is not necessary when Paper is being used.
|
||||
When using Spigot / CraftBukkit, [ProtocolLib](https://github.com/aadnk/ProtocolLib) needs to be installed.
|
||||
|
||||
### Setup
|
||||
Setting up the plugin is easy as cake. Please follow [these](https://docs.tcpshield.com/onboarding-1/tcpshield-plugin) guidelines.
|
||||
Setting up the plugin is easy as cake. Please follow [these](https://docs.tcpshield.com/onboarding/tcpshield-plugin) guidelines.
|
||||
|
||||
### Compiling
|
||||
In order to compile TCPShield, [install Gradle](https://docs.gradle.org/current/userguide/installation.html) and run the following command in the project folder:
|
||||
|
||||
+4
-1
@@ -21,6 +21,9 @@ plugins {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://repo1.maven.org/maven2/'
|
||||
}
|
||||
maven {
|
||||
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
|
||||
}
|
||||
@@ -65,7 +68,7 @@ configurations {
|
||||
testImplementation.extendsFrom compileOnly
|
||||
}
|
||||
|
||||
version = '2.2'
|
||||
version = '2.3'
|
||||
group = 'net.tcpshield.tcpshield'
|
||||
archivesBaseName = 'TCPShield'
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ import java.util.Arrays;
|
||||
|
||||
public class ReflectionUtils {
|
||||
|
||||
private static final Table<Class<?>, String, Field> CACHED_FIELDS = HashBasedTable.create();
|
||||
private static final Table<Class<?>, String, Field> CACHED_FIELDS_BY_NAME = HashBasedTable.create();
|
||||
private static final Table<Class<?>, Class<?>, Field> CACHED_FIELDS_BY_CLASS = HashBasedTable.create();
|
||||
private static final Field MODIFIERS_FIELD;
|
||||
|
||||
static {
|
||||
@@ -68,17 +69,26 @@ public class ReflectionUtils {
|
||||
}
|
||||
|
||||
public static Field searchFieldByClass(Class<?> clazz, Class<?> searchFor) {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
if (f.getType() == searchFor) {
|
||||
return f;
|
||||
Field cachedField = CACHED_FIELDS_BY_CLASS.get(clazz, searchFor);
|
||||
if (cachedField != null) return cachedField;
|
||||
|
||||
Class<?> currentClass = clazz;
|
||||
while (currentClass.getSuperclass() != null) {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getType() != searchFor) continue;
|
||||
|
||||
CACHED_FIELDS_BY_CLASS.put(clazz, searchFor, field);
|
||||
return field;
|
||||
}
|
||||
|
||||
currentClass = clazz.getSuperclass();
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("no " + searchFor.getName() + " field for clazz = " + clazz.getName() + " found");
|
||||
}
|
||||
|
||||
public static Field getDeclaredField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
|
||||
Field cachedField = CACHED_FIELDS.get(clazz, fieldName);
|
||||
Field cachedField = CACHED_FIELDS_BY_NAME.get(clazz, fieldName);
|
||||
if (cachedField != null) return cachedField;
|
||||
|
||||
Field field;
|
||||
@@ -93,7 +103,7 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
CACHED_FIELDS.put(clazz, fieldName, field);
|
||||
CACHED_FIELDS_BY_NAME.put(clazz, fieldName, field);
|
||||
return field;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.tcpshield.tcpshield.bukkit;
|
||||
|
||||
import net.tcpshield.tcpshield.bukkit.paper.TCPShieldPaper;
|
||||
import net.tcpshield.tcpshield.bukkit.protocollib.TCPShieldProtocolLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TCPShieldBukkit extends JavaPlugin {
|
||||
@@ -11,6 +12,12 @@ public class TCPShieldBukkit extends JavaPlugin {
|
||||
if (isPaper()) {
|
||||
new TCPShieldPaper(this).load();
|
||||
} else {
|
||||
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||
//this.getLogger().warning("TCPShield not loading because ProtocolLib is not installed. Either use Paper to enable native compatibility or install ProtocolLib.");
|
||||
this.getLogger().warning("TCPShield not loading because ProtocolLib is not installed. Please install ProtocolLib in order to use our plugin.");
|
||||
return;
|
||||
}
|
||||
|
||||
new TCPShieldProtocolLib(this).load();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.tcpshield.tcpshield.bukkit.protocollib;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TCPShieldProtocolLib {
|
||||
@@ -12,11 +11,6 @@ public class TCPShieldProtocolLib {
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||
plugin.getLogger().warning("TCPShield not loading because ProtocolLib is not installed. Either use Paper to enable native compatibility or install ProtocolLib.");
|
||||
return;
|
||||
}
|
||||
|
||||
ProtocolLibHandshakePacketHandler packetHandler = new ProtocolLibHandshakePacketHandler(plugin);
|
||||
com.comphenix.protocol.ProtocolLibrary.getProtocolManager().addPacketListener(packetHandler);
|
||||
}
|
||||
|
||||
+17
-6
@@ -2,10 +2,10 @@ package net.tcpshield.tcpshield.bukkit.protocollib.impl;
|
||||
|
||||
import com.comphenix.protocol.injector.server.SocketInjector;
|
||||
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
|
||||
import io.netty.channel.AbstractChannel;
|
||||
import net.tcpshield.tcpshield.ReflectionUtils;
|
||||
import net.tcpshield.tcpshield.abstraction.IPlayer;
|
||||
import net.tcpshield.tcpshield.exception.IPModificationFailureException;
|
||||
import net.tcpshield.tcpshield.exception.TCPShieldInitializationException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -15,9 +15,23 @@ import java.net.SocketAddress;
|
||||
public class ProtocolLibPlayerImpl implements IPlayer {
|
||||
|
||||
private static Field socketAddressField;
|
||||
private static Field remoteAddressField;
|
||||
private static Class<?> abstractChannelClass;
|
||||
private final Player player;
|
||||
private String ip;
|
||||
|
||||
static {
|
||||
try {
|
||||
abstractChannelClass = Class.forName("io.netty.channel.AbstractChannel");
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
abstractChannelClass = Class.forName("net.minecraft.util.io.netty.channel.AbstractChannel");
|
||||
} catch (ClassNotFoundException e2) {
|
||||
throw new TCPShieldInitializationException(e2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ProtocolLibPlayerImpl(Player player) {
|
||||
this.player = player;
|
||||
this.ip = player.getAddress().getAddress().getHostAddress();
|
||||
@@ -46,14 +60,11 @@ public class ProtocolLibPlayerImpl implements IPlayer {
|
||||
SocketInjector ignored = TemporaryPlayerFactory.getInjectorFromPlayer(player);
|
||||
Object injector = ReflectionUtils.getObjectInPrivateField(ignored, "injector");
|
||||
Object networkManager = ReflectionUtils.getObjectInPrivateField(injector, "networkManager");
|
||||
if (socketAddressField == null) {
|
||||
socketAddressField = ReflectionUtils.searchFieldByClass(networkManager.getClass(), SocketAddress.class);
|
||||
}
|
||||
|
||||
ReflectionUtils.setFinalField(networkManager, socketAddressField, ip);
|
||||
ReflectionUtils.setFinalField(networkManager, ReflectionUtils.searchFieldByClass(networkManager.getClass(), SocketAddress.class), ip);
|
||||
|
||||
Object channel = ReflectionUtils.getObjectInPrivateField(injector, "originalChannel");
|
||||
ReflectionUtils.setFinalField(channel, ReflectionUtils.getDeclaredField(AbstractChannel.class, "remoteAddress"), ip);
|
||||
ReflectionUtils.setFinalField(channel, ReflectionUtils.getDeclaredField(abstractChannelClass, "remoteAddress"), ip);
|
||||
} catch (Exception e) {
|
||||
throw new IPModificationFailureException(e);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import net.tcpshield.tcpshield.HandshakePacketHandler;
|
||||
import net.tcpshield.tcpshield.abstraction.IPacket;
|
||||
import net.tcpshield.tcpshield.abstraction.IPlayer;
|
||||
@@ -21,7 +22,7 @@ public class BungeeHandshakePacketHandler implements Listener {
|
||||
this.handshakePacketHandler = new HandshakePacketHandler(plugin.getLogger(), new BungeeConfigImpl(plugin));
|
||||
}
|
||||
|
||||
@EventHandler(priority = -64)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onProxyPingEvent(ProxyPingEvent e) {
|
||||
PendingConnection connection = e.getConnection();
|
||||
if (!connection.isLegacy()) return;
|
||||
@@ -29,7 +30,7 @@ public class BungeeHandshakePacketHandler implements Listener {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
@EventHandler(priority = -64)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerHandshake(PlayerHandshakeEvent e) {
|
||||
IPacket packet = new BungeePacketImpl(e.getHandshake(), e.getConnection());
|
||||
IPlayer player = new BungeePlayerImpl(e.getConnection());
|
||||
|
||||
@@ -6,7 +6,9 @@ import net.tcpshield.tcpshield.ReflectionUtils;
|
||||
import net.tcpshield.tcpshield.abstraction.IPlayer;
|
||||
import net.tcpshield.tcpshield.exception.IPModificationFailureException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BungeePlayerImpl implements IPlayer {
|
||||
@@ -45,7 +47,13 @@ public class BungeePlayerImpl implements IPlayer {
|
||||
Object channelWrapper = ReflectionUtils.getObjectInPrivateField(pendingConnection, "ch");
|
||||
Object channel = ReflectionUtils.getObjectInPrivateField(channelWrapper, "ch");
|
||||
|
||||
ReflectionUtils.setFinalField(channelWrapper, "remoteAddress", ip);
|
||||
try {
|
||||
Field socketAddressField = ReflectionUtils.searchFieldByClass(channelWrapper.getClass(), SocketAddress.class);
|
||||
ReflectionUtils.setFinalField(channelWrapper, socketAddressField, ip);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// Some BungeeCord versions, notably those on 1.7 (e.g. zBungeeCord) don't have an SocketAddress field in the ChannelWrapper class
|
||||
}
|
||||
|
||||
ReflectionUtils.setFinalField(channel, ReflectionUtils.getPrivateField(AbstractChannel.class, "remoteAddress"), ip);
|
||||
ReflectionUtils.setFinalField(channel, ReflectionUtils.getPrivateField(AbstractChannel.class, "localAddress"), ip);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.tcpshield.tcpshield.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyPingEvent;
|
||||
@@ -21,13 +22,13 @@ public class VelocityHandshakePacketHandler {
|
||||
this.handshakePacketHandler = new HandshakePacketHandler(logger, new VelocityConfigImpl(dataFolder));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onHandshake(ConnectionHandshakeEvent e) {
|
||||
InboundConnection connection = e.getConnection();
|
||||
handleEvent(connection);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onProxyPing(ProxyPingEvent e) {
|
||||
InboundConnection connection = e.getConnection();
|
||||
handleEvent(connection);
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.net.InetSocketAddress;
|
||||
|
||||
public class VelocityPlayerImpl implements IPlayer {
|
||||
|
||||
private static final Class<?> initialInboundConnectionClass;
|
||||
private static final Field MINECRAFT_CONNECTION_FIELD;
|
||||
private static final Field LEGACY_MINECRAFT_CONNECTION_FIELD;
|
||||
private static final Field REMOTE_ADDRESS_FIELD;
|
||||
@@ -19,7 +20,8 @@ public class VelocityPlayerImpl implements IPlayer {
|
||||
|
||||
static {
|
||||
try {
|
||||
MINECRAFT_CONNECTION_FIELD = ReflectionUtils.getPrivateField(Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection"), "connection");
|
||||
initialInboundConnectionClass = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection");
|
||||
MINECRAFT_CONNECTION_FIELD = ReflectionUtils.getPrivateField(initialInboundConnectionClass, "connection");
|
||||
LEGACY_MINECRAFT_CONNECTION_FIELD = ReflectionUtils.getPrivateField(Class.forName("com.velocitypowered.proxy.connection.client.HandshakeSessionHandler$LegacyInboundConnection"), "connection");
|
||||
|
||||
Class<?> minecraftConnection = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection");
|
||||
@@ -36,7 +38,7 @@ public class VelocityPlayerImpl implements IPlayer {
|
||||
|
||||
public VelocityPlayerImpl(InboundConnection inboundConnection) {
|
||||
this.inboundConnection = inboundConnection;
|
||||
this.legacy = inboundConnection.getProtocolVersion().isUnknown() || inboundConnection.getProtocolVersion().isLegacy();
|
||||
this.legacy = inboundConnection.getClass() != initialInboundConnectionClass;
|
||||
this.ip = inboundConnection.getRemoteAddress().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: TCPShield
|
||||
version: '2.2'
|
||||
version: '2.3'
|
||||
main: net.tcpshield.tcpshield.bungee.TCPShieldBungee
|
||||
author: https://tcpshield.com
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: '2.2'
|
||||
version: '2.3'
|
||||
main: net.tcpshield.tcpshield.bukkit.TCPShieldBukkit
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "tcpshield",
|
||||
"name": "TCPShield",
|
||||
"version": "2.0",
|
||||
"version": "2.3",
|
||||
"description": "TCPShield IP parsing capabilities for Velocity",
|
||||
"authors": [
|
||||
"TCPShield"
|
||||
|
||||
@@ -10,7 +10,7 @@ public class TestConstants {
|
||||
|
||||
public static final String VALID_PAYLOAD_INVALID_TIMESTAMP = "homeserver.fuzzlemann.de///79.227.33.179:53462///1589573485///MGQCMHFac1If9Y8vGAkZMTVapmC6l4M7EfD0YJ0b3pQy73IFjEPsOQn+yxp9lAKSZz7X3AIwGJ2rSxGu4JvlW5sm0pyzqUrc6mfd0xHUWC9JkusrSBSKDfiFV7TCmSZc0gGivgTs";
|
||||
public static final String VALID_PAYLOAD_INVALID_TIMESTAMP_FML_TAGGED = VALID_PAYLOAD_INVALID_TIMESTAMP + "\0FML\0";
|
||||
public static final String INVALID_PAYLOAD_INVALID_SIGNATURE = "homeserver.fuzzlemann.de///79.227.33.179:53462///1589573485///MGQCMHFac1If9Y8vGAkZMTVapmC6l4M7EfD0YJ0b3pQy73IFjEPsOQn+yxp9lAKSZz7X3AIwGJ2rSxGu4JvlW5sm0pyzqUrc6mfd0xHUWC9JkusrSBSKDfiFV7TCmSZc0gGivgTsEXCEPTION";
|
||||
public static final String INVALID_PAYLOAD_MALFORMED_PAYLOAD = "malformed_payload";
|
||||
public static final String INVALID_PAYLOAD_INVALID_SIGNATURE = VALID_PAYLOAD_INVALID_TIMESTAMP + "_INVALID_SIGNATURE";
|
||||
public static final String INVALID_PAYLOAD_MALFORMED_PAYLOAD = "MALFORMED_PAYLOAD";
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user