Example #1
0
    def restore(self, server_reload=True):
        """
        Restore our monitors after a reload. This is called
        by the server process.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        self.monitors = defaultdict(lambda: defaultdict(dict))
        restored_monitors = ServerConfig.objects.conf(key=self.savekey)
        if restored_monitors:
            restored_monitors = dbunserialize(restored_monitors)
            for (obj, fieldname, idstring, path, persistent,
                 kwargs) in restored_monitors:
                try:
                    if not persistent and not server_reload:
                        # this monitor will not be restarted
                        continue
                    modname, varname = path.rsplit(".", 1)
                    callback = variable_from_module(modname, varname)
                    if obj and hasattr(obj, fieldname):
                        self.monitors[obj][fieldname][idstring] = (callback,
                                                                   persistent,
                                                                   kwargs)
                except Exception:
                    continue
        # make sure to clean data from database
        ServerConfig.objects.conf(key=self.savekey, delete=True)
Example #2
0
    def restore(self, server_reload=True):
        """
        Restore our monitors after a reload. This is called
        by the server process.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        self.monitors = defaultdict(lambda: defaultdict(dict))
        restored_monitors = ServerConfig.objects.conf(key=self.savekey)
        if restored_monitors:
            restored_monitors = dbunserialize(restored_monitors)
            for (obj, fieldname, idstring, path, persistent, kwargs) in restored_monitors:
                try:
                    if not persistent and not server_reload:
                        # this monitor will not be restarted
                        continue
                    modname, varname = path.rsplit(".", 1)
                    callback = variable_from_module(modname, varname)
                    if obj and hasattr(obj, fieldname):
                        self.monitors[obj][fieldname][idstring] = (callback, persistent, kwargs)
                except Exception:
                    continue
        # make sure to clean data from database
        ServerConfig.objects.conf(key=self.savekey, delete=True)
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            self.ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    # at this point obj is the actual object (or None) due to how
                    # the dbunserialize works
                    obj, callfunc, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if isinstance(callfunc, basestring) and not obj:
                        # methods must have an existing object
                        continue
                    # we must rebuild the store_key here since obj must not be
                    # stored as the object itself for the store_key to be hashable.
                    store_key = self._store_key(obj, path, interval, callfunc,
                                                idstring, persistent)

                    if obj and callfunc:
                        kwargs["_callback"] = callfunc
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    else:
                        # Neither object nor path - discard this ticker
                        log_err(
                            "Tickerhandler: Removing malformed ticker: %s" %
                            str(store_key))
                        continue
                except Exception:
                    # this suggests a malformed save or missing objects
                    log_trace("Tickerhandler: Removing malformed ticker: %s" %
                              str(store_key))
                    continue
                # if we get here we should create a new ticker
                self.ticker_storage[store_key] = (args, kwargs)
                self.ticker_pool.add(store_key, *args, **kwargs)
Example #4
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            self.ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    # at this point obj is the actual object (or None) due to how
                    # the dbunserialize works
                    obj, callfunc, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if isinstance(callfunc, basestring) and not obj:
                        # methods must have an existing object
                        continue
                    # we must rebuild the store_key here since obj must not be
                    # stored as the object itself for the store_key to be hashable.
                    store_key = self._store_key(obj, path, interval, callfunc, idstring, persistent)

                    if obj and callfunc:
                        kwargs["_callback"] = callfunc
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    else:
                        # Neither object nor path - discard this ticker
                        log_err("Tickerhandler: Removing malformed ticker: %s" % str(store_key))
                        continue
                except Exception:
                    # this suggests a malformed save or missing objects
                    log_trace("Tickerhandler: Removing malformed ticker: %s" % str(store_key))
                    continue
                # if we get here we should create a new ticker
                self.ticker_storage[store_key] = (args, kwargs)
                self.ticker_pool.add(store_key, *args, **kwargs)
Example #5
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    obj, methodname, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if obj and methodname:
                        kwargs["_callback"] = methodname
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    ticker_storage[store_key] = (args, kwargs)
                except Exception as err:
                    # this suggests a malformed save or missing objects
                    log_err(
                        "%s\nTickerhandler: Removing malformed ticker: %s" %
                        (err, str(store_key)))
                    continue
                self.ticker_storage = ticker_storage
                self.ticker_pool.add(store_key, *args, **kwargs)
