当前位置: 首页>>代码示例>>Python>>正文


Python SESSIONS.get_sessions方法代码示例

本文整理汇总了Python中evennia.server.sessionhandler.SESSIONS.get_sessions方法的典型用法代码示例。如果您正苦于以下问题:Python SESSIONS.get_sessions方法的具体用法?Python SESSIONS.get_sessions怎么用?Python SESSIONS.get_sessions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在evennia.server.sessionhandler.SESSIONS的用法示例。


在下文中一共展示了SESSIONS.get_sessions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_weather

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
 def update_weather(self, *args, **kwargs):
     """
     Called by the tickerhandler at regular intervals. Even so, we
     only update 20% of the time, picking a random weather message
     when we do. The tickerhandler requires that this hook accepts
     any arguments and keyword arguments (hence the *args, **kwargs
     even though we don't actually use them in this example)
     """
     slow_room = True
     empty_room = True
     session_list = SESSIONS.get_sessions()
     for session in session_list:
         character = session.get_puppet()
         if not session.logged_in or not character or character.location != self:
             continue
         empty_room = False
         if session.cmd_last_visible > self.ndb.weather_time:
             slow_room = False
             break
     if empty_room:
         return
     if slow_room:
         self.attempt_weather_update(0.05)  # only attempt update 5% of the time
     else:
         self.attempt_weather_update(0.20)
开发者ID:Pinacolada64,项目名称:NOW,代码行数:27,代码来源:rooms.py

示例2: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
 def func(self):
     """returns the list of online characters"""
     count_accounts = (SESSIONS.account_count())
     self.caller.msg("[%s] Through the fog you see:" % self.key)
     session_list = SESSIONS.get_sessions()
     table = evtable.EvTable(border='none')
     table.add_row('Character', 'On for', 'Idle',  'Location')
     for session in session_list:
         if not session.logged_in:
             continue
         delta_cmd = time.time() - session.cmd_last_visible
         delta_conn = time.time() - session.conn_time
         puppet = session.get_puppet()
         location = puppet.location.key if puppet and puppet.location else 'Nothingness'
         table.add_row(puppet.key if puppet else 'None', utils.time_format(delta_conn, 0),
                       utils.time_format(delta_cmd, 1), location)
     table.reformat_column(0, width=25, align='l')
     table.reformat_column(1, width=12, align='l')
     table.reformat_column(2, width=7, align='l')
     table.reformat_column(3, width=25, align='l')
     is_one = count_accounts == 1
     string = '%s' % 'A' if is_one else str(count_accounts)
     string += ' single ' if is_one else ' unique '
     plural = ' is' if is_one else 's are'
     string += 'account%s logged in.' % plural
     self.caller.msg(table)
     self.caller.msg(string)
开发者ID:Pinacolada64,项目名称:NOW,代码行数:29,代码来源:prelogin.py

示例3: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def func(self):
        """
        Get all connected accounts by polling session.
        """

        account = self.account
        session_list = SESSIONS.get_sessions()

        session_list = sorted(session_list, key=lambda o: o.account.key)

        if self.cmdstring == "doing":
            show_session_data = False
        else:
            show_session_data = account.check_permstring("Developer") or account.check_permstring("Admins")

        naccounts = (SESSIONS.account_count())
        if show_session_data:
            # privileged info
            table = evtable.EvTable("|wAccount Name",
                                    "|wOn for",
                                    "|wIdle",
                                    "|wPuppeting",
                                    "|wRoom",
                                    "|wCmds",
                                    "|wProtocol",
                                    "|wHost")
            for session in session_list:
                if not session.logged_in:
                    continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                account = session.get_account()
                puppet = session.get_puppet()
                location = puppet.location.key if puppet and puppet.location else "None"
                table.add_row(utils.crop(account.name, width=25),
                              utils.time_format(delta_conn, 0),
                              utils.time_format(delta_cmd, 1),
                              utils.crop(puppet.key if puppet else "None", width=25),
                              utils.crop(location, width=25),
                              session.cmd_total,
                              session.protocol_key,
                              isinstance(session.address, tuple) and session.address[0] or session.address)
        else:
            # unprivileged
            table = evtable.EvTable("|wAccount name", "|wOn for", "|wIdle")
            for session in session_list:
                if not session.logged_in:
                    continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                account = session.get_account()
                table.add_row(utils.crop(account.key, width=25),
                              utils.time_format(delta_conn, 0),
                              utils.time_format(delta_cmd, 1))
        is_one = naccounts == 1
        self.msg("|wAccounts:|n\n%s\n%s unique account%s logged in."
                 % (table, "One" if is_one else naccounts, "" if is_one else "s"))
