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:
parent
7436621481
commit
679bf2fca9
@ -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<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
private final Queue<DefinedPacket> packetQueue = new LinkedList<>();
|
||||
|
||||
@Synchronized("players")
|
||||
public void addPlayer(ProxiedPlayer player)
|
||||
@ -87,10 +87,13 @@ public class BungeeServerInfo implements ServerInfo
|
||||
{
|
||||
server.sendData( channel, data );
|
||||
} else
|
||||
{
|
||||
synchronized ( packetQueue )
|
||||
{
|
||||
packetQueue.add( new PacketFAPluginMessage( channel, data ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ping(final Callback<ServerPing> callback)
|
||||
|
@ -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<DefinedPacket> packetQueue = ( (BungeeServerInfo) target ).getPacketQueue();
|
||||
Queue<DefinedPacket> packetQueue = target.getPacketQueue();
|
||||
synchronized ( packetQueue )
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -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 );
|
||||
if ( forge )
|
||||
{
|
||||
writeInt( dimension );
|
||||
} else
|
||||
{
|
||||
writeByte( dimension );
|
||||
}
|
||||
writeByte( difficulty );
|
||||
writeByte( unused );
|
||||
writeByte( maxPlayers );
|
||||
|
Loading…
Reference in New Issue
Block a user