Added a plugin system for server and portal. This allows for plugging in your own services without having to edit any modules in src/server/. Also made some various cleanups and fixes.

This commit is contained in:
Griatch 2012-09-18 22:52:33 +02:00
parent ee450a4fed
commit 83fa9397d5
8 changed files with 100 additions and 80 deletions

View file

@ -19,9 +19,11 @@ from twisted.application import internet, service
from twisted.internet import protocol, reactor
from twisted.web import server, static
from django.conf import settings
from src.utils.utils import get_evennia_version
from src.utils.utils import get_evennia_version, mod_import
from src.server.sessionhandler import PORTAL_SESSIONS
PORTAL_SERVICES_PLUGIN_MODULE = mod_import(settings.PORTAL_SERVICES_PLUGIN_MODULE)
if os.name == 'nt':
# For Windows we need to handle pid files manually.
PORTAL_PIDFILE = os.path.join(settings.GAME_DIR, 'portal.pid')
@ -285,6 +287,11 @@ if WEBSERVER_ENABLED:
webserver.setName('EvenniaWebServer%s' % pstring)
PORTAL.services.addService(webserver)
if PORTAL_SERVICES_PLUGIN_MODULE:
# external plugin services to start
PORTAL_SERVICES_PLUGIN_MODULE.start_plugin_services(PORTAL)
if os.name == 'nt':
# Windows only: Set PID file manually
f = open(os.path.join(settings.GAME_DIR, 'portal.pid'), 'w')

View file

@ -40,7 +40,11 @@ if os.name == 'nt':
SERVER_RESTART = os.path.join(settings.GAME_DIR, 'server.restart')
# module containing hook methods
SERVER_HOOK_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE)
SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE)
# module containing plugin services
SERVER_SERVICES_PLUGIN_MODULE = mod_import(settings.SERVER_SERVICES_PLUGIN_MODULE)
#------------------------------------------------------------
# Evennia Server settings
@ -214,8 +218,8 @@ class Evennia(object):
[(p.typeclass, p.at_init()) for p in PlayerDB.get_all_cached_instances()]
# call server hook.
if SERVER_HOOK_MODULE:
SERVER_HOOK_MODULE.at_server_start()
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_start()
def terminal_output(self):
"""
@ -296,8 +300,8 @@ class Evennia(object):
ServerConfig.objects.conf("server_restart_mode", "reset")
if SERVER_HOOK_MODULE:
SERVER_HOOK_MODULE.at_server_stop()
if SERVER_STARTSTOP_MODULE:
SERVER_STARTSTOP_MODULE.at_server_stop()
# if _reactor_stopping is true, reactor does not need to be stopped again.
if os.name == 'nt' and os.path.exists(SERVER_PIDFILE):
# for Windows we need to remove pid files manually
@ -401,6 +405,10 @@ if RSS_ENABLED:
from src.comms import rss
rss.connect_all()
if SERVER_SERVICES_PLUGIN_MODULE:
# external plugin protocols
SERVER_SERVICES_PLUGIN_MODULE.start_plugin_services(EVENNIA)
# clear server startup mode
ServerConfig.objects.conf("server_starting_mode", delete=True)