[6830] Implement custom exit codes on server shutdown/restart

Added the possibility to use custom process return values
instead of hardcoded 0 (shutdown) or 2 (restart) to allow using them
for various custom external features / better handling.

This can be used through 4 commands in ".server" family:
 - shutdown
 - restart
 - idleshutdown
 - idlerestart

Those have from now on 2 arguments, where the second (return value)
is optional:

.server <command> <time> [return_value]

If return_value is not specified, default value (0 or 2) is used.

Signed-off-by: freghar <compmancz@gmail.com>

Set restart exist code for SIGINT singnal case.
Some code simplifications for original patch.
Related code cleanups.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
freghar 2008-11-12 21:09:56 +01:00 committed by VladimirMangos
parent 3d72b06fcd
commit 528a9d830a
8 changed files with 149 additions and 49 deletions

View file

@ -62,6 +62,7 @@
INSTANTIATE_SINGLETON_1( World );
volatile bool World::m_stopEvent = false;
uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
volatile uint32 World::m_worldLoopCounter = 0;
float World::m_MaxVisibleDistanceForCreature = DEFAULT_VISIBILITY_DISTANCE;
@ -2315,13 +2316,13 @@ void World::_UpdateGameTime()
m_gameTime = thisTime;
///- if there is a shutdown timer
if(m_ShutdownTimer > 0 && elapsed > 0)
if(!m_stopEvent && m_ShutdownTimer > 0 && elapsed > 0)
{
///- ... and it is overdue, stop the world (set m_stopEvent)
if( m_ShutdownTimer <= elapsed )
{
if(!(m_ShutdownMask & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount()==0)
m_stopEvent = true;
m_stopEvent = true; // exist code already set
else
m_ShutdownTimer = 1; // minimum timer value to wait idle state
}
@ -2336,15 +2337,20 @@ void World::_UpdateGameTime()
}
/// Shutdown the server
void World::ShutdownServ(uint32 time, uint32 options)
void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
{
// ignore if server shutdown at next tick
if(m_stopEvent)
return;
m_ShutdownMask = options;
m_ExitCode = exitcode;
///- If the shutdown time is 0, set m_stopEvent (except if shutdown is 'idle' with remaining sessions)
if(time==0)
{
if(!(options & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount()==0)
m_stopEvent = true;
m_stopEvent = true; // exist code already set
else
m_ShutdownTimer = 1; //So that the session count is re-evaluated at next world tick
}
@ -2389,13 +2395,15 @@ void World::ShutdownMsg(bool show, Player* player)
/// Cancel a planned server shutdown
void World::ShutdownCancel()
{
if(!m_ShutdownTimer)
// nothing cancel or too later
if(!m_ShutdownTimer || m_stopEvent)
return;
uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_CANCELLED : SERVER_MSG_SHUTDOWN_CANCELLED;
m_ShutdownMask = 0;
m_ShutdownTimer = 0;
m_ExitCode = SHUTDOWN_EXIT_CODE; // to default value
SendServerMessage(msgid);
DEBUG_LOG("Server %s cancelled.",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown"));