mirror of
https://github.com/evennia/evennia.git
synced 2026-04-02 14:07:16 +02:00
Added at_server_start() and at_server_stop() hooks to allow users to safely initialize their custom systems whenever the server restarts.
This commit is contained in:
parent
7818ca077a
commit
309c03ce43
7 changed files with 81 additions and 33 deletions
30
game/gamesrc/conf/at_server_startstop.py
Normal file
30
game/gamesrc/conf/at_server_startstop.py
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ from src.settings_default import *
|
|||
###################################################
|
||||
|
||||
###################################################
|
||||
# Evennia in-game parsers
|
||||
# Evennia pluggable modules
|
||||
###################################################
|
||||
|
||||
###################################################
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
###################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue