Added @cset command for changing a channel's access restriction settings. Added @cboot and a few more missing channel commands. Cleaned out the utils commands and fixed formatting on a few default commands.

This commit is contained in:
Griatch 2011-04-21 10:29:24 +00:00
parent 7f7016ad7d
commit 7b43c4a608
8 changed files with 265 additions and 411 deletions

View file

@ -163,6 +163,7 @@ class CmdSetHandler(object):
"Display current commands" "Display current commands"
string = "" string = ""
merged = False
if len(self.cmdset_stack) > 1: if len(self.cmdset_stack) > 1:
# We have more than one cmdset in stack; list them all # We have more than one cmdset in stack; list them all
num = 0 num = 0
@ -175,17 +176,18 @@ class CmdSetHandler(object):
string += "\n %i: <%s (%s, prio %i)>: %s" % \ string += "\n %i: <%s (%s, prio %i)>: %s" % \
(snum, cmdset.key, mergetype, (snum, cmdset.key, mergetype,
cmdset.priority, cmdset) cmdset.priority, cmdset)
string += "\n (combining %i cmdsets):" % (num+1) string += "\n"
else: merged = True
string += "\n "
# Display the currently active cmdset # Display the currently active cmdset
mergetype = self.mergetype_stack[-1] mergetype = self.mergetype_stack[-1]
if mergetype != self.current.mergetype: if mergetype != self.current.mergetype:
merged_on = self.cmdset_stack[-2].key merged_on = self.cmdset_stack[-2].key
mergetype = "custom %s on %s" % (mergetype, merged_on) mergetype = "custom %s on %s" % (mergetype, merged_on)
string += " <%s (%s)> %s" % (self.current.key, if merged:
mergetype, self.current) string += " <Merged (%s)>: %s" % (mergetype, self.current)
else:
string += " <%s (%s)>: %s" % (self.current.key, mergetype, self.current)
return string.strip() return string.strip()
def update(self, init_mode=False): def update(self, init_mode=False):

View file

@ -1414,18 +1414,6 @@ class CmdExamine(ObjManipCommand):
locks = "cmd:perm(examine) or perm(Builders)" locks = "cmd:perm(examine) or perm(Builders)"
help_category = "Building" help_category = "Building"
def crop_line(self, text, heading="", line_width=79):
"""
Crops a line of text, adding [...] if doing so.
heading + text + eventual [...] will not exceed line_width.
"""
headlen = len(str(heading))
textlen = len(str(text))
if textlen > (line_width - headlen):
text = "%s[...]" % text[:line_width - headlen - 5]
return text
def format_attributes(self, obj, attrname=None, crop=True): def format_attributes(self, obj, attrname=None, crop=True):
""" """
Helper function that returns info about attributes and/or Helper function that returns info about attributes and/or
@ -1449,13 +1437,13 @@ class CmdExamine(ObjManipCommand):
string += "\n{wPersistent attributes{n:" string += "\n{wPersistent attributes{n:"
for attr, value in db_attr: for attr, value in db_attr:
if crop: if crop:
value = self.crop_line(value, attr) value = utils.crop(value)
string += "\n %s = %s" % (attr, value) string += "\n %s = %s" % (attr, value)
if ndb_attr and ndb_attr[0]: if ndb_attr and ndb_attr[0]:
string += "\n{wNon-persistent attributes{n:" string += "\n{wNon-persistent attributes{n:"
for attr, value in ndb_attr: for attr, value in ndb_attr:
if crop: if crop:
value = self.crop_line(value, attr) value = utils.crop(value)
string += "\n %s = %s" % (attr, value) string += "\n %s = %s" % (attr, value)
return string return string
@ -1466,11 +1454,14 @@ class CmdExamine(ObjManipCommand):
returns a string. returns a string.
""" """
string = "\n{wName/key{n: %s (#%i)" % (obj.name, obj.id) if obj.has_player:
string = "\n{wName/key{n: {c%s{n (%s)" % (obj.name, obj.dbref)
else:
string = "\n{wName/key{n: {C%s{n (%s)" % (obj.name, obj.dbref)
if obj.aliases: if obj.aliases:
string += "\n{wAliases{n: %s" % (", ".join(obj.aliases)) string += "\n{wAliases{n: %s" % (", ".join(obj.aliases))
if obj.has_player: if obj.has_player:
string += "\n{wPlayer{n: %s" % obj.player.name string += "\n{wPlayer{n: {c%s{n" % obj.player.name
perms = obj.player.permissions perms = obj.player.permissions
if obj.player.is_superuser: if obj.player.is_superuser:
perms = ["<Superuser>"] perms = ["<Superuser>"]
@ -1487,9 +1478,11 @@ class CmdExamine(ObjManipCommand):
string += "\n{wPermissions{n: %s" % (", ".join(perms)) string += "\n{wPermissions{n: %s" % (", ".join(perms))
locks = str(obj.locks) locks = str(obj.locks)
if locks: if locks:
string += "\n{wLocks{n: %s" % ("; ".join([lock for lock in locks.split(';')])) string += "\n{wLocks{n:" + utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"): if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
string += "\n{wCurrent Cmdset (before permission checks){n:\n %s" % obj.cmdset cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
string += "\n{wCurrent Cmdset (before permission checks){n:\n %s" % cmdsetstr
if obj.scripts.all(): if obj.scripts.all():
string += "\n{wScripts{n:\n %s" % obj.scripts string += "\n{wScripts{n:\n %s" % obj.scripts
# add the attributes # add the attributes
@ -1514,7 +1507,7 @@ class CmdExamine(ObjManipCommand):
string += "\n{wContents{n: " + ", ".join([cont.name for cont in obj.contents string += "\n{wContents{n: " + ", ".join([cont.name for cont in obj.contents
if cont not in exits and cont not in pobjs]) if cont not in exits and cont not in pobjs])
#output info #output info
return "-"*50 + '\n' + string.strip() + "\n" + '-'*50 return "-"*78 + '\n' + string.strip() + "\n" + '-'*78
def func(self): def func(self):
"Process command" "Process command"

