def node_mssp_start(wizard): mssp_module = mod_import(settings.MSSP_META_MODULE or "server.conf.mssp") try: filename = mssp_module.__file__ except AttributeError: filename = "server/conf/mssp.py" text = f""" MSSP (Mud Server Status Protocol) has a vast amount of options so it must be modified outside this wizard by directly editing its config file here: '{filename}' MSSP allows traditional online MUD-listing sites/crawlers to continuously monitor your game and list information about it. Some of this, like active player-count, Evennia will automatically add for you, whereas most fields you need to set manually. To use MSSP you should generally have a publicly open game that external players can connect to. You also need to register at a MUD listing site to tell them to crawl your game. """ wizard.display(text) wizard.ask_continue() node_start(wizard)
def _save_changes(wizard): """ Perform the save """ # add import statement to settings file import_stanza = "from .connection_settings import *" setting_module = mod_import("server.conf.settings") with open(setting_module.__file__, "r+") as f: txt = f.read() # moves pointer to end of file if import_stanza not in txt: # add to the end of the file f.write("\n\n" "try:\n" " # Created by the `evennia connections` wizard\n" f" {import_stanza}\n" "except ImportError:\n" " pass") connect_settings_file = path.join(settings.GAME_DIR, "server", "conf", "connection_settings.py") with open(connect_settings_file, "w") as f: f.write( "# This file is auto-generated by the `evennia connections` wizard.\n" "# Don't edit manually, your changes will be overwritten.\n\n") f.write(wizard.save_output) wizard.display(f"saving to {connect_settings_file} ...")
def _parse_menudata(self, menudata): """ Parse a menufile for node functions and store in dictionary map. Alternatively, accept a pre-made mapping dictionary of node functions. Args: menudata (str, module or dict): The python.path to the menufile, or the python module itself. If a dict, this should be a mapping nodename:callable, where the callable must match the criteria for a menu node. Returns: menutree (dict): A {nodekey: func} """ if isinstance(menudata, dict): # This is assumed to be a pre-loaded menu tree. return menudata else: # a python path of a module module = mod_import(menudata) return dict( (key, func) for key, func in module.__dict__.items() if isfunction(func) and not key.startswith("_") )
def node_mssp_start(wizard): mssp_module = mod_import(settings.MSSP_META_MODULE) filename = mssp_module.__file__ text = f""" MSSP (Mud Server Status Protocol) allows online MUD-listing sites/crawlers to continuously monitor your game and list information about it. Some of this, like active player-count, Evennia will automatically add for you, whereas many fields are manually added info about your game. To use MSSP you should generally have a publicly open game that external players can connect to. You also need to register at a MUD listing site to tell them to list your game. MSSP has a large number of configuration options and we found it was simply a lot easier to set them in a file rather than using this wizard. So to configure MSSP, edit the empty template listing found here: '{filename}' """ wizard.display(text) wizard.ask_continue() node_start(wizard)
def _cache_lockfuncs(): "Updates the cache." global _LOCKFUNCS _LOCKFUNCS = {} for modulepath in settings.LOCK_FUNC_MODULES: mod = utils.mod_import(modulepath) if mod: for tup in (tup for tup in inspect.getmembers(mod) if callable(tup[1])): _LOCKFUNCS[tup[0]] = tup[1] else: logger.log_errmsg("Couldn't load %s from PERMISSION_FUNC_MODULES." % modulepath)
def _parse_menufile(self, menufile): """ Parse a menufile, split it into #node sections, convert each to an executable python code and store in a dictionary map. Args: menufile (str or module): The python.path to the menufile, or the python module itself. Returns: menutree (dict): A {nodekey: func} """ module = mod_import(menufile) return dict((key, func) for key, func in module.__dict__.items() if isfunction(func) and not key.startswith("_"))
def _parse_menudata(self, menudata): """ Parse a menufile for node functions and store in dictionary map. Alternatively, accept a pre-made mapping dictionary of node functions. Args: menudata (str, module or dict): The python.path to the menufile, or the python module itself. If a dict, this should be a mapping nodename:callable, where the callable must match the criteria for a menu node. Returns: menutree (dict): A {nodekey: func} """ if isinstance(menudata, dict): # This is assumed to be a pre-loaded menu tree. return menudata else: # a python path of a module module = mod_import(menudata) return dict((key, func) for key, func in module.__dict__.items() if isfunction(func) and not key.startswith("_"))
from twisted.application import internet, service from twisted.internet import protocol, reactor from twisted.internet.task import LoopingCall from twisted.web import server import django django.setup() from django.conf import settings import evennia evennia._init() from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS from evennia.server.webserver import EvenniaReverseProxyResource PORTAL_SERVICES_PLUGIN_MODULES = [mod_import(module) for module in make_iter(settings.PORTAL_SERVICES_PLUGIN_MODULES)] LOCKDOWN_MODE = settings.LOCKDOWN_MODE PORTAL_PIDFILE = "" if os.name == 'nt': # For Windows we need to handle pid files manually. PORTAL_PIDFILE = os.path.join(settings.GAME_DIR, "server", 'portal.pid') # ------------------------------------------------------------- # Evennia Portal settings # ------------------------------------------------------------- VERSION = get_evennia_version() SERVERNAME = settings.SERVERNAME
from evennia.server import initial_setup from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.utils import logger from evennia.comms import channelhandler from evennia.server.sessionhandler import SESSIONS from django.utils.translation import gettext as _ _SA = object.__setattr__ # a file with a flag telling the server to restart after shutdown or not. SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", "server.restart") # module containing hook methods called during start_stop SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) # modules containing plugin services SERVER_SERVICES_PLUGIN_MODULES = make_iter( settings.SERVER_SERVICES_PLUGIN_MODULES) # ------------------------------------------------------------ # Evennia Server settings # ------------------------------------------------------------ SERVERNAME = settings.SERVERNAME VERSION = get_evennia_version() AMP_ENABLED = True AMP_HOST = settings.AMP_HOST AMP_PORT = settings.AMP_PORT
from evennia.server import initial_setup from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.utils import logger from evennia.comms import channelhandler from evennia.server.sessionhandler import SESSIONS from django.utils.translation import ugettext as _ _SA = object.__setattr__ # a file with a flag telling the server to restart after shutdown or not. SERVER_RESTART = os.path.join(settings.GAME_DIR, "server", 'server.restart') # module containing hook methods called during start_stop SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) # modules containing plugin services SERVER_SERVICES_PLUGIN_MODULES = [ mod_import(module) for module in make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES) ] # ------------------------------------------------------------ # Evennia Server settings # ------------------------------------------------------------ SERVERNAME = settings.SERVERNAME VERSION = get_evennia_version() AMP_ENABLED = True
errmsg = "Exception in %s(*%s, **%s):\n%s" % (oobfuncname, args, kwargs, err) if _OOB_ERROR: _OOB_ERROR(session, errmsg, *args, **kwargs) errmsg = "OOB ERROR: %s" % errmsg logger.log_trace(errmsg) # access object OOB_HANDLER = OOBHandler() # load resources from plugin module. This must happen # AFTER the OOB_HANDLER has been initialized since the # commands will want to import it. _OOB_FUNCS = {} for modname in make_iter(settings.OOB_PLUGIN_MODULES): _OOB_FUNCS.update(mod_import(modname).CMD_MAP) # get the command to receive eventual error strings _OOB_ERROR = _OOB_FUNCS.get("oob_error", None) if not _OOB_ERROR: # no custom error set; create default oob error message function def oob_error(session, errmsg, *args, **kwargs): """ Fallback error handler. This will be used if no custom oob_error is defined and just echoes the error back to the session. Args: errmsg (str): Error message to echo. args, kwargs (any): Not used.
evennia._init() from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS from evennia.utils import logger from evennia.server.webserver import EvenniaReverseProxyResource # we don't need a connection to the database so close it right away try: connection.close() except Exception: pass PORTAL_SERVICES_PLUGIN_MODULES = [ mod_import(module) for module in make_iter(settings.PORTAL_SERVICES_PLUGIN_MODULES) ] LOCKDOWN_MODE = settings.LOCKDOWN_MODE # ------------------------------------------------------------- # Evennia Portal settings # ------------------------------------------------------------- VERSION = get_evennia_version() SERVERNAME = settings.SERVERNAME PORTAL_RESTART = os.path.join(settings.GAME_DIR, "server", "portal.restart") TELNET_PORTS = settings.TELNET_PORTS SSL_PORTS = settings.SSL_PORTS
errmsg = "Exception in %s(*%s, **%s):\n%s" % (oobfuncname, args, kwargs, err) if _OOB_ERROR: _OOB_ERROR(session, errmsg, *args, **kwargs) errmsg = "OOB ERROR: %s" % errmsg logger.log_trace(errmsg) # access object OOB_HANDLER = OOBHandler() # load resources from plugin module. This must happen # AFTER the OOB_HANDLER has been initialized since the # commands will want to import it. _OOB_FUNCS = {} for modname in make_iter(settings.OOB_PLUGIN_MODULES): _OOB_FUNCS.update(mod_import(modname).CMD_MAP) # get the command to receive eventual error strings _OOB_ERROR = _OOB_FUNCS.get("oob_error", None) if not _OOB_ERROR: # no custom error set; create default oob error message function def oob_error(session, errmsg, *args, **kwargs): """ Fallback error handler. This will be used if no custom oob_error is defined and just echoes the error back to the session. """ session.msg(oob=("err", ("ERROR ", errmsg))) _OOB_ERROR = oob_error
from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.comms import channelhandler from evennia.server.sessionhandler import SESSIONS _SA = object.__setattr__ if os.name == 'nt': # For Windows we need to handle pid files manually. SERVER_PIDFILE = os.path.join(settings.GAME_DIR, "server", '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", 'server.restart') # module containing hook methods called during start_stop SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) # module containing plugin services SERVER_SERVICES_PLUGIN_MODULES = [ mod_import(module) for module in make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES) ] #------------------------------------------------------------ # Evennia Server settings #------------------------------------------------------------ SERVERNAME = settings.SERVERNAME VERSION = get_evennia_version() AMP_ENABLED = True
def test_mod_import(self): loaded_mod = utils.mod_import("evennia.utils.ansi") self.assertIsNotNone(loaded_mod)
evennia._init() from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS from evennia.utils import logger from evennia.server.webserver import EvenniaReverseProxyResource from django.db import connection # we don't need a connection to the database so close it right away try: connection.close() except Exception: pass PORTAL_SERVICES_PLUGIN_MODULES = [mod_import(module) for module in make_iter(settings.PORTAL_SERVICES_PLUGIN_MODULES)] LOCKDOWN_MODE = settings.LOCKDOWN_MODE # ------------------------------------------------------------- # Evennia Portal settings # ------------------------------------------------------------- VERSION = get_evennia_version() SERVERNAME = settings.SERVERNAME PORTAL_RESTART = os.path.join(settings.GAME_DIR, "server", 'portal.restart') TELNET_PORTS = settings.TELNET_PORTS SSL_PORTS = settings.SSL_PORTS SSH_PORTS = settings.SSH_PORTS
def test_mod_import_invalid(self): loaded_mod = utils.mod_import("evennia.utils.invalid_module") self.assertIsNone(loaded_mod)
""" import re import json import html from twisted.internet.protocol import Protocol from django.conf import settings from evennia.server.session import Session from evennia.utils.utils import to_str, mod_import from evennia.utils.ansi import parse_ansi from evennia.utils.text2html import parse_html from autobahn.twisted.websocket import WebSocketServerProtocol _RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE) _CLIENT_SESSIONS = mod_import(settings.SESSION_ENGINE).SessionStore _UPSTREAM_IPS = settings.UPSTREAM_IPS # Status Code 1000: Normal Closure # called when the connection was closed through JavaScript CLOSE_NORMAL = WebSocketServerProtocol.CLOSE_STATUS_CODE_NORMAL # Status Code 1001: Going Away # called when the browser is navigating away from the page GOING_AWAY = WebSocketServerProtocol.CLOSE_STATUS_CODE_GOING_AWAY class WebSocketClient(WebSocketServerProtocol, Session): """ Implements the server-side of the Websocket connection. """
evennia._init() from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS from evennia.utils import logger from evennia.server.webserver import EvenniaReverseProxyResource from django.db import connection # we don't need a connection to the database so close it right away try: connection.close() except Exception: pass PORTAL_SERVICES_PLUGIN_MODULES = [ mod_import(module) for module in make_iter(settings.PORTAL_SERVICES_PLUGIN_MODULES) ] LOCKDOWN_MODE = settings.LOCKDOWN_MODE # ------------------------------------------------------------- # Evennia Portal settings # ------------------------------------------------------------- VERSION = get_evennia_version() SERVERNAME = settings.SERVERNAME PORTAL_RESTART = os.path.join(settings.GAME_DIR, "server", "portal.restart") TELNET_PORTS = settings.TELNET_PORTS
from twisted.internet import protocol, reactor from twisted.internet.task import LoopingCall from twisted.web import server import django django.setup() from django.conf import settings import evennia evennia._init() from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.server.portal.portalsessionhandler import PORTAL_SESSIONS from evennia.server.webserver import EvenniaReverseProxyResource PORTAL_SERVICES_PLUGIN_MODULES = [ mod_import(module) for module in make_iter(settings.PORTAL_SERVICES_PLUGIN_MODULES) ] LOCKDOWN_MODE = settings.LOCKDOWN_MODE PORTAL_PIDFILE = "" if os.name == 'nt': # For Windows we need to handle pid files manually. PORTAL_PIDFILE = os.path.join(settings.GAME_DIR, "server", 'portal.pid') #------------------------------------------------------------ # Evennia Portal settings #------------------------------------------------------------ VERSION = get_evennia_version()
which represents an "inputfunc" to be called on the Evennia side with *args, **kwargs. The most common inputfunc is "text", which takes just the text input from the command line and interprets it as an Evennia Command: `["text", ["look"], {}]` """ import re import json from twisted.internet.protocol import Protocol from django.conf import settings from evennia.server.session import Session from evennia.utils.utils import to_str, mod_import from evennia.utils.ansi import parse_ansi from evennia.utils.text2html import parse_html _RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE) _CLIENT_SESSIONS = mod_import(settings.SESSION_ENGINE).SessionStore class WebSocketClient(Protocol, Session): """ Implements the server-side of the Websocket connection. """ def __init__(self, *args, **kwargs): super(WebSocketClient, self).__init__(*args, **kwargs) self.protocol_key = "webclient/websocket" def connectionMade(self): """ This is called when the connection is first established. """
from evennia.utils.utils import get_evennia_version, mod_import, make_iter from evennia.comms import channelhandler from evennia.server.sessionhandler import SESSIONS _SA = object.__setattr__ if os.name == 'nt': # For Windows we need to handle pid files manually. SERVER_PIDFILE = os.path.join(settings.GAME_DIR, "server", '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", 'server.restart') # module containing hook methods called during start_stop SERVER_STARTSTOP_MODULE = mod_import(settings.AT_SERVER_STARTSTOP_MODULE) # modules containing plugin services SERVER_SERVICES_PLUGIN_MODULES = [mod_import(module) for module in make_iter(settings.SERVER_SERVICES_PLUGIN_MODULES)] try: WEB_PLUGINS_MODULE = mod_import(settings.WEB_PLUGINS_MODULE) except ImportError: WEB_PLUGINS_MODULE = None print ("WARNING: settings.WEB_PLUGINS_MODULE not found - " "copy 'evennia/game_template/server/conf/web_plugins.py to mygame/server/conf.") #------------------------------------------------------------ # Evennia Server settings #------------------------------------------------------------ SERVERNAME = settings.SERVERNAME
def run_update(no_autodoc=False): if no_autodoc: return cmdsets = ( ("evennia.commands.default.cmdset_character", "CharacterCmdSet"), ("evennia.commands.default.cmdset_account", "AccountCmdSet"), ("evennia.commands.default.cmdset_unloggedin", "UnloggedinCmdSet"), ("evennia.commands.default.cmdset_session", "SessionCmdSet"), ) cmd_modules = ( "evennia.commands.default.account", "evennia.commands.default.batchprocess", "evennia.commands.default.building", "evennia.commands.default.comms", "evennia.commands.default.general", "evennia.commands.default.help", "evennia.commands.default.syscommandsyyp", "evennia.commands.default.system", "evennia.commands.default.unloggedin", ) cmds_per_cmdset = {} cmd_to_cmdset_map = {} for modname, cmdsetname in cmdsets: cmdset = variable_from_module(modname, variable=cmdsetname)() cmdset.at_cmdset_creation() cmds_per_cmdset[cmdsetname] = cmdset.commands for cmd in cmdset.commands: cmd_to_cmdset_map[f"{cmd.__module__}.{cmd.__class__.__name__}"] = cmdset cmds_per_module = {} cmd_to_module_map = {} cmds_alphabetically = [] for modname in cmd_modules: module = mod_import(modname) cmds_per_module[module] = [ cmd for cmd in callables_from_module(module).values() if cmd.__name__.startswith("Cmd")] for cmd in cmds_per_module[module]: cmd_to_module_map[cmd] = module cmds_alphabetically.append(cmd) cmds_alphabetically = list(sorted(cmds_alphabetically, key=lambda c: c.key)) cmd_infos = [] for cmd in cmds_alphabetically: aliases = f" [{', '.join(cmd.aliases)}]" if cmd.aliases else "" cmdlink = f"[**{cmd.key}**{aliases}]({cmd.__module__}.{cmd.__name__})" category = f"help-category: _{cmd.help_category.capitalize()}_" cmdset = cmd_to_cmdset_map.get(f"{cmd.__module__}.{cmd.__name__}", None) if cmdset: cmodule = cmdset.__module__ cname = cmdset.__class__.__name__ cmdsetlink = f"cmdset: [{cname}]({cmodule}.{cname}), " else: # we skip commands not in the default cmdsets continue cmd_infos.append(f"{cmdlink} ({cmdsetlink}{category})") txt = PAGE.format( ncommands=len(cmd_to_cmdset_map), nfiles=len(cmds_per_module), alphabetical="\n".join(f"- {info}" for info in cmd_infos)) outdir = pathjoin(dirname(dirname(abspath(__file__))), "source") fname = pathjoin(outdir, "Default-Commands.md") with open(fname, 'w') as fil: fil.write(txt) print(" -- Updated Default Command index.")