Skip to content

Expose sendPacketQueued to unsafe interface #3797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/src/main/java/net/md_5/bungee/api/connection/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,20 @@ interface Unsafe
* @param packet the packet to send
*/
void sendPacket(DefinedPacket packet);

/**
* Queue a packet to this connection.
* If the packet is not registered for the connections current encoder protocol, it will be queued until it is,
* otherwise it will be sent immediately.
* <p>
* If the version of this connection is less than 1.20.2 you should not use this method.
*
* @param packet the packet to queued
* @throws UnsupportedOperationException if used for a PendingConnection
*/
default void sendPacketQueued(DefinedPacket packet)
{
throw new UnsupportedOperationException( "Not supported." );
}
}
}
8 changes: 8 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/ServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public void sendPacket(DefinedPacket packet)
{
ch.write( packet );
}

@Override
public void sendPacketQueued(DefinedPacket packet)
{
ServerConnection.this.sendPacketQueued( packet );
}
};

public void sendPacketQueued(DefinedPacket packet)
Expand All @@ -53,6 +59,8 @@ public void sendPacketQueued(DefinedPacket packet)
Protocol encodeProtocol = ch.getEncodeProtocol();
if ( !encodeProtocol.TO_SERVER.hasPacket( packet.getClass(), ch.getEncodeVersion() ) )
{
// we should limit this so bad api usage won't oom the server.
Preconditions.checkState( packetQueue.size() <= 2 << 11, "too many queued packets" );
packetQueue.add( packet );
} else
{
Expand Down
8 changes: 8 additions & 0 deletions proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public void sendPacket(DefinedPacket packet)
{
ch.write( packet );
}

@Override
public void sendPacketQueued(DefinedPacket packet)
{
UserConnection.this.sendPacketQueued( packet );
}
};

public boolean init()
Expand Down Expand Up @@ -191,6 +197,8 @@ public void sendPacketQueued(DefinedPacket packet)
Protocol encodeProtocol = ch.getEncodeProtocol();
if ( !encodeProtocol.TO_CLIENT.hasPacket( packet.getClass(), getPendingConnection().getVersion() ) )
{
// we should limit this so bad api usage won't oom the server.
Preconditions.checkState( packetQueue.size() <= 2 << 11, "too many queued packets" );
packetQueue.add( packet );
} else
{
Expand Down