diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 3d747d15..107d5dc5 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -9,9 +9,9 @@ import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.LinkedList; import java.util.Objects; import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Synchronized; @@ -40,7 +40,7 @@ public class BungeeServerInfo implements ServerInfo @Getter private final boolean restricted; @Getter - private final Queue packetQueue = new ConcurrentLinkedQueue<>(); + private final Queue packetQueue = new LinkedList<>(); @Synchronized("players") public void addPlayer(ProxiedPlayer player) @@ -88,7 +88,10 @@ public class BungeeServerInfo implements ServerInfo server.sendData( channel, data ); } else { - packetQueue.add( new PacketFAPluginMessage( channel, data ) ); + synchronized ( packetQueue ) + { + packetQueue.add( new PacketFAPluginMessage( channel, data ) ); + } } } 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 29eb5af7..4715cda5 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -75,14 +75,15 @@ public class ServerConnector extends PacketHandler ServerConnectedEvent event = new ServerConnectedEvent( user, server ); bungee.getPluginManager().callEvent( event ); - ch.write( BungeeCord.getInstance().registerChannels() ); - - // TODO: Race conditions with many connects - Queue packetQueue = ( (BungeeServerInfo) target ).getPacketQueue(); - while ( !packetQueue.isEmpty() ) + Queue packetQueue = target.getPacketQueue(); + synchronized ( packetQueue ) { - ch.write( packetQueue.poll() ); + while ( !packetQueue.isEmpty() ) + { + ch.write( packetQueue.poll() ); + } } + if ( user.getSettings() != null ) { ch.write( user.getSettings() ); @@ -103,7 +104,8 @@ public class ServerConnector extends PacketHandler (byte) login.dimension, login.difficulty, login.unused, - (byte) user.getPendingConnection().getListener().getTabListSize() ); + (byte) user.getPendingConnection().getListener().getTabListSize(), + false ); user.sendPacket( modLogin ); } else { diff --git a/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java b/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java index 6caebdf2..a38d0be1 100644 --- a/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java +++ b/proxy/src/main/java/net/md_5/bungee/packet/Packet1Login.java @@ -16,13 +16,19 @@ public class Packet1Login extends DefinedPacket public byte unused; public byte maxPlayers; - public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers) + public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers, boolean forge) { super( 0x01 ); writeInt( entityId ); writeUTF( levelType ); writeByte( gameMode ); - writeByte( dimension ); + if ( forge ) + { + writeInt( dimension ); + } else + { + writeByte( dimension ); + } writeByte( difficulty ); writeByte( unused ); writeByte( maxPlayers );