View file

@ -3,7 +3,7 @@ This module ties together all the commands of the default command set.
""" """
from src.commands.cmdset import CmdSet from src.commands.cmdset import CmdSet
from src.commands.default import general, help, admin, system from src.commands.default import general, help, admin, system
from src.commands.default import utils, comms, building from src.commands.default import comms, building
from src.commands.default import batchprocess from src.commands.default import batchprocess
class DefaultCmdSet(CmdSet): class DefaultCmdSet(CmdSet):
@ -87,6 +87,10 @@ class DefaultCmdSet(CmdSet):
self.add(comms.CmdChannels()) self.add(comms.CmdChannels())
self.add(comms.CmdCdestroy()) self.add(comms.CmdCdestroy())
self.add(comms.CmdChannelCreate()) self.add(comms.CmdChannelCreate())
self.add(comms.CmdCset())
self.add(comms.CmdCBoot())
self.add(comms.CmdCemit())
self.add(comms.CmdCWho())
self.add(comms.CmdCdesc()) self.add(comms.CmdCdesc())
self.add(comms.CmdPage()) self.add(comms.CmdPage())
self.add(comms.CmdIRC2Chan()) self.add(comms.CmdIRC2Chan())
@ -97,8 +101,3 @@ class DefaultCmdSet(CmdSet):
# Batchprocessor commands # Batchprocessor commands
self.add(batchprocess.CmdBatchCommands()) self.add(batchprocess.CmdBatchCommands())
self.add(batchprocess.CmdBatchCode()) self.add(batchprocess.CmdBatchCode())
# Testing/Utility commands
self.add(utils.CmdTest())
#self.add(utils.CmdTestPerms())
self.add(utils.TestCom())

View file

