mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-19 05:41:21 +01:00
Ensure that player connections reference are not kept for viewable packets
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
b9746a0574
commit
a6f59fc9e9
@ -170,7 +170,7 @@ public final class PacketUtils {
|
|||||||
public static void flush() {
|
public static void flush() {
|
||||||
synchronized (VIEWABLE_PACKET_LOCK) {
|
synchronized (VIEWABLE_PACKET_LOCK) {
|
||||||
for (ViewableStorage viewableStorage : VIEWABLE_STORAGE_MAP.values()) {
|
for (ViewableStorage viewableStorage : VIEWABLE_STORAGE_MAP.values()) {
|
||||||
viewableStorage.process();
|
viewableStorage.process(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ public final class PacketUtils {
|
|||||||
process(new SingleEntry(framedPacket, connection));
|
process(new SingleEntry(framedPacket, connection));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!buffer.canWrite(packetSize)) process();
|
if (!buffer.canWrite(packetSize)) process(null);
|
||||||
final int start = buffer.writerOffset();
|
final int start = buffer.writerOffset();
|
||||||
buffer.write(framedPacket);
|
buffer.write(framedPacket);
|
||||||
final int end = buffer.writerOffset();
|
final int end = buffer.writerOffset();
|
||||||
@ -262,10 +262,11 @@ public final class PacketUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void process(@Nullable SingleEntry singleEntry) {
|
private synchronized void process(@Nullable SingleEntry singleEntry) {
|
||||||
if (buffer.writerOffset() == 0)
|
final Viewable viewable;
|
||||||
return; // TODO: there is nothing in the buffer, remove from VIEWABLE_STORAGE_MAP
|
if (buffer.writerOffset() == 0 || (viewable = this.viewable.get()) == null) {
|
||||||
final Viewable viewable = this.viewable.get();
|
clear();
|
||||||
if (viewable == null) return;
|
return;
|
||||||
|
}
|
||||||
for (Player player : viewable.getViewers()) {
|
for (Player player : viewable.getViewers()) {
|
||||||
PlayerConnection connection = player.getPlayerConnection();
|
PlayerConnection connection = player.getPlayerConnection();
|
||||||
Consumer<ByteBuffer> writer = connection instanceof PlayerSocketConnection
|
Consumer<ByteBuffer> writer = connection instanceof PlayerSocketConnection
|
||||||
@ -298,13 +299,12 @@ public final class PacketUtils {
|
|||||||
writer.accept(singleEntry.buffer.position(0));
|
writer.accept(singleEntry.buffer.position(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clear state
|
clear();
|
||||||
this.entityIdMap.clear();
|
|
||||||
this.buffer.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process() {
|
private void clear() {
|
||||||
process(null);
|
this.entityIdMap.clear();
|
||||||
|
this.buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class SingleEntry {
|
private static final class SingleEntry {
|
||||||
|
Loading…
Reference in New Issue
Block a user