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.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)
|
||||||
@ -87,10 +87,13 @@ public class BungeeServerInfo implements ServerInfo
|
|||||||
{
|
{
|
||||||
server.sendData( channel, data );
|
server.sendData( channel, data );
|
||||||
} else
|
} else
|
||||||
|
{
|
||||||
|
synchronized ( packetQueue )
|
||||||
{
|
{
|
||||||
packetQueue.add( new PacketFAPluginMessage( channel, data ) );
|
packetQueue.add( new PacketFAPluginMessage( channel, data ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ping(final Callback<ServerPing> callback)
|
public void ping(final Callback<ServerPing> callback)
|
||||||
|
@ -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() )
|
while ( !packetQueue.isEmpty() )
|
||||||
{
|
{
|
||||||
ch.write( packetQueue.poll() );
|
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
|
||||||
{
|
{
|
||||||
|
@ -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 );
|
||||||
|
if ( forge )
|
||||||
|
{
|
||||||
|
writeInt( dimension );
|
||||||
|
} else
|
||||||
|
{
|
||||||
writeByte( dimension );
|
writeByte( dimension );
|
||||||
|
}
|
||||||
writeByte( difficulty );
|
writeByte( difficulty );
|
||||||
writeByte( unused );
|
writeByte( unused );
|
||||||
writeByte( maxPlayers );
|
writeByte( maxPlayers );
|
||||||
|
Loading…
Reference in New Issue
Block a user