Move packet construction of schedule send methods to event loop as well

Fixes #3306
This commit is contained in:
Nassim Jahnke 2023-04-26 12:18:08 +02:00
parent a2e214ae18
commit b67e3c30fd
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B

View File

@ -266,20 +266,37 @@ public class PacketWrapperImpl implements PacketWrapper {
} }
private void send0(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { private void send0(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (isCancelled()) return; if (isCancelled()) {
return;
try {
ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND);
if (currentThread) {
user().sendRawPacket(output);
} else {
user().scheduleSendRawPacket(output);
}
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
} }
final UserConnection connection = user();
if (currentThread) {
try {
final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND);
connection.sendRawPacket(output);
} catch (final Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
}
return;
}
connection.getChannel().eventLoop().submit(() -> {
try {
final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND);
connection.sendRawPacket(output);
} catch (final RuntimeException e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
} catch (final Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw new RuntimeException(e);
}
}
});
} }
/** /**
@ -434,7 +451,9 @@ public class PacketWrapperImpl implements PacketWrapper {
} }
private void sendToServerRaw(boolean currentThread) throws Exception { private void sendToServerRaw(boolean currentThread) throws Exception {
if (isCancelled()) return; if (isCancelled()) {
return;
}
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
try { try {
@ -464,18 +483,33 @@ public class PacketWrapperImpl implements PacketWrapper {
return; return;
} }
try { final UserConnection connection = user();
ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND); if (currentThread) {
if (currentThread) { try {
user().sendRawPacketToServer(output); final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND);
} else { connection.sendRawPacketToServer(output);
user().scheduleSendRawPacketToServer(output); } catch (final Exception e) {
} if (!PipelineUtil.containsCause(e, CancelException.class)) {
} catch (Exception e) { throw e;
if (!PipelineUtil.containsCause(e, CancelException.class)) { }
throw e;
} }
return;
} }
connection.getChannel().eventLoop().submit(() -> {
try {
final ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND);
connection.sendRawPacketToServer(output);
} catch (final RuntimeException e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
} catch (final Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw new RuntimeException(e);
}
}
});
} }
@Override @Override