示例#1
0
    def execute_cmd(self, raw_string):
        """
        Do something as this object. This command transparently
        lets its typeclass execute the command. Evennia also calls
        this method whenever the player sends a command on the command line.

        Argument:
        raw_string (string) - raw command input

        Returns Deferred - this is an asynchronous Twisted object that will
            not fire until the command has actually finished executing. To overload
            this one needs to attach callback functions to it, with addCallback(function).
            This function will be called with an eventual return value from the command
            execution.

            This return is not used at all by Evennia by default, but might be useful
            for coders intending to implement some sort of nested command structure.
        """
        # nick replacement - we require full-word matching.

        # do text encoding conversion
        raw_string = to_unicode(raw_string)

        raw_list = raw_string.split(None)
        raw_list = [" ".join(raw_list[:i+1]) for i in range(len(raw_list)) if raw_list[:i+1]]
        nicks = ObjectNick.objects.filter(db_obj=self, db_type__in=("inputline", "channel"))
        if self.has_player:
            nicks = list(nicks) + list(PlayerNick.objects.filter(db_obj=self.db_player, db_type__in=("inputline","channel")))
        for nick in nicks:
            if nick.db_nick in raw_list:
                raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1)
                break
        return cmdhandler.cmdhandler(_GA(self, "typeclass"), raw_string)
示例#2
0
文件: models.py 项目: Aumnren/evennia
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this player. This method is never called normally,
        but only when the player object itself is supposed to execute the
        command. It does not take nicks on eventual puppets into account.

        raw_string - raw command input coming from the command line.
        """
        # nick replacement - we require full-word matching.

        raw_string = utils.to_unicode(raw_string)

        raw_list = raw_string.split(None)
        raw_list = [" ".join(raw_list[:i + 1]) for i in range(len(raw_list)) if raw_list[:i + 1]]
        # get the nick replacement data directly from the database to be
        # able to use db_category__in
        nicks = self.db_attributes.filter(db_category__in=("nick_inputline", "nick_channel"))
        for nick in nicks:
            if nick.db_key in raw_list:
                raw_string = raw_string.replace(nick.db_key, nick.db_strvalue, 1)
                break
        if not sessid and _MULTISESSION_MODE in (0, 1):
            # in this case, we should either have only one sessid, or the sessid
            # should not matter (since the return goes to all of them we can
            # just use the first one as the source)
            sessid = self.get_all_sessions()[0].sessid
        return cmdhandler.cmdhandler(self.typeclass, raw_string,
                                     callertype="player", sessid=sessid)
示例#3
0
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this object. This method is a copy of the execute_
        cmd method on the session. This is never called normally, it's only
        used when wanting specifically to let an object be the caller of a
        command. It makes use of nicks of eventual connected players as well.

        Argument:
        raw_string (string) - raw command input
        sessid (int) - optional session id to return results to

        Returns Deferred - this is an asynchronous Twisted object that will
            not fire until the command has actually finished executing. To
            overload this one needs to attach callback functions to it, with
            addCallback(function). This function will be called with an
            eventual return value from the command execution.

            This return is not used at all by Evennia by default, but might
            be useful for coders intending to implement some sort of nested
            command structure.
        """
        # nick replacement - we require full-word matching.

        # do text encoding conversion
        raw_string = to_unicode(raw_string)
        raw_string = self.nicks.nickreplace(raw_string, categories=("inputline", "channel"), include_player=True)
        return cmdhandler.cmdhandler(_GA(self, "typeclass"), raw_string, callertype="object", sessid=sessid)
