Shutdown class NPE fix and minor improvements.

This commit is contained in:
MobiusDev
2016-07-24 13:36:01 +00:00
parent ee5c640077
commit 0796247376

View File

@@ -86,14 +86,7 @@ public class Shutdown extends Thread
{ {
LOGGER.warning("IP: " + IP + " issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!"); LOGGER.warning("IP: " + IP + " issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!");
if (restart) _shutdownMode = restart ? GM_RESTART : GM_SHUTDOWN;
{
_shutdownMode = GM_RESTART;
}
else
{
_shutdownMode = GM_SHUTDOWN;
}
if (_shutdownMode > 0) if (_shutdownMode > 0)
{ {
@@ -115,11 +108,15 @@ public class Shutdown extends Thread
case 3: case 3:
case 2: case 2:
case 1: case 1:
{
break; break;
}
default: default:
{
SendServerQuit(seconds); SendServerQuit(seconds);
} }
} }
}
if (_counterInstance != null) if (_counterInstance != null)
{ {
@@ -165,14 +162,7 @@ public class Shutdown extends Thread
seconds = 0; seconds = 0;
} }
_secondsShut = seconds; _secondsShut = seconds;
if (restart) _shutdownMode = restart ? GM_RESTART : GM_SHUTDOWN;
{
_shutdownMode = GM_RESTART;
}
else
{
_shutdownMode = GM_SHUTDOWN;
}
} }
/** /**
@@ -301,19 +291,25 @@ public class Shutdown extends Thread
switch (_shutdownMode) switch (_shutdownMode)
{ {
case GM_SHUTDOWN: case GM_SHUTDOWN:
{
getInstance().setMode(GM_SHUTDOWN); getInstance().setMode(GM_SHUTDOWN);
System.exit(0); System.exit(0);
break; break;
}
case GM_RESTART: case GM_RESTART:
{
getInstance().setMode(GM_RESTART); getInstance().setMode(GM_RESTART);
System.exit(2); System.exit(2);
break; break;
}
case ABORT: case ABORT:
{
LoginServerThread.getInstance().setServerStatus(ServerStatus.STATUS_AUTO); LoginServerThread.getInstance().setServerStatus(ServerStatus.STATUS_AUTO);
break; break;
} }
} }
} }
}
/** /**
* This functions starts a shutdown countdown. * This functions starts a shutdown countdown.
@@ -323,17 +319,17 @@ public class Shutdown extends Thread
*/ */
public void startShutdown(L2PcInstance activeChar, int seconds, boolean restart) public void startShutdown(L2PcInstance activeChar, int seconds, boolean restart)
{ {
if (restart) _shutdownMode = restart ? GM_RESTART : GM_SHUTDOWN;
if (activeChar != null)
{ {
_shutdownMode = GM_RESTART; LOGGER.warning("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!");
} }
else else
{ {
_shutdownMode = GM_SHUTDOWN; LOGGER.warning("Server scheduled restart issued shutdown command. Restart in " + seconds + " seconds!");
} }
LOGGER.warning("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") issued shutdown command. " + MODE_TEXT[_shutdownMode] + " in " + seconds + " seconds!");
if (_shutdownMode > 0) if (_shutdownMode > 0)
{ {
switch (seconds) switch (seconds)
@@ -354,11 +350,15 @@ public class Shutdown extends Thread
case 3: case 3:
case 2: case 2:
case 1: case 1:
{
break; break;
}
default: default:
{
SendServerQuit(seconds); SendServerQuit(seconds);
} }
} }
}
if (_counterInstance != null) if (_counterInstance != null)
{ {
@@ -406,64 +406,94 @@ public class Shutdown extends Thread
*/ */
private void countdown() private void countdown()
{ {
try try
{ {
while (_secondsShut > 0) while (_secondsShut > 0)
{ {
switch (_secondsShut) switch (_secondsShut)
{ {
case 540: case 540:
{
SendServerQuit(540); SendServerQuit(540);
break; break;
}
case 480: case 480:
{
SendServerQuit(480); SendServerQuit(480);
break; break;
}
case 420: case 420:
{
SendServerQuit(420); SendServerQuit(420);
break; break;
}
case 360: case 360:
{
SendServerQuit(360); SendServerQuit(360);
break; break;
}
case 300: case 300:
{
SendServerQuit(300); SendServerQuit(300);
break; break;
}
case 240: case 240:
{
SendServerQuit(240); SendServerQuit(240);
break; break;
}
case 180: case 180:
{
SendServerQuit(180); SendServerQuit(180);
break; break;
}
case 120: case 120:
{
SendServerQuit(120); SendServerQuit(120);
break; break;
}
case 60: case 60:
{
LoginServerThread.getInstance().setServerStatus(ServerStatus.STATUS_DOWN); // avoids new players from logging in LoginServerThread.getInstance().setServerStatus(ServerStatus.STATUS_DOWN); // avoids new players from logging in
SendServerQuit(60); SendServerQuit(60);
break; break;
}
case 30: case 30:
{
SendServerQuit(30); SendServerQuit(30);
break; break;
}
case 10: case 10:
{
SendServerQuit(10); SendServerQuit(10);
break; break;
}
case 5: case 5:
{
SendServerQuit(5); SendServerQuit(5);
break; break;
}
case 4: case 4:
{
SendServerQuit(4); SendServerQuit(4);
break; break;
}
case 3: case 3:
{
SendServerQuit(3); SendServerQuit(3);
break; break;
}
case 2: case 2:
{
SendServerQuit(2); SendServerQuit(2);
break; break;
}
case 1: case 1:
{
SendServerQuit(1); SendServerQuit(1);
break; break;
} }
}
_secondsShut--; _secondsShut--;
@@ -490,15 +520,20 @@ public class Shutdown extends Thread
switch (_shutdownMode) switch (_shutdownMode)
{ {
case SIGTERM: case SIGTERM:
{
LOGGER.info("SIGTERM received. Shutting down NOW!"); LOGGER.info("SIGTERM received. Shutting down NOW!");
break; break;
}
case GM_SHUTDOWN: case GM_SHUTDOWN:
{
LOGGER.info("GM shutdown received. Shutting down NOW!"); LOGGER.info("GM shutdown received. Shutting down NOW!");
break; break;
}
case GM_RESTART: case GM_RESTART:
{
LOGGER.info("GM restart received. Restarting NOW!"); LOGGER.info("GM restart received. Restarting NOW!");
break; break;
}
} }
/* /*
@@ -585,6 +620,11 @@ public class Shutdown extends Thread
client.setActiveChar(null); client.setActiveChar(null);
player.setClient(null); player.setClient(null);
} }
else if ((client == null) || client.isDetached())
// player is probably a bot - force logout
{
player.logout();
}
player.deleteMe(); player.deleteMe();
} }
catch (Throwable t) catch (Throwable t)