@ -16,6 +16,9 @@ def find_channel(caller, channelname, silent=False):
""" """
channels = Channel.objects.channel_search(channelname) channels = Channel.objects.channel_search(channelname)
if not channels: if not channels:
channels = [chan for chan in Channel.objects.all() if channelname in chan.aliases]
if channels:
return channels[0]
if not silent: if not silent:
caller.msg("Channel '%s' not found." % channelname) caller.msg("Channel '%s' not found." % channelname)
return None return None
@ -223,7 +226,7 @@ class CmdChannels(MuxCommand):
key = "@channels" key = "@channels"
aliases = ["@clist", "channels", "comlist", "chanlist", "channellist", "all channels"] aliases = ["@clist", "channels", "comlist", "chanlist", "channellist", "all channels"]
help_category = "Comms" help_category = "Comms"
locks = "cmd:all()" locks = "cmd: not perm(channel_banned)"
def func(self): def func(self):
"Implement function" "Implement function"
@ -291,7 +294,7 @@ class CmdCdestroy(MuxCommand):
key = "@cdestroy" key = "@cdestroy"
help_category = "Comms" help_category = "Comms"
locks = "cmd:all()" locks = "cmd: not perm(channel_banned)"
def func(self): def func(self):
"Destroy objects cleanly." "Destroy objects cleanly."
@ -315,226 +318,146 @@ class CmdCdestroy(MuxCommand):
CHANNELHANDLER.update() CHANNELHANDLER.update()
caller.msg("%s was destroyed." % channel) caller.msg("%s was destroyed." % channel)
class CmdCBoot(MuxCommand):
"""
@cboot
## def cmd_cset(self): Usage:
## """ @cboot[/quiet] <channel> = <player> [:reason]
## @cset
## Sets various flags on a channel. Switches:
## """ quiet - don't notify the channel
## # TODO: Implement cmd_cset
## pass
## def cmd_ccharge(self): Kicks a player or object from a channel you control.
## """
## @ccharge
## Sets the cost to transmit over a channel. Default is free. """
## """
## # TODO: Implement cmd_ccharge
## pass
## def cmd_cboot(self): key = "@cboot"
## """ locks = "cmd: not perm(channel_banned)"
## @cboot help_category = "Comms"
## Usage: def func(self):
## @cboot[/quiet] <channel> = <player or object> "implement the function"
## Kicks a player or object from a channel you control. if not self.args or not self.rhs:
## """ string = "Usage: @cboot[/quiet] <channel> = <player> [:reason]"
## caller = self.caller self.caller.msg(string)
## args = self.args return
## switches = self.self_switches
## if not args or not "=" in args: channel = find_channel(self.caller, self.lhs)
## caller.msg("Usage: @cboot[/quiet] <channel> = <object>") if not channel:
## return return
## cname, objname = args.split("=",1) reason = ""
## cname, objname = cname.strip(), objname.strip() player = None
## if not cname or not objname: if ":" in self.rhs:
## caller.msg("You must supply both channel and object.") playername, reason = self.rhs.rsplit(":", 1)
## return player = self.caller.search("*%s" % playername.lstrip('*'))
## try: if not player:
## channel = CommChannel.objects.get(name__iexact=cname) player = self.caller.search("*%s" % self.rhs.lstrip('*'))
## except CommChannel.DoesNotExist: if not player:
## caller.msg("Could not find channel %s." % cname) return
## return if reason:
reason = " (reason: %s)" % reason
if not channel.access(self.caller, "control"):
string = "You don't control this channel."
self.caller.msg(string)
return
if not PlayerChannelConnection.objects.has_connection(player, channel):
string = "Player %s is not connected to channel %s." % (player.key, channel.key)
self.caller.msg(string)
return
if not "quiet" in self.switches:
string = "%s boots %s from channel.%s" % (self.caller, player.key, reason)
channel.msg(string)
# find all player's nicks linked to this channel and delete them
for nick in [nick for nick in player.character.nicks.get(nick_type="channel")
if nick.db_real.lower() == channel.key]:
nick.delete()
# disconnect player
channel.disconnect_from(player)
## #do we have power over this channel? class CmdCemit(MuxCommand):
## if not channel.controlled_by(caller) or caller.has_perm("channels.channel_admin"): """
## caller.msg("You don't have that power in channel '%s'." % cname) @cemit - send a message to channel
## return
## #mux specification requires an * before player objects. Usage:
## player_boot = False @cemit[/switches] <channel> = <message>
## if objname[0] == '*':
## player_boot = True
## objname = objname[1:]
## bootobj = Object.objects.player_name_search(objname)
## if not bootobj:
## caller.msg("Object '%s' not found." % objname)
## return
## if bootobj.is_player() and not player_boot:
## caller.msg("To boot players you need to start their name with an '*'. ")
## return
## #check so that this object really is on the channel in the first place Switches:
## membership = bootobj.channel_membership_set.filter(channel__name__iexact=cname) noheader - don't show the [channel] header before the message
## if not membership: sendername - attach the sender's name before the message
## caller.msg("'%s' is not on channel '%s'." % (objname,cname)) quiet - don't echo the message back to sender
## return
## #announce to channel Allows the user to broadcast a message over a channel as long as
## if not 'quiet' in switches: they control it. It does not show the user's name unless they
## comsys.send_cmessage(cname, "%s boots %s from channel." % \ provide the /sendername switch.
## (caller.get_name(show_dbref=False), objname))
## #all is set, boot the object by removing all its aliases from the channel. """
## for mship in membership:
## comsys.plr_del_channel(bootobj, mship.user_alias)
## GLOBAL_CMD_TABLE.add_self("@cboot", cmd_cboot, help_category="Comms") key = "@cemit"
aliases = ["@cmsg"]
locks = "cmd: not perm(channel_banned)"
help_category = "Comms"
def func(self):
"Implement function"
## def cmd_cemit(self): if not self.args or not self.rhs:
## """ string = "Usage: @cemit[/switches] <channel> = <message>"
## @cemit - send a message to channel self.caller.msg(string)
return
channel = find_channel(self.caller, self.lhs)
if not channel:
return
if not channel.access(self.caller, "control"):
string = "You don't control this channel."
self.caller.msg(string)
return
message = self.rhs
if "sendername" in self.switches:
message = "%s: %s" % (self.caller.key, message)
if not "noheader" in self.switches:
message = "[%s] %s" % (channel.key, message)
channel.msg(message)
if not "quiet" in self.switches:
string = "Sent to channel %s: %s" % (channel.key, message)
self.caller.msg(string)
## Usage: class CmdCWho(MuxCommand):
## @cemit <channel>=<message> """
## @cemit/noheader <channel>=<message> @cwho
## @cemit/sendername <channel>=<message>
## Allows the user to send a message over a channel as long as Usage:
## they own or control it. It does not show the user's name unless they @cwho <channel>
## provide the /sendername switch.
## [[channel_selfs]] List who is connected to a given channel you have access to.
"""
key = "@cwho"
locks = "cmd: not perm(channel_banned)"
help_category = "Comms"
## Useful channel selfs def func(self):
## (see their help pages for detailed help and options) "implement function"
## - Listing channels if not self.args:
## clist - show all channels available to you string = "Usage: @cwho <channel>"
## comlist - show channels you listen to self.caller.msg(string)
return
## - Joining/parting channels channel = find_channel(self.caller, self.lhs)
## addcom - add your alias for a channel if not channel:
## delcom - remove alias for channel return
## (leave channel if no more aliases) if not channel.access(self.caller, "listen"):
## allcom - view, on/off or remove all your channels string = "You can't access this channel."
## clearcom - removes all channels self.caller.msg(string)
string = "\n{CChannel subscriptions{n"
## - Other string += "\n{w%s:{n\n" % channel.key
## who - list who's online conns = PlayerChannelConnection.objects.get_all_connections(channel)
## <chanalias> off - silence channel temporarily if conns:
## <chanalias> on - turn silenced channel back on string += " " + ", ".join([conn.player.key for conn in conns])
## """ else:
## caller = self.caller string += " <None>"
self.caller.msg(string.strip())
## if not self.args:
## caller.msg("@cemit[/switches] <channel> = <message>")
## return
## eq_args = self.args.split('=', 1)
## if len(eq_args) != 2:
## caller.msg("You must provide a channel name and a message to emit.")
## return
## cname = eq_args[0].strip()
## cmessage = eq_args[1].strip()
## final_cmessage = cmessage
## if len(cname) == 0:
## caller.msg("You must provide a channel name to emit to.")
## return
## if len(cmessage) == 0:
## caller.msg("You must provide a message to emit.")
## return
## name_matches = comsys.cname_search(cname, exact=True)
## if name_matches:
## cname_parsed = name_matches[0].get_name()
## else:
## caller.msg("Could not find channel %s." % (cname,))
## return
## # If this is False, don't show the channel header before
## # the message. For example: [Public] Woohoo!
## show_channel_header = True
## if "noheader" in self.self_switches:
## if not caller.has_perm("objects.emit_commchannel"):
## caller.msg(defines_global.NOPERMS_MSG)
## return
## final_cmessage = cmessage
## show_channel_header = False
## else:
## if "sendername" in self.self_switches:
## if not comsys.plr_has_channel(self.session, cname_parsed,
## return_muted=False):
## caller.msg("You must be on %s to do that." % (cname_parsed,))
## return
## final_cmessage = "%s: %s" % (caller.get_name(show_dbref=False),
## cmessage)
## else:
## if not caller.has_perm("objects.emit_commchannel"):
## caller.msg(defines_global.NOPERMS_MSG)
## return
## final_cmessage = cmessage
## if not "quiet" in self.self_switches:
## caller.msg("Sent - %s" % (name_matches[0],))
## comsys.send_cmessage(cname_parsed, final_cmessage,
## show_header=show_channel_header)
## #pipe to external channels (IRC, IMC) eventually mapped to this channel
## comsys.send_cexternal(cname_parsed, cmessage, caller=caller)
## GLOBAL_CMD_TABLE.add_self("@cemit", cmd_cemit,priv_tuple=("channels.emit_commchannel",),
## help_category="Comms")
## def cmd_cwho(self):
## """
## @cwho
## Usage:
## @cwho channel[/all]
## Displays the name, status and object type for a given channel.
## Adding /all after the channel name will list disconnected players
## as well.
## """
## session = self.session
## caller = self.caller
## if not self.args:
## cmd_clist(self)
## caller.msg("Usage: @cwho <channel>[/all]")
## return
## channel_name = self.args
## if channel_name.strip() == '':
## caller.msg("You must specify a channel name.")
## return
## name_matches = comsys.cname_search(channel_name, exact=True)
## if name_matches:
## # Check to make sure the user has permission to use @cwho.
## is_channel_admin = caller.has_perm("objects.channel_admin")
## is_controlled_by_plr = name_matches[0].controlled_by(caller)
## if is_controlled_by_plr or is_channel_admin:
## comsys.msg_cwho(caller, channel_name)
## else:
## caller.msg("Permission denied.")
## return
## else:
## caller.msg("No channel with that name was found.")
## return
## GLOBAL_CMD_TABLE.add_self("@cwho", cmd_cwho, help_category="Comms")
class CmdChannelCreate(MuxCommand): class CmdChannelCreate(MuxCommand):
""" """
@ -583,47 +506,50 @@ class CmdChannelCreate(MuxCommand):
caller.msg("Created channel %s and connected to it." % new_chan.key) caller.msg("Created channel %s and connected to it." % new_chan.key)
## def cmd_cchown(self): class CmdCset(MuxCommand):
## """ """
## @cchown @cset - changes channel access restrictions
## Usage: Usage:
## @cchown <channel> = <player> @cset <channel> [= <lockstring>]
## Changes the owner of a channel. Changes the lock access restrictions of a channel. If no
## """ lockstring was given, view the current lock definitions.
## caller = self.caller """
## args = self.args
## if not args or "=" not in args: key = "@cset"
## caller.msg("Usage: @cchown <channel> = <player>") locks = "cmd:not perm(channel_banned)"
## return aliases = ["@cclock"]
## cname, pname = args.split("=",1) help_category = "Comms"
## cname, pname = cname.strip(), pname.strip()
## #locate channel def func(self):
## try: "run the function"
## channel = CommChannel.objects.get(name__iexact=cname)
## except CommChannel.DoesNotExist: if not self.args:
## caller.msg("Channel '%s' not found." % cname) string = "Usage: @cset channel [= lockstring]"
## return self.caller.msg(string)
## #check so we have ownership to give away. return
## if not channel.controlled_by(caller) and not caller.has_perm("channels.channel_admin"):
## caller.msg("You don't control this channel.") channel = find_channel(self.caller, self.lhs)
## return if not channel:
## #find the new owner return
## new_owner = Object.objects.player_name_search(pname) if not self.rhs:
## if not new_owner: # no =, so just view the current locks
## caller.msg("New owner '%s' not found." % pname) string = "Current locks on %s:" % channel.key
## return string = "%s\n %s" % (string, channel.locks)
## old_owner = channel.get_owner() self.caller.msg(string)
## old_pname = old_owner.get_name(show_dbref=False) return
## if old_owner == new_owner: # we want to add/change a lock.
## caller.msg("Owner unchanged.") if not channel.access(self.caller, "control"):
## return string = "You don't control this channel."
## #all is set, change owner self.caller.msg(string)
## channel.set_owner(new_owner) return
## caller.msg("Owner of %s changed from %s to %s." % (cname, old_pname, pname)) # Try to add the lock
## new_owner.msg("%s transfered ownership of channel '%s' to you." % (old_pname, cname)) channel.locks.add(self.rhs)
## GLOBAL_CMD_TABLE.add_self("@cchown", cmd_cchown, help_category="Comms") string = "Lock(s) applied. "
string += "Current locks on %s:" % channel.key
string = "%s\n %s" % (string, channel.locks)
self.caller.msg(string)
class CmdCdesc(MuxCommand): class CmdCdesc(MuxCommand):

