Revert disconnect change. Forgot we use void futures.

This commit is contained in:
md_5 2014-02-08 12:42:27 +11:00
parent 98a5db9abf
commit 9a4f0a6f59
2 changed files with 19 additions and 18 deletions

View File

@ -1,7 +1,7 @@
package net.md_5.bungee;
import io.netty.channel.ChannelFutureListener;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@ -41,7 +41,7 @@ public class ServerConnection implements Server
}
@Override
public void disconnect(String reason)
public synchronized void disconnect(String reason)
{
disconnect( TextComponent.fromLegacyText( reason ) );
}
@ -49,7 +49,20 @@ public class ServerConnection implements Server
@Override
public void disconnect(BaseComponent... reason)
{
ch.write( new Kick( ComponentSerializer.toString( reason ) ), ChannelFutureListener.CLOSE );
if ( !ch.isClosed() )
{
// TODO: Can we just use a future here?
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
ch.getHandle().eventLoop().schedule( new Runnable()
{
@Override
public void run()
{
ch.getHandle().close();
}
}, 100, TimeUnit.MILLISECONDS );
}
}
@Override

View File

@ -3,8 +3,6 @@ package net.md_5.bungee.netty;
import net.md_5.bungee.protocol.PacketWrapper;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
@ -36,32 +34,22 @@ public class ChannelWrapper
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
}
public synchronized void write(Object packet, ChannelFutureListener future)
public synchronized void write(Object packet)
{
if ( !closed )
{
ChannelFuture listener;
if ( packet instanceof PacketWrapper )
{
( (PacketWrapper) packet ).setReleased( true );
listener = ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() );
ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() );
} else
{
listener = ch.write( packet, ch.voidPromise() );
}
if ( future != null )
{
listener.addListener( future );
ch.write( packet, ch.voidPromise() );
}
ch.flush();
}
}
public synchronized void write(Object packet)
{
write( packet, null );
}
public synchronized void close()
{
if ( !closed )