コード例 #1
0
ファイル: lockhandler.py プロジェクト: Descyndis/mud
def _cache_lockfuncs():
    """
    Updates the cache.
    """
    global _LOCKFUNCS
    _LOCKFUNCS = {}
    for modulepath in settings.LOCK_FUNC_MODULES:
        _LOCKFUNCS.update(utils.callables_from_module(modulepath))
コード例 #2
0
ファイル: lockhandler.py プロジェクト: Henddher/evennia
def _cache_lockfuncs():
    """
    Updates the cache.
    """
    global _LOCKFUNCS
    _LOCKFUNCS = {}
    for modulepath in settings.LOCK_FUNC_MODULES:
        _LOCKFUNCS.update(utils.callables_from_module(modulepath))
コード例 #3
0
def _cache_conditionfuncs():
    """
    Updates the cache.
    """
    global _MAGIC_CONDITION_FUNCS
    _MAGIC_CONDITION_FUNCS = {}
    for modulepath in settings.MAGIC_CONDITION_MODULES:
        _MAGIC_CONDITION_FUNCS.update(utils.callables_from_module(modulepath))
コード例 #4
0
    def options(self, *args, **kwargs):
        """
        Returns a list of Archetypes. Each Archetype class has a `.modifiers`
        dict on it with values keyed to enums for the bonuses/drawbacks of that
        archetype. The archetype's name is the class name, retrieved with `.__name__`.

        """
        from . import archetypes
        return callables_from_module(archetypes)
コード例 #5
0
ファイル: containers.py プロジェクト: g33kcub/evennia-1
    def load_data(self):
        """
        Delayed import to avoid eventual circular imports from inside
        the storage modules.

        """
        if self.loaded_data is None:
            self.loaded_data = {}
            for module in self.storage_modules:
                self.loaded_data.update(callables_from_module(module))
コード例 #6
0
    def func(self):
        """Show the connect screen."""

        callables = utils.callables_from_module(CONNECTION_SCREEN_MODULE)
        if "connection_screen" in callables:
            connection_screen = callables['connection_screen']()
        else:
            connection_screen = utils.random_string_from_module(CONNECTION_SCREEN_MODULE)
            if not connection_screen:
                connection_screen = "No connection screen found. Please contact an admin."
        self.caller.msg(connection_screen)
コード例 #7
0
ファイル: unloggedin.py プロジェクト: Vikka/TerazurEngine
    def func(self):
        """Show the connect screen."""

        callables = utils.callables_from_module(CONNECTION_SCREEN_MODULE)
        if "connection_screen" in callables:
            connection_screen = callables["connection_screen"]()
        else:
            connection_screen = utils.random_string_from_module(
                CONNECTION_SCREEN_MODULE)
            if not connection_screen:
                connection_screen = "Pas d'écran de connexion, veuillez contacter l'assistance."
        self.caller.msg(connection_screen)
コード例 #8
0
    def options(self, *args, **kwargs):
        """
        Returns a list of races. Each Race class has the following properties:
        ::
            size = enum for small, average, large
            bodytype = enum for slim, average, stocky
            modifiers = dict of enums and bonuses/drawbacks
            foci = list of which Focus may be chosen for this race
            feats = list of which Feats may be chosen for this race

        """
        from . import races
        all_ = callables_from_module(races)
        return [race for race in all_ if inherits_from(race, race.Race)]
コード例 #9
0
# i18n
from django.utils.translation import ugettext as _

_SERVERNAME = settings.SERVERNAME
_MULTISESSION_MODE = settings.MULTISESSION_MODE
_IDLE_TIMEOUT = settings.IDLE_TIMEOUT
_DELAY_CMD_LOGINSTART = settings.DELAY_CMD_LOGINSTART
_MAX_SERVER_COMMANDS_PER_SECOND = 100.0
_MAX_SESSION_COMMANDS_PER_SECOND = 5.0
_MODEL_MAP = None

# input handlers

_INPUT_FUNCS = {}
for modname in make_iter(settings.INPUT_FUNC_MODULES):
    _INPUT_FUNCS.update(callables_from_module(modname))


def delayed_import():
    """
    Helper method for delayed import of all needed entities.

    """
    global _ServerSession, _AccountDB, _ServerConfig, _ScriptDB
    if not _ServerSession:
        # we allow optional arbitrary serversession class for overloading
        modulename, classname = settings.SERVER_SESSION_CLASS.rsplit(".", 1)
        _ServerSession = variable_from_module(modulename, classname)
    if not _AccountDB:
        from evennia.accounts.models import AccountDB as _AccountDB
    if not _ServerConfig:
コード例 #10
0
ファイル: sessionhandler.py プロジェクト: ESPADACAGE/evennia
# i18n
from django.utils.translation import ugettext as _

_SERVERNAME = settings.SERVERNAME
_MULTISESSION_MODE = settings.MULTISESSION_MODE
_IDLE_TIMEOUT = settings.IDLE_TIMEOUT
_MAX_SERVER_COMMANDS_PER_SECOND = 100.0
_MAX_SESSION_COMMANDS_PER_SECOND = 5.0
_MODEL_MAP = None

# input handlers

_INPUT_FUNCS = {}
for modname in make_iter(settings.INPUT_FUNC_MODULES):
    _INPUT_FUNCS.update(callables_from_module(modname))

def delayed_import():
    """
    Helper method for delayed import of all needed entities.

    """
    global _ServerSession, _PlayerDB, _ServerConfig, _ScriptDB
    if not _ServerSession:
        # we allow optional arbitrary serversession class for overloading
        modulename, classname = settings.SERVER_SESSION_CLASS.rsplit(".", 1)
        _ServerSession = variable_from_module(modulename, classname)
    if not _PlayerDB:
        from evennia.players.models import PlayerDB as _PlayerDB
    if not _ServerConfig:
        from evennia.server.models import ServerConfig as _ServerConfig
