Drop bungeecord support
This commit is contained in:
1 parent
a1a412f45a
commit
da25b6a7b6
6 files changed
-341
No files matched your search
@@ -69,7 +69,6 @@ repositories {
|
||||
dependencies {
|
||||
compileOnly(files("libs/ProtocolLib-5.0.jar")) // Import Legacy ProtocolLib API.
|
||||
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
|
||||
compileOnly("net.md-5:bungeecord-api:1.14-SNAPSHOT")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0-M1")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0-M1")
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package net.tcpshield.tcpshield.bungee;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import net.tcpshield.tcpshield.provider.ConfigProvider;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigLoadException;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigReloadException;
|
||||
import net.tcpshield.tcpshield.util.exception.config.ConfigResetException;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.ConfigException;
|
||||
import net.tcpshield.tcpshield.velocity.VelocityConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
/**
|
||||
* Bungee's configuration implementation
|
||||
*/
|
||||
public class BungeeConfig extends ConfigProvider {
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
private Configuration loadedConfiguration;
|
||||
|
||||
public BungeeConfig(Plugin plugin) throws ConfigException {
|
||||
this.plugin = plugin;
|
||||
this.dataFolder = plugin.getDataFolder();
|
||||
this.configFile = new File(dataFolder, "config.yml");
|
||||
|
||||
try {
|
||||
reload();
|
||||
} catch (Exception e) {
|
||||
throw new ConfigException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkNodes(String... nodes) {
|
||||
for (String node : nodes) {
|
||||
if (!loadedConfiguration.contains(node))
|
||||
throw new ConfigException("The node \"" + node + "\" does not exist in the config.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reset() throws ConfigResetException {
|
||||
try {
|
||||
loadedConfiguration = null; // To the garbage collector you go
|
||||
|
||||
try {
|
||||
configFile.delete();
|
||||
} catch (Exception ignored) {
|
||||
// Just ignore since it either does not exist, or we can overwrite
|
||||
}
|
||||
|
||||
try (InputStream in = plugin.getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, configFile.toPath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ConfigResetException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() throws ConfigLoadException {
|
||||
try {
|
||||
ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||
loadedConfiguration = configProvider.load(configFile);
|
||||
|
||||
checkNodes("only-allow-proxy-connections", "timestamp-validation", "debug-mode");
|
||||
|
||||
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");
|
||||
} catch (Exception e) {
|
||||
throw new ConfigLoadException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() throws ConfigReloadException {
|
||||
try {
|
||||
if (!dataFolder.exists())
|
||||
dataFolder.mkdir();
|
||||
|
||||
if (!configFile.exists())
|
||||
reset();
|
||||
|
||||
try {
|
||||
load();
|
||||
} catch (ConfigLoadException exception) {
|
||||
plugin.getLogger().warning("Config loading failed, resetting to default config. (This can be ignored if you just switched builds of TCPShield)");
|
||||
reset();
|
||||
reload(); // Redo cycle, possible StackOverFlow, but realistically only happens if reset fails
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ConfigReloadException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package net.tcpshield.tcpshield.bungee;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import net.tcpshield.tcpshield.TCPShieldPacketHandler;
|
||||
import net.tcpshield.tcpshield.TCPShieldPlugin;
|
||||
import net.tcpshield.tcpshield.bungee.handler.BungeeHandshakeHandler;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The entry point for Bungee servers
|
||||
*/
|
||||
public class TCPShieldBungee extends Plugin implements TCPShieldPlugin, Listener {
|
||||
|
||||
private ConfigProvider configProvider;
|
||||
private TCPShieldPacketHandler packetHandler;
|
||||
private Debugger debugger;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
configProvider = new BungeeConfig(this);
|
||||
debugger = Debugger.createDebugger(this);
|
||||
packetHandler = new TCPShieldPacketHandler(this);
|
||||
|
||||
PluginManager pluginManager = this.getProxy().getPluginManager();
|
||||
pluginManager.registerListener(this, new BungeeHandshakeHandler(this));
|
||||
|
||||
GeyserUtils.initGeyser(this, configProvider);
|
||||
|
||||
initialization();
|
||||
} catch (Exception e) {
|
||||
throw new InitializationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The provider's base methods
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ConfigProvider getConfigProvider() {
|
||||
return configProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TCPShieldPacketHandler getPacketHandler() {
|
||||
return packetHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Debugger getDebugger() {
|
||||
return debugger;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package net.tcpshield.tcpshield.bungee.handler;
|
||||
|
||||
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.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import net.tcpshield.tcpshield.TCPShieldPlugin;
|
||||
import net.tcpshield.tcpshield.util.exception.phase.HandshakeException;
|
||||
|
||||
/**
|
||||
* The handshake handler for Bungee
|
||||
*/
|
||||
public class BungeeHandshakeHandler implements Listener {
|
||||
|
||||
private final TCPShieldPlugin plugin;
|
||||
|
||||
public BungeeHandshakeHandler(TCPShieldPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onProxyPingEvent(ProxyPingEvent e) {
|
||||
PendingConnection connection = e.getConnection();
|
||||
if (!connection.isLegacy())
|
||||
return;
|
||||
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerHandshake(PlayerHandshakeEvent e) {
|
||||
BungeePacket packet = new BungeePacket(e.getHandshake(), e.getConnection());
|
||||
BungeePlayer player = new BungeePlayer(e.getConnection());
|
||||
|
||||
this.plugin.getDebugger().warn("BungeeCord: Raw player hostname: " + packet.getPayloadString());
|
||||
|
||||
try {
|
||||
plugin.getPacketHandler().handleHandshake(packet, player);
|
||||
} catch (HandshakeException exception) {
|
||||
plugin.getDebugger().exception(exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package net.tcpshield.tcpshield.bungee.handler;
|
||||
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.protocol.packet.Handshake;
|
||||
import net.tcpshield.tcpshield.provider.PacketProvider;
|
||||
import net.tcpshield.tcpshield.util.ReflectionUtil;
|
||||
import net.tcpshield.tcpshield.util.exception.manipulate.PacketManipulationException;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* A packet wrapper for Bungee
|
||||
*/
|
||||
public class BungeePacket implements PacketProvider {
|
||||
|
||||
private final Handshake handshake;
|
||||
private final PendingConnection pendingConnection;
|
||||
|
||||
public BungeePacket(Handshake handshake, PendingConnection pendingConnection) {
|
||||
this.handshake = handshake;
|
||||
this.pendingConnection = pendingConnection;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPayloadString() {
|
||||
return handshake.getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPacketHostname(String hostname) throws PacketManipulationException {
|
||||
try {
|
||||
InetSocketAddress virtualHost = InetSocketAddress.createUnresolved(hostname, handshake.getPort());
|
||||
try {
|
||||
ReflectionUtil.setFinalField(pendingConnection, "virtualHost", virtualHost);
|
||||
} catch (Exception ex) {
|
||||
ReflectionUtil.setFinalField(pendingConnection, "vHost", virtualHost);
|
||||
}
|
||||
|
||||
ReflectionUtil.setField(handshake, "host", hostname);
|
||||
} catch (Exception e) {
|
||||
throw new PacketManipulationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package net.tcpshield.tcpshield.bungee.handler;
|
||||
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.tcpshield.tcpshield.provider.PlayerProvider;
|
||||
import net.tcpshield.tcpshield.util.ReflectionUtil;
|
||||
import net.tcpshield.tcpshield.util.exception.manipulate.PlayerManipulationException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A player wrapper for Bungee
|
||||
*/
|
||||
public class BungeePlayer implements PlayerProvider {
|
||||
|
||||
private final PendingConnection pendingConnection;
|
||||
private String ip;
|
||||
|
||||
public BungeePlayer(PendingConnection pendingConnection) {
|
||||
this.pendingConnection = pendingConnection;
|
||||
this.ip = pendingConnection.getAddress().getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trys to grab the UUID of the handshake
|
||||
*
|
||||
* @return If found, the corrosponding uuid, if not, unknown
|
||||
*/
|
||||
@Override
|
||||
public String getUUID() {
|
||||
UUID uuid = pendingConnection.getUniqueId();
|
||||
if (uuid == null)
|
||||
return "unknown";
|
||||
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return pendingConnection.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIP() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIP(InetSocketAddress ip) throws PlayerManipulationException {
|
||||
try {
|
||||
this.ip = ip.getAddress().getHostAddress();
|
||||
|
||||
Object channelWrapper = ReflectionUtil.getObjectInPrivateField(pendingConnection, "ch");
|
||||
Object channel = ReflectionUtil.getObjectInPrivateField(channelWrapper, "ch");
|
||||
|
||||
try {
|
||||
Field socketAddressField = ReflectionUtil.searchFieldByClass(channelWrapper.getClass(), SocketAddress.class);
|
||||
ReflectionUtil.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
|
||||
}
|
||||
|
||||
ReflectionUtil.setFinalField(channel, ReflectionUtil.getPrivateField(channel.getClass(), "remoteAddress"), ip);
|
||||
try {
|
||||
ReflectionUtil.setFinalField(channel, ReflectionUtil.getPrivateField(channel.getClass(), "localAddress"), ip);
|
||||
} catch (Throwable t) {
|
||||
// ChannelWrapper doesn't have a localAddress
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new PlayerManipulationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
pendingConnection.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user