示例#4
0
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this object. This method is a copy of the execute_
        cmd method on the session. This is never called normally, it's only
        used when wanting specifically to let an object be the caller of a
        command. It makes use of nicks of eventual connected players as well.

        Argument:
        raw_string (string) - raw command input
        sessid (int) - optional session id to return results to

        Returns Deferred - this is an asynchronous Twisted object that will
            not fire until the command has actually finished executing. To
            overload this one needs to attach callback functions to it, with
            addCallback(function). This function will be called with an
            eventual return value from the command execution.

            This return is not used at all by Evennia by default, but might
            be useful for coders intending to implement some sort of nested
            command structure.
        """
        # nick replacement - we require full-word matching.

        # do text encoding conversion
        raw_string = to_unicode(raw_string)
        raw_string = self.nicks.nickreplace(raw_string,
                                            categories=("inputline",
                                                        "channel"),
                                            include_player=True)
        return cmdhandler.cmdhandler(_GA(self, "typeclass"),
                                     raw_string,
                                     callertype="object",
                                     sessid=sessid)
示例#5
0
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this player. This method is never called normally,
        but only when the player object itself is supposed to execute the
        command. It takes player nicks into account, but not nicks of
        eventual puppets.

        raw_string - raw command input coming from the command line.
        """
        raw_string = utils.to_unicode(raw_string)
        raw_string = self.nicks.nickreplace(raw_string,
                                            categories=("inputline",
                                                        "channel"),
                                            include_player=False)
        if not sessid and _MULTISESSION_MODE in (0, 1):
            # in this case, we should either have only one sessid, or the sessid
            # should not matter (since the return goes to all of them we can
            # just use the first one as the source)
            try:
                sessid = self.get_all_sessions()[0].sessid
            except IndexError:
                # this can happen for bots
                sessid = None
        return cmdhandler.cmdhandler(self.typeclass,
                                     raw_string,
                                     callertype="player",
                                     sessid=sessid)
示例#6
0
    def execute_cmd(self, raw_string, sessid=None, **kwargs):
        """
        Do something as this player. This method is never called normally,
        but only when the player object itself is supposed to execute the
        command. It takes player nicks into account, but not nicks of
        eventual puppets.

        raw_string - raw command input coming from the command line.
        sessid - the optional session id to be responsible for the command-send
        **kwargs - other keyword arguments will be added to the found command
                   object instace as variables before it executes. This is
                   unused by default Evennia but may be used to set flags and
                   change operating paramaters for commands at run-time.
        """
        raw_string = utils.to_unicode(raw_string)
        raw_string = self.nicks.nickreplace(raw_string,
                          categories=("inputline", "channel"), include_player=False)
        if not sessid and _MULTISESSION_MODE in (0, 1):
            # in this case, we should either have only one sessid, or the sessid
            # should not matter (since the return goes to all of them we can
            # just use the first one as the source)
            try:
                sessid = self.get_all_sessions()[0].sessid
            except IndexError:
                # this can happen for bots
                sessid = None
        return cmdhandler.cmdhandler(self.typeclass, raw_string,
                                     callertype="player", sessid=sessid, **kwargs)
示例#7
0
    def data_in(self, text=None, **kwargs):
        """
        Send User->Evennia. This will in effect
        execute a command string on the server.

        Especially handled keywords:

        oob - this should hold a dictionary of oob command calls from
              the oob-supporting protocol.
        """
        if text:
            # this is treated as a command input
            text = to_unicode(text)
            # handle the 'idle' command
            if text.strip() == IDLE_COMMAND:
                self.update_session_counters(idle=True)
                return
            if self.player:
                # nick replacement
                puppet = self.player.get_puppet(self.sessid)
                if puppet:
                    text = puppet.nicks.nickreplace(text,
                                                    categories=("inputline",
                                                                "channel"),
                                                    include_player=True)
                else:
                    text = self.player.nicks.nickreplace(
                        text,
                        categories=("inputline", "channels"),
                        include_player=False)
            cmdhandler.cmdhandler(self,
                                  text,
                                  callertype="session",
                                  sessid=self.sessid)
            self.update_session_counters()
        if "oob" in kwargs:
            # handle oob instructions
            global _OOB_HANDLER
            if not _OOB_HANDLER:
                from src.server.oobhandler import OOB_HANDLER as _OOB_HANDLER
            oobstruct = self.sessionhandler.oobstruct_parser(
                kwargs.pop("oob", None))
            #print "session.data_in: oobstruct:",oobstruct
            for (funcname, args, kwargs) in oobstruct:
                if funcname:
                    _OOB_HANDLER.execute_cmd(self, funcname, *args, **kwargs)