开发者ID:RyanStein,项目名称:evennia,代码行数:59,代码来源:account.py

示例4: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def func(self):
        """
        Get all connected players by polling session.
        """

        player = self.player
        session_list = SESSIONS.get_sessions()

        session_list = sorted(session_list, key=lambda o: o.player.key)

        if self.cmdstring == "doing":
            show_session_data = False
        else:
            show_session_data = player.check_permstring("Immortals") or player.check_permstring("Wizards")

        nplayers = (SESSIONS.player_count())
        if show_session_data:
            # privileged info
            table = prettytable.PrettyTable(["{wPlayer Name",
                                             "{wOn for",
                                             "{wIdle",
                                             "{wPuppeting",
                                             "{wRoom",
                                             "{wCmds",
                                             "{wProtocol",
                                             "{wHost"])
            for session in session_list:
                if not session.logged_in: continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                player = session.get_player()
                puppet = session.get_puppet()
                location = puppet.location.key if puppet else "None"
                table.add_row([utils.crop(player.name, width=25),
                               utils.time_format(delta_conn, 0),
                               utils.time_format(delta_cmd, 1),
                               utils.crop(puppet.key if puppet else "None", width=25),
                               utils.crop(location, width=25),
                               session.cmd_total,
                               session.protocol_key,
                               isinstance(session.address, tuple) and session.address[0] or session.address])
        else:
            # unprivileged
            table = prettytable.PrettyTable(["{wPlayer name", "{wOn for", "{wIdle"])
            for session in session_list:
                if not session.logged_in:
                    continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                player = session.get_player()
                table.add_row([utils.crop(player.key, width=25),
                               utils.time_format(delta_conn, 0),
                               utils.time_format(delta_cmd, 1)])

        isone = nplayers == 1
        string = "{wPlayers:{n\n%s\n%s unique account%s logged in." % (table, "One" if isone else nplayers, "" if isone else "s")
        self.msg(string)
开发者ID:Antraeus,项目名称:evennia,代码行数:59,代码来源:player.py

示例5: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def func(self):
        """
        Get all connected players by polling session.
        """

        player = self.player
        session_list = SESSIONS.get_sessions()

        session_list = sorted(session_list, key=lambda o: o.player.key)

        if self.cmdstring == "doing":
            show_session_data = False
        else:
            show_session_data = player.check_permstring("Immortals") or player.check_permstring("Wizards")

        nplayers = (SESSIONS.player_count())
        if show_session_data:
            # privileged info
            table = prettytable.PrettyTable(["{wИмя игрока",
                                             "{wВ игре",
                                             "{wIdle",
                                             "{wУправляет",
                                             "{wКомната",
                                             "{wCmds",
                                             "{wПротокол",
                                             "{wХост"])
            for session in session_list:
                if not session.logged_in: continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                player = session.get_player()
                puppet = session.get_puppet()
                location = puppet.location.key if puppet and puppet.location else "None"
                table.add_row([utils.crop(player.name, width=25),
                               utils.time_format(delta_conn, 0),
                               utils.time_format(delta_cmd, 1),
                               utils.crop(puppet.key if puppet else "None", width=25),
                               utils.crop(location, width=25),
                               session.cmd_total,
                               session.protocol_key,
                               isinstance(session.address, tuple) and session.address[0] or session.address])
        else:
            # unprivileged
            table = prettytable.PrettyTable(["{wИмя игрока", "{wВ игре", "{wIdle"])
            for session in session_list:
                if not session.logged_in:
                    continue
                delta_cmd = time.time() - session.cmd_last_visible
                delta_conn = time.time() - session.conn_time
                player = session.get_player()
                table.add_row([utils.crop(player.key, width=25),
                               utils.time_format(delta_conn, 0),
                               utils.time_format(delta_cmd, 1)])

        isone = nplayers == 1
        string = "{wИгроков:{n\n%s\n%s уникальных аккаунтов%s залогинено." % (table, "Один" if isone else nplayers, "" if isone else "")
        self.msg(string)
