예제 #1
0
    def search(self, searchdata, return_puppet=False, **kwargs):
        """
        This is similar to the ObjectDB search method but will search for
        Players only. Errors will be echoed, and None returned if no Player
        is found.
        searchdata - search criterion, the Player's key or dbref to search for
        return_puppet  - will try to return the object the player controls
                           instead of the Player object itself. If no
                           puppeted object exists (since Player is OOC), None will
                           be returned.
        Extra keywords are ignored, but are allowed in call in order to make
                           API more consistent with objects.models.TypedObject.search.
        """
        #TODO deprecation
        if "return_character" in kwargs:
            logger.log_depmsg("Player.search's 'return_character' keyword is deprecated. Use the return_puppet keyword instead.")
            return_puppet = kwargs.get("return_character")

        matches = _GA(self, "__class__").objects.player_search(searchdata)
        matches = _AT_SEARCH_RESULT(self, searchdata, matches, global_search=True)
        if matches and return_puppet:
            try:
                return _GA(matches, "puppet")
            except AttributeError:
                return None
        return matches
예제 #2
0
파일: models.py 프로젝트: Aumnren/evennia
    def search(self, ostring, return_puppet=False,
               return_character=False, **kwargs):
        """
        This is similar to the ObjectDB search method but will search for
        Players only. Errors will be echoed, and None returned if no Player
        is found.

        return_character - will try to return the character the player controls
                           instead of the Player object itself. If no
                           Character exists (since Player is OOC), None will
                           be returned.
        Extra keywords are ignored, but are allowed in call in order to make
                           API more consistent with objects.models.
                           TypedObject.search.
        """
        if return_character:
            logger.log_depmsg("Player.search's 'return_character' keyword is deprecated. Use the return_puppet keyword instead.")
            #return_puppet = return_character
        # handle me, self
        if ostring in (_ME, _SELF, '*' + _ME, '*' + _SELF):
            return self

        matches = _GA(self, "__class__").objects.player_search(ostring)
        matches = _AT_SEARCH_RESULT(self, ostring, matches, global_search=True)
        if matches and return_character:
            try:
                return _GA(matches, "character")
            except:
                pass
        return matches
예제 #3
0
    def search(self, searchdata, return_puppet=False, **kwargs):
        """
        This is similar to the ObjectDB search method but will search for
        Players only. Errors will be echoed, and None returned if no Player
        is found.
        searchdata - search criterion, the Player's key or dbref to search for
        return_puppet  - will try to return the object the player controls
                           instead of the Player object itself. If no
                           puppeted object exists (since Player is OOC), None will
                           be returned.
        Extra keywords are ignored, but are allowed in call in order to make
                           API more consistent with objects.models.TypedObject.search.
        """
        #TODO deprecation
        if "return_character" in kwargs:
            logger.log_depmsg("Player.search's 'return_character' keyword is deprecated. Use the return_puppet keyword instead.")
            return_puppet = kwargs.get("return_character")

        matches = _GA(self, "__class__").objects.player_search(searchdata)
        matches = _AT_SEARCH_RESULT(_GA(self, "typeclass"), searchdata, matches, global_search=True)
        if matches and return_puppet:
            try:
                return _GA(matches, "puppet")
            except AttributeError:
                return None
        return matches
예제 #4
0
파일: models.py 프로젝트: Aumnren/evennia
    def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
        """
        Emits something to a session attached to the object.

        message (str): The message to send
        from_obj (obj): object that is sending.
        data (object): an optional data object that may or may not
                       be used by the protocol.
        sessid (int): sessid to relay to, if any.
                      If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
                      If None, echo to all connected sessions
        """
        global _SESSIONS
        if not _SESSIONS:
            from src.server.sessionhandler import SESSIONS as _SESSIONS

        text = to_str(text, force_string=True) if text else ""

        if "data" in kwargs:
            # deprecation warning
            logger.log_depmsg("ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead.")
            data = kwargs.pop("data")
            if isinstance(data, dict):
                kwargs.update(data)

        if from_obj:
            # call hook
            try:
                _GA(from_obj, "at_msg_send")(text=text, to_obj=self, **kwargs)
            except Exception:
                pass

        session = _SESSIONS.session_from_sessid(sessid if sessid else _GA(self, "sessid"))
        if session:
            session.msg(text=text, **kwargs)