示例#8
0
 def data_in(self, command_string):
     """
     Send Player->Evennia. This will in effect
     execute a command string on the server.
     Eventual extra data moves through oob_data_in
     """
     # handle the 'idle' command
     if str(command_string).strip() == IDLE_COMMAND:
         self.update_session_counters(idle=True)
         return
     if self.logged_in:
         # the inmsg handler will relay to the right place
         self.player.inmsg(command_string, self)
     else:
         # we are not logged in. Execute cmd with the the session directly
         # (it uses the settings.UNLOGGEDIN cmdset)
         cmdhandler.cmdhandler(self, command_string, sessid=self.sessid)
     self.update_session_counters()
示例#9
0
    def data_in(self, text=None, **kwargs):
        """
        Send User->Evennia. This will in effect
        execute a command string on the server.

        Especially handled keywords:

        oob - this should hold a dictionary of oob command calls from
              the oob-supporting protocol.
        """
        #explicitly check for None since text can be an empty string, which is
        #also valid
        if text is not None:
            # this is treated as a command input
            #text = to_unicode(escape_control_sequences(text), encoding=self.encoding)
            # handle the 'idle' command
            if text.strip() == IDLE_COMMAND:
                self.update_session_counters(idle=True)
                return
            if self.player:
                # nick replacement
                puppet = self.player.get_puppet(self.sessid)
                if puppet:
                    text = puppet.nicks.nickreplace(text,
                                  categories=("inputline", "channel"), include_player=True)
                else:
                    text = self.player.nicks.nickreplace(text,
                                categories=("inputline", "channels"), include_player=False)
            cmdhandler(self, text, callertype="session", sessid=self.sessid)
            self.update_session_counters()
        if "oob" in kwargs:
            # handle oob instructions
            global _OOB_HANDLER
            if not _OOB_HANDLER:
                from src.server.oobhandler import OOB_HANDLER as _OOB_HANDLER
            oobstruct = self.sessionhandler.oobstruct_parser(kwargs.pop("oob", None))
            #print "session.data_in: oobstruct:",oobstruct
            for (funcname, args, kwargs) in oobstruct:
                if funcname:
                    _OOB_HANDLER.execute_cmd(self, funcname, *args, **kwargs)
示例#10
0
    def execute_cmd(self, command_string):
        """
        Execute a command string on the server.
        """
        # handle the 'idle' command
        if str(command_string).strip() == IDLE_COMMAND:
            self.update_session_counters(idle=True)
            return

        # all other inputs, including empty inputs
        character = self.get_character()
        if character:
            character.execute_cmd(command_string)
        else:
            if self.logged_in:
                # there is no character, but we are logged in. Use player instead.
                self.get_player().execute_cmd(command_string)
            else:
                # we are not logged in. Use the session directly
                # (it uses the settings.UNLOGGEDIN cmdset)
                cmdhandler.cmdhandler(self, command_string)
        self.update_session_counters()
示例#11
0
 def data_in(self, text=None, **kwargs):
     """
     Send User->Evennia. This will in effect
     execute a command string on the server.
     Eventual extra data moves through oob_data_in
     """
     if text:
         # this is treated as a command input
         text = to_str(text)
         # handle the 'idle' command
         if text.strip() == IDLE_COMMAND:
             self.update_session_counters(idle=True)
             return
         if self.player:
             # nick replacement
             nicks = self.player.db_attributes.filter(db_category__in=("nick_inputline", "nick_channel"))
             puppet = self.player.get_puppet(self.sessid)
             if puppet:
                 # merge, give prio to the lowest level (puppet)
                 nicks = list(puppet.db_attributes.filter(db_category__in=("nick_inputline", "nick_channel"))) + list(nicks)
             raw_list = text.split(None)
             raw_list = [" ".join(raw_list[:i + 1])
                           for i in range(len(raw_list)) if raw_list[:i + 1]]
             for nick in nicks:
                 if nick.db_key in raw_list:
                     text = text.replace(nick.db_key, nick.db_strvalue, 1)
                     break
         cmdhandler.cmdhandler(self, text, callertype="session", sessid=self.sessid)
         self.update_session_counters()
     if "oob" in kwargs:
         # handle oob instructions
         global _OOB_HANDLER
         if not _OOB_HANDLER:
             from src.server.oobhandler import OOB_HANDLER as _OOB_HANDLER
         oobstruct = self.sessionhandler.oobstruct_parser(kwargs.pop("oob", None))
         for (funcname, args, kwargs) in oobstruct:
             if funcname:
                 _OOB_HANDLER.execute_cmd(self, funcname, *args, **kwargs)