开发者ID:Gazzilow,项目名称:mu2ch,代码行数:59,代码来源:command.py

示例6: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def func(self):
        """Implementing the function"""
        caller = self.caller
        args = self.args

        if not args:
            caller.msg("Usage: @boot[/switches] <player> [:reason]")
            return

        if ':' in args:
            args, reason = [a.strip() for a in args.split(':', 1)]
        else:
            args, reason = args, ""

        boot_list = []

        if 'sid' in self.switches:
            # Boot a particular session id.
            sessions = SESSIONS.get_sessions(True)
            for sess in sessions:
                # Find the session with the matching session id.
                if sess.sessid == int(args):
                    boot_list.append(sess)
                    break
        else:
            # Boot by player object
            pobj = search.player_search(args)
            if not pobj:
                caller.msg("Player %s was not found." % args)
                return
            pobj = pobj[0]
            if not pobj.access(caller, 'boot'):
                string = "You don't have the permission to boot %s." % (pobj.key, )
                caller.msg(string)
                return
            # we have a bootable object with a connected user
            matches = SESSIONS.sessions_from_player(pobj)
            for match in matches:
                boot_list.append(match)

        if not boot_list:
            caller.msg("No matching sessions found. The Player does not seem to be online.")
            return

        # Carry out the booting of the sessions in the boot list.

        feedback = None
        if 'quiet' not in self.switches:
            feedback = "You have been disconnected by %s.\n" % caller.name
            if reason:
                feedback += "\nReason given: %s" % reason

        for session in boot_list:
            session.msg(feedback)
            session.player.disconnect_session_from_player(session)
开发者ID:helix-0311,项目名称:evennia,代码行数:57,代码来源:admin.py

示例7: verify_online_player

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
def verify_online_player(caller, value):
    """
    Example 'verify function' that matches player input to an online character
    or else rejects their input as invalid.

    Args:
        caller (obj): Player entering the form data.
        value (str): String player entered into the form, to be verified.

    Returns:
        matched_character (obj or False): dbref to a currently logged in
            character object - reference to the object will be stored in
            the form instead of a string. Returns False if no match is
            made.
    """
    # Get a list of sessions
    session_list = SESSIONS.get_sessions()
    char_list = []
    matched_character = None

    # Get a list of online characters
    for session in session_list:
        if not session.logged_in:
            # Skip over logged out characters
            continue
        # Append to our list of online characters otherwise
        char_list.append(session.get_puppet())

    # Match player input to a character name
    for character in char_list:
        if value.lower() == character.key.lower():
            matched_character = character

    # If input didn't match to a character
    if not matched_character:
        # Send the player an error message unique to this function
        caller.msg("No character matching '%s' is online." % value)
        # Returning False indicates the new value is not valid
        return False

    # Returning anything besides True or False will replace the player's input with the returned
    # value. In this case, the value becomes a reference to the character object. You can store data
    # besides strings and integers in the 'formdata' dictionary this way!
    return matched_character
开发者ID:Henddher,项目名称:evennia,代码行数:46,代码来源:fieldfill.py