View file

@ -213,10 +213,24 @@ class CmdInventory(MuxCommand):
locks = "cmd:all()" locks = "cmd:all()"
def func(self): def func(self):
"hook function" "check inventory"
string = "You are carrying:" items = self.caller.contents
for item in self.caller.contents: if not items:
string += "\n %s" % item.name string = "You are not carrying anything."
else:
# format item list into nice collumns
cols = [[],[]]
for item in items:
cols[0].append(item.name)
desc = utils.crop(item.db.desc)
if not desc:
desc = ""
cols[1].append(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) self.caller.msg(string)
class CmdGet(MuxCommand): class CmdGet(MuxCommand):
@ -552,8 +566,16 @@ class CmdAccess(MuxCommand):
hierarchy_full = settings.PERMISSION_HIERARCHY hierarchy_full = settings.PERMISSION_HIERARCHY
string = "\n{wPermission Hierarchy{n (climbing):\n %s" % ", ".join(hierarchy_full) string = "\n{wPermission Hierarchy{n (climbing):\n %s" % ", ".join(hierarchy_full)
hierarchy = [p.lower() for p in hierarchy_full] hierarchy = [p.lower() for p in hierarchy_full]
if self.caller.player.is_superuser:
cperms = "<Superuser>"
pperms = "<Superuser>"
else:
cperms = ", ".join(caller.permissions)
pperms = ", ".join(caller.player.permissions)
string += "\n{wYour access{n:" string += "\n{wYour access{n:"
string += "\nCharacter %s: %s" % (caller.key, ", ".join(caller.permissions)) string += "\nCharacter {c%s{n: %s" % (caller.key, cperms)
if hasattr(caller, 'player'): if hasattr(caller, 'player'):
string += "\nPlayer %s: %s" % (caller.player.key, ", ".join(caller.player.permissions)) string += "\nPlayer {c%s{n: %s" % (caller.player.key, pperms)
caller.msg(string) caller.msg(string)

