Guest cleanup and server hooks
Outstanding guest objects (say, from crashes) are now cleaned up at startup. Copied the at_server_startstop.py hooks directly into Server object, and set them to reference SERVER_STARTSTOP_MODULE. This seemed to be the cleanest way to go about things.
This commit is contained in:
parent
f6b3535021
commit
d43c003cc8
1 changed files with 71 additions and 17 deletions
|
|
@ -73,6 +73,8 @@ AMP_INTERFACE = settings.AMP_INTERFACE
|
||||||
WEBSERVER_PORTS = settings.WEBSERVER_PORTS
|
WEBSERVER_PORTS = settings.WEBSERVER_PORTS
|
||||||
WEBSERVER_INTERFACES = settings.WEBSERVER_INTERFACES
|
WEBSERVER_INTERFACES = settings.WEBSERVER_INTERFACES
|
||||||
|
|
||||||
|
GUEST_ENABLED = settings.GUEST_ENABLED
|
||||||
|
|
||||||
# server-channel mappings
|
# server-channel mappings
|
||||||
WEBSERVER_ENABLED = settings.WEBSERVER_ENABLED and WEBSERVER_PORTS and WEBSERVER_INTERFACES
|
WEBSERVER_ENABLED = settings.WEBSERVER_ENABLED and WEBSERVER_PORTS and WEBSERVER_INTERFACES
|
||||||
IMC2_ENABLED = settings.IMC2_ENABLED
|
IMC2_ENABLED = settings.IMC2_ENABLED
|
||||||
|
|
@ -240,17 +242,16 @@ class Evennia(object):
|
||||||
from src.scripts.tickerhandler import TICKER_HANDLER
|
from src.scripts.tickerhandler import TICKER_HANDLER
|
||||||
TICKER_HANDLER.restore()
|
TICKER_HANDLER.restore()
|
||||||
|
|
||||||
if SERVER_STARTSTOP_MODULE:
|
# call correct server hook based on start file value
|
||||||
# call correct server hook based on start file value
|
if mode in ('True', 'reload'):
|
||||||
if mode in ('True', 'reload'):
|
# True was the old reload flag, kept for compatibilty
|
||||||
# True was the old reload flag, kept for compatibilty
|
self.at_server_reload_start()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_reload_start()
|
elif mode in ('reset', 'shutdown'):
|
||||||
elif mode in ('reset', 'shutdown'):
|
self.at_server_cold_start()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_cold_start()
|
# clear eventual lingering session storages
|
||||||
# clear eventual lingering session storages
|
ObjectDB.objects.clear_all_sessids()
|
||||||
ObjectDB.objects.clear_all_sessids()
|
# always call this regardless of start type
|
||||||
# always call this regardless of start type
|
self.at_server_start()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_start()
|
|
||||||
|
|
||||||
def set_restart_mode(self, mode=None):
|
def set_restart_mode(self, mode=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -316,8 +317,7 @@ class Evennia(object):
|
||||||
from src.scripts.tickerhandler import TICKER_HANDLER
|
from src.scripts.tickerhandler import TICKER_HANDLER
|
||||||
TICKER_HANDLER.save()
|
TICKER_HANDLER.save()
|
||||||
|
|
||||||
if SERVER_STARTSTOP_MODULE:
|
self.at_server_reload_stop()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_reload_stop()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if mode == 'reset':
|
if mode == 'reset':
|
||||||
|
|
@ -339,15 +339,13 @@ class Evennia(object):
|
||||||
yield ObjectDB.objects.clear_all_sessids()
|
yield ObjectDB.objects.clear_all_sessids()
|
||||||
ServerConfig.objects.conf("server_restart_mode", "reset")
|
ServerConfig.objects.conf("server_restart_mode", "reset")
|
||||||
|
|
||||||
if SERVER_STARTSTOP_MODULE:
|
self.at_server_cold_stop()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_cold_stop()
|
|
||||||
|
|
||||||
# stopping time
|
# stopping time
|
||||||
from src.utils import gametime
|
from src.utils import gametime
|
||||||
gametime.save()
|
gametime.save()
|
||||||
|
|
||||||
if SERVER_STARTSTOP_MODULE:
|
self.at_server_stop()
|
||||||
SERVER_STARTSTOP_MODULE.at_server_stop()
|
|
||||||
# if _reactor_stopping is true, reactor does not need to
|
# if _reactor_stopping is true, reactor does not need to
|
||||||
# be stopped again.
|
# be stopped again.
|
||||||
if os.name == 'nt' and os.path.exists(SERVER_PIDFILE):
|
if os.name == 'nt' and os.path.exists(SERVER_PIDFILE):
|
||||||
|
|
@ -358,6 +356,62 @@ class Evennia(object):
|
||||||
# flag to avoid loops.
|
# flag to avoid loops.
|
||||||
self.shutdown_complete = True
|
self.shutdown_complete = True
|
||||||
reactor.callLater(0, reactor.stop)
|
reactor.callLater(0, reactor.stop)
|
||||||
|
|
||||||
|
# server start/stop hooks
|
||||||
|
|
||||||
|
def at_server_start(self):
|
||||||
|
"""
|
||||||
|
This is called every time the server starts up, regardless of
|
||||||
|
how it was shut down.
|
||||||
|
"""
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_start()
|
||||||
|
|
||||||
|
|
||||||
|
def at_server_stop(self):
|
||||||
|
"""
|
||||||
|
This is called just before a server is shut down, regardless
|
||||||
|
of it is fore a reload, reset or shutdown.
|
||||||
|
"""
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_stop()
|
||||||
|
|
||||||
|
|
||||||
|
def at_server_reload_start(self):
|
||||||
|
"""
|
||||||
|
This is called only when server starts back up after a reload.
|
||||||
|
"""
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_reload_start()
|
||||||
|
|
||||||
|
|
||||||
|
def at_server_reload_stop(self):
|
||||||
|
"""
|
||||||
|
This is called only time the server stops before a reload.
|
||||||
|
"""
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_reload_stop()
|
||||||
|
|
||||||
|
|
||||||
|
def at_server_cold_start(self):
|
||||||
|
"""
|
||||||
|
This is called only when the server starts "cold", i.e. after a
|
||||||
|
shutdown or a reset.
|
||||||
|
"""
|
||||||
|
if GUEST_ENABLED:
|
||||||
|
for guest in PlayerDB.objects.all().filter(db_typeclass_path=settings.BASE_GUEST_TYPECLASS):
|
||||||
|
for character in filter(None, guest.db._playable_characters):
|
||||||
|
character.delete()
|
||||||
|
guest.delete()
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_cold_start()
|
||||||
|
|
||||||
|
def at_server_cold_stop(self):
|
||||||
|
"""
|
||||||
|
This is called only when the server goes down due to a shutdown or reset.
|
||||||
|
"""
|
||||||
|
if SERVER_STARTSTOP_MODULE:
|
||||||
|
SERVER_STARTSTOP_MODULE.at_server_cold_stop()
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue