mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Prevent framed packets from being corrupted
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
581c97e2ba
commit
8f1e84ffdb
@ -252,7 +252,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void write(@NotNull FramedPacket framedPacket) {
|
public void write(@NotNull FramedPacket framedPacket) {
|
||||||
write(framedPacket.body().flip());
|
write(framedPacket.body().position(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(@NotNull ServerPacket packet) {
|
public void write(@NotNull ServerPacket packet) {
|
||||||
|
@ -109,7 +109,7 @@ public final class PacketUtils {
|
|||||||
// Send grouped packet...
|
// Send grouped packet...
|
||||||
if (!PACKET_LISTENER_MANAGER.processServerPacket(packet, players))
|
if (!PACKET_LISTENER_MANAGER.processServerPacket(packet, players))
|
||||||
return;
|
return;
|
||||||
final ByteBuffer finalBuffer = createFramedPacket(packet);
|
final ByteBuffer finalBuffer = createFramedPacket(packet).flip();
|
||||||
final FramedPacket framedPacket = new FramedPacket(packet.getId(), finalBuffer, packet);
|
final FramedPacket framedPacket = new FramedPacket(packet.getId(), finalBuffer, packet);
|
||||||
// Send packet to all players
|
// Send packet to all players
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
@ -228,7 +228,8 @@ public final class PacketUtils {
|
|||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
||||||
final ByteBuffer temp = PacketUtils.createFramedPacket(packet).flip();
|
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);
|
return new FramedPacket(packet.getId(), buffer, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user