コード例 #11
0
                       for lstring in prototype.get("prototype_locks", "").split(';')
                       if ":" in lstring]
    locktypes = [tup[0].strip() for tup in prototype_locks]
    if "spawn" not in locktypes:
        prototype_locks.append(("spawn", "all()"))
    if "edit" not in locktypes:
        prototype_locks.append(("edit", "all()"))
    prototype_locks = ";".join(":".join(tup) for tup in prototype_locks)
    prototype['prototype_locks'] = prototype_locks


# Protfunc parsing (in-prototype functions)

for mod in settings.PROT_FUNC_MODULES:
    try:
        callables = callables_from_module(mod)
        PROT_FUNCS.update(callables)
    except ImportError:
        logger.log_trace()
        raise


def protfunc_parser(value, available_functions=None, testing=False, stacktrace=False, **kwargs):
    """
    Parse a prototype value string for a protfunc and process it.

    Available protfuncs are specified as callables in one of the modules of
    `settings.PROTFUNC_MODULES`, or specified on the command line.

    Args:
        value (any): The value to test for a parseable protfunc. Only strings will be parsed for
コード例 #12
0
_INLINE_FUNCS = {}

# we specify a default nomatch function to use if no matching func was
# found. This will be overloaded by any nomatch function defined in
# the imported modules.
_DEFAULT_FUNCS = {
    "nomatch": lambda *args, **kwargs: "<UNKNOWN>",
    "stackfull": lambda *args, **kwargs: "\n (not parsed: ",
}

_INLINE_FUNCS.update(_DEFAULT_FUNCS)

# load custom inline func modules.
for module in utils.make_iter(settings.INLINEFUNC_MODULES):
    try:
        _INLINE_FUNCS.update(utils.callables_from_module(module))
    except ImportError as err:
        if module == "server.conf.inlinefuncs":
            # a temporary warning since the default module changed name
            raise ImportError(
                "Error: %s\nPossible reason: mygame/server/conf/inlinefunc.py should "
                "be renamed to mygame/server/conf/inlinefuncs.py (note "
                "the S at the end)." % err
            )
        else:
            raise


# regex definitions

_RE_STARTTOKEN = re.compile(r"(?<!\\)\$(\w+)\(")  # unescaped $funcname( (start of function call)
コード例 #13
0
ファイル: inlinefuncs.py プロジェクト: helix-0311/evennia
    else:
        text += "|n"
    return text


# we specify a default nomatch function to use if no matching func was
# found. This will be overloaded by any nomatch function defined in
# the imported modules.
_INLINE_FUNCS = {"nomatch": lambda *args, **kwargs: "<UKNOWN>",
        "stackfull": lambda *args, **kwargs: "\n (not parsed: inlinefunc stack size exceeded.)"}


# load custom inline func modules.
for module in utils.make_iter(settings.INLINEFUNC_MODULES):
    try:
        _INLINE_FUNCS.update(utils.callables_from_module(module))
    except ImportError as err:
        if module == "server.conf.inlinefuncs":
            # a temporary warning since the default module changed name
            raise ImportError("Error: %s\nPossible reason: mygame/server/conf/inlinefunc.py should "
                  "be renamed to mygame/server/conf/inlinefuncs.py (note the S at the end)." % err)
        else:
            raise


# remove the core function if we include examples in this module itself
#_INLINE_FUNCS.pop("inline_func_parse", None)


# The stack size is a security measure. Set to <=0 to disable.
try:
コード例 #14
0
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.")
コード例 #15
0
ファイル: menu_login.py プロジェクト: Descyndis/mud
def node_enter_username(caller, raw_text, **kwargs):
    """
    Start node of menu
    Start login by displaying the connection screen and ask for a user name.

    """
    def _check_input(caller, username, **kwargs):
        """
        'Goto-callable', set up to be called from the _default option below.

        Called when user enters a username string. Check if this username already exists and set the flag
        'new_user' if not. Will also directly login if the username is 'guest'
        and GUEST_ENABLED is True.

        The return from this goto-callable determines which node we go to next
        and what kwarg it will be called with.

        """
        username = username.rstrip('\n')

        if username == 'guest' and _GUEST_ENABLED:
            # do an immediate guest login
            session = caller
            address = session.address
            account, errors = _GUEST.authenticate(ip=address)
            if account:
                return "node_quit_or_login", {
                    "login": True,
                    "account": account
                }
            else:
                session.msg("|R{}|n".format("\n".join(errors)))
                return None  # re-run the username node

        try:
            _ACCOUNT.objects.get(username__iexact=username)
        except _ACCOUNT.DoesNotExist:
            new_user = True
        else:
            new_user = False

        # pass username/new_user into next node as kwargs
        return "node_enter_password", {
            'new_user': new_user,
            'username': username
        }

    callables = callables_from_module(_CONNECTION_SCREEN_MODULE)
    if "connection_screen" in callables:
        connection_screen = callables['connection_screen']()
    else:
        connection_screen = random_string_from_module(
            _CONNECTION_SCREEN_MODULE)

    if _GUEST_ENABLED:
        text = "Enter a new or existing user name to login (write 'guest' for a guest login):"
    else:
        text = "Enter a new or existing user name to login:"******"{}\n\n{}".format(connection_screen, text)

    options = ({
        "key": "",
        "goto": "node_enter_username"
    }, {
        "key": ("quit", "q"),
        "goto": "node_quit_or_login"
    }, {
        "key": ("help", "h"),
        "goto": (_show_help, {
            "help_entry": _ACCOUNT_HELP,
            **kwargs
        })
    }, {
        "key": "_default",
        "goto": _check_input
    })
    return text, options