Remove players on exceptionCaught with IOEXception. MINA closes sessions automatically and does not call sessionClosed when an IOException is caught. (#389)

This commit is contained in:
MedicOP
2019-02-04 03:40:57 +01:00
committed by Ronan Lana
parent fdcc03c5f7
commit 55c78c1094

View File

@@ -87,7 +87,7 @@ public class MapleServerHandler extends IoHandlerAdapter {
} }
@Override @Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception { public void exceptionCaught(IoSession session, Throwable cause) {
if (cause instanceof org.apache.mina.core.write.WriteToClosedSessionException) { if (cause instanceof org.apache.mina.core.write.WriteToClosedSessionException) {
return; return;
} }
@@ -97,12 +97,26 @@ public class MapleServerHandler extends IoHandlerAdapter {
cause.printStackTrace(); cause.printStackTrace();
*/ */
if (cause instanceof IOException || cause instanceof ClassCastException) { MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
return;
} if (client != null) {
MapleClient mc = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY); if (cause instanceof IOException) { // mina closes session automatically and does not call sessionClosed on IOException
if (mc != null && mc.getPlayer() != null) { if (isLoginServerHandler()) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, cause, "Exception caught by: " + mc.getPlayer()); MapleSessionCoordinator.getInstance().closeLoginSession(session);
} else {
MapleSessionCoordinator.getInstance().closeSession(session, null);
}
try {
client.disconnect(false, client.getPlayer() != null && client.getPlayer().getCashShop().isOpened());
} catch (Throwable t) {
FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, t);
} finally {
session.removeAttribute(MapleClient.CLIENT_KEY);
}
} else if (client.getPlayer() != null) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, cause, "Exception caught by: " + client.getPlayer());
}
} }
} }