diff --git a/game/gamesrc/conf/at_server_startstop.py b/game/gamesrc/conf/at_server_startstop.py new file mode 100644 index 0000000000..19a5490d29 --- /dev/null +++ b/game/gamesrc/conf/at_server_startstop.py @@ -0,0 +1,30 @@ +""" +This module contains functions that are imported and called by the +server whenever it changes its running status. At the point these +functions are run, all applicable hooks on individual objects have +already been executed. The main purpose of this is module is to have a +safe place to initialize eventual custom modules that your game needs +to start up or load. + +The module should define at least these global functions: + +at_server_start() +at_server_stop() + +The module used is defined by settings.AT_SERVER_STARTSTOP_MODULE. + +""" + +def at_server_start(): + """ + This is called every time the server starts up (also after a + reload or reset). + """ + pass + +def at_server_stop(): + """ + This is called just before a server is shut down, reloaded or + reset. + """ + pass diff --git a/game/gamesrc/conf/connection_screens.py b/game/gamesrc/conf/connection_screens.py index 96294d449a..a143cc8ef8 100644 --- a/game/gamesrc/conf/connection_screens.py +++ b/game/gamesrc/conf/connection_screens.py @@ -1,20 +1,23 @@ -# -# This module holds textual connection screen definitions. All global -# string variables (only) in this module are read by Evennia and -# assumed to define a Connection screen. You can change which module is -# used with settings.CONNECTION_SCREEN_MODULE. -# -# The names of the string variables doesn't matter (except they -# shouldn't start with _), but each should hold a string defining a -# connection screen - as seen when first connecting to the game -# (before having logged in). -# -# OBS - If there are more than one string variable viable in this -# module, a random one is picked! -# -# After adding new connection screens to this module you must either -# reboot or reload the server to make them available. -# +""" + This module holds textual connection screen definitions. All global + string variables (only) in this module are read by Evennia and + assumed to define a Connection screen. + + The names of the string variables doesn't matter (except they + shouldn't start with _), but each should hold a string defining a + connection screen - as seen when first connecting to the game + (before having logged in). + + OBS - If there are more than one string variable viable in this + module, a random one is picked! + + After adding new connection screens to this module you must either + reboot or reload the server to make them available. + +You can change which module is used with +settings.CONNECTION_SCREEN_MODULE. + +""" from src.utils import utils from src.commands.connection_screen import DEFAULT_SCREEN diff --git a/game/gamesrc/conf/lockfuncs.py b/game/gamesrc/conf/lockfuncs.py index 05a84663d2..d603cb96d6 100644 --- a/game/gamesrc/conf/lockfuncs.py +++ b/game/gamesrc/conf/lockfuncs.py @@ -15,6 +15,7 @@ arguments should be handled (excess ones calling magic (*args, eventual tracebacks by logging the error and returning False. See many more examples of lock functions in src.locks.lockfuncs. + """ def myfalse(accessing_obj, accessed_obj, *args, **kwargs): diff --git a/game/gamesrc/conf/oobfuncs.py b/game/gamesrc/conf/oobfuncs.py index 2dd2863721..db2d5b56cc 100644 --- a/game/gamesrc/conf/oobfuncs.py +++ b/game/gamesrc/conf/oobfuncs.py @@ -1,14 +1,14 @@ -# -# Example module holding functions for out-of-band protocols to -# import and map to given commands from the client. This module -# is selected by settings.OOB_FUNC_MODULE. -# -# All functions defined global in this module will be available -# for the oob system to call. They will be called with a session/character -# as first argument (depending on if the session is logged in or not), -# following by any number of extra arguments. The return value will -# be packed and returned to the oob protocol and can be on any form. -# +""" + Example module holding functions for out-of-band protocols to + import and map to given commands from the client. This module + is selected by settings.OOB_FUNC_MODULE. + + All functions defined global in this module will be available + for the oob system to call. They will be called with a session/character + as first argument (depending on if the session is logged in or not), + following by any number of extra arguments. The return value will + be packed and returned to the oob protocol and can be on any form. +""" def testoob(character, *args, **kwargs): "Simple test function" diff --git a/game/manage.py b/game/manage.py index 4a9ee2c769..122d4b7cc0 100755 --- a/game/manage.py +++ b/game/manage.py @@ -54,7 +54,7 @@ from src.settings_default import * ################################################### ################################################### -# Evennia in-game parsers +# Evennia pluggable modules ################################################### ################################################### diff --git a/src/server/server.py b/src/server/server.py index 2d4c352564..b9a850dad2 100644 --- a/src/server/server.py +++ b/src/server/server.py @@ -27,7 +27,7 @@ from src.scripts.models import ScriptDB from src.server.models import ServerConfig from src.server import initial_setup -from src.utils.utils import get_evennia_version +from src.utils.utils import get_evennia_version, mod_import from src.comms import channelhandler from src.server.sessionhandler import SESSIONS @@ -35,8 +35,12 @@ if os.name == 'nt': # For Windows we need to handle pid files manually. SERVER_PIDFILE = os.path.join(settings.GAME_DIR, 'server.pid') +# a file with a flag telling the server to restart after shutdown or not. SERVER_RESTART = os.path.join(settings.GAME_DIR, 'server.restart') +# module containing hook methods +SERVER_HOOK_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) + # i18n from django.utils.translation import ugettext as _ @@ -158,6 +162,9 @@ class Evennia(object): [(o.typeclass, o.at_init()) for o in ObjectDB.get_all_cached_instances()] [(p.typeclass, p.at_init()) for p in PlayerDB.get_all_cached_instances()] + # call server hook. + SERVER_HOOK_MODULE.at_server_start() + def terminal_output(self): """ Outputs server startup info to the terminal. @@ -221,12 +228,14 @@ class Evennia(object): [(o.typeclass, o.at_server_shutdown()) for o in ObjectDB.get_all_cached_instances()] else: # shutdown [(o.typeclass, o.at_disconnect(), o.at_server_shutdown()) for o in ObjectDB.get_all_cached_instances()] + [(p.typeclass, p.at_server_shutdown()) for p in PlayerDB.get_all_cached_instances()] - [(s.typeclass, s.at_server_shutdown()) for s in ScriptDB.get_all_cached_instances()] + [(s.typeclass, s.at_server_shutdown()) for s in ScriptDB.get_all_cached_instances()] ServerConfig.objects.conf("server_restart_mode", "reset") - + if not _abrupt: + SERVER_HOOK_MODULE.at_server_stop() reactor.callLater(0, reactor.stop) if os.name == 'nt' and os.path.exists(SERVER_PIDFILE): # for Windows we need to remove pid files manually diff --git a/src/settings_default.py b/src/settings_default.py index 31939aeff6..b2f21c06c7 100644 --- a/src/settings_default.py +++ b/src/settings_default.py @@ -142,7 +142,7 @@ DATABASE_HOST = '' DATABASE_PORT = '' ################################################### -# Evennia in-game parsers +# Evennia pluggable modules ################################################### # An alternate command parser module to use @@ -163,9 +163,14 @@ CONNECTION_SCREEN_MODULE = "game.gamesrc.conf.connection_screens" # the server's initial setup sequence (the very first startup of the system). # The check will fail quietly if module doesn't exist or fails to load. AT_INITIAL_SETUP_HOOK_MODULE = "game.gamesrc.conf.at_initial_setup" +# Module holding at_server_start(), at_server_reload() and +# at_server_stop() methods. These methods will be called every time +# the server starts, reloads and resets/stops. +AT_SERVER_STARTSTOP_MODULE = "game.gamesrc.conf.at_server_startstop" # Module holding server-side functions for out-of-band protocols to call. OOB_FUNC_MODULE = "game.gamesrc.conf.oobfuncs" + ################################################### # Default command sets ###################################################