Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
def format_script_list(scripts):
    "Takes a list of scripts and formats the output."
    if not scripts:
        return "<No scripts>"

    table = EvTable("{wdbref{n", "{wobj{n", "{wkey{n", "{wintval{n", "{wnext{n",
                    "{wrept{n", "{wdb", "{wtypeclass{n", "{wdesc{n",
                    align='r', border="tablecols")
    for script in scripts:
        nextrep = script.time_until_next_repeat()
        if nextrep is None:
            nextrep = "PAUS" if script.db._paused_time else "--"
        else:
            nextrep = "%ss" % nextrep

        maxrepeat = script.repeats
        if maxrepeat:
            rept = "%i/%i" % (maxrepeat - script.remaining_repeats(), maxrepeat)
        else:
            rept = "-/-"

        table.add_row(script.id,
                      script.obj.key if (hasattr(script, 'obj') and script.obj) else "<Global>",
                      script.key,
                      script.interval if script.interval > 0 else "--",
                      nextrep,
                      rept,
                      "*" if script.persistent else "-",
                      script.typeclass_path.rsplit('.', 1)[-1],
                      crop(script.desc, width=20))
    return "%s" % table
Esempio n. 4
0
 def __str__(self):
     "This handles what is shown when e.g. printing the message"
     senders = ",".join(obj.key for obj in self.senders)
     receivers = ",".join(["[%s]" % obj.key for obj in self.channels] +
                          [obj.key for obj in self.receivers])
     return "%s->%s: %s" % (senders, receivers, crop(self.message,
                                                     width=40))
Esempio n. 5
0
def format_script_list(scripts):
    "Takes a list of scripts and formats the output."
    if not scripts:
        return "<No scripts>"

    table = EvTable("{wdbref{n", "{wobj{n", "{wkey{n", "{wintval{n", "{wnext{n",
                    "{wrept{n", "{wdb", "{wtypeclass{n", "{wdesc{n",
                    align='r', border="tablecols")
    for script in scripts:
        nextrep = script.time_until_next_repeat()
        if nextrep is None:
            nextrep = "PAUS" if script.db._paused_time else "--"
        else:
            nextrep = "%ss" % nextrep

        maxrepeat = script.repeats
        if maxrepeat:
            rept = "%i/%i" % (maxrepeat - script.remaining_repeats(), maxrepeat)
        else:
            rept = "-/-"

        table.add_row(script.id,
                      script.obj.key if (hasattr(script, 'obj') and script.obj) else "<Global>",
                      script.key,
                      script.interval if script.interval > 0 else "--",
                      nextrep,
                      rept,
                      "*" if script.persistent else "-",
                      script.typeclass_path.rsplit('.', 1)[-1],
                      crop(script.desc, width=20))
    return "%s" % table
Esempio n. 6
0
def crop(text, *args, **kwargs):
    "Crop to width. crop(text, width=78, suffix='[...]')"
    width = 78
    suffix = "[...]"
    for iarg, arg in enumerate(args):
        if iarg == 0:
            width = int(arg) if arg.isdigit() else width
        elif iarg == 1:
            suffix = arg
        else:
            break
    return utils.crop(text, width=width, suffix=suffix)
Esempio n. 7
0
def crop(text, *args, **kwargs):
    "Crop to width. crop(text, width=78, suffix='[...]')"
    width = 78
    suffix = "[...]"
    for iarg, arg in enumerate(args):
        if iarg == 0:
            width = int(arg) if arg.isdigit() else width
        elif iarg == 1:
            suffix = arg
        else:
            break
    return utils.crop(text, width=width, suffix=suffix)
Esempio n. 8
0
def format_header(caller, entry):
    """
    Formats a header
    """
    width = _HEADER_WIDTH - 10
    entry = entry.strip()
    header = utils.crop(entry, width=width)
    ptr = caller.ndb.batch_stackptr + 1
    stacklen = len(caller.ndb.batch_stack)
    header = "{w%02i/%02i{G: %s{n" % (ptr, stacklen, header)
    # add extra space to the side for padding.
    header = "%s%s" % (header, " "*(width - len(header)))
    header = header.replace('\n', '\\n')

    return header
Esempio n. 9
0
def format_header(caller, entry):
    """
    Formats a header
    """
    width = _HEADER_WIDTH - 10
    entry = entry.strip()
    header = utils.crop(entry, width=width)
    ptr = caller.ndb.batch_stackptr + 1
    stacklen = len(caller.ndb.batch_stack)
    header = "{w%02i/%02i{G: %s{n" % (ptr, stacklen, header)
    # add extra space to the side for padding.
    header = "%s%s" % (header, " " * (width - len(header)))
    header = header.replace('\n', '\\n')

    return header
Esempio n. 10
0
 def test_crop(self):
     # No text, return no text
     self.assertEqual("", utils.crop("", width=10, suffix="[...]"))
     # Input length equal to max width, no crop
     self.assertEqual("0123456789", utils.crop("0123456789", width=10, suffix="[...]"))
     # Input length greater than max width, crop (suffix included in width)
     self.assertEqual("0123[...]", utils.crop("0123456789", width=9, suffix="[...]"))
     # Input length less than desired width, no crop
     self.assertEqual("0123", utils.crop("0123", width=9, suffix="[...]"))
     # Width too small or equal to width of suffix
     self.assertEqual("012", utils.crop("0123", width=3, suffix="[...]"))
     self.assertEqual("01234", utils.crop("0123456", width=5, suffix="[...]"))
Esempio n. 11
0
 def func(self):
     "check inventory"
     items = self.caller.contents
     if not items:
         string = "You are not carrying anything."
     else:
         # format item list into nice collumns
         cols = [[],[]]
         for item in items:
             cols[0].append(item.name)
             desc = item.db.desc
             if not desc:
                 desc = ""
             cols[1].append(utils.crop(str(desc)))
         # auto-format the columns to make them evenly wide
         ftable = utils.format_table(cols)
         string = "You are carrying:"
         for row in ftable:
             string += "\n " + "{C%s{n - %s" % (row[0], row[1])
     self.caller.msg(string)
 def test_crop(self):
     # No text, return no text
     self.assertEqual("", utils.crop("", width=10, suffix="[...]"))
     # Input length equal to max width, no crop
     self.assertEqual("0123456789",
                      utils.crop("0123456789", width=10, suffix="[...]"))
     # Input length greater than max width, crop (suffix included in width)
     self.assertEqual("0123[...]",
                      utils.crop("0123456789", width=9, suffix="[...]"))
     # Input length less than desired width, no crop
     self.assertEqual("0123", utils.crop("0123", width=9, suffix="[...]"))
     # Width too small or equal to width of suffix
     self.assertEqual("012", utils.crop("0123", width=3, suffix="[...]"))
     self.assertEqual("01234", utils.crop("0123456",
                                          width=5,
                                          suffix="[...]"))
Esempio n. 13
0
 def __str__(self):
     "This handles what is shown when e.g. printing the message"
     senders = ",".join(obj.key for obj in self.senders)
     receivers = ",".join(["[%s]" % obj.key for obj in self.channels] + [obj.key for obj in self.receivers])
     return "%s->%s: %s" % (senders, receivers, crop(self.message, width=40))