mirror of
https://github.com/TCPShield/RealIP.git
synced 2026-11-04 17:00:10 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e20f2df589 | ||
|
|
b2fdd4dc4e | ||
|
|
d348727586 | ||
|
|
b5df9d9427 | ||
|
|
2cf6b46c5d | ||
|
|
a608a4c168 | ||
|
|
f6030d24d6 | ||
|
|
6f1820cb6d | ||
|
|
62658147a3 | ||
|
|
3172f51728 | ||
|
|
ef77cd7bcd | ||
|
|
5bed462a2a | ||
|
|
ef7b7c6510 | ||
|
|
82d05ea316 | ||
|
|
b316629e04 | ||
|
|
554d6c300e | ||
|
|
133cef037e | ||
|
|
bb7511d37f | ||
|
|
78666de764 | ||
|
|
0534b8eae8 | ||
|
|
1af7f1efde | ||
|
|
41ff3f412c |
No files matched your search
+11
-13
@@ -26,7 +26,7 @@ plugins {
|
||||
// --
|
||||
// Variables
|
||||
// --
|
||||
version = '2.5.5'
|
||||
version = '2.8.1'
|
||||
group = 'net.tcpshield.tcpshield'
|
||||
archivesBaseName = 'TCPShield'
|
||||
|
||||
@@ -60,8 +60,8 @@ sourceSets {
|
||||
}
|
||||
|
||||
compileJava {
|
||||
sourceCompatibility = "8"
|
||||
targetCompatibility = "8"
|
||||
sourceCompatibility = 17
|
||||
targetCompatibility = 17
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
@@ -82,10 +82,7 @@ repositories {
|
||||
url = 'https://oss.sonatype.org/content/repositories/snapshots'
|
||||
}
|
||||
maven {
|
||||
url = 'https://papermc.io/repo/repository/maven-public/'
|
||||
}
|
||||
maven {
|
||||
url = 'https://repo.velocitypowered.com/snapshots/'
|
||||
url = 'https://repo.papermc.io/repository/maven-public/'
|
||||
}
|
||||
maven {
|
||||
url = "https://repo.opencollab.dev/maven-snapshots/"
|
||||
@@ -94,22 +91,23 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// Bukkit
|
||||
compileOnly group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
|
||||
compileOnly group: 'com.comphenix.protocol', name: 'ProtocolLib', version: '4.4.0'
|
||||
// compileOnly group: 'com.comphenix.protocol', name: 'ProtocolLib', version: '5.3.0-SNAPSHOT'
|
||||
|
||||
// Paper
|
||||
compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.15.2-R0.1-SNAPSHOT'
|
||||
compileOnly(files("libs/ProtocolLib.jar")) // Temporary, currently using build #726 from the CI server since the maven repository is out of date.
|
||||
|
||||
// Paper - 1.19.4 so we can bump from JDK 8 -> JDK 17, using 1.20.x as a dependency would require bumping from JDK 8 -> JDK 21
|
||||
compileOnly group: 'io.papermc.paper', name: 'paper-api', version: '1.19.4-R0.1-SNAPSHOT'
|
||||
|
||||
// BungeeCord
|
||||
compileOnly group: 'net.md-5', name: 'bungeecord-api', version: '1.14-SNAPSHOT'
|
||||
|
||||
// Velocity
|
||||
compileOnly group: 'com.velocitypowered', name: 'velocity-api', version: '1.0.0-SNAPSHOT'
|
||||
compileOnly group: 'com.velocitypowered', name: 'velocity-api', version: '3.3.0-SNAPSHOT'
|
||||
|
||||
// Testing
|
||||
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0-M1'
|
||||
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.0-M1'
|
||||
compileOnly 'org.geysermc.floodgate:api:2.0-SNAPSHOT'
|
||||
compileOnly 'org.geysermc.floodgate:api:2.1.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.tcpshield.tcpshield.util.validation.timestamp.TimestampValidator;
|
||||
import net.tcpshield.tcpshield.util.validation.timestamp.impl.HTPDateTimestampValidator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -108,7 +109,7 @@ public class TCPShieldPacketHandler {
|
||||
|
||||
String hostname = payload[0];
|
||||
String ipData = payload[1];
|
||||
int timestamp = Integer.parseInt(payload[2]);
|
||||
long timestamp = Long.parseLong(payload[2]);
|
||||
String signature = payload[3];
|
||||
|
||||
String[] ipParts;
|
||||
|
||||
@@ -66,12 +66,13 @@ public class BukkitConfig extends ConfigProvider {
|
||||
try {
|
||||
loadedConfiguration = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode", "enable-geyser-support", "prefer-protocollib");
|
||||
|
||||
this.onlyProxy = loadedConfiguration.getBoolean("only-allow-proxy-connections");
|
||||
this.timestampValidationMode = loadedConfiguration.getString("timestamp-validation");
|
||||
this.doDebug = loadedConfiguration.getBoolean("debug-mode");
|
||||
this.geyser = loadedConfiguration.getBoolean("enable-geyser-support");
|
||||
this.preferProtocolLib = loadedConfiguration.getBoolean("prefer-protocollib");
|
||||
} catch (Exception e) {
|
||||
throw new ConfigLoadException(e);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.tcpshield.tcpshield.bukkit;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import net.tcpshield.tcpshield.TCPShieldPacketHandler;
|
||||
import net.tcpshield.tcpshield.TCPShieldPlugin;
|
||||
import net.tcpshield.tcpshield.bukkit.paper.BukkitPaper;
|
||||
@@ -9,6 +10,7 @@ import net.tcpshield.tcpshield.geyser.GeyserUtils;
|
||||
import net.tcpshield.tcpshield.provider.ConfigProvider;
|
||||
import net.tcpshield.tcpshield.util.Debugger;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.InitializationException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
@@ -29,15 +31,34 @@ public class TCPShieldBukkit extends JavaPlugin implements TCPShieldPlugin {
|
||||
debugger = Debugger.createDebugger(this);
|
||||
packetHandler = new TCPShieldPacketHandler(this);
|
||||
|
||||
if (BukkitImplProvider.hasPaperEvent())
|
||||
bukkitImpl = new BukkitPaper(this);
|
||||
else {
|
||||
if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
|
||||
getLogger().severe("TCPShield not loading because ProtocolLib is not installed. Either use Paper to enable native compatibility or install ProtocolLib.");
|
||||
return;
|
||||
}
|
||||
// check force plib option -> paper -> plib -> error
|
||||
if (this.configProvider.preferProtocolLib() && getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||
try {
|
||||
String[] protocolLibVersion = getServer().getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion().split("-")[0].split("\\.");
|
||||
int major = Integer.parseInt(protocolLibVersion[0]);
|
||||
int minor = Integer.parseInt(protocolLibVersion[1]);
|
||||
int patch = Integer.parseInt(protocolLibVersion[2]);
|
||||
|
||||
String minecraftVersion = Bukkit.getBukkitVersion().split("-")[0];
|
||||
if (BukkitImplProvider.hasPaperEvent() && major <= 5 && minor <= 2 && patch <= 1 && (minecraftVersion.equals("1.20.5") || minecraftVersion.equals("1.20.6"))) {
|
||||
getLogger().severe("TCPShield is incompatible with ProtocolLib <= 5.2.1 on Paper 1.20.5/1.20.6 due to lack of support from ProtocolLib. Reverting to default Paper handler to prevent issues. This error can be avoided by disabling 'prefer-protocollib' in the config.");
|
||||
bukkitImpl = new BukkitPaper(this);
|
||||
} else {
|
||||
bukkitImpl = new BukkitProtocolLib(this);
|
||||
}
|
||||
} catch (Exception t) {
|
||||
getLogger().warning("Failed to check Paper or ProtocolLib version. This is not a critical error unless you are running Paper 1.20.5/1.20.6 with ProtocolLib version 5.2.1 or below.");
|
||||
getDebugger().exception(t);
|
||||
|
||||
bukkitImpl = new BukkitProtocolLib(this);
|
||||
}
|
||||
} else if (BukkitImplProvider.hasPaperEvent()) {
|
||||
bukkitImpl = new BukkitPaper(this);
|
||||
} else if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
|
||||
bukkitImpl = new BukkitProtocolLib(this);
|
||||
} else {
|
||||
getLogger().severe("TCPShield not loading because ProtocolLib is not installed. Either use Paper to enable native compatibility or install ProtocolLib.");
|
||||
return;
|
||||
}
|
||||
|
||||
bukkitImpl.load();
|
||||
@@ -48,6 +69,7 @@ public class TCPShieldBukkit extends JavaPlugin implements TCPShieldPlugin {
|
||||
} catch (Exception e) {
|
||||
throw new InitializationException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -70,4 +92,9 @@ public class TCPShieldBukkit extends JavaPlugin implements TCPShieldPlugin {
|
||||
return configProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return super.getLogger();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,6 @@ public class BukkitPaper extends BukkitImplProvider {
|
||||
super(bukkitPlugin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
PaperHandshakeHandler packetHandler = new PaperHandshakeHandler(this);
|
||||
|
||||
+2
-1
@@ -19,7 +19,6 @@ public class PaperHandshakeHandler implements Listener {
|
||||
this.bukkitProvider = bukkitProvider;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onHandshake(PlayerHandshakeEvent e) {
|
||||
PaperPacket packet = new PaperPacket(e);
|
||||
@@ -36,6 +35,8 @@ public class PaperHandshakeHandler implements Listener {
|
||||
public void onServerPing(PaperServerListPingEvent e) {
|
||||
if (e.getClient().isLegacy())
|
||||
e.setCancelled(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,6 @@ public class PaperPacket implements PacketProvider {
|
||||
this.handshakeEvent = handshakeEvent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPayloadString() {
|
||||
return handshakeEvent.getOriginalHandshake();
|
||||
|
||||
@@ -18,7 +18,6 @@ public class PaperPlayer implements PlayerProvider {
|
||||
this.handshakeEvent = handshakeEvent;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trys to grab the UUID of the handshake
|
||||
* @return If found, the corrosponding uuid, if not, unknown
|
||||
@@ -58,7 +57,7 @@ public class PaperPlayer implements PlayerProvider {
|
||||
@Override
|
||||
public void disconnect() {
|
||||
handshakeEvent.setCancelled(false); // Caused issues with newer versions of Paper (Thanks https://github.com/realDragonium)
|
||||
handshakeEvent.setFailMessage("Connection failed. Please try again or contract an administrator.");
|
||||
handshakeEvent.setFailMessage("Connection failed. Please try again or contact an administrator.");
|
||||
handshakeEvent.setFailed(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ public class BukkitProtocolLib extends BukkitImplProvider {
|
||||
super(bukkitPlugin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
ProtocolLibHandshakeHandler packetHandler = new ProtocolLibHandshakeHandler(this);
|
||||
|
||||
-1
@@ -19,7 +19,6 @@ public class ProtocolLibHandshakeHandler extends PacketAdapter {
|
||||
this.bukkitProvider = bukkitProvider;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent e) {
|
||||
ProtocolLibPacket packet = new ProtocolLibPacket(e.getPacket());
|
||||
|
||||
-1
@@ -17,7 +17,6 @@ public class ProtocolLibPacket implements PacketProvider {
|
||||
this.rawPayload = packetContainer.getStrings().read(0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPayloadString() {
|
||||
return rawPayload;
|
||||
|
||||
+5
-7
@@ -1,7 +1,7 @@
|
||||
package net.tcpshield.tcpshield.bukkit.protocollib.handler;
|
||||
|
||||
import com.comphenix.protocol.injector.server.SocketInjector;
|
||||
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.injector.temporary.TemporaryPlayerFactory;
|
||||
import net.tcpshield.tcpshield.provider.PlayerProvider;
|
||||
import net.tcpshield.tcpshield.util.ReflectionUtil;
|
||||
import net.tcpshield.tcpshield.util.exception.manipulate.PlayerManipulationException;
|
||||
@@ -34,7 +34,6 @@ public class ProtocolLibPlayer implements PlayerProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final Player player;
|
||||
private String ip;
|
||||
|
||||
@@ -72,13 +71,12 @@ public class ProtocolLibPlayer implements PlayerProvider {
|
||||
try {
|
||||
this.ip = ip.getAddress().getHostAddress();
|
||||
|
||||
SocketInjector ignored = TemporaryPlayerFactory.getInjectorFromPlayer(player);
|
||||
Object injector = ReflectionUtil.getObjectInPrivateField(ignored, "injector");
|
||||
Object networkManager = ReflectionUtil.getObjectInPrivateField(injector, "networkManager");
|
||||
Injector ignored = TemporaryPlayerFactory.getInjectorFromPlayer(player);
|
||||
Object networkManager = ReflectionUtil.getObjectInPrivateField(ignored, "networkManager");
|
||||
|
||||
ReflectionUtil.setFinalField(networkManager, ReflectionUtil.searchFieldByClass(networkManager.getClass(), SocketAddress.class), ip);
|
||||
|
||||
Object channel = ReflectionUtil.getObjectInPrivateField(injector, "originalChannel");
|
||||
Object channel = ReflectionUtil.getObjectInPrivateField(ignored, "channel");
|
||||
ReflectionUtil.setFinalField(channel, ReflectionUtil.getDeclaredField(abstractChannelClass, "remoteAddress"), ip);
|
||||
} catch (Exception e) {
|
||||
throw new PlayerManipulationException(e);
|
||||
|
||||
@@ -19,16 +19,24 @@ public abstract class ConfigProvider {
|
||||
protected String timestampValidationMode = "htpdate";
|
||||
protected boolean doDebug = true; // Fail-safe default set to true
|
||||
protected boolean geyser = false;
|
||||
protected boolean velocityHandlePreLoginEvent = true;
|
||||
|
||||
// spigot/paper only option
|
||||
protected boolean preferProtocolLib;
|
||||
|
||||
protected File dataFolder;
|
||||
protected File configFile;
|
||||
|
||||
public boolean isOnlyProxy() {
|
||||
return onlyProxy;
|
||||
return this.onlyProxy;
|
||||
}
|
||||
|
||||
public boolean isGeyser() {
|
||||
return geyser;
|
||||
return this.geyser;
|
||||
}
|
||||
|
||||
public boolean handlePreLoginEvent() {
|
||||
return this.velocityHandlePreLoginEvent;
|
||||
}
|
||||
|
||||
public String getTimestampValidationMode() {
|
||||
@@ -36,7 +44,11 @@ public abstract class ConfigProvider {
|
||||
}
|
||||
|
||||
public boolean doDebug() {
|
||||
return doDebug;
|
||||
return this.doDebug;
|
||||
}
|
||||
|
||||
public boolean preferProtocolLib() {
|
||||
return this.preferProtocolLib;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
|
||||
@@ -34,25 +34,33 @@ public abstract class CIDRMatcher {
|
||||
String[] split = cidrMatchString.split("/");
|
||||
|
||||
String parsedIPAddress;
|
||||
if (split.length != 0) {
|
||||
if (split.length > 1) {
|
||||
parsedIPAddress = split[0];
|
||||
|
||||
this.maskBits = Integer.parseInt(split[1]);
|
||||
this.simpleCIDR = maskBits == 32;
|
||||
if (maskBits < 0)
|
||||
throw new CIDRException("Invalid mask: " + split[1]);
|
||||
} else {
|
||||
parsedIPAddress = cidrMatchString;
|
||||
|
||||
this.maskBits = -1;
|
||||
this.simpleCIDR = true;
|
||||
}
|
||||
|
||||
this.maskBytes = simpleCIDR ? -1 : maskBits / 8;
|
||||
if (parsedIPAddress.isEmpty())
|
||||
throw new CIDRException("Empty CIDR entry");
|
||||
|
||||
try {
|
||||
cidrAddress = InetAddress.getByName(parsedIPAddress);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new CIDRException(e);
|
||||
}
|
||||
|
||||
int addressBits = cidrAddress.getAddress().length * 8;
|
||||
if (maskBits > addressBits)
|
||||
throw new CIDRException("Invalid mask: " + maskBits + " is longer than the " + addressBits + " bit address " + parsedIPAddress);
|
||||
|
||||
this.simpleCIDR = maskBits == -1 || maskBits == addressBits;
|
||||
this.maskBytes = simpleCIDR ? -1 : maskBits / 8;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* A CIDR validator for TCPShield
|
||||
@@ -18,7 +19,7 @@ public class CIDRValidator {
|
||||
private final File ipWhitelistFolder;
|
||||
|
||||
private final List<CIDRMatcher> cidrMatchers;
|
||||
private final Set<String> cache = new HashSet<>(); // Max potential size is equilivent to the amount of whitelisted IP's
|
||||
private final Set<String> cache = ConcurrentHashMap.newKeySet(); // Max potential size is equilivent to the amount of whitelisted IP's
|
||||
|
||||
public CIDRValidator(TCPShieldPlugin plugin) throws CIDRException {
|
||||
this.plugin = plugin;
|
||||
|
||||
+15
-9
@@ -7,6 +7,7 @@ import net.tcpshield.tcpshield.util.validation.timestamp.TimestampValidator;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
@@ -24,6 +25,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class HTPDateTimestampValidator extends TimestampValidator {
|
||||
|
||||
private static final int TIMEOUT = 10000; // In milliseconds
|
||||
|
||||
private volatile long htpDateOffset = 0;
|
||||
|
||||
public HTPDateTimestampValidator(TCPShieldPlugin plugin) {
|
||||
@@ -40,20 +43,23 @@ public class HTPDateTimestampValidator extends TimestampValidator {
|
||||
|
||||
|
||||
private void updateHTPDateOffset() throws IOException {
|
||||
Socket socket = new Socket("google.com", 80);
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.connect(new InetSocketAddress("google.com", 80), TIMEOUT);
|
||||
socket.setSoTimeout(TIMEOUT);
|
||||
|
||||
String payload = "HEAD http://google.com/ HTTP/1.1\r\nHost: google.com\r\nUser-Agent: tcpshield/1.0\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n";
|
||||
socket.getOutputStream().write(payload.getBytes());
|
||||
String payload = "HEAD http://google.com/ HTTP/1.1\r\nHost: google.com\r\nUser-Agent: tcpshield/1.0\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n";
|
||||
socket.getOutputStream().write(payload.getBytes());
|
||||
|
||||
long readTime = System.currentTimeMillis(); // assuming server -> client time is negligible
|
||||
long readTime = System.currentTimeMillis(); // assuming server -> client time is negligible
|
||||
|
||||
List<String> response = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.toList());
|
||||
List<String> response = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Date serverDate = parseDate(response);
|
||||
Date serverDate = parseDate(response);
|
||||
|
||||
htpDateOffset = Math.round((serverDate.getTime() - readTime) / 1000.0) * 1000; // the HTTP protocol only returns time in seconds; round offset
|
||||
htpDateOffset = Math.round((serverDate.getTime() - readTime) / 1000.0) * 1000; // the HTTP protocol only returns time in seconds; round offset
|
||||
}
|
||||
}
|
||||
|
||||
private Date parseDate(List<String> response) {
|
||||
|
||||
@@ -65,12 +65,13 @@ public class VelocityConfig extends ConfigProvider {
|
||||
try {
|
||||
loadedToml = new Toml().read(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode", "enable-geyser-support", "pre-login-event");
|
||||
|
||||
this.onlyProxy = loadedToml.getBoolean("only-allow-proxy-connections");
|
||||
this.timestampValidationMode = loadedToml.getString("timestamp-validation");
|
||||
this.doDebug = loadedToml.getBoolean("debug-mode");
|
||||
this.geyser = loadedToml.getBoolean("enable-geyser-support");
|
||||
this.velocityHandlePreLoginEvent = loadedToml.getBoolean("pre-login-event");
|
||||
} catch (Exception e) {
|
||||
throw new ConfigLoadException(e);
|
||||
}
|
||||
|
||||
+26
-5
@@ -16,6 +16,17 @@ public class VelocityHandshakeHandler {
|
||||
|
||||
private final TCPShieldPlugin plugin;
|
||||
|
||||
|
||||
private static Class<?> CONNECTED_PLAYER_CONNECTION_CLASS;
|
||||
|
||||
static {
|
||||
try {
|
||||
CONNECTED_PLAYER_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.ConnectedPlayer");
|
||||
} catch (Exception e) {
|
||||
// ignore for old velocity versions
|
||||
}
|
||||
}
|
||||
|
||||
public VelocityHandshakeHandler(TCPShieldPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@@ -23,11 +34,15 @@ public class VelocityHandshakeHandler {
|
||||
// Turns out this event sometimes passes erroneous hostnames
|
||||
// which have the null bytes terminated as FML data which causes
|
||||
// issues with the verification process.
|
||||
// @Subscribe(order = PostOrder.FIRST)
|
||||
// public void onPreLogin(PreLoginEvent e) {
|
||||
// InboundConnection connection = e.getConnection();
|
||||
// handleEvent(connection, "onPreLogin");
|
||||
// }
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPreLogin(PreLoginEvent e) {
|
||||
if (!this.plugin.getConfigProvider().handlePreLoginEvent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
InboundConnection connection = e.getConnection();
|
||||
handleEvent(connection, "onPreLogin");
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onHandshake(ConnectionHandshakeEvent e) {
|
||||
@@ -38,6 +53,12 @@ public class VelocityHandshakeHandler {
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onProxyPing(ProxyPingEvent e) {
|
||||
InboundConnection connection = e.getConnection();
|
||||
|
||||
if (connection.getClass() == CONNECTED_PLAYER_CONNECTION_CLASS) {
|
||||
// new ServerData (0x42) packet on connect, we don't care about it
|
||||
return;
|
||||
}
|
||||
|
||||
handleEvent(connection, "onProxyPing");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,15 @@ public class VelocityPacket implements PacketProvider {
|
||||
Class<?> inboundConnection = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection");
|
||||
|
||||
HANDSHAKE_FIELD = ReflectionUtil.getPrivateField(inboundConnection, "handshake");
|
||||
HOSTNAME_FIELD = ReflectionUtil.getPrivateField(Class.forName("com.velocitypowered.proxy.protocol.packet.Handshake"), "serverAddress");
|
||||
|
||||
Field hostnameField;
|
||||
try {
|
||||
hostnameField = ReflectionUtil.getPrivateField(Class.forName("com.velocitypowered.proxy.protocol.packet.HandshakePacket"), "serverAddress");
|
||||
} catch (Exception e) {
|
||||
hostnameField = ReflectionUtil.getPrivateField(Class.forName("com.velocitypowered.proxy.protocol.packet.Handshake"), "serverAddress");
|
||||
}
|
||||
HOSTNAME_FIELD = hostnameField;
|
||||
|
||||
CLEANED_ADDRESS_FIELD = ReflectionUtil.getPrivateField(inboundConnection, "cleanedAddress");
|
||||
} catch (Exception e) {
|
||||
throw new InitializationException(new ReflectionException(e));
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.velocitypowered.api.proxy.InboundConnection;
|
||||
import net.tcpshield.tcpshield.provider.PlayerProvider;
|
||||
import net.tcpshield.tcpshield.util.ReflectionUtil;
|
||||
import net.tcpshield.tcpshield.util.exception.manipulate.PlayerManipulationException;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.HandshakeException;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.InitializationException;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.ReflectionException;
|
||||
|
||||
@@ -27,6 +26,7 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
private static final Method CLOSE_CHANNEL_METHOD;
|
||||
|
||||
// new velocity support
|
||||
|
||||
private static Class<?> LOGIN_INBOUND_CONNECTION_CLASS;
|
||||
private static Field LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD;
|
||||
|
||||
@@ -149,7 +149,7 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
}
|
||||
|
||||
enum ConnectionType {
|
||||
LOGIN_INBOUND, INITIAL_INBOUND, LEGACY;
|
||||
LOGIN_INBOUND, INITIAL_INBOUND, LEGACY
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: 2.5.5
|
||||
version: 2.8.1
|
||||
main: net.tcpshield.tcpshield.bungee.TCPShieldBungee
|
||||
author: https://tcpshield.com
|
||||
softdepends:
|
||||
|
||||
@@ -9,3 +9,6 @@ debug-mode = false
|
||||
|
||||
# Toggle to enable support for Geyser/Floodgate v2
|
||||
enable-geyser-support = false
|
||||
|
||||
# enable handling handshake on PreLoginEvent
|
||||
pre-login-event = true
|
||||
@@ -9,3 +9,6 @@ debug-mode: false
|
||||
|
||||
# Toggle to enable support for Geyser/Floodgate v2
|
||||
enable-geyser-support: false
|
||||
|
||||
# Spigot/Paper option only, does not affect bungeecord
|
||||
prefer-protocollib: false
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: 2.5.5
|
||||
version: 2.8.1
|
||||
main: net.tcpshield.tcpshield.bukkit.TCPShieldBukkit
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
@@ -7,3 +7,4 @@ softdepend:
|
||||
author: https://tcpshield.com
|
||||
description: TCPShield IP parsing capabilities for Velocity
|
||||
api-version: 1.16
|
||||
folia-supported: true
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "tcpshield",
|
||||
"name": "TCPShield",
|
||||
"version": "2.5.5",
|
||||
"version": "2.8.1",
|
||||
"description": "TCPShield IP parsing capabilities for Velocity",
|
||||
"authors": [
|
||||
"TCPShield"
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package net.tcpshield.tcpshield.util.validation.cidr;
|
||||
|
||||
import net.tcpshield.tcpshield.util.exception.phase.CIDRException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class CIDRMatcherTest {
|
||||
|
||||
private static boolean matches(String cidr, String address) throws UnknownHostException {
|
||||
return CIDRMatcher.create(cidr).match(InetAddress.getByName(address));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bareAddressMatchesOnlyItself() throws UnknownHostException {
|
||||
assertTrue(matches("203.0.113.7", "203.0.113.7"));
|
||||
assertFalse(matches("203.0.113.7", "203.0.113.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bareIPv6AddressMatchesOnlyItself() throws UnknownHostException {
|
||||
assertTrue(matches("2001:db8::1", "2001:db8::1"));
|
||||
assertFalse(matches("2001:db8::1", "2001:db8::2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyEntryIsRejected() {
|
||||
assertThrows(CIDRException.class, () -> CIDRMatcher.create(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6PrefixOf32BitsMatchesTheWholePrefix() throws UnknownHostException {
|
||||
assertTrue(matches("2001:db8::/32", "2001:db8::"));
|
||||
assertTrue(matches("2001:db8::/32", "2001:db8:ffff:ffff:ffff:ffff:ffff:ffff"));
|
||||
assertFalse(matches("2001:db8::/32", "2001:db9::"));
|
||||
assertFalse(matches("2001:db8::/32", "2002:db8::"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6PrefixOf128BitsMatchesOnlyItself() throws UnknownHostException {
|
||||
assertTrue(matches("2001:db8::1/128", "2001:db8::1"));
|
||||
assertFalse(matches("2001:db8::1/128", "2001:db8::2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv4PrefixOf32BitsMatchesOnlyItself() throws UnknownHostException {
|
||||
assertTrue(matches("203.0.113.7/32", "203.0.113.7"));
|
||||
assertFalse(matches("203.0.113.7/32", "203.0.113.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void masksLongerThanTheAddressAreRejected() {
|
||||
assertThrows(CIDRException.class, () -> CIDRMatcher.create("203.0.113.0/33"));
|
||||
assertThrows(CIDRException.class, () -> CIDRMatcher.create("2001:db8::/129"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeMasksAreRejected() {
|
||||
assertThrows(CIDRException.class, () -> CIDRMatcher.create("203.0.113.0/-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv4MaskEdges() throws UnknownHostException {
|
||||
assertTrue(matches("0.0.0.0/0", "203.0.113.7"));
|
||||
assertTrue(matches("128.0.0.0/1", "203.0.113.7"));
|
||||
assertFalse(matches("128.0.0.0/1", "127.255.255.255"));
|
||||
assertTrue(matches("203.0.0.0/8", "203.255.255.255"));
|
||||
assertFalse(matches("203.0.0.0/8", "204.0.0.0"));
|
||||
assertTrue(matches("203.0.0.0/9", "203.127.255.255"));
|
||||
assertFalse(matches("203.0.0.0/9", "203.128.0.0"));
|
||||
assertTrue(matches("203.0.112.0/23", "203.0.113.255"));
|
||||
assertFalse(matches("203.0.112.0/23", "203.0.114.0"));
|
||||
assertTrue(matches("203.0.113.0/24", "203.0.113.255"));
|
||||
assertFalse(matches("203.0.113.0/24", "203.0.112.255"));
|
||||
assertTrue(matches("203.0.113.128/25", "203.0.113.255"));
|
||||
assertFalse(matches("203.0.113.128/25", "203.0.113.127"));
|
||||
assertTrue(matches("203.0.113.6/31", "203.0.113.7"));
|
||||
assertFalse(matches("203.0.113.6/31", "203.0.113.8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ipv6MaskEdges() throws UnknownHostException {
|
||||
assertTrue(matches("::/0", "2001:db8::1"));
|
||||
assertTrue(matches("8000::/1", "ffff::1"));
|
||||
assertFalse(matches("8000::/1", "7fff::1"));
|
||||
assertTrue(matches("2001:db8::/48", "2001:db8:0:ffff::1"));
|
||||
assertFalse(matches("2001:db8::/48", "2001:db8:1::1"));
|
||||
assertTrue(matches("2001:db8::/49", "2001:db8:0:7fff::1"));
|
||||
assertFalse(matches("2001:db8::/49", "2001:db8:0:8000::1"));
|
||||
assertTrue(matches("2001:db8::/127", "2001:db8::1"));
|
||||
assertFalse(matches("2001:db8::/127", "2001:db8::2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addressFamiliesNeverMatchEachOther() throws UnknownHostException {
|
||||
assertFalse(matches("0.0.0.0/0", "2001:db8::1"));
|
||||
assertFalse(matches("::/0", "203.0.113.7"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user