8 Commits
11 changed files with 51 additions and 10 deletions

No files matched your search

+8 -1
View File
@@ -22,4 +22,11 @@ gradle build
The dependencies should install themselves automatically. After the build has finished, the compiled jar file can be found under `/build/libs`.
### Support
See [Contact](https://docs.tcpshield.com/about-us)
See [Contact](https://docs.tcpshield.com/about-us)
### Contributors
These wonderful contributors have helped TCPShield make this plugin better!
* [Fuzzlemann](https://github.com/Fuzzlemann)
* [RyanDeLap](https://github.com/RyanDeLap)
+1 -1
View File
@@ -65,7 +65,7 @@ configurations {
testImplementation.extendsFrom compileOnly
}
version = '2.0'
version = '2.1'
group = 'net.tcpshield.tcpshield'
archivesBaseName = 'TCPShield'
@@ -92,7 +92,7 @@ public class HandshakePacketHandler {
private void handleInvalidTimestamp(IPlayer player, long timestamp, long currentTime) {
if (config.isDebug()) {
this.logger.warning(String.format("%s[%s/%s] provided valid handshake information, but timestamp was not valid. " +
"Provided timestamp: %d vs. system timestamp: %d. Please check your machine time.", player.getName(), player.getUUID(), player.getIP(), timestamp, currentTime));
"Provided timestamp: %d vs. system timestamp: %d. Please check your machine time. Timestamp validation mode: %s", player.getName(), player.getUUID(), player.getIP(), timestamp, currentTime, config.getTimestampValidationMode()));
}
if (config.isOnlyProxy()) {
@@ -58,7 +58,18 @@ public class ReflectionUtils {
Field cachedField = CACHED_FIELDS.get(clazz, fieldName);
if (cachedField != null) return cachedField;
Field field = clazz.getDeclaredField(fieldName);
Field field;
try {
field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
Class<?> superclass = clazz.getSuperclass();
if (superclass != null) {
return getDeclaredField(superclass, fieldName);
} else {
throw e;
}
}
CACHED_FIELDS.put(clazz, fieldName, field);
return field;
}
@@ -16,6 +16,8 @@ public class TCPShieldBukkit extends JavaPlugin {
}
private boolean isPaper() {
if (true) return false; // disabled for now
try {
Class.forName("com.destroystokyo.paper.event.player.PlayerHandshakeEvent");
return true;
@@ -39,6 +39,7 @@ public class PaperPlayerImpl implements IPlayer {
@Override
public void disconnect() {
handshakeEvent.setCancelled(false);
handshakeEvent.setFailMessage("Connection failed. Please try again or contract an administrator.");
handshakeEvent.setFailed(true);
}
@@ -6,7 +6,6 @@ import com.velocitypowered.api.event.proxy.ProxyPingEvent;
import com.velocitypowered.api.proxy.InboundConnection;
import net.tcpshield.tcpshield.HandshakePacketHandler;
import net.tcpshield.tcpshield.abstraction.IPacket;
import net.tcpshield.tcpshield.abstraction.IPlayer;
import net.tcpshield.tcpshield.velocity.impl.VelocityConfigImpl;
import net.tcpshield.tcpshield.velocity.impl.VelocityPacketImpl;
import net.tcpshield.tcpshield.velocity.impl.VelocityPlayerImpl;
@@ -35,7 +34,12 @@ public class VelocityHandshakePacketHandler {
}
private void handleEvent(InboundConnection connection) {
IPlayer player = new VelocityPlayerImpl(connection);
VelocityPlayerImpl player = new VelocityPlayerImpl(connection);
if (player.isLegacy()) {
player.disconnect();
return;
}
IPacket packet = new VelocityPacketImpl(connection);
handshakePacketHandler.onHandshake(packet, player);
@@ -11,11 +11,15 @@ public class VelocityPacketImpl implements IPacket {
private static final Field HANDSHAKE_FIELD;
private static final Field HOSTNAME_FIELD;
private static final Field CLEANED_ADDRESS_FIELD;
static {
try {
HANDSHAKE_FIELD = ReflectionUtils.getPrivateField(Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection"), "handshake");
Class<?> inboundConnection = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection");
HANDSHAKE_FIELD = ReflectionUtils.getPrivateField(inboundConnection, "handshake");
HOSTNAME_FIELD = ReflectionUtils.getPrivateField(Class.forName("com.velocitypowered.proxy.protocol.packet.Handshake"), "serverAddress");
CLEANED_ADDRESS_FIELD = ReflectionUtils.getPrivateField(inboundConnection, "cleanedAddress");
} catch (NoSuchFieldException | ClassNotFoundException e) {
throw new TCPShieldInitializationException(e);
}
@@ -40,6 +44,8 @@ public class VelocityPacketImpl implements IPacket {
@Override
public void modifyOriginalPacket(String hostname) throws Exception {
ReflectionUtils.setFinalField(inboundConnection, CLEANED_ADDRESS_FIELD, hostname);
Object handshake = HANDSHAKE_FIELD.get(inboundConnection);
HOSTNAME_FIELD.set(handshake, hostname);
}
@@ -13,12 +13,14 @@ import java.net.InetSocketAddress;
public class VelocityPlayerImpl implements IPlayer {
private static final Field MINECRAFT_CONNECTION_FIELD;
private static final Field LEGACY_MINECRAFT_CONNECTION_FIELD;
private static final Field REMOTE_ADDRESS_FIELD;
private static final Method CLOSE_CHANNEL_METHOD;
static {
try {
MINECRAFT_CONNECTION_FIELD = ReflectionUtils.getPrivateField(Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection"), "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");
REMOTE_ADDRESS_FIELD = ReflectionUtils.getPrivateField(minecraftConnection, "remoteAddress");
@@ -29,10 +31,12 @@ public class VelocityPlayerImpl implements IPlayer {
}
private final InboundConnection inboundConnection;
private final boolean legacy;
private String ip;
public VelocityPlayerImpl(InboundConnection inboundConnection) {
this.inboundConnection = inboundConnection;
this.legacy = inboundConnection.getProtocolVersion().isUnknown() || inboundConnection.getProtocolVersion().isLegacy();
this.ip = inboundConnection.getRemoteAddress().getAddress().getHostAddress();
}
@@ -41,6 +45,7 @@ public class VelocityPlayerImpl implements IPlayer {
return "unknown"; // not supported
}
@Override
public String getName() {
return "unknown"; // not supported
}
@@ -50,6 +55,10 @@ public class VelocityPlayerImpl implements IPlayer {
return ip;
}
public boolean isLegacy() {
return legacy;
}
@Override
public void setIP(InetSocketAddress ip) throws IPModificationFailureException {
this.ip = ip.getAddress().getHostAddress();
@@ -65,7 +74,8 @@ public class VelocityPlayerImpl implements IPlayer {
@Override
public void disconnect() {
try {
Object minecraftConnection = MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
Object minecraftConnection = legacy ? LEGACY_MINECRAFT_CONNECTION_FIELD.get(inboundConnection) : MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
CLOSE_CHANNEL_METHOD.invoke(minecraftConnection);
} catch (Exception e) {
throw new RuntimeException(e); // pass exception on
+1 -1
View File
@@ -1,4 +1,4 @@
name: TCPShield
version: '2.0'
version: '2.1'
main: net.tcpshield.tcpshield.bungee.TCPShieldBungee
author: https://tcpshield.com
+1 -1
View File
@@ -1,5 +1,5 @@
name: TCPShield
version: '2.0'
version: '2.1'
main: net.tcpshield.tcpshield.bukkit.TCPShieldBukkit
softdepend:
- ProtocolLib