View file

@ -270,14 +270,14 @@ class CmdObjects(MuxCommand):
nplayers = PlayerDB.objects.count() nplayers = PlayerDB.objects.count()
nobjs = ObjectDB.objects.count() nobjs = ObjectDB.objects.count()
base_typeclass = settings.BASE_CHARACTER_TYPECLASS base_char_typeclass = settings.BASE_CHARACTER_TYPECLASS
nchars = ObjectDB.objects.filter(db_typeclass_path=base_typeclass).count() nchars = ObjectDB.objects.filter(db_typeclass_path=base_char_typeclass).count()
nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=base_typeclass).count() nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=base_char_typeclass).count()
nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count() nexits = ObjectDB.objects.filter(db_location__isnull=False, db_destination__isnull=False).count()
string += "\n{wPlayers:{n %i" % nplayers string += "\n{wPlayers:{n %i" % nplayers
string += "\n{wObjects:{n %i" % nobjs string += "\n{wObjects:{n %i" % nobjs
string += "\n{w Characters (base type):{n %i" % nchars string += "\n{w Characters (BASE_CHARACTER_TYPECLASS):{n %i" % nchars
string += "\n{w Rooms (location==None):{n %i" % nrooms string += "\n{w Rooms (location==None):{n %i" % nrooms
string += "\n{w Exits (destination!=None):{n %i" % nexits string += "\n{w Exits (destination!=None):{n %i" % nexits
string += "\n{w Other:{n %i\n" % (nobjs - nchars - nrooms - nexits) string += "\n{w Other:{n %i\n" % (nobjs - nchars - nrooms - nexits)
@ -579,8 +579,6 @@ class CmdServerLoad(MuxCommand):
caller.msg(string) caller.msg(string)
#TODO - expand @ps as we add irc/imc2 support.
class CmdPs(MuxCommand): class CmdPs(MuxCommand):
""" """
list processes list processes

