Ensure that player connections reference are not kept for viewable packets

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-10-03 19:23:09 +02:00
parent b9746a0574
commit a6f59fc9e9
1 changed files with 11 additions and 11 deletions

View File

@ -170,7 +170,7 @@ public final class PacketUtils {
public static void flush() {
synchronized (VIEWABLE_PACKET_LOCK) {
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));
return;
}
if (!buffer.canWrite(packetSize)) process();
if (!buffer.canWrite(packetSize)) process(null);
final int start = buffer.writerOffset();
buffer.write(framedPacket);
final int end = buffer.writerOffset();
@ -262,10 +262,11 @@ public final class PacketUtils {
}
private synchronized void process(@Nullable SingleEntry singleEntry) {
if (buffer.writerOffset() == 0)
return; // TODO: there is nothing in the buffer, remove from VIEWABLE_STORAGE_MAP
final Viewable viewable = this.viewable.get();
if (viewable == null) return;
final Viewable viewable;
if (buffer.writerOffset() == 0 || (viewable = this.viewable.get()) == null) {
clear();
return;
}
for (Player player : viewable.getViewers()) {
PlayerConnection connection = player.getPlayerConnection();
Consumer<ByteBuffer> writer = connection instanceof PlayerSocketConnection
@ -298,13 +299,12 @@ public final class PacketUtils {
writer.accept(singleEntry.buffer.position(0));
}
}
// Clear state
this.entityIdMap.clear();
this.buffer.clear();
clear();
}
private void process() {
process(null);
private void clear() {
this.entityIdMap.clear();
this.buffer.clear();
}
private static final class SingleEntry {