示例8: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def func(self):
        """Performs the summon, accounting for in-world conditions."""

        char = self.character
        loc = char.location
        account = self.account
        args = self.args
        lhs, rhs = self.lhs, self.rhs
        # opt = self.switches  # TODO - add code to make the switches work.

        if char and char.ndb.currently_moving:
            account.msg("You can not summon while moving. (|rstop|n, then try again.)")
            return
        if not args:
            char.msg("Could not find target to summon. Usage: summon <character or NPC>")
            return
        session_list = SESSIONS.get_sessions()
        target = []
        for session in session_list:
            if not (session.logged_in and session.get_puppet()):
                continue
            puppet = session.get_puppet()
            if lhs.lower() in puppet.get_display_name(char, plain=True).lower():
                target.append(puppet)
        if len(target) < 1:
            char.msg("Error: character not found.")
            return
        if len(target) > 1:  # Too many partial matches, try exact matching.
            char.msg("Error: character not found.")
            return
        else:
            target[0].msg("You are being summoned to %s " % loc.get_display_name(target[0]) +
                          "by %s" % char.get_display_name(target[0]) +
                          ". A portal should appear soon that will take you to " +
                          "%s." % char.get_display_name(target[0]))
            char.msg("You begin to summon a portal between %s" % target[0].get_display_name(char) +
                     " and your location.")
        # Check the pool for objects to use.  Filter a list of objects tagged "pool" by those located in None.
        obj_pool = [each for each in evennia.search_tag('pool', category='portal') if not each.location]
        print('Object pool total: %i' % len(obj_pool))
        if len(obj_pool) < 2:
            char.msg('Portals are currently out of stock or in use elsewhere.')
            return
        portal_enter, portal_exit = obj_pool[-2:]

        def open_portal():
            """Move inflatable portals into place."""
            portal_enter.move_to(target[0].location)
            portal_exit.move_to(loc)

        delay(10, callback=open_portal)  # 10 seconds later, the portal (exit pair) appears.

        def close_portal():
            """Remove and store inflatable portals in Nothingness."""
            for each in portal_enter.contents:
                each.move_to(target[0].location)
            for each in portal_exit.contents:
                each.move_to(loc)
            portal_enter.location.msg_contents("|r%s|n vanishes into |222Nothingness|n." % portal_enter)
            portal_exit.location.msg_contents("|r%s|n vanishes into |222Nothingness|n." % portal_exit)
            portal_enter.move_to(None, to_none=True)
            portal_exit.move_to(None, to_none=True)

        delay(180, callback=close_portal)  # Wait, then move portal objects to the portal pool in Nothingness
开发者ID:Pinacolada64,项目名称:NOW,代码行数:66,代码来源:summon.py