View file

@ -1,101 +0,0 @@
"""
This defines some test commands for use while testing the MUD and its components.
"""
from django.conf import settings
from django.db import IntegrityError
from src.comms.models import Msg
from src.utils import create, debug, utils
from src.commands.default.muxcommand import MuxCommand
from src.commands import cmdsethandler
# Test permissions
class CmdTest(MuxCommand):
"""
test the command system
Usage:
@test <any argument or switch>
This command will echo back all argument or switches
given to it, showcasing the muxcommand style.
"""
key = "@test"
aliases = ["@te", "@test all"]
help_category = "Utils"
locks = "cmd:perm(Wizards)"
# the muxcommand class itself handles the display
# so we just defer to it by not adding any function.
def func(self):
def test():
li = []
for l in range(10000):
li.append(l)
self.caller.msg(li[-1])
return "This is the return text"
#print 1/0
def succ(f):
self.caller.msg("This is called after successful completion. Return value: %s" % f)
def err(e):
self.caller.msg("An error was encountered... %s" % e)
#self.caller.msg("printed before call to sync run ...")
#test()
#self.caller.msg("after after call to sync run...")
self.caller.msg("printed before call to async run ...")
utils.run_async(test, at_return=succ, at_err=err)
self.caller.msg("printed after call to async run ...")
#cmdsetname = "game.gamesrc.commands.default.cmdset_default.DefaultCmdSet"
#self.caller.msg(cmdsethandler.CACHED_CMDSETS)
#cmdsethandler.import_cmdset(cmdsetname, self, self)
#self.caller.msg("Imported %s" % cmdsetname)
#self.caller.msg(cmdsethandler.CACHED_CMDSETS)
class TestCom(MuxCommand):
"""
Test the command system
Usage:
@testcom/create/list [channel]
"""
key = "@testcom"
locks = "cmd:perm(Wizards)"
help_category = "Utils"
def func(self):
"Run the test program"
caller = self.caller
if 'create' in self.switches:
if self.args:
chankey = self.args
try:
channel = create.create_channel(chankey)
except IntegrityError:
caller.msg("Channel '%s' already exists." % chankey)
return
channel.connect_to(caller)
caller.msg("Created new channel %s" % chankey)
msgobj = create.create_message(caller.player,
"First post to new channel!")
channel.msg(msgobj)
return
elif 'list' in self.switches:
msgresults = Msg.objects.get_messages_by_sender(caller)
string = "\n".join(["%s %s: %s" % (msg.date_sent,
[str(chan.key) for chan in msg.channels.all()],
msg.message)
for msg in msgresults])
caller.msg(string)
return
caller.msg("Usage: @testcom/create channel")

