Huge overhaul in the way objects and sessions are used with commands. We now pass all commands through objects (aside from unlogged commands), which means session.msg() is now deprecated for any use other than unlogged out.

As a side-effect of all of this, logging in more than once acts as behaves now. Also, this will allow things/rooms/exits (IE: not players) or un-logged in players to run commands or be forced to run them via @fo. All of this will bring us more in-line with MUX behavior.
This commit is contained in:
Greg Taylor 2009-01-24 20:30:46 +00:00
parent 50f4d04096
commit 9407eb0ee4
20 changed files with 680 additions and 712 deletions

View file

@ -6,13 +6,11 @@ import os
import time
from src.util import functions_general
if not functions_general.host_os_is('nt'):
# Don't import the resource module if the host OS is Windows.
import resource
import django
from src.objects.models import Object
from src import scheduler
from src import defines_global
@ -22,104 +20,104 @@ def cmd_version(command):
"""
Version info command.
"""
session = command.session
retval = "-"*50 +"\n\r"
retval += " Evennia %s\n\r" % (defines_global.EVENNIA_VERSION,)
retval += " Django %s\n\r" % (django.get_version())
retval += "-"*50
session.msg(retval)
command.source_object.emit_to(retval)
def cmd_time(command):
"""
Server local time.
"""
session = command.session
session.msg('Current server time : %s' %
command.source_object.emit_to('Current server time : %s' %
(time.strftime('%a %b %d %H:%M:%S %Y (%Z)', time.localtime(),)))
def cmd_uptime(command):
"""
Server uptime and stats.
"""
session = command.session
server = command.server
source_object = command.source_object
server = command.session.server
start_delta = time.time() - server.start_time
session.msg('Current server time : %s' %
source_object.emit_to('Current server time : %s' %
(time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
session.msg('Server start time : %s' %
source_object.emit_to('Server start time : %s' %
(time.strftime('%a %b %d %H:%M %Y', time.localtime(server.start_time),)))
session.msg('Server uptime : %s' %
source_object.emit_to('Server uptime : %s' %
functions_general.time_format(start_delta, style=2))
# os.getloadavg() is not available on Windows.
if not functions_general.host_os_is('nt'):
loadavg = os.getloadavg()
session.msg('Server load (1 min) : %.2f' %
source_object.emit_to('Server load (1 min) : %.2f' %
loadavg[0])
def cmd_list(command):
"""
Shows some game related information.
"""
session = command.session
pobject = session.get_pobject()
server = command.session.server
source_object = command.source_object
msg_invalid = "Unknown option. Use one of: commands, flags, process"
if not command.command_argument:
session.msg(msg_invalid)
source_object.emit_to(msg_invalid)
elif command.command_argument == "commands":
session.msg('Commands: '+ ' '.join(session.server.command_list()))
source_object.emit_to('Commands: '+ ' '.join(server.command_list()))
elif command.command_argument == "process":
if not functions_general.host_os_is('nt'):
loadvg = os.getloadavg()
psize = resource.getpagesize()
rusage = resource.getrusage(resource.RUSAGE_SELF)
session.msg("Process ID: %10d %10d bytes per page" %
(os.getpid(), psize))
session.msg("Time used: %10d user %10d sys" %
(rusage[0],rusage[1]))
session.msg("Integral mem:%10d shared %10d private%10d stack" %
(rusage[3], rusage[4], rusage[5]))
session.msg("Max res mem: %10d pages %10d bytes" %
(rusage[2],rusage[2] * psize))
session.msg("Page faults: %10d hard %10d soft %10d swapouts" %
(rusage[7], rusage[6], rusage[8]))
session.msg("Disk I/O: %10d reads %10d writes" %
(rusage[9], rusage[10]))
session.msg("Network I/O: %10d in %10d out" %
(rusage[12], rusage[11]))
session.msg("Context swi: %10d vol %10d forced %10d sigs" %
(rusage[14], rusage[15], rusage[13]))
source_object.emit_to("Process ID: %10d %10d bytes per page" %
(os.getpid(), psize))
source_object.emit_to("Time used: %10d user %10d sys" %
(rusage[0],rusage[1]))
source_object.emit_to("Integral mem:%10d shared %10d private%10d stack" %
(rusage[3], rusage[4], rusage[5]))
source_object.emit_to("Max res mem: %10d pages %10d bytes" %
(rusage[2],rusage[2] * psize))
source_object.emit_to("Page faults: %10d hard %10d soft %10d swapouts" %
(rusage[7], rusage[6], rusage[8]))
source_object.emit_to("Disk I/O: %10d reads %10d writes" %
(rusage[9], rusage[10]))
source_object.emit_to("Network I/O: %10d in %10d out" %
(rusage[12], rusage[11]))
source_object.emit_to("Context swi: %10d vol %10d forced %10d sigs" %
(rusage[14], rusage[15], rusage[13]))
else:
session.msg("Feature not available on Windows.")
source_object.emit_to("Feature not available on Windows.")
return
elif command.command_argument == "flags":
session.msg("Flags: "+" ".join(flags.SERVER_FLAGS))
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
else:
session.msg(msg_invalid)
source_object.emit_to(msg_invalid)
def cmd_ps(command):
"""
Shows the process/event table.
"""
session = command.session
session.msg("-- Interval Events --")
source_object = command.source_object
source_object.emit_to("-- Interval Events --")
for event in scheduler.schedule:
session.msg(" [%d/%d] %s" % (scheduler.get_event_nextfire(event),
scheduler.get_event_interval(event),
scheduler.get_event_description(event)))
session.msg("Totals: %d interval events" % (len(scheduler.schedule),))
source_object.emit_to(" [%d/%d] %s" % (
scheduler.get_event_nextfire(event),
scheduler.get_event_interval(event),
scheduler.get_event_description(event)))
source_object.emit_to("Totals: %d interval events" % (len(scheduler.schedule),))
def cmd_stats(command):
"""
Shows stats about the database.
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
"""
session = command.session
stats_dict = Object.objects.object_totals()
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" %
command.source_object.emit_to(
"%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" %
(stats_dict["objects"],
stats_dict["rooms"],
stats_dict["exits"],