Indentation change 3-4 spaces.

Possible files that need to be cleanedup;
commands/info.py:cmd_list
commands/general.py:cmd_who
commands/comsys.py:cmd_who

cmdtable.py
ansi.py
This commit is contained in:
loki77 2008-06-13 19:52:29 +00:00
parent 740d715c72
commit 3fe644ef17
31 changed files with 1856 additions and 1856 deletions

View file

@ -13,281 +13,281 @@ now.
"""
def cmd_addcom(cdat):
"""
addcom
"""
addcom
Adds an alias for a channel.
addcom foo=Bar
"""
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
if len(args) == 0:
session.msg("You need to specify a channel alias and name.")
return
eq_args = args[0].split('=')
Adds an alias for a channel.
addcom foo=Bar
"""
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
if len(args) == 0:
session.msg("You need to specify a channel alias and name.")
return
eq_args = args[0].split('=')
if len(eq_args) < 2:
session.msg("You need to specify a channel name.")
return
chan_alias = eq_args[0]
chan_name = eq_args[1]
if len(eq_args) < 2:
session.msg("You need to specify a channel name.")
return
chan_alias = eq_args[0]
chan_name = eq_args[1]
if len(chan_name) == 0:
session.msg("You need to specify a channel name.")
return
if len(chan_name) == 0:
session.msg("You need to specify a channel name.")
return
if chan_alias in session.channels_subscribed:
session.msg("You are already on that channel.")
return
if chan_alias in session.channels_subscribed:
session.msg("You are already on that channel.")
return
name_matches = functions_comsys.cname_search(chan_name, exact=True)
name_matches = functions_comsys.cname_search(chan_name, exact=True)
if name_matches:
chan_name_parsed = name_matches[0].get_name()
session.msg("You join %s, with an alias of %s." % \
(chan_name_parsed, chan_alias))
functions_comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
if name_matches:
chan_name_parsed = name_matches[0].get_name()
session.msg("You join %s, with an alias of %s." % \
(chan_name_parsed, chan_alias))
functions_comsys.plr_set_channel(session, chan_alias, chan_name_parsed, True)
# Announce the user's joining.
join_msg = "[%s] %s has joined the channel." % \
(chan_name_parsed, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
else:
session.msg("Could not find channel %s." % (chan_name,))
# Announce the user's joining.
join_msg = "[%s] %s has joined the channel." % \
(chan_name_parsed, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name_parsed, join_msg)
else:
session.msg("Could not find channel %s." % (chan_name,))
def cmd_delcom(cdat):
"""
delcom
"""
delcom
Removes the specified alias to a channel. If this is the last alias,
the user is effectively removed from the channel.
"""
session = cdat['session']
pobject = session.get_pobject()
uinput= cdat['uinput']['splitted']
chan_alias = ' '.join(uinput[1:])
Removes the specified alias to a channel. If this is the last alias,
the user is effectively removed from the channel.
"""
session = cdat['session']
pobject = session.get_pobject()
uinput= cdat['uinput']['splitted']
chan_alias = ' '.join(uinput[1:])
if len(chan_alias) == 0:
session.msg("You must specify a channel alias.")
return
if len(chan_alias) == 0:
session.msg("You must specify a channel alias.")
return
if chan_alias not in session.channels_subscribed:
session.msg("You are not on that channel.")
return
if chan_alias not in session.channels_subscribed:
session.msg("You are not on that channel.")
return
chan_name = session.channels_subscribed[chan_alias][0]
session.msg("You have left %s." % (chan_name,))
functions_comsys.plr_del_channel(session, chan_alias)
chan_name = session.channels_subscribed[chan_alias][0]
session.msg("You have left %s." % (chan_name,))
functions_comsys.plr_del_channel(session, chan_alias)
# Announce the user's leaving.
leave_msg = "[%s] %s has left the channel." % \
(chan_name, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name, leave_msg)
# Announce the user's leaving.
leave_msg = "[%s] %s has left the channel." % \
(chan_name, pobject.get_name(show_dbref=False))
functions_comsys.send_cmessage(chan_name, leave_msg)
def cmd_comlist(cdat):
"""
Lists the channels a user is subscribed to.
"""
session = cdat['session']
"""
Lists the channels a user is subscribed to.
"""
session = cdat['session']
session.msg("Alias Channel Status")
for chan in session.channels_subscribed:
if session.channels_subscribed[chan][1]:
chan_on = "On"
else:
chan_on = "Off"
session.msg("%-9.9s %-19.19s %s" %
(chan, session.channels_subscribed[chan][0], chan_on))
session.msg("-- End of comlist --")
session.msg("Alias Channel Status")
for chan in session.channels_subscribed:
if session.channels_subscribed[chan][1]:
chan_on = "On"
else:
chan_on = "Off"
session.msg("%-9.9s %-19.19s %s" %
(chan, session.channels_subscribed[chan][0], chan_on))
session.msg("-- End of comlist --")
def cmd_allcom(cdat):
"""
allcom
"""
allcom
Allows the user to universally turn off or on all channels they are on,
as well as perform a "who" for all channels they are on.
"""
pass
Allows the user to universally turn off or on all channels they are on,
as well as perform a "who" for all channels they are on.
"""
pass
def cmd_clearcom(cdat):
"""
clearcom
"""
clearcom
Effectively runs delcom on all channels the user is on. It will remove their aliases,
remove them from the channel, and clear any titles they have set.
"""
pass
Effectively runs delcom on all channels the user is on. It will remove their aliases,
remove them from the channel, and clear any titles they have set.
"""
pass
def cmd_clist(cdat):
"""
@clist
"""
@clist
Lists all available channels on the game.
"""
session = cdat['session']
session.msg("** Channel Owner Description")
for chan in functions_comsys.get_all_channels():
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description'))
session.msg("-- End of Channel List --")
Lists all available channels on the game.
"""
session = cdat['session']
session.msg("** Channel Owner Description")
for chan in functions_comsys.get_all_channels():
session.msg("%s%s %-13.13s %-15.15s %-45.45s" %
('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description'))
session.msg("-- End of Channel List --")
def cmd_cdestroy(cdat):
"""
@cdestroy
"""
@cdestroy
Destroys a channel.
"""
session = cdat['session']
uinput= cdat['uinput']['splitted']
cname = ' '.join(uinput[1:])
Destroys a channel.
"""
session = cdat['session']
uinput= cdat['uinput']['splitted']
cname = ' '.join(uinput[1:])
if cname == '':
session.msg("You must supply a name!")
return
if cname == '':
session.msg("You must supply a name!")
return
name_matches = functions_comsys.cname_search(cname, exact=True)
name_matches = functions_comsys.cname_search(cname, exact=True)
if not name_matches:
session.msg("Could not find channel %s." % (cname,))
else:
session.msg("Channel %s destroyed." % (name_matches[0],))
name_matches.delete()
if not name_matches:
session.msg("Could not find channel %s." % (cname,))
else:
session.msg("Channel %s destroyed." % (name_matches[0],))
name_matches.delete()
def cmd_cset(cdat):
"""
@cset
"""
@cset
Sets various flags on a channel.
"""
pass
Sets various flags on a channel.
"""
pass
def cmd_ccharge(cdat):
"""
@ccharge
"""
@ccharge
Sets the cost to transmit over a channel. Default is free.
"""
pass
Sets the cost to transmit over a channel. Default is free.
"""
pass
def cmd_cboot(cdat):
"""
@cboot
"""
@cboot
Kicks a player or object from the channel.
"""
pass
Kicks a player or object from the channel.
"""
pass
def cmd_cemit(cdat):
"""
@cemit
@cemit/noheader <message>
@cemit/sendername <message>
"""
@cemit
@cemit/noheader <message>
@cemit/sendername <message>
Allows the user to send a message over a channel as long as
they own or control it. It does not show the user's name unless they
provide the /sendername switch.
"""
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
switches = cdat['uinput']['root_chunk'][1:]
Allows the user to send a message over a channel as long as
they own or control it. It does not show the user's name unless they
provide the /sendername switch.
"""
session = cdat['session']
pobject = session.get_pobject()
server = cdat['server']
args = cdat['uinput']['splitted'][1:]
switches = cdat['uinput']['root_chunk'][1:]
if len(args) == 0:
session.msg("Channel emit what?")
return
if len(args) == 0:
session.msg("Channel emit what?")
return
# Combine the arguments into one string, split it by equal signs into
# channel (entry 0 in the list), and message (entry 1 and above).
eq_args = ' '.join(args).split('=')
cname = eq_args[0]
cmessage = ' '.join(eq_args[1:])
if len(eq_args) != 2:
session.msg("You must provide a channel name and a message to emit.")
return
if len(cname) == 0:
session.msg("You must provide a channel name to emit to.")
return
if len(cmessage) == 0:
session.msg("You must provide a message to emit.")
return
# Combine the arguments into one string, split it by equal signs into
# channel (entry 0 in the list), and message (entry 1 and above).
eq_args = ' '.join(args).split('=')
cname = eq_args[0]
cmessage = ' '.join(eq_args[1:])
if len(eq_args) != 2:
session.msg("You must provide a channel name and a message to emit.")
return
if len(cname) == 0:
session.msg("You must provide a channel name to emit to.")
return
if len(cmessage) == 0:
session.msg("You must provide a message to emit.")
return
name_matches = functions_comsys.cname_search(cname, exact=True)
name_matches = functions_comsys.cname_search(cname, exact=True)
try:
# Safety first, kids!
cname_parsed = name_matches[0].get_name()
except:
session.msg("Could not find channel %s." % (cname,))
return
try:
# Safety first, kids!
cname_parsed = name_matches[0].get_name()
except:
session.msg("Could not find channel %s." % (cname,))
return
if "noheader" in switches:
if not pobject.user_has_perm("objects.emit_commchannel"):
session.msg(defines_global.NOPERMS_MSG)
return
final_cmessage = cmessage
else:
if "sendername" in switches:
if not functions_comsys.plr_has_channel(session, cname_parsed, return_muted=False):
session.msg("You must be on %s to do that." % (cname_parsed,))
return
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
else:
if not pobject.user_has_perm("objects.emit_commchannel"):
if "noheader" in switches:
if not pobject.user_has_perm("objects.emit_commchannel"):
session.msg(defines_global.NOPERMS_MSG)
return
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
final_cmessage = cmessage
else:
if "sendername" in switches:
if not functions_comsys.plr_has_channel(session, cname_parsed, return_muted=False):
session.msg("You must be on %s to do that." % (cname_parsed,))
return
final_cmessage = "[%s] %s: %s" % (cname_parsed, pobject.get_name(show_dbref=False), cmessage)
else:
if not pobject.user_has_perm("objects.emit_commchannel"):
session.msg(defines_global.NOPERMS_MSG)
return
final_cmessage = "[%s] %s" % (cname_parsed, cmessage)
if not "quiet" in switches:
session.msg("Sent - %s" % (name_matches[0],))
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
if not "quiet" in switches:
session.msg("Sent - %s" % (name_matches[0],))
functions_comsys.send_cmessage(cname_parsed, final_cmessage)
def cmd_cwho(cdat):
"""
@cwho
"""
@cwho
Displays the name, status and object type for a given channel.
Adding /all after the channel name will list disconnected players
as well.
"""
pass
Displays the name, status and object type for a given channel.
Adding /all after the channel name will list disconnected players
as well.
"""
pass
def cmd_ccreate(cdat):
"""
@ccreate
"""
@ccreate
Creates a new channel with the invoker being the default owner.
"""
session = cdat['session']
pobject = session.get_pobject()
uinput= cdat['uinput']['splitted']
cname = ' '.join(uinput[1:])
Creates a new channel with the invoker being the default owner.
"""
session = cdat['session']
pobject = session.get_pobject()
uinput= cdat['uinput']['splitted']
cname = ' '.join(uinput[1:])
if cname == '':
session.msg("You must supply a name!")
return
if cname == '':
session.msg("You must supply a name!")
return
name_matches = functions_comsys.cname_search(cname, exact=True)
name_matches = functions_comsys.cname_search(cname, exact=True)
if name_matches:
session.msg("A channel with that name already exists.")
else:
# Create and set the object up.
cdat = {"name": cname, "owner": pobject}
new_chan = functions_comsys.create_channel(cdat)
session.msg("Channel %s created." % (new_chan.get_name(),))
if name_matches:
session.msg("A channel with that name already exists.")
else:
# Create and set the object up.
cdat = {"name": cname, "owner": pobject}
new_chan = functions_comsys.create_channel(cdat)
session.msg("Channel %s created." % (new_chan.get_name(),))
def cmd_cchown(cdat):
"""
@cchown
"""
@cchown
Changes the owner of a channel.
"""
pass
Changes the owner of a channel.
"""
pass

View file

@ -1,70 +1,70 @@
import gameconf
if not gameconf.host_os_is('nt'):
# Don't import the resource module if the host OS is Windows.
import resource
# Don't import the resource module if the host OS is Windows.
import resource
import os
import functions_db
import scheduler
def cmd_list(cdat):
"""
Shows some game related information.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
argstr = ''.join(args)
msg_invalid = "Unknown option. Use one of: commands, flags, process"
if len(argstr) == 0:
session.msg(msg_invalid)
elif argstr == "commands":
session.msg('Commands: '+ ' '.join(session.server.command_list()))
elif argstr == "process":
if not gameconf.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]))
else:
session.msg("Feature not available on Windows.")
return
elif argstr == "flags":
session.msg("Flags: "+" ".join(defines_global.SERVER_FLAGS))
else:
session.msg(msg_invalid)
"""
Shows some game related information.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
argstr = ''.join(args)
msg_invalid = "Unknown option. Use one of: commands, flags, process"
if len(argstr) == 0:
session.msg(msg_invalid)
elif argstr == "commands":
session.msg('Commands: '+ ' '.join(session.server.command_list()))
elif argstr == "process":
if not gameconf.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]))
else:
session.msg("Feature not available on Windows.")
return
elif argstr == "flags":
session.msg("Flags: "+" ".join(defines_global.SERVER_FLAGS))
else:
session.msg(msg_invalid)
def cmd_ps(cdat):
"""
Shows the process/event table.
"""
session = cdat['session']
session.msg("-- 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),))
"""
Shows the process/event table.
"""
session = cdat['session']
session.msg("-- 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),))
def cmd_stats(cdat):
"""
Shows stats about the database.
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
"""
session = cdat['session']
stats_dict = functions_db.object_totals()
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" % (stats_dict["objects"],
stats_dict["rooms"],
stats_dict["exits"],
stats_dict["things"],
stats_dict["players"],
stats_dict["garbage"]))
"""
Shows stats about the database.
4012 objects = 144 rooms, 212 exits, 613 things, 1878 players. (1165 garbage)
"""
session = cdat['session']
stats_dict = functions_db.object_totals()
session.msg("%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)" % (stats_dict["objects"],
stats_dict["rooms"],
stats_dict["exits"],
stats_dict["things"],
stats_dict["players"],
stats_dict["garbage"]))

View file

@ -9,122 +9,122 @@ are generally @-prefixed commands, but there are exceptions.
"""
def cmd_reload(cdat):
"""
Reloads all modules.
"""
session = cdat['session']
server = session.server.reload(session)
"""
Reloads all modules.
"""
session = cdat['session']
server = session.server.reload(session)
def cmd_boot(cdat):
"""
Boot a player object from the server.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
eq_args = ' '.join(args).split('=')
searchstring = ''.join(eq_args[0])
switches = cdat['uinput']['root_chunk'][1:]
switch_quiet = False
switch_port = False
"""
Boot a player object from the server.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
eq_args = ' '.join(args).split('=')
searchstring = ''.join(eq_args[0])
switches = cdat['uinput']['root_chunk'][1:]
switch_quiet = False
switch_port = False
if not pobject.is_staff():
session.msg("You do not have permission to do that.")
return
if not pobject.is_staff():
session.msg("You do not have permission to do that.")
return
if "quiet" in switches:
switch_quiet = True
if "quiet" in switches:
switch_quiet = True
if "port" in switches:
switch_port = True
if "port" in switches:
switch_port = True
if len(args) == 0:
session.msg("Who would you like to boot?")
return
else:
boot_list = []
if switch_port:
sessions = session_mgr.get_session_list(True)
for sess in sessions:
if sess.getClientAddress()[1] == int(searchstring):
boot_list.append(sess)
# We're done here
break
else:
# Grab the objects that match
objs = functions_db.global_object_name_search(searchstring)
if len(objs) < 1:
session.msg("Who would you like to boot?")
if len(args) == 0:
session.msg("Who would you like to boot?")
return
else:
boot_list = []
if switch_port:
sessions = session_mgr.get_session_list(True)
for sess in sessions:
if sess.getClientAddress()[1] == int(searchstring):
boot_list.append(sess)
# We're done here
break
else:
# Grab the objects that match
objs = functions_db.global_object_name_search(searchstring)
if len(objs) < 1:
session.msg("Who would you like to boot?")
return
if not objs[0].is_player():
session.msg("You can only boot players.")
return
if not pobject.controls_other(objs[0]):
if objs[0].is_superuser():
session.msg("You cannot boot a Wizard.")
return
else:
session.msg("You do not have permission to boot that player.")
return
if objs[0].is_connected_plr():
boot_list.append(session_mgr.session_from_object(objs[0]))
for boot in boot_list:
if not switch_quiet:
boot.msg("You have been disconnected by %s." % (pobject.name))
boot.disconnectClient()
session_mgr.remove_session(boot)
return
if not objs[0].is_player():
session.msg("You can only boot players.")
return
if not pobject.controls_other(objs[0]):
if objs[0].is_superuser():
session.msg("You cannot boot a Wizard.")
return
else:
session.msg("You do not have permission to boot that player.")
return
if objs[0].is_connected_plr():
boot_list.append(session_mgr.session_from_object(objs[0]))
for boot in boot_list:
if not switch_quiet:
boot.msg("You have been disconnected by %s." % (pobject.name))
boot.disconnectClient()
session_mgr.remove_session(boot)
return
def cmd_newpassword(cdat):
"""
Set a player's password.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
eq_args = ' '.join(args).split('=')
searchstring = ''.join(eq_args[0])
newpass = ''.join(eq_args[1:])
if len(args) == 0:
session.msg("What player's password do you want to change")
return
if len(newpass) == 0:
session.msg("You must supply a new password.")
return
"""
Set a player's password.
"""
session = cdat['session']
pobject = session.get_pobject()
args = cdat['uinput']['splitted'][1:]
eq_args = ' '.join(args).split('=')
searchstring = ''.join(eq_args[0])
newpass = ''.join(eq_args[1:])
if len(args) == 0:
session.msg("What player's password do you want to change")
return
if len(newpass) == 0:
session.msg("You must supply a new password.")
return
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
target_obj = functions_db.standard_plr_objsearch(session, searchstring)
# Use standard_plr_objsearch to handle duplicate/nonexistant results.
if not target_obj:
return
if not target_obj.is_player():
session.msg("You can only change passwords on players.")
elif not pobject.controls_other(target_obj):
session.msg("You do not control %s." % (target_obj.get_name(),))
else:
uaccount = target_obj.get_user_account()
if len(newpass) == 0:
uaccount.set_password()
else:
uaccount.set_password(newpass)
uaccount.save()
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
target_obj.emit_to("%s has changed your password." % (pobject.get_name(show_dbref=False),))
if not target_obj.is_player():
session.msg("You can only change passwords on players.")
elif not pobject.controls_other(target_obj):
session.msg("You do not control %s." % (target_obj.get_name(),))
else:
uaccount = target_obj.get_user_account()
if len(newpass) == 0:
uaccount.set_password()
else:
uaccount.set_password(newpass)
uaccount.save()
session.msg("%s - PASSWORD set." % (target_obj.get_name(),))
target_obj.emit_to("%s has changed your password." % (pobject.get_name(show_dbref=False),))
def cmd_shutdown(cdat):
"""
Shut the server down gracefully.
"""
session = cdat['session']
server = cdat['server']
pobject = session.get_pobject()
session.msg('Shutting down...')
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
server.shutdown()
"""
Shut the server down gracefully.
"""
session = cdat['session']
server = cdat['server']
pobject = session.get_pobject()
session.msg('Shutting down...')
print 'Server shutdown by %s' % (pobject.get_name(show_dbref=False),)
server.shutdown()