示例9: execute_cmd

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
    def execute_cmd(self, session=None, txt=None, **kwargs):
        """
        Take incoming data and send it to connected channel. This is
        triggered by the bot_data_in Inputfunc.

        Args:
            session (Session, optional): Session responsible for this
                command. Note that this is the bot.
            txt (str, optional):  Command string.
        Kwargs:
            user (str): The name of the user who sent the message.
            channel (str): The name of channel the message was sent to.
            type (str): Nature of message. Either 'msg', 'action', 'nicklist' or 'ping'.
            nicklist (list, optional): Set if `type='nicklist'`. This is a list of nicks returned by calling
                the `self.get_nicklist`. It must look for a list `self._nicklist_callers`
                which will contain all callers waiting for the nicklist.
            timings (float, optional): Set if `type='ping'`. This is the return (in seconds) of a
                ping request triggered with `self.ping`. The return must look for a list
                `self._ping_callers` which will contain all callers waiting for the ping return.

        """
        if kwargs["type"] == "nicklist":
            # the return of a nicklist request
            if hasattr(self, "_nicklist_callers") and self._nicklist_callers:
                chstr = "%s (%s:%s)" % (self.db.irc_channel, self.db.irc_network, self.db.irc_port)
                nicklist = ", ".join(sorted(kwargs["nicklist"], key=lambda n: n.lower()))
                for obj in self._nicklist_callers:
                    obj.msg("Nicks at %s:\n %s" % (chstr, nicklist))
                self._nicklist_callers = []
            return

        elif kwargs["type"] == "ping":
            # the return of a ping
            if hasattr(self, "_ping_callers") and self._ping_callers:
                chstr = "%s (%s:%s)" % (self.db.irc_channel, self.db.irc_network, self.db.irc_port)
                for obj in self._ping_callers:
                    obj.msg("IRC ping return from %s took %ss." % (chstr, kwargs["timing"]))
                self._ping_callers = []
            return

        elif kwargs["type"] == "privmsg":
            # A private message to the bot - a command.
            user = kwargs["user"]

            if txt.lower().startswith("who"):
                # return server WHO list (abbreviated for IRC)
                global _SESSIONS
                if not _SESSIONS:
                    from evennia.server.sessionhandler import SESSIONS as _SESSIONS
                whos = []
                t0 = time.time()
                for sess in _SESSIONS.get_sessions():
                    delta_cmd = t0 - sess.cmd_last_visible
                    delta_conn = t0 - session.conn_time
                    player = sess.get_player()
                    whos.append("%s (%s/%s)" % (utils.crop("|w%s|n" % player.name, width=25),
                                                utils.time_format(delta_conn, 0),
                                                utils.time_format(delta_cmd, 1)))
                text = "Who list (online/idle): %s" % ", ".join(sorted(whos, key=lambda w: w.lower()))
            elif txt.lower().startswith("about"):
                # some bot info
                text = "This is an Evennia IRC bot connecting from '%s'." % settings.SERVERNAME
            else:
                text = "I understand 'who' and 'about'."
            super(IRCBot, self).msg(privmsg=((text,), {"user": user}))
        else:
            # something to send to the main channel
            if kwargs["type"] == "action":
                # An action (irc pose)
                text = "%[email protected]%s %s" % (kwargs["user"], kwargs["channel"], txt)
            else:
                # msg - A normal channel message
                text = "%[email protected]%s: %s" % (kwargs["user"], kwargs["channel"], txt)

            if not self.ndb.ev_channel and self.db.ev_channel:
                # cache channel lookup
                self.ndb.ev_channel = self.db.ev_channel
            if self.ndb.ev_channel:
                self.ndb.ev_channel.msg(text, senders=self.id)
开发者ID:helix-0311,项目名称:evennia,代码行数:81,代码来源:bots.py