예제 #5
0
    def at_access_failure(self, accessing_obj, access_type):
        """
        OBS: DEPRECATED. Use at_access instead

        This hook is called whenever accessing_obj fails a lock check of type
        access_type on this object, for whatever reason. The return value of
        this hook is not used, the lock will still fail regardless of what
        this hook does (use lockstring/funcs to tweak the lock result).
        """
        log_depmsg("at_access_failure is deprecated. Use at_access(result,**kwargs) instead.")
        pass
예제 #6
0
    def at_access_failure(self, accessing_obj, access_type):
        """
        OBS: DEPRECATED. Use at_access instead

        This hook is called whenever accessing_obj fails a lock check of type
        access_type on this object, for whatever reason. The return value of
        this hook is not used, the lock will still fail regardless of what
        this hook does (use lockstring/funcs to tweak the lock result).
        """
        log_depmsg("at_access_failure is deprecated. Use at_access(result,**kwargs) instead.")
        pass
예제 #7
0
    def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
        """
        Emits something to a session attached to the object.

        message (str): The message to send
        from_obj (obj): object that is sending.
        data (object): an optional data object that may or may not
                       be used by the protocol.
        sessid (int): sessid to relay to, if any.
                      If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
                      If None, echo to all connected sessions

        When this message is called, from_obj.at_msg_send and self.at_msg_receive are called.

        """
        global _SESSIONS
        if not _SESSIONS:
            from src.server.sessionhandler import SESSIONS as _SESSIONS

        text = to_str(text, force_string=True) if text else ""

        if "data" in kwargs:
            # deprecation warning
            logger.log_depmsg(
                "ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead."
            )
            data = kwargs.pop("data")
            if isinstance(data, dict):
                kwargs.update(data)

        if from_obj:
            # call hook
            try:
                _GA(from_obj, "at_msg_send")(text=text,
                                             to_obj=_GA(self, "typeclass"),
                                             **kwargs)
            except Exception:
                logger.log_trace()
        try:
            if not _GA(_GA(self, "typeclass"), "at_msg_receive")(text=text,
                                                                 **kwargs):
                # if at_msg_receive returns false, we abort message to this object
                return
        except Exception:
            logger.log_trace()

        sessions = _SESSIONS.session_from_sessid(
            [sessid] if sessid else make_iter(_GA(self, "sessid").get()))
        for session in sessions:
            session.msg(text=text, **kwargs)
예제 #8
0
파일: models.py 프로젝트: totalgit/evennia
    def msg(self, text=None, from_obj=None, sessid=None, **kwargs):
        """
        Evennia -> User
        This is the main route for sending data back to the user from the
        server.

        outgoing_string (string) - text data to send
        from_obj (Object/Player) - source object of message to send. Its
                 at_msg_send() hook will be called.
        sessid - the session id of the session to send to. If not given, return
                 to all sessions connected to this player. This is usually only
                 relevant when using msg() directly from a player-command (from
                 a command on a Character, the character automatically stores
                 and handles the sessid). Can also be a list of sessids.
        kwargs (dict) - All other keywords are parsed as extra data.
        """
        if "data" in kwargs:
            # deprecation warning
            logger.log_depmsg(
                "PlayerDB:msg() 'data'-dict keyword is deprecated. Use **kwargs instead."
            )
            data = kwargs.pop("data")
            if isinstance(data, dict):
                kwargs.update(data)

        text = to_str(text, force_string=True) if text else ""
        if from_obj:
            # call hook
            try:
                _GA(from_obj, "at_msg_send")(text=text,
                                             to_obj=_GA(self, "typeclass"),
                                             **kwargs)
            except Exception:
                pass
        sessions = _MULTISESSION_MODE > 1 and sessid and _GA(
            self, "get_session")(sessid) or None
        if sessions:
            for session in make_iter(sessions):
                obj = session.puppet
                if obj and not obj.at_msg_receive(text=text, **kwargs):
                    # if hook returns false, cancel send
                    continue
                session.msg(text=text, **kwargs)
        else:
            # if no session was specified, send to them all
            for sess in _GA(self, 'get_all_sessions')():
                sess.msg(text=text, **kwargs)
