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

@ -56,7 +56,7 @@ def cmdparser(raw_string, cmdset, caller, match_index=None):
and (not cmd.arg_regex or
cmd.arg_regex.match(l_raw_string[len(cmdname):]))])
except Exception:
log_trace("raw_input:%s" % raw_string)
log_trace("cmdhandler error. raw_input:%s" % raw_string)
if not matches:
# no matches found.

View file

@ -391,19 +391,11 @@ class CmdSet(object):
unique[cmd.key] = cmd
self.commands = unique.values()
def at_cmdset_creation(self):
"""
Hook method - this should be overloaded in the inheriting
class, and should take care of populating the cmdset
by use of self.add().
"""
pass
def get_all_cmd_keys_and_aliases(self, caller=None):
"""
Returns a list of all command keys and aliases
available in this cmdset. If caller is given, the
comands is checked for access on the "call" type
commands is checked for access on the "call" type
before being returned.
"""
names = []
@ -412,3 +404,11 @@ class CmdSet(object):
else:
[names.extend(cmd._keyaliases) for cmd in self.commands]
return names
def at_cmdset_creation(self):
"""
Hook method - this should be overloaded in the inheriting
class, and should take care of populating the cmdset
by use of self.add().
"""
pass

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)

View file

@ -152,9 +152,12 @@ DATABASE_PORT = ''
######################################################################
# Evennia pluggable modules
######################################################################
# Plugin modules extend Evennia in various ways. In the cases with no
# existing default, there are examples of many of these modules
# in game/gamesrc/conf/examples.
# The command parser module to use. See the default module for which
# functions it must implement.
# functions it must implement
COMMAND_PARSER = "src.commands.cmdparser.cmdparser"
# The handler that outputs errors when searching
# objects using object.search().
@ -176,6 +179,14 @@ AT_INITIAL_SETUP_HOOK_MODULE = ""
# at_server_stop() methods. These methods will be called every time
# the server starts, reloads and resets/stops respectively.
AT_SERVER_STARTSTOP_MODULE = ""
# Module containing a function start_plugin_services(application). This module
# will be called with the main Evennia Server application when the Server is initiated.
# It will be called last in the startup sequence.
SERVER_SERVICES_PLUGIN_MODULE = ""
# Module containing a function start_plugin_services(application). This module
# will be called with the main Evennia Portal application when the Portal is initiated.
# It will be called last in the startup sequence.
PORTAL_SERVICES_PLUGIN_MODULE = ""
# Module holding MSSP meta data. This is used by MUD-crawlers to determine
# what type of game you are running, how many players you have etc.
MSSP_META_MODULE = ""