Optimize / clean up server disconnect method
This commit is contained in:
parent
f08df9555c
commit
4abffa9f24
@ -1,7 +1,7 @@
|
|||||||
package net.md_5.bungee;
|
package net.md_5.bungee;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -41,7 +41,7 @@ public class ServerConnection implements Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void disconnect(String reason)
|
public void disconnect(String reason)
|
||||||
{
|
{
|
||||||
disconnect( TextComponent.fromLegacyText( reason ) );
|
disconnect( TextComponent.fromLegacyText( reason ) );
|
||||||
}
|
}
|
||||||
@ -49,20 +49,7 @@ public class ServerConnection implements Server
|
|||||||
@Override
|
@Override
|
||||||
public void disconnect(BaseComponent... reason)
|
public void disconnect(BaseComponent... reason)
|
||||||
{
|
{
|
||||||
if ( !ch.isClosed() )
|
ch.write( new Kick( ComponentSerializer.toString( reason ) ), ChannelFutureListener.CLOSE );
|
||||||
{
|
|
||||||
// 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
|
@Override
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package net.md_5.bungee;
|
package net.md_5.bungee;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
@ -3,6 +3,8 @@ package net.md_5.bungee.netty;
|
|||||||
import net.md_5.bungee.protocol.PacketWrapper;
|
import net.md_5.bungee.protocol.PacketWrapper;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -34,22 +36,32 @@ public class ChannelWrapper
|
|||||||
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
ch.pipeline().get( MinecraftEncoder.class ).setProtocolVersion( protocol );
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void write(Object packet)
|
public synchronized void write(Object packet, ChannelFutureListener future)
|
||||||
{
|
{
|
||||||
if ( !closed )
|
if ( !closed )
|
||||||
{
|
{
|
||||||
|
ChannelFuture listener;
|
||||||
if ( packet instanceof PacketWrapper )
|
if ( packet instanceof PacketWrapper )
|
||||||
{
|
{
|
||||||
( (PacketWrapper) packet ).setReleased( true );
|
( (PacketWrapper) packet ).setReleased( true );
|
||||||
ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() );
|
listener = ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
ch.write( packet, ch.voidPromise() );
|
listener = ch.write( packet, ch.voidPromise() );
|
||||||
|
}
|
||||||
|
if ( future != null )
|
||||||
|
{
|
||||||
|
listener.addListener( future );
|
||||||
}
|
}
|
||||||
ch.flush();
|
ch.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void write(Object packet)
|
||||||
|
{
|
||||||
|
write( packet, null );
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void close()
|
public synchronized void close()
|
||||||
{
|
{
|
||||||
if ( !closed )
|
if ( !closed )
|
||||||
|
Loading…
Reference in New Issue
Block a user