From 0646a3090a2f1b5246ea3f7e1d69218e92018af5 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 19 Feb 2016 09:07:12 +1100 Subject: [PATCH] Fix scoreboards / tab lists getting out of sync due to race conditions / overlap. --- .../java/net/md_5/bungee/ServerConnector.java | 2 +- .../md_5/bungee/connection/DownstreamBridge.java | 15 +++++++++------ .../java/net/md_5/bungee/netty/HandlerBoss.java | 4 ++-- .../java/net/md_5/bungee/netty/PacketHandler.java | 5 +++++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 5282033a..0d987de5 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -207,6 +207,7 @@ public class ServerConnector extends PacketHandler } } else { + user.getServer().setObsolete( true ); user.getTabListHandler().onServerChange(); Scoreboard serverScoreboard = user.getServerSentScoreboard(); @@ -226,7 +227,6 @@ public class ServerConnector extends PacketHandler user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) ); // Remove from old servers - user.getServer().setObsolete( true ); user.getServer().disconnect( "Quitting" ); } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index 96a866e2..7335f71a 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -89,14 +89,17 @@ public class DownstreamBridge extends PacketHandler bungee.getPluginManager().callEvent( serverDisconnectEvent ); } + @Override + public boolean shouldHandle(PacketWrapper packet) throws Exception + { + return !server.isObsolete(); + } + @Override public void handle(PacketWrapper packet) throws Exception { - if ( !server.isObsolete() ) - { - con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); - con.sendPacket( packet ); - } + con.getEntityRewrite().rewriteClientbound( packet.buf, con.getServerEntityId(), con.getClientEntityId() ); + con.sendPacket( packet ); } @Override @@ -451,7 +454,7 @@ public class DownstreamBridge extends PacketHandler con.getServer().sendData( "BungeeCord", b ); } } - + throw CancelSendSignal.INSTANCE; } } diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java index bd914d9c..8b9712bf 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java @@ -66,10 +66,10 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter if ( handler != null ) { PacketWrapper packet = (PacketWrapper) msg; - boolean sendPacket = true; + boolean sendPacket = handler.shouldHandle( packet ); try { - if ( packet.packet != null ) + if ( sendPacket && packet.packet != null ) { try { diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java index 08ab8152..7958eaa3 100644 --- a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java @@ -8,6 +8,11 @@ public abstract class PacketHandler extends net.md_5.bungee.protocol.AbstractPac @Override public abstract String toString(); + public boolean shouldHandle(PacketWrapper packet) throws Exception + { + return true; + } + public void exception(Throwable t) throws Exception { }