示例10: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
 def func(self):
     """Get all connected players by polling session."""
     player = self.player
     session_list = SESSIONS.get_sessions()
     session_list = sorted(session_list, key=lambda o: o.player.key)
     show_session_data = player.check_permstring('Immortals') if 'f' in self.switches else False
     nplayers = (SESSIONS.player_count())
     if 'f' in self.switches or 'full' in self.switches:
         if show_session_data:
             # privileged info - who/f by wizard or immortal
             table = prettytable.PrettyTable(["|wPlayer Name",
                                              "|wOn for",
                                              "|wIdle",
                                              "|wCharacter",
                                              "|wRoom",
                                              "|wCmds",
                                              "|wProtocol",
                                              "|wHost"])
             for session in session_list:
                 if not session.logged_in:
                     continue
                 delta_cmd = time.time() - session.cmd_last_visible
                 delta_conn = time.time() - session.conn_time
                 player = session.get_player()
                 puppet = session.get_puppet()
                 location = puppet.location.key if puppet else 'None'
                 table.add_row([utils.crop(player.name, width=25),
                                utils.time_format(delta_conn, 0),
                                utils.time_format(delta_cmd, 1),
                                utils.crop(puppet.key if puppet else 'None', width=25),
                                utils.crop(location, width=25),
                                session.cmd_total,
                                session.protocol_key,
                                isinstance(session.address, tuple) and session.address[0] or session.address])
         else:  # unprivileged info - who/f by player
             table = prettytable.PrettyTable(["|wCharacter", "|wOn for", "|wIdle", "|wLocation"])
             for session in session_list:
                 if not session.logged_in:
                     continue
                 delta_cmd = time.time() - session.cmd_last_visible
                 delta_conn = time.time() - session.conn_time
                 character = session.get_puppet()
                 location = character.location.key if character and character.location else 'None'
                 table.add_row([utils.crop(character.key if character else '- Unknown -', width=25),
                                utils.time_format(delta_conn, 0),
                                utils.time_format(delta_cmd, 1),
                                utils.crop(location, width=25)])
     else:
         if 's' in self.switches or 'species' in self.switches or self.cmdstring == 'ws':
             my_character = self.caller.get_puppet(self.session)
             if not (my_character and my_character.location):
                 self.msg("You can't see anyone here.")
                 return
             table = prettytable.PrettyTable(["|wCharacter", "|wOn for", "|wIdle", "|wSpecies"])
             for session in session_list:
                 character = session.get_puppet()
                 # my_character = self.caller.get_puppet(self.session)
                 if not session.logged_in or character.location != my_character.location:
                     continue
                 delta_cmd = time.time() - session.cmd_last_visible
                 delta_conn = time.time() - session.conn_time
                 character = session.get_puppet()
                 species = character.attributes.get('species', default='- None -')
                 table.add_row([utils.crop(character.key if character else '- Unknown -', width=25),
                                utils.time_format(delta_conn, 0),
                                utils.time_format(delta_cmd, 1),
                                utils.crop(species, width=25)])
         else:  # unprivileged info - who
             table = prettytable.PrettyTable(["|wCharacter", "|wOn for", "|wIdle"])
             for session in session_list:
                 if not session.logged_in:
                     continue
                 delta_cmd = time.time() - session.cmd_last_visible
                 delta_conn = time.time() - session.conn_time
                 character = session.get_puppet()
                 table.add_row([utils.crop(character.key if character else '- Unknown -', width=25),
                                utils.time_format(delta_conn, 0),
                                utils.time_format(delta_cmd, 1)])
     isone = nplayers == 1
     string = "%s\n%s " % (table, 'A' if isone else nplayers)
     string += 'single' if isone else 'unique'
     plural = '' if isone else 's'
     string += " account%s logged in." % plural
     self.msg(string)
开发者ID:carriercomm,项目名称:NOW-2,代码行数:86,代码来源:command.py

示例11: func

