Skip to content

Commit

Permalink
fix player connection resources not being fully closed if channel closed
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jul 5, 2024
1 parent 8b78e6c commit 79cf4e4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/com/zenith/network/server/ServerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.zenith.Shared.*;
Expand Down Expand Up @@ -245,12 +246,17 @@ public void callDisconnected(Component reason, Throwable cause) {

@Override
public void disconnect(@Nullable final Component reason, final Throwable cause) {
var disconnectPacket = getDisconnectPacket(reason);
if (disconnectPacket != null) {
send(disconnectPacket, future -> super.disconnect(reason, cause));
} else {
super.disconnect(reason, cause);
if (this.getChannel() != null && this.getChannel().isActive()) {
var disconnectPacket = getDisconnectPacket(reason);
if (disconnectPacket != null) {
try {
send(disconnectPacket).get(1L, TimeUnit.SECONDS);
} catch (final Exception e) {
// fall through
}
}
}
super.disconnect(reason, cause);
}

private @Nullable Packet getDisconnectPacket(@Nullable final Component reason) {
Expand Down

0 comments on commit 79cf4e4

Please sign in to comment.