adding at_server_init to at_server_startstop

This commit is contained in:
Andrew Bastien 2022-07-25 17:16:00 -04:00
parent 99d300799e
commit 18edbce624
3 changed files with 38 additions and 14 deletions

View file

@ -7,6 +7,7 @@ allows for customizing the server operation as desired.
This module must contain at least these global functions: This module must contain at least these global functions:
at_server_init()
at_server_start() at_server_start()
at_server_stop() at_server_stop()
at_server_reload_start() at_server_reload_start()
@ -16,6 +17,11 @@ at_server_cold_stop()
""" """
def at_server_init():
"""
This is called first as the server is starting up, regardless of how.
"""
pass
def at_server_start(): def at_server_start():
""" """

View file

@ -46,8 +46,8 @@ _SA = object.__setattr__
# a file with a flag telling the server to restart after shutdown or not. # a file with a flag telling the server to restart after shutdown or not.
SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart") SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart")
# module containing hook methods called during start_stop # modules containing hook methods called during start_stop
SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) SERVER_STARTSTOP_MODULES = [mod_import(m) for m in make_iter(settings.AT_SERVER_STARTSTOP_MODULE) if isinstance(m, str)]
# modules containing plugin services # modules containing plugin services
SERVER_SERVICES_PLUGIN_MODULES = make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES) SERVER_SERVICES_PLUGIN_MODULES = make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES)
@ -413,6 +413,8 @@ class Evennia:
for typeclass_db in TypedObject.__subclasses__() for typeclass_db in TypedObject.__subclasses__()
] ]
self.at_server_init()
# call correct server hook based on start file value # call correct server hook based on start file value
if mode == "reload": if mode == "reload":
logger.log_msg("Server successfully reloaded.") logger.log_msg("Server successfully reloaded.")
@ -525,14 +527,23 @@ class Evennia:
# server start/stop hooks # server start/stop hooks
def at_server_init(self):
"""
This is called first when the server is starting, before any other hooks, regardless of how it's starting.
"""
for m in SERVER_STARTSTOP_MODULES:
if hasattr(m, "at_server_init"):
m.at_server_init()
def at_server_start(self): def at_server_start(self):
""" """
This is called every time the server starts up, regardless of This is called every time the server starts up, regardless of
how it was shut down. how it was shut down.
""" """
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_start() if hasattr(m, "at_server_start"):
m.at_server_start()
def at_server_stop(self): def at_server_stop(self):
""" """
@ -540,16 +551,18 @@ class Evennia:
of it is fore a reload, reset or shutdown. of it is fore a reload, reset or shutdown.
""" """
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_stop() if hasattr(m, "at_server_stop"):
m.at_server_stop()
def at_server_reload_start(self): def at_server_reload_start(self):
""" """
This is called only when server starts back up after a reload. This is called only when server starts back up after a reload.
""" """
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_reload_start() if hasattr(m, "at_server_reload_start"):
m.at_server_reload_start()
def at_post_portal_sync(self, mode): def at_post_portal_sync(self, mode):
""" """
@ -589,8 +602,9 @@ class Evennia:
This is called only time the server stops before a reload. This is called only time the server stops before a reload.
""" """
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_reload_stop() if hasattr(m, "at_server_reload_stop"):
m.at_server_reload_stop()
def at_server_cold_start(self): def at_server_cold_start(self):
""" """
@ -618,16 +632,18 @@ class Evennia:
if character: if character:
character.delete() character.delete()
guest.delete() guest.delete()
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_cold_start() if hasattr(m, "at_server_cold_start"):
m.at_server_cold_start()
def at_server_cold_stop(self): def at_server_cold_stop(self):
""" """
This is called only when the server goes down due to a shutdown or reset. This is called only when the server goes down due to a shutdown or reset.
""" """
if SERVER_STARTSTOP_MODULE: for m in SERVER_STARTSTOP_MODULES:
SERVER_STARTSTOP_MODULE.at_server_cold_stop() if hasattr(m, "at_server_cold_stop"):
m.at_server_cold_stop()
# ------------------------------------------------------------ # ------------------------------------------------------------

View file

@ -389,6 +389,8 @@ AT_INITIAL_SETUP_HOOK_MODULE = "server.conf.at_initial_setup"
# Module containing your custom at_server_start(), at_server_reload() and # Module containing your custom at_server_start(), at_server_reload() and
# at_server_stop() methods. These methods will be called every time # at_server_stop() methods. These methods will be called every time
# the server starts, reloads and resets/stops respectively. # the server starts, reloads and resets/stops respectively.
# Now supports a list of python paths or a single string.
# If it's a list, each module's hooks will be called by list order.
AT_SERVER_STARTSTOP_MODULE = "server.conf.at_server_startstop" AT_SERVER_STARTSTOP_MODULE = "server.conf.at_server_startstop"
# List of one or more module paths to modules containing a function start_ # List of one or more module paths to modules containing a function start_
# plugin_services(application). This module will be called with the main # plugin_services(application). This module will be called with the main