View file

@ -10,7 +10,6 @@ import datetime
import random import random
from twisted.internet import threads from twisted.internet import threads
from django.conf import settings from django.conf import settings
from src.utils import ansi
ENCODINGS = settings.ENCODINGS ENCODINGS = settings.ENCODINGS
@ -32,16 +31,33 @@ def is_iter(iterable):
# except TypeError: # except TypeError:
# return False # return False
def fill(text, width=78): def fill(text, width=78, indent=0):
""" """
Safely wrap text to a certain number of characters. Safely wrap text to a certain number of characters.
text: (str) The text to wrap. text: (str) The text to wrap.
width: (int) The number of characters to wrap to. width: (int) The number of characters to wrap to.
indent: (int) How much to indent new lines (the first line
will not be indented)
""" """
if not text: if not text:
return "" return ""
return textwrap.fill(str(text), width) indent = " " * indent
return textwrap.fill(str(text), width, subsequent_indent=indent)
def crop(text, width=78, suffix="[...]"):
"""
Crop text to a certain width, adding suffix to show the line
continues. Cropping will be done so that the suffix will also fit
within the given width.
"""
ltext = len(str(text))
if ltext <= width:
return text
else:
lsuffix = len(suffix)
return text[:width-lsuffix] + suffix
def dedent(text): def dedent(text):
""" """
@ -353,8 +369,7 @@ def format_table(table, extra_space=1):
if not table: if not table:
return [[]] return [[]]
max_widths = [max([len(str(val)) max_widths = [max([len(str(val)) for val in col]) for col in table]
for val in col]) for col in table]
ftable = [] ftable = []
for irow in range(len(table[0])): for irow in range(len(table[0])):
ftable.append([str(col[irow]).ljust(max_widths[icol]) + " " * extra_space ftable.append([str(col[irow]).ljust(max_widths[icol]) + " " * extra_space