Prevent framed packets from being corrupted

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-07 01:24:51 +02:00
parent 581c97e2ba
commit 8f1e84ffdb
2 changed files with 4 additions and 3 deletions

View File

@ -252,7 +252,7 @@ public class PlayerSocketConnection extends PlayerConnection {
}
public void write(@NotNull FramedPacket framedPacket) {
write(framedPacket.body().flip());
write(framedPacket.body().position(0));
}
public void write(@NotNull ServerPacket packet) {

View File

@ -109,7 +109,7 @@ public final class PacketUtils {
// Send grouped packet...
if (!PACKET_LISTENER_MANAGER.processServerPacket(packet, players))
return;
final ByteBuffer finalBuffer = createFramedPacket(packet);
final ByteBuffer finalBuffer = createFramedPacket(packet).flip();
final FramedPacket framedPacket = new FramedPacket(packet.getId(), finalBuffer, packet);
// Send packet to all players
for (Player player : players) {
@ -228,7 +228,8 @@ public final class PacketUtils {
@ApiStatus.Internal
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
final ByteBuffer temp = PacketUtils.createFramedPacket(packet).flip();
final ByteBuffer buffer = ByteBuffer.allocateDirect(temp.remaining()).put(temp).asReadOnlyBuffer();
final ByteBuffer buffer = ByteBuffer.allocateDirect(temp.remaining())
.put(temp).flip().asReadOnlyBuffer();
return new FramedPacket(packet.getId(), buffer, packet);
}