From 6f3f150442f5cbbe3dcea4b1b569a256d14ba07c Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sun, 3 Dec 2006 02:44:17 +0000 Subject: [PATCH] A MUX style wiz WHO command. Will get around to making the non-staff version once we've got enough work done to merit it. --- evennia/trunk/commands_general.py | 26 ++++++++++-- evennia/trunk/functions_general.py | 63 ++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 evennia/trunk/functions_general.py diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index 693b03e26c..5a482bd1db 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -1,4 +1,6 @@ import settings +import time +import functions_general from ansi import * """ @@ -39,9 +41,25 @@ def do_who(cdat): session_list = cdat['server'].session_list session = cdat['session'] - retval = "Player Name\n\r" + retval = "Player Name On For Idle Room Cmds Host\n\r" for player in session_list: - retval += '%s\n\r' % (player,) + delta_cmd = time.time() - player.cmd_last + delta_conn = time.time() - player.conn_time + + retval += '%-16s%9s %4s%-3s#%-6d%5d%3s%-25s\r\n' % \ + (player.name, \ + # On-time + functions_general.time_format(delta_conn,0), \ + # Idle time + functions_general.time_format(delta_cmd,1), \ + # Flags + '', \ + # Location + player.pobject.location.id, \ + player.cmd_total, \ + # More flags? + '', \ + player.address[0]) retval += '%d Players logged in.' % (len(session_list),) session.msg(retval) @@ -52,10 +70,10 @@ def do_say(cdat): """ session_list = cdat['server'].session_list session = cdat['session'] - speech = cdat['uinput']['splitted'][1:] + speech = ''.join(cdat['uinput']['splitted'][1:]) players_present = [player for player in session_list if player.player_loc == session.player_loc and player != session] - retval = "You say, '%s'" % (''.join(speech),) + retval = "You say, '%s'" % (speech,) for player in players_present: player.msg("%s says, '%s'" % (session.name, speech,)) diff --git a/evennia/trunk/functions_general.py b/evennia/trunk/functions_general.py new file mode 100644 index 0000000000..402b47e05f --- /dev/null +++ b/evennia/trunk/functions_general.py @@ -0,0 +1,63 @@ +""" +General commonly used functions. +""" + +def time_format(seconds, style=0): + """ + Function to return a 'prettified' version of a value in seconds. + + Style 0: 1d 08:30 + Style 1: 1d + Style 2: 1 day, 8 hours, 30 minutes, 10 seconds + """ + if seconds < 0: + seconds = 0 + else: + # We'll just use integer math, no need for decimal precision. + seconds = int(seconds) + + days = seconds / 86400 + seconds -= days * 86400 + hours = seconds / 3600 + seconds -= hours * 3600 + minutes = seconds / 60 + seconds -= minutes * 60 + + if style is 0: + """ + Standard colon-style output. + """ + if days > 0: + retval = '%id %02i:%02i' % (days, hours, minutes,) + else: + retval = '%02i:%02i' % (hours, minutes,) + + return retval + elif style is 1: + """ + Simple, abbreviated form that only shows the highest time amount. + """ + if days > 0: + return '%id' % (days,) + elif hours > 0: + return '%ih' % (hours,) + elif minutes > 0: + return '%im' % (minutes,) + else: + return '%is' % (seconds,) + + elif style is 2: + """ + Full-detailed, long-winded format. + """ + days_str = hours_str = minutes_str = '' + if days > 0: + days_str = '%i days, ' % (days,) + if days or hours > 0: + hours_str = '%i hours, ' % (hours,) + if hours or minutes > 0: + minutes_str = '%i minutes, ' % (minutes,) + seconds_str = '%i seconds' % (seconds,) + + retval = '%s%s%s%s' % (days_str, hours_str, minutes_str, seconds_str,) + return retval