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

@ -0,0 +1,23 @@
"""
This plugin module can define user-created services for the Server to start.
To use, copy this module up one level to game/gamesrc/conf/ and set
settings.SERVER_SERVICES_PLUGIN_MODULE to point to this module.
This module must handle all imports and setups required to start a twisted
services (see examples in src/server/server.py). It must also contain a
function start_plugin_services(application). Evennia will call this function
with the main Server application (so your services can be added to it). The
function should not return anything. Plugin services are started last in
the Server startup process.
"""
def start_plugin_services(server):
"""
This hook is called by Evennia, last in the Server startup process.
server - a reference to the main server application.
"""
pass

View file

@ -0,0 +1,23 @@
"""
This plugin module can define user-created services for the Portal to start.
To use, copy this module up one level to game/gamesrc/conf/ and set
settings.PORTAL_SERVICES_PLUGIN_MODULE to point to this module.
This module must handle all imports and setups required to start a twisted
service (see examples in src/server/server.py). It must also contain a
function start_plugin_services(application). Evennia will call this function
with the main Portal application (so your services can be added to it). The
function should not return anything. Plugin services are started last in
the Portal startup process.
"""
def start_plugin_services(portal):
"""
This hook is called by Evennia, last in the Portal startup process.
portal - a reference to the main portal application.
"""
pass

View file

@ -40,7 +40,8 @@ if not os.path.exists('settings.py'):
_CREATED_SETTINGS = True
string = \
"""#
"""
######################################################################
# Evennia MU* server configuration file
#
# You may customize your setup by copy&pasting the variables you want
@ -50,60 +51,14 @@ if not os.path.exists('settings.py'):
# This way you'll always have a sane default to fall back on
# (also, the master config file may change with server updates).
#
######################################################################
from src.settings_default import *
######################################################################
# Evennia base server config
# Custom settings
######################################################################
######################################################################
# Evennia Database config
######################################################################
######################################################################
# Evennia pluggable modules
######################################################################
######################################################################
# Default command sets
######################################################################
######################################################################
# Typeclasses
######################################################################
######################################################################
# Batch processors
######################################################################
######################################################################
# Game Time setup
######################################################################
######################################################################
# In-game access
######################################################################
######################################################################
# In-game Channels created from server start
######################################################################
######################################################################
# External Channel connections
######################################################################
######################################################################
# Process Pool setup
######################################################################
######################################################################
# Django web features
######################################################################
######################################################################
# Evennia components
######################################################################
######################################################################
# SECRET_KEY was randomly seeded when settings.py was first created.
@ -120,17 +75,15 @@ SECRET_KEY = '%s'
# obs - this string cannot be under i18n since settings didn't exist yet.
print """
Welcome to Evennia (version %(version)s)!
Welcome to Evennia!
This looks like your first startup so we created a fresh
game/settings.py file for you. No database has yet been created,
so you may configure your settings file now if you want. If you
are just playing around to test things out, you don't have to
touch anything.
This looks like your first startup, so we created a fresh
game/settings.py file for you. No database has yet been created.
You may edit the settings file now if you like, but if you just
want to quickly get started you don't have to touch anything.
(re)run 'python manage.py syncdb' once you are ready to continue.
""" % {'version': VERSION}
"""
#------------------------------------------------------------
@ -166,13 +119,8 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'game.settings'
#------------------------------------------------------------
if __name__ == "__main__":
# checks if the settings file was created this run
if _CREATED_SETTINGS:
print """
Edit your new settings.py file as needed, then run
'python manage syncdb' and follow the prompts to
create the database and your superuser account.
"""
# if settings were created, info has already been printed.
sys.exit()
# run the standard django manager, if dependencies match

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 = ""