예제 #9
0
    def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
        """
        Emits something to a session attached to the object.

        message (str): The message to send
        from_obj (obj): object that is sending.
        data (object): an optional data object that may or may not
                       be used by the protocol.
        sessid (int): sessid to relay to, if any.
                      If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
                      If None, echo to all connected sessions

        When this message is called, from_obj.at_msg_send and self.at_msg_receive are called.

        """
        global _SESSIONS
        if not _SESSIONS:
            from src.server.sessionhandler import SESSIONS as _SESSIONS

        text = to_str(text, force_string=True) if text else ""

        if "data" in kwargs:
            # deprecation warning
            logger.log_depmsg("ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead.")
            data = kwargs.pop("data")
            if isinstance(data, dict):
                kwargs.update(data)

        if from_obj:
            # call hook
            try:
                _GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
            except Exception:
                logger.log_trace()
        try:
            if not _GA(_GA(self, "typeclass"), "at_msg_receive")(text=text, **kwargs):
                # if at_msg_receive returns false, we abort message to this object
                return
        except Exception:
            logger.log_trace()

        sessions = _SESSIONS.session_from_sessid([sessid] if sessid else make_iter(_GA(self, "sessid").get()))
        for session in sessions:
            session.msg(text=text, **kwargs)
예제 #10
0
    def msg(self, text=None, from_obj=None, sessid=None, **kwargs):
        """
        Evennia -> User
        This is the main route for sending data back to the user from the
        server.

        outgoing_string (string) - text data to send
        from_obj (Object/Player) - source object of message to send. Its
                 at_msg_send() hook will be called.
        sessid - the session id of the session to send to. If not given, return
                 to all sessions connected to this player. This is usually only
                 relevant when using msg() directly from a player-command (from
                 a command on a Character, the character automatically stores
                 and handles the sessid). Can also be a list of sessids.
        kwargs (dict) - All other keywords are parsed as extra data.
        """
        if "data" in kwargs:
            # deprecation warning
            logger.log_depmsg("PlayerDB:msg() 'data'-dict keyword is deprecated. Use **kwargs instead.")
            data = kwargs.pop("data")
            if isinstance(data, dict):
                kwargs.update(data)

        text = to_str(text, force_string=True) if text else ""
        if from_obj:
            # call hook
            try:
                _GA(from_obj, "at_msg_send")(text=text, to_obj=_GA(self, "typeclass"), **kwargs)
            except Exception:
                pass
        sessions = _MULTISESSION_MODE > 1 and sessid and _GA(self, "get_session")(sessid) or None
        if sessions:
            for session in make_iter(sessions):
                obj = session.puppet
                if obj and not obj.at_msg_receive(text=text, **kwargs):
                    # if hook returns false, cancel send
                    continue
                session.msg(text=text, **kwargs)
        else:
            # if no session was specified, send to them all
            for sess in _GA(self, 'get_all_sessions')():
                sess.msg(text=text, **kwargs)
예제 #11
0
 def emit_to_contents(self, message, exclude=None, from_obj=None, data=None):
     "Deprecated. Alias for msg_contents"
     logger.log_depmsg("emit_to_contents() is deprecated. Use msg_contents() instead.")
     self.msg_contents(message, exclude=exclude, from_obj=from_obj, data=data)
예제 #12
0
 def emit_to(self, message, from_obj=None, data=None):
     "Deprecated. Alias for msg"
     logger.log_depmsg("emit_to() is deprecated. Use msg() instead.")
     _GA(self, "msg")(message, from_obj, data)