Improved disconnection handling

This commit is contained in:
kuroppoi 2021-04-24 20:32:46 +02:00
parent 46f3fb1906
commit 3f4e12e944
2 changed files with 11 additions and 4 deletions

View file

@ -213,8 +213,10 @@ public class Player extends Entity implements CommandExecutor {
if(zone != null) {
zone.removePlayer(this);
activeChunks.clear();
dialogs.clear();
}
dialogs.clear();
connection = null;
}
/**

View file

@ -39,6 +39,8 @@ public class Connection extends SimpleChannelInboundHandler<Request> {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
kick("Connection terminated");
if(player == null) {
return;
}
@ -67,8 +69,9 @@ public class Connection extends SimpleChannelInboundHandler<Request> {
return;
}
logger.warn(cause.getMessage());
// log warn, kick connection.
String error = cause.getMessage();
logger.warn(error);
//kick(error);
}
public ChannelFuture sendMessage(Message message) {
@ -86,7 +89,9 @@ public class Connection extends SimpleChannelInboundHandler<Request> {
}
public void kick(String reason, boolean shouldReconnect) {
sendMessage(new KickMessage(reason, shouldReconnect)).addListener(ChannelFutureListener.CLOSE);
if(isOpen()) {
sendMessage(new KickMessage(reason, shouldReconnect)).addListener(ChannelFutureListener.CLOSE);
}
}
public void setPlayer(Player player) {