Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4e41d2c28 | ||
|
|
751bcafcc6 | ||
|
|
a641acdfb6 | ||
|
|
c89705c0c8 |
No files matched your search
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.tcpshield.realip</groupId>
|
||||
<artifactId>RealIP</artifactId>
|
||||
<version>1.4-SNAPSHOT</version>
|
||||
<artifactId>TCPShield</artifactId>
|
||||
<version>1.7-SNAPSHOT</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
|
||||
</properties>
|
||||
@@ -55,7 +55,7 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>RealIP</finalName>
|
||||
<finalName>TCPShield</finalName>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
|
||||
+14
-28
@@ -1,18 +1,14 @@
|
||||
package net.tcpshield.realip;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Handshake.Client;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.server.SocketInjector;
|
||||
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import io.netty.channel.AbstractChannel;
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
@@ -24,14 +20,13 @@ import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PacketHandler
|
||||
extends PacketAdapter {
|
||||
public class HandshakePacketHandler extends PacketAdapter {
|
||||
private String properField = null;
|
||||
private final Logger logger;
|
||||
private final boolean onlyProxy;
|
||||
private final boolean debugMode;
|
||||
|
||||
public PacketHandler(Logger logger, boolean onlyProxy, boolean debugMode) {
|
||||
public HandshakePacketHandler(Logger logger, boolean onlyProxy, boolean debugMode) {
|
||||
super(TCPShieldBukkit.getInstance(), new PacketType[]{PacketType.Handshake.Client.SET_PROTOCOL});
|
||||
this.logger = logger;
|
||||
this.onlyProxy = onlyProxy;
|
||||
@@ -43,6 +38,12 @@ public class PacketHandler
|
||||
String raw = null;
|
||||
try {
|
||||
raw = (String) event.getPacket().getStrings().read(0);
|
||||
String extraData = "";
|
||||
String[] hostnameSplits = raw.split("\0", 2);
|
||||
if(hostnameSplits.length > 1) {
|
||||
extraData = hostnameSplits[1];
|
||||
}
|
||||
raw = hostnameSplits[0];
|
||||
|
||||
String[] payload = raw.split("///", 3);
|
||||
if (payload.length >= 3) {
|
||||
@@ -59,10 +60,6 @@ public class PacketHandler
|
||||
|
||||
String reconstructedPayload = hostname + "///" + host + ":" + port + "///" + timestamp;
|
||||
|
||||
if (signature.contains("%%%")) {
|
||||
signature = signature.split("%%%", 2)[0];
|
||||
}
|
||||
|
||||
if (!Signing.verify(reconstructedPayload.getBytes(StandardCharsets.UTF_8), signature)) {
|
||||
throw new Exception("Couldn't verify signature.");
|
||||
}
|
||||
@@ -85,21 +82,22 @@ public class PacketHandler
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
hostname = hostname + extraData;
|
||||
event.getPacket().getStrings().write(0, hostname);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Player player;
|
||||
ex.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if ((this.onlyProxy) && (!proxyConnection)) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(this.debugMode) {
|
||||
if (this.debugMode) {
|
||||
this.logger.warning("Disconnecting " + player.getAddress() + " because no proxy info was received and only-allow-proxy-connections is enabled.");
|
||||
}
|
||||
|
||||
if(raw != null) {
|
||||
if (raw != null) {
|
||||
this.logger.warning(raw);
|
||||
}
|
||||
player.kickPlayer("");
|
||||
@@ -107,20 +105,8 @@ public class PacketHandler
|
||||
}
|
||||
}
|
||||
|
||||
private Channel getChannel(Player player) {
|
||||
try {
|
||||
Class<? extends Player> playerClass = player.getClass();
|
||||
Object playerHandle = playerClass.getMethod("getHandle", new Class[0]).invoke(player, new Object[0]);
|
||||
Object playerConnection = getNmsClass("EntityPlayer").getField("playerConnection").get(playerHandle);
|
||||
Object networkManager = getNmsClass("PlayerConnection").getField("networkManager").get(playerConnection);
|
||||
return (Channel) getNmsClass("NetworkManager").getField("channel").get(networkManager);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Couldn't get player channel", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class getNmsClass(String name)
|
||||
throws ClassNotFoundException {
|
||||
private Class getNmsClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(getNmsPackage() + "." + name);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package net.tcpshield.realip;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TCPShieldBukkit
|
||||
extends JavaPlugin {
|
||||
public class TCPShieldBukkit extends JavaPlugin implements Listener {
|
||||
private static TCPShieldBukkit INSTANCE;
|
||||
private static Boolean stopping = Boolean.valueOf(false);
|
||||
private boolean onlyProxy;
|
||||
@@ -26,14 +22,17 @@ public class TCPShieldBukkit
|
||||
getLogger().severe("Couldn't initialize signing module.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
saveDefaultConfig();
|
||||
FileConfiguration config = getConfig();
|
||||
this.onlyProxy = config.getBoolean("only-allow-proxy-connections");
|
||||
this.debugMode = config.getBoolean("debug-mode");
|
||||
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketHandler(getLogger(), this.onlyProxy, this.debugMode));
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new HandshakePacketHandler(getLogger(), this.onlyProxy, this.debugMode));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void onDisable() {
|
||||
stopping = Boolean.valueOf(true);
|
||||
INSTANCE = null;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.CopyOption;
|
||||
@@ -20,6 +21,7 @@ import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
|
||||
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.api.plugin.PluginManager;
|
||||
@@ -28,9 +30,7 @@ import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class TCPShieldBungee
|
||||
extends Plugin
|
||||
implements Listener {
|
||||
public class TCPShieldBungee extends Plugin implements Listener {
|
||||
private boolean onlyProxy;
|
||||
private boolean debugMode;
|
||||
|
||||
@@ -116,6 +116,23 @@ public class TCPShieldBungee
|
||||
return new File(dataFolder, "config.yml");
|
||||
}
|
||||
|
||||
@EventHandler(priority = -64)
|
||||
public void onProxyPingEvent(ProxyPingEvent event) {
|
||||
if(event.getConnection().isLegacy()) {
|
||||
try {
|
||||
Field wrapperField = event.getConnection().getClass().getDeclaredField("ch");
|
||||
wrapperField.setAccessible(true);
|
||||
Object wrapper = wrapperField.get(event.getConnection());
|
||||
wrapperField.setAccessible(false);
|
||||
Method m = wrapper.getClass().getMethod("close");
|
||||
m.invoke(wrapper);
|
||||
|
||||
} catch(Exception e) {
|
||||
event.getConnection().disconnect(new BaseComponent[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = -64)
|
||||
public void onPlayerHandshake(PlayerHandshakeEvent e) {
|
||||
boolean proxyConnection = false;
|
||||
@@ -166,8 +183,6 @@ public class TCPShieldBungee
|
||||
throw new Exception("Invalid signature timestamp, please check system's local clock if error persists.");
|
||||
}
|
||||
|
||||
hostname = hostname.replace("%%%", "\0");
|
||||
|
||||
PendingConnection connection = e.getConnection();
|
||||
|
||||
InetSocketAddress sockadd = new InetSocketAddress(host, port);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: TCPShield
|
||||
version: 1.6
|
||||
version: 1.7
|
||||
main: net.tcpshield.realip.TCPShieldBungee
|
||||
author: 'https://tcpshield.com'
|
||||
@@ -1,5 +1,5 @@
|
||||
name: TCPShield
|
||||
version: 1.6
|
||||
version: 1.7
|
||||
main: net.tcpshield.realip.TCPShieldBukkit
|
||||
depend: ['ProtocolLib']
|
||||
author: 'https://tcpshield.com'
|
||||
Reference in new issue
Block a user