Synchronize on pending packet queue, add forge/no forge constructor argument to login packet, and don't send channel registers twice

This commit is contained in:
md_5 2013-05-03 20:29:36 +10:00
parent 7436621481
commit 679bf2fca9
3 changed files with 23 additions and 12 deletions

View File

@ -9,9 +9,9 @@ import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.Objects; import java.util.Objects;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Synchronized; import lombok.Synchronized;
@ -40,7 +40,7 @@ public class BungeeServerInfo implements ServerInfo
@Getter @Getter
private final boolean restricted; private final boolean restricted;
@Getter @Getter
private final Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>(); private final Queue<DefinedPacket> packetQueue = new LinkedList<>();
@Synchronized("players") @Synchronized("players")
public void addPlayer(ProxiedPlayer player) public void addPlayer(ProxiedPlayer player)
@ -88,7 +88,10 @@ public class BungeeServerInfo implements ServerInfo
server.sendData( channel, data ); server.sendData( channel, data );
} else } else
{ {
packetQueue.add( new PacketFAPluginMessage( channel, data ) ); synchronized ( packetQueue )
{
packetQueue.add( new PacketFAPluginMessage( channel, data ) );
}
} }
} }

View File

@ -75,14 +75,15 @@ public class ServerConnector extends PacketHandler
ServerConnectedEvent event = new ServerConnectedEvent( user, server ); ServerConnectedEvent event = new ServerConnectedEvent( user, server );
bungee.getPluginManager().callEvent( event ); bungee.getPluginManager().callEvent( event );
ch.write( BungeeCord.getInstance().registerChannels() ); Queue<DefinedPacket> packetQueue = target.getPacketQueue();
synchronized ( packetQueue )
// TODO: Race conditions with many connects
Queue<DefinedPacket> packetQueue = ( (BungeeServerInfo) target ).getPacketQueue();
while ( !packetQueue.isEmpty() )
{ {
ch.write( packetQueue.poll() ); while ( !packetQueue.isEmpty() )
{
ch.write( packetQueue.poll() );
}
} }
if ( user.getSettings() != null ) if ( user.getSettings() != null )
{ {
ch.write( user.getSettings() ); ch.write( user.getSettings() );
@ -103,7 +104,8 @@ public class ServerConnector extends PacketHandler
(byte) login.dimension, (byte) login.dimension,
login.difficulty, login.difficulty,
login.unused, login.unused,
(byte) user.getPendingConnection().getListener().getTabListSize() ); (byte) user.getPendingConnection().getListener().getTabListSize(),
false );
user.sendPacket( modLogin ); user.sendPacket( modLogin );
} else } else
{ {

View File

@ -16,13 +16,19 @@ public class Packet1Login extends DefinedPacket
public byte unused; public byte unused;
public byte maxPlayers; 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 ); super( 0x01 );
writeInt( entityId ); writeInt( entityId );
writeUTF( levelType ); writeUTF( levelType );
writeByte( gameMode ); writeByte( gameMode );
writeByte( dimension ); if ( forge )
{
writeInt( dimension );
} else
{
writeByte( dimension );
}
writeByte( difficulty ); writeByte( difficulty );
writeByte( unused ); writeByte( unused );
writeByte( maxPlayers ); writeByte( maxPlayers );