Better support for ChannelInitializer detection (incase they do something funny, fixes latest PS dev)

This commit is contained in:
Myles 2016-10-26 17:34:09 +01:00
parent 55fccba711
commit bd11c98e45
2 changed files with 32 additions and 2 deletions

View File

@ -72,7 +72,22 @@ public class BukkitViaInjector implements ViaInjector {
private void injectChannelFuture(ChannelFuture future) throws Exception {
try {
ChannelHandler bootstrapAcceptor = future.channel().pipeline().first();
List<String> names = future.channel().pipeline().names();
ChannelHandler bootstrapAcceptor = null;
// Pick best
for (String name : names) {
ChannelHandler handler = future.channel().pipeline().get(name);
try {
ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
bootstrapAcceptor = handler;
} catch (Exception e) {
// Not this one
}
}
// Default to first (Also allows blame to work)
if (bootstrapAcceptor == null) {
bootstrapAcceptor = future.channel().pipeline().first();
}
try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer newInit = new BukkitChannelInitializer(oldInit);

View File

@ -71,7 +71,22 @@ public class SpongeViaInjector implements ViaInjector {
private void injectChannelFuture(ChannelFuture future) throws Exception {
try {
ChannelHandler bootstrapAcceptor = future.channel().pipeline().first();
List<String> names = future.channel().pipeline().names();
ChannelHandler bootstrapAcceptor = null;
// Pick best
for (String name : names) {
ChannelHandler handler = future.channel().pipeline().get(name);
try {
ReflectionUtil.get(handler, "childHandler", ChannelInitializer.class);
bootstrapAcceptor = handler;
} catch (Exception e) {
// Not this one
}
}
// Default to first (Also allows blame to work)
if (bootstrapAcceptor == null) {
bootstrapAcceptor = future.channel().pipeline().first();
}
try {
ChannelInitializer<SocketChannel> oldInit = ReflectionUtil.get(bootstrapAcceptor, "childHandler", ChannelInitializer.class);
ChannelInitializer newInit = new SpongeChannelInitializer(oldInit);