Support Velocity's new LoginInboundConnection class.
This commit is contained in:
1 parent
cf97e37632
commit
cfbd6ffac5
7 files changed
+86
-20
No files matched your search
+2
-7
@@ -5,7 +5,6 @@ import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
|
||||
// --
|
||||
// Building
|
||||
// --
|
||||
@@ -24,15 +23,13 @@ plugins {
|
||||
id 'idea'
|
||||
}
|
||||
|
||||
|
||||
// --
|
||||
// Variables
|
||||
// --
|
||||
version = '2.5.4'
|
||||
version = '2.5.5'
|
||||
group = 'net.tcpshield.tcpshield'
|
||||
archivesBaseName = 'TCPShield'
|
||||
|
||||
|
||||
// --
|
||||
// Misc.
|
||||
// --
|
||||
@@ -68,7 +65,6 @@ compileJava {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
|
||||
// --
|
||||
// Dependencies
|
||||
// --
|
||||
@@ -97,7 +93,6 @@ 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'
|
||||
@@ -180,4 +175,4 @@ void updateJsons() {
|
||||
}
|
||||
}
|
||||
|
||||
build.dependsOn updateVersion
|
||||
build.dependsOn updateVersion
|
||||
+1
-1
@@ -43,7 +43,7 @@ public class VelocityHandshakeHandler {
|
||||
|
||||
private void handleEvent(InboundConnection connection, String debugSource) {
|
||||
VelocityPlayer player = new VelocityPlayer(connection);
|
||||
if (player.isLegacy()) {
|
||||
if (player.getConnectionType() == VelocityPlayer.ConnectionType.LEGACY) {
|
||||
player.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ public class VelocityPacket implements PacketProvider {
|
||||
private static final Field HOSTNAME_FIELD;
|
||||
private static final Field CLEANED_ADDRESS_FIELD;
|
||||
|
||||
// new velocity support
|
||||
private static Class<?> LOGIN_INBOUND_CONNECTION_CLASS;
|
||||
private static Field LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD;
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<?> inboundConnection = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection");
|
||||
@@ -32,6 +36,14 @@ public class VelocityPacket implements PacketProvider {
|
||||
} catch (Exception e) {
|
||||
throw new InitializationException(new ReflectionException(e));
|
||||
}
|
||||
|
||||
// LoginInboundConnection support
|
||||
try {
|
||||
LOGIN_INBOUND_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.LoginInboundConnection");
|
||||
LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD = ReflectionUtil.getPrivateField(LOGIN_INBOUND_CONNECTION_CLASS, "delegate");
|
||||
} catch (Exception e) {
|
||||
// ignore for old versions of velocity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +51,15 @@ public class VelocityPacket implements PacketProvider {
|
||||
private final String rawPayload;
|
||||
|
||||
public VelocityPacket(InboundConnection inboundConnection) {
|
||||
// support new velocity connection type
|
||||
if (inboundConnection.getClass() == LOGIN_INBOUND_CONNECTION_CLASS) {
|
||||
try {
|
||||
inboundConnection = (InboundConnection) LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD.get(inboundConnection);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.inboundConnection = inboundConnection;
|
||||
try {
|
||||
this.rawPayload = (String) HOSTNAME_FIELD.get(HANDSHAKE_FIELD.get(inboundConnection));
|
||||
|
||||
@@ -26,6 +26,10 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
private static final Field REMOTE_ADDRESS_FIELD;
|
||||
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;
|
||||
|
||||
static {
|
||||
try {
|
||||
INITIAL_INBOUND_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.InitialInboundConnection");
|
||||
@@ -38,22 +42,39 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
} catch (Exception e) {
|
||||
throw new InitializationException(new ReflectionException(e));
|
||||
}
|
||||
|
||||
// LoginInboundConnection support
|
||||
try {
|
||||
LOGIN_INBOUND_CONNECTION_CLASS = Class.forName("com.velocitypowered.proxy.connection.client.LoginInboundConnection");
|
||||
LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD = ReflectionUtil.getPrivateField(LOGIN_INBOUND_CONNECTION_CLASS, "delegate");
|
||||
} catch (Exception e) {
|
||||
// ignore for old versions of velocity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final InboundConnection inboundConnection;
|
||||
private final boolean legacy;
|
||||
// private final boolean legacy;
|
||||
private final ConnectionType connectionType;
|
||||
private String ip;
|
||||
|
||||
public VelocityPlayer(InboundConnection inboundConnection) {
|
||||
this.inboundConnection = inboundConnection;
|
||||
this.legacy = inboundConnection.getClass() != INITIAL_INBOUND_CONNECTION_CLASS;
|
||||
// this.legacy = inboundConnection.getClass() != INITIAL_INBOUND_CONNECTION_CLASS && inboundConnection.getClass() != LOGIN_INBOUND_CONNECTION_CLASS;
|
||||
this.ip = inboundConnection.getRemoteAddress().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
if (this.inboundConnection.getClass() == INITIAL_INBOUND_CONNECTION_CLASS) {
|
||||
this.connectionType = ConnectionType.INITIAL_INBOUND;
|
||||
} else if (this.inboundConnection.getClass() == LOGIN_INBOUND_CONNECTION_CLASS) {
|
||||
this.connectionType = ConnectionType.LOGIN_INBOUND;
|
||||
} else {
|
||||
this.connectionType = ConnectionType.LEGACY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported with Velocity handshakes
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
@Override
|
||||
@@ -63,6 +84,7 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
|
||||
/**
|
||||
* Unsupported with Velocity handshakes
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
@Override
|
||||
@@ -75,26 +97,26 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public boolean isLegacy() {
|
||||
return legacy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIP(InetSocketAddress ip) throws PlayerManipulationException {
|
||||
try {
|
||||
this.ip = ip.getAddress().getHostAddress();
|
||||
|
||||
Object minecraftConnection = MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
|
||||
Object minecraftConnection = this.getMinecraftConnection();
|
||||
REMOTE_ADDRESS_FIELD.set(minecraftConnection, ip);
|
||||
} catch (Exception e) {
|
||||
throw new PlayerManipulationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// public boolean isLegacy() {
|
||||
// return legacy;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
try {
|
||||
Object minecraftConnection = legacy ? LEGACY_MINECRAFT_CONNECTION_FIELD.get(inboundConnection) : MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
|
||||
Object minecraftConnection = this.getMinecraftConnection();
|
||||
|
||||
CLOSE_CHANNEL_METHOD.invoke(minecraftConnection);
|
||||
} catch (Exception e) {
|
||||
@@ -102,4 +124,32 @@ public class VelocityPlayer implements PlayerProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private Object getMinecraftConnection() {
|
||||
try {
|
||||
switch (this.connectionType) {
|
||||
case LEGACY:
|
||||
return LEGACY_MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
|
||||
case INITIAL_INBOUND:
|
||||
return MINECRAFT_CONNECTION_FIELD.get(inboundConnection);
|
||||
case LOGIN_INBOUND: {
|
||||
// starts as login_inbound, get delegate initial_inbound
|
||||
Object initialInboundConnection = LOGIN_INBOUND_CONNECTION_DELEGATE_FIELD.get(this.inboundConnection);
|
||||
return MINECRAFT_CONNECTION_FIELD.get(initialInboundConnection);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConnectionType getConnectionType() {
|
||||
return connectionType;
|
||||
}
|
||||
|
||||
enum ConnectionType {
|
||||
LOGIN_INBOUND, INITIAL_INBOUND, LEGACY;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: 2.5.4
|
||||
version: 2.5.5
|
||||
main: net.tcpshield.tcpshield.bungee.TCPShieldBungee
|
||||
author: https://tcpshield.com
|
||||
softdepends:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: 2.5.4
|
||||
version: 2.5.5
|
||||
main: net.tcpshield.tcpshield.bukkit.TCPShieldBukkit
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "tcpshield",
|
||||
"name": "TCPShield",
|
||||
"version": "2.5.4",
|
||||
"version": "2.5.5",
|
||||
"description": "TCPShield IP parsing capabilities for Velocity",
|
||||
"authors": [
|
||||
"TCPShield"
|
||||
|
||||
Reference in new issue
Block a user