forked from SteamWar/SteamWar
Kick player on Channel injection failure
This commit is contained in:
@@ -22,10 +22,8 @@ package com.comphenix.tinyprotocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.Reflection.Field;
|
||||
import de.steamwar.core.Core;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -57,15 +55,14 @@ public class TinyProtocol implements Listener {
|
||||
private static final Class<?> networkManager = Reflection.getClass("net.minecraft.network.NetworkManager");
|
||||
public static final Field<List> networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager);
|
||||
|
||||
private static final String HANDLER_NAME = "tiny-steamwar";
|
||||
public static final TinyProtocol instance = new TinyProtocol(Core.getInstance());
|
||||
private static int id = 0;
|
||||
|
||||
public static void init() {
|
||||
//enforce init
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
private final String handlerName;
|
||||
private final List<?> connections;
|
||||
private boolean closed;
|
||||
|
||||
@@ -74,7 +71,6 @@ public class TinyProtocol implements Listener {
|
||||
|
||||
private TinyProtocol(final Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.handlerName = "tiny-" + plugin.getName() + "-" + ++id;
|
||||
this.connections = networkManagers.get(getServerConnection(plugin));
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
@@ -148,7 +144,7 @@ public class TinyProtocol implements Listener {
|
||||
this.player = player;
|
||||
|
||||
channel = getChannel.get(connections.stream().filter(connection -> player.getUniqueId().equals(getUUID.get(connection))).findAny().orElseThrow(() -> {
|
||||
player.kickPlayer("An injection failure happend.");
|
||||
Bukkit.getScheduler().runTask(plugin, () -> player.kickPlayer("Connection failure."));
|
||||
return new SecurityException("Could not find channel for player " + player.getName());
|
||||
}));
|
||||
|
||||
@@ -159,7 +155,12 @@ public class TinyProtocol implements Listener {
|
||||
playerInterceptors.put(player, this);
|
||||
}
|
||||
|
||||
channel.pipeline().addBefore("packet_handler", handlerName, this);
|
||||
try {
|
||||
channel.pipeline().addBefore("packet_handler", HANDLER_NAME, this);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> player.kickPlayer("Connection failure."));
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(Object packet) {
|
||||
@@ -174,7 +175,7 @@ public class TinyProtocol implements Listener {
|
||||
if(channel.isActive()) {
|
||||
channel.eventLoop().execute(() -> {
|
||||
try {
|
||||
channel.pipeline().remove(handlerName);
|
||||
channel.pipeline().remove(HANDLER_NAME);
|
||||
} catch (NoSuchElementException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user