示例#12
0
    def execute_cmd(self, raw_string):
        """
        Do something as this player. This command transparently
        lets its typeclass execute the command.
        raw_string - raw command input coming from the command line.
        """
        # nick replacement - we require full-word matching.

        raw_string = utils.to_unicode(raw_string)

        raw_list = raw_string.split(None)
        raw_list = [" ".join(raw_list[:i+1]) for i in range(len(raw_list)) if raw_list[:i+1]]
        for nick in PlayerNick.objects.filter(db_obj=self, db_type__in=("inputline","channel")):
            if nick.db_nick in raw_list:
                raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1)
                break
        return cmdhandler.cmdhandler(self.typeclass, raw_string)
示例#13
0
文件: models.py 项目: Aumnren/evennia
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this object. This method is a copy of the execute_
        cmd method on the session. This is never called normally, it's only
        used when wanting specifically to let an object be the caller of a
        command. It makes use of nicks of eventual connected players as well.

        Argument:
        raw_string (string) - raw command input
        sessid (int) - optional session id to return results to

        Returns Deferred - this is an asynchronous Twisted object that will
            not fire until the command has actually finished executing. To
            overload this one needs to attach callback functions to it, with
            addCallback(function). This function will be called with an
            eventual return value from the command execution.

            This return is not used at all by Evennia by default, but might
            be useful for coders intending to implement some sort of nested
            command structure.
        """
        # nick replacement - we require full-word matching.

        # do text encoding conversion
        raw_string = to_unicode(raw_string)

        raw_list = raw_string.split(None)
        raw_list = [" ".join(raw_list[:i + 1]) for i in range(len(raw_list))
                                                        if raw_list[:i + 1]]
        # fetch the nick data efficiently
        nicks = self.db_attributes.filter(db_category__in=("nick_inputline", "nick_channel"))
        if self.has_player:
            # attach player nicks as well, but after the object-level nicks
            nicks = list(nicks) + list(self.player.db_attributes.filter(db_category__in=("nick_inputline", "nick_channel")))
        for nick in nicks:
            if nick.db_key in raw_list:
                raw_string = raw_string.replace(nick.db_key, nick.db_strvalue, 1)
                break
        return cmdhandler.cmdhandler(_GA(self, "typeclass"), raw_string, callertype="object", sessid=sessid)
示例#14
0
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this player. This command transparently
        lets its typeclass execute the command.
        raw_string - raw command input coming from the command line.
        """
        # nick replacement - we require full-word matching.

        raw_string = utils.to_unicode(raw_string)

        raw_list = raw_string.split(None)
        raw_list = [" ".join(raw_list[: i + 1]) for i in range(len(raw_list)) if raw_list[: i + 1]]
        for nick in PlayerNick.objects.filter(db_obj=self, db_type__in=("inputline", "channel")):
            if nick.db_nick in raw_list:
                raw_string = raw_string.replace(nick.db_nick, nick.db_real, 1)
                break
        if not sessid and _MULTISESSION_MODE in (0, 1):
            # in this case, we should either have only one sessid, or the sessid
            # should not matter (since the return goes to all of them we can just
            # use the first one as the source)
            sessid = self.get_all_sessions()[0].sessid
        return cmdhandler.cmdhandler(self.typeclass, raw_string, sessid=sessid)
示例#15
0
    def execute_cmd(self, raw_string, sessid=None):
        """
        Do something as this player. This method is never called normally,
        but only when the player object itself is supposed to execute the
        command. It takes player nicks into account, but not nicks of
        eventual puppets.

        raw_string - raw command input coming from the command line.
        """
        raw_string = utils.to_unicode(raw_string)
        raw_string = self.nicks.nickreplace(raw_string,
                          categories=("inputline", "channel"), include_player=False)
        if not sessid and _MULTISESSION_MODE in (0, 1):
            # in this case, we should either have only one sessid, or the sessid
            # should not matter (since the return goes to all of them we can
            # just use the first one as the source)
            try:
                sessid = self.get_all_sessions()[0].sessid
            except IndexError:
                # this can happen for bots
                sessid = None
        return cmdhandler.cmdhandler(self.typeclass, raw_string,
                                     callertype="player", sessid=sessid)