Example #6
0
    def restore(self, server_reload=True):
        """
        Restore ticker_storage from database and re-initialize the
        handler from storage. This is triggered by the server at
        restart.

        Args:
            server_reload (bool, optional): If this is False, it means
                the server went through a cold reboot and all
                non-persistent tickers must be killed.

        """
        # load stored command instructions and use them to re-initialize handler
        restored_tickers = ServerConfig.objects.conf(key=self.save_name)
        if restored_tickers:
            # the dbunserialize will convert all serialized dbobjs to real objects

            restored_tickers = dbunserialize(restored_tickers)
            ticker_storage = {}
            for store_key, (args, kwargs) in restored_tickers.iteritems():
                try:
                    obj, methodname, path, interval, idstring, persistent = store_key
                    if not persistent and not server_reload:
                        # this ticker will not be restarted
                        continue
                    if obj and methodname:
                        kwargs["_callback"] = methodname
                        kwargs["_obj"] = obj
                    elif path:
                        modname, varname = path.rsplit(".", 1)
                        callback = variable_from_module(modname, varname)
                        kwargs["_callback"] = callback
                        kwargs["_obj"] = None
                    ticker_storage[store_key] = (args, kwargs)
                except Exception as err:
                    # this suggests a malformed save or missing objects
                    log_err("%s\nTickerhandler: Removing malformed ticker: %s" % (err, str(store_key)))
                    continue
                self.ticker_storage = ticker_storage
                self.ticker_pool.add(store_key, *args, **kwargs)
Example #7
0
2) `@dig` a room of type `contrib.extended_room.ExtendedRoom` (or make it the
   default room type)
3) Use `@desc` and `@detail` to customize the room, then play around!

"""
from __future__ import division

import re
from django.conf import settings
from evennia import DefaultRoom
from evennia import gametime
from evennia import default_cmds
from evennia import utils

# error return function, needed by Extended Look command
_AT_SEARCH_RESULT = utils.variable_from_module(
    *settings.SEARCH_AT_RESULT.rsplit('.', 1))

# regexes for in-desc replacements
RE_MORNING = re.compile(r"<morning>(.*?)</morning>", re.IGNORECASE)
RE_AFTERNOON = re.compile(r"<afternoon>(.*?)</afternoon>", re.IGNORECASE)
RE_EVENING = re.compile(r"<evening>(.*?)</evening>", re.IGNORECASE)
RE_NIGHT = re.compile(r"<night>(.*?)</night>", re.IGNORECASE)
# this map is just a faster way to select the right regexes (the first
# regex in each tuple will be parsed, the following will always be weeded out)
REGEXMAP = {
    "morning": (RE_MORNING, RE_AFTERNOON, RE_EVENING, RE_NIGHT),
    "afternoon": (RE_AFTERNOON, RE_MORNING, RE_EVENING, RE_NIGHT),
    "evening": (RE_EVENING, RE_MORNING, RE_AFTERNOON, RE_NIGHT),
    "night": (RE_NIGHT, RE_MORNING, RE_AFTERNOON, RE_EVENING)
}
Example #8
0
   (see Wiki for how to do this).
2) `@dig` a room of type `contrib.extended_room.ExtendedRoom` (or make it the
   default room type)
3) Use `@desc` and `@detail` to customize the room, then play around!

"""

import re
from django.conf import settings
from evennia import DefaultRoom
from evennia import gametime
from evennia import default_cmds
from evennia import utils

# error return function, needed by Extended Look command
_AT_SEARCH_RESULT = utils.variable_from_module(*settings.SEARCH_AT_RESULT.rsplit('.', 1))

# regexes for in-desc replacements
RE_MORNING = re.compile(r"<morning>(.*?)</morning>", re.IGNORECASE)
RE_AFTERNOON = re.compile(r"<afternoon>(.*?)</afternoon>", re.IGNORECASE)
RE_EVENING = re.compile(r"<evening>(.*?)</evening>", re.IGNORECASE)
RE_NIGHT = re.compile(r"<night>(.*?)</night>", re.IGNORECASE)
# this map is just a faster way to select the right regexes (the first
# regex in each tuple will be parsed, the following will always be weeded out)
REGEXMAP = {"morning": (RE_MORNING, RE_AFTERNOON, RE_EVENING, RE_NIGHT),
            "afternoon": (RE_AFTERNOON, RE_MORNING, RE_EVENING, RE_NIGHT),
            "evening": (RE_EVENING, RE_MORNING, RE_AFTERNOON, RE_NIGHT),
            "night": (RE_NIGHT, RE_MORNING, RE_AFTERNOON, RE_EVENING)}

# set up the seasons and time slots. This assumes gametime started at the
# beginning of the year (so month 1 is equivalent to January), and that
Example #9
0
The Object is the "naked" base class for things in the game world.

Note that the default Character, Room and Exit does not inherit from
this Object, but from their respective default implementations in the
evennia library. If you want to use this class as a parent to change
the other types, you can do so by adding this as a multiple
inheritance.

"""
from django.conf import settings
from evennia import DefaultObject
from evennia.objects.models import ObjectDB
from evennia.utils import variable_from_module, make_iter

_AT_SEARCH_RESULT = variable_from_module(
    *settings.SEARCH_AT_RESULT.rsplit(".", 1))


class Object(DefaultObject):
    """
    This is the root typeclass object, implementing an in-game Evennia
    game object, such as having a location, being able to be
    manipulated or looked at, etc. If you create a new typeclass, it
    must always inherit from this object (or any of the other objects
    in this file, since they all actually inherit from BaseObject, as
    seen in src.object.objects).

    The BaseObject class implements several hooks tying into the game
    engine. By re-implementing these hooks you can control the
    system. You should never need to re-implement special Python
    methods, such as __init__ and especially never __getattribute__ and