Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Resolve merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleiss committed Jan 15, 2017
2 parents 5a1da1f + 81de9d5 commit 1bea2cb
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 49 deletions.
7 changes: 7 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ public void run()
connectionLock.readLock().unlock();
}

try
{
Thread.sleep( 500 );
} catch ( InterruptedException ex )
{
}

getLogger().info( "Closing IO threads" );
eventLoops.shutdownGracefully();
try
Expand Down
12 changes: 1 addition & 11 deletions proxy/src/main/java/net/md_5/bungee/ServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ public void disconnect(BaseComponent... reason)
{
Preconditions.checkArgument( reason.length == 0, "Server cannot have disconnect reason" );

if ( !ch.isClosed() )
{
ch.getHandle().eventLoop().schedule( new Runnable()
{
@Override
public void run()
{
ch.getHandle().close();
}
}, 100, TimeUnit.MILLISECONDS );
}
ch.delayedClose( null );
}

@Override
Expand Down
12 changes: 2 additions & 10 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,7 @@ public void disconnect0(final BaseComponent... reason)
getName(), BaseComponent.toLegacyText( reason )
} );

ch.delayedClose( new Runnable()
{

@Override
public void run()
{
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
}
} );
ch.delayedClose( new Kick( ComponentSerializer.toString( reason ) ) );

if ( server != null )
{
Expand Down Expand Up @@ -624,7 +616,7 @@ public String getExtraDataInHandshake()

public void setCompressionThreshold(int compressionThreshold)
{
if ( ch.getHandle().isActive() && this.compressionThreshold == -1 && getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 && compressionThreshold >= 0 )
if ( !ch.isClosing() && this.compressionThreshold == -1 && getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_8 && compressionThreshold >= 0 )
{
this.compressionThreshold = compressionThreshold;
unsafe.sendPacket( new SetCompression( compressionThreshold ) );
Expand Down
22 changes: 8 additions & 14 deletions proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public void handle(PluginMessage pluginMessage) throws Exception
public void handle(LegacyHandshake legacyHandshake) throws Exception
{
this.legacy = true;
ch.getHandle().writeAndFlush( bungee.getTranslation( "outdated_client" ) );
ch.close();
ch.close( bungee.getTranslation( "outdated_client" ) );
}

@Override
Expand Down Expand Up @@ -492,7 +491,7 @@ public void done(LoginEvent result, Throwable error)
@Override
public void run()
{
if ( ch.getHandle().isActive() )
if ( !ch.isClosing() )
{
UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this );
userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() );
Expand Down Expand Up @@ -544,18 +543,13 @@ public void disconnect(String reason)
@Override
public void disconnect(final BaseComponent... reason)
{
ch.delayedClose( new Runnable()
if ( thisState != State.STATUS && thisState != State.PING )
{

@Override
public void run()
{
if ( thisState != State.STATUS && thisState != State.PING )
{
unsafe().sendPacket( new Kick( ComponentSerializer.toString( reason ) ) );
}
}
} );
ch.delayedClose( new Kick( ComponentSerializer.toString( reason ) ) );
} else
{
ch.close();
}
}

@Override
Expand Down
42 changes: 28 additions & 14 deletions proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import java.util.concurrent.TimeUnit;
Expand All @@ -12,6 +13,7 @@
import net.md_5.bungee.protocol.MinecraftEncoder;
import net.md_5.bungee.protocol.PacketWrapper;
import net.md_5.bungee.protocol.Protocol;
import net.md_5.bungee.protocol.packet.Kick;

public class ChannelWrapper
{
Expand Down Expand Up @@ -56,41 +58,53 @@ public void write(Object packet)
}

public void close()
{
close( null );
}

public void close(Object packet)
{
if ( !closed )
{
closed = closing = true;
ch.flush();
ch.close();

if ( packet != null && ch.isActive() )
{
ch.writeAndFlush( packet ).addListeners( ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, ChannelFutureListener.CLOSE );
ch.eventLoop().schedule( new Runnable()
{
@Override
public void run()
{
ch.close();
}
}, 250, TimeUnit.MILLISECONDS );
} else
{
ch.flush();
ch.close();
}
}
}

public void delayedClose(final Runnable runnable)
public void delayedClose(final Kick kick)
{
Preconditions.checkArgument( runnable != null, "runnable" );

if ( !closing )
{
closing = true;

// Minecraft client can take some time to switch protocols.
// Sending the wrong disconnect packet whilst a protocol switch is in progress will crash it.
// Delay 500ms to ensure that the protocol switch (if any) has definitely taken place.
// Delay 250ms to ensure that the protocol switch (if any) has definitely taken place.
ch.eventLoop().schedule( new Runnable()
{

@Override
public void run()
{
try
{
runnable.run();
} finally
{
ChannelWrapper.this.close();
}
close( kick );
}
}, 500, TimeUnit.MILLISECONDS );
}, 250, TimeUnit.MILLISECONDS );
}
}

Expand Down

0 comments on commit 1bea2cb

Please sign in to comment.