# 需要导入模块: from evennia.server.sessionhandler import SESSIONS [as 别名]
# 或者: from evennia.server.sessionhandler.SESSIONS import get_sessions [as 别名]
 def func(self):
     """Get all connected accounts by polling session."""
     you = self.account
     session_list = SESSIONS.get_sessions()
     cmd = self.cmdstring
     show_session_data = you.check_permstring('Immortals') and not you.attributes.has('_quell')
     account_count = (SESSIONS.account_count())
     table = evtable.EvTable(border='none', pad_width=0, border_width=0, maxwidth=79)
     if cmd == 'wa' or cmd == 'where':
         # Example output expected:
         # Occ, Location,  Avg Time, Top 3 Active, Directions
         # #3 	Park 		5m 		Rulan, Amber, Tria		Taxi, Park
         # Other possible sort methods: Alphabetical by name, by occupant count, by activity, by distance
         # Nick = Global Nick (no greater than five A/N or randomly created if not a Global Nick
         #
         # WA with name parameters to pull up more extensive information about the direction
         # Highest Occupants (since last reboot), Last Visited, Last Busy (3+) etc. (more ideas here)
         table.add_header('|wOcc', '|wLocation', '|wAvg Time', '|cTop 3 Active', '|gDirections')
         table.reformat_column(0, width=4, align='l')
         table.reformat_column(1, width=25, align='l')
         table.reformat_column(2, width=6, align='l')
         table.reformat_column(3, width=16, pad_right=1, align='l')
         table.reformat_column(4, width=20, align='l')
         locations = {}  # Create an empty dictionary to gather locations information.
         for session in session_list:  # Go through connected list and see who's where.
             if not session.logged_in:
                 continue
             character = session.get_puppet()
             if not character:
                 continue
             if character.location not in locations:
                 locations[character.location] = []
             locations[character.location].append(character)  # Build the list of who's in a location
         for place in locations:
             location = place.get_display_name(you) if place else '|222Nothingness|n'
             table.add_row(len(locations[place]), location, '?',
                           ', '.join(each.get_display_name(you) for each in locations[place]),
                           'Summon or walk')
     elif cmd == 'ws':
         my_character = self.caller.get_puppet(self.session)
         if not (my_character and my_character.location):
             self.msg("You can't see anyone here.")
             return
         table.add_header('|wCharacter', '|wOn for', '|wIdle')
         table.reformat_column(0, width=45, align='l')
         table.reformat_column(1, width=8, align='l')
         table.reformat_column(2, width=7, pad_right=1, align='r')
         for element in my_character.location.contents:
             if not element.has_account:
                 continue
             delta_cmd = time.time() - max([each.cmd_last_visible for each in element.sessions.all()])
             delta_con = time.time() - min([each.conn_time for each in element.sessions.all()])
             name = element.get_display_name(you)
             type = element.attributes.get('species', default='')
             table.add_row(name + ', ' + type if type else name,
                           utils.time_format(delta_con, 0), utils.time_format(delta_cmd, 1))
     elif cmd == 'what' or cmd == 'wot':
         table.add_header('|wCharacter  - Doing', '|wIdle')
         table.reformat_column(0, width=72, align='l')
         table.reformat_column(1, width=7, align='r')
         for session in session_list:
             if not session.logged_in or not session.get_puppet():
                 continue
             delta_cmd = time.time() - session.cmd_last_visible
             character = session.get_puppet()
             doing = character.get_display_name(you, pose=True)
             table.add_row(doing, utils.time_format(delta_cmd, 1))
     else:  # Default to displaying who
         if show_session_data:  # privileged info shown to Immortals and higher only when not quelled
             table.add_header('|wCharacter', '|wAccount', '|wQuell', '|wCmds', '|wProtocol', '|wAddress')
             table.reformat_column(0, align='l')
             table.reformat_column(1, align='r')
             table.reformat_column(2, width=7, align='r')
             table.reformat_column(3, width=6, pad_right=1, align='r')
             table.reformat_column(4, width=11, align='l')
             table.reformat_column(5, width=16, align='r')
             session_list = sorted(session_list, key=lambda o: o.account.key)
             for session in session_list:
                 if not session.logged_in:
                     continue
                 account = session.get_account()
                 puppet = session.get_puppet()
                 table.add_row(puppet.get_display_name(you) if puppet else 'None',
                               account.get_display_name(you),
                               '|gYes|n' if account.attributes.get('_quell') else '|rNo|n',
                               session.cmd_total, session.protocol_key,
                               isinstance(session.address, tuple) and session.address[0] or session.address)
         else:  # unprivileged info shown to everyone, including Immortals and higher when quelled
             table.add_header('|wCharacter', '|wOn for', '|wIdle')
             table.reformat_column(0, width=40, align='l')
             table.reformat_column(1, width=8, align='l')
             table.reformat_column(2, width=7, align='r')
             for session in session_list:
                 if not session.logged_in:
                     continue
                 delta_cmd = time.time() - session.cmd_last_visible
                 delta_conn = time.time() - session.conn_time
                 character = session.get_puppet()
                 if not character:
                     continue
#.........这里部分代码省略.........
开发者ID:Pinacolada64,项目名称:NOW,代码行数:103,代码来源:who.py


注:本文中的evennia.server.sessionhandler.SESSIONS.get_sessions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。