mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Improved disconnection handling
This commit is contained in:
parent
46f3fb1906
commit
3f4e12e944
2 changed files with 11 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue