Implements @cboot as per MUX specifications (Issue 20). Some code cleanup.

This commit is contained in:
Griatch 2009-08-29 22:29:19 +00:00
parent 69cb8e5655
commit ceaf7d2a2f
4 changed files with 76 additions and 46 deletions

View file

@ -101,7 +101,8 @@ def cmd_comlist(command):
source_object = command.source_object
session = command.session
source_object.emit_to("Alias Channel Status")
s = "Your subscibed channels (to see all, use @clist)\n"
s += "Alias Channel Status\n"
for membership in source_object.channel_membership_set.all():
chan = membership.channel
if membership.is_listening:
@ -109,10 +110,11 @@ def cmd_comlist(command):
else:
chan_on = "Off"
source_object.emit_to("%-9.9s %-19.19s %s" % (membership.user_alias,
chan.get_name(),
chan_on))
source_object.emit_to("-- End of comlist --")
s += "%-9.9s %-19.19s %s\n" % (membership.user_alias,
chan.get_name(),
chan_on)
s += "-- End of comlist --"
source_object.emit_to(s)
GLOBAL_CMD_TABLE.add_command("comlist", cmd_comlist),
def cmd_allcom(command):
@ -143,16 +145,19 @@ def cmd_clist(command):
"""
session = command.session
source_object = command.source_object
s = "All channels (use comlist to see your subscriptions)\n"
source_object.emit_to("** Channel Owner Description")
s += "** Channel Owner Description\n"
for chan in comsys.get_all_channels():
source_object.emit_to("%s%s %-15.14s%-22.15s%s" %
s += "%s%s %-15.14s%-22.15s%s\n" % \
('-',
'-',
chan.get_name(),
chan.get_owner().get_name(show_dbref=False),
chan.description))
source_object.emit_to("** End of Channel List **")
chan.description)
s += "** End of Channel List **"
source_object.emit_to(s)
GLOBAL_CMD_TABLE.add_command("@clist", cmd_clist),
def cmd_cdestroy(command):
@ -192,7 +197,6 @@ def cmd_cset(command):
# TODO: Implement cmd_cset
pass
def cmd_ccharge(command):
"""
@ccharge
@ -204,12 +208,64 @@ def cmd_ccharge(command):
def cmd_cboot(command):
"""
@cboot
@cboot[/quiet] <channel>=<object>
Kicks a player or object from the channel.
Kicks a player or object from the channel
"""
# TODO: Implement cmd_cboot
pass
source_object = command.source_object
args = command.command_argument
switches = command.command_switches
if not args or not "=" in args:
source_object.emit_to("Usage: @cboot[/quiet] <channel>=<object>")
return
cname, objname = args.split("=",1)
cname, objname = cname.strip(), objname.strip()
if not cname or not objname:
source_object.emit_to("You must supply both channel and object.")
return
try:
channel = CommChannel.objects.get(name__iexact=cname)
except CommChannel.DoesNotExist:
source_object.emit_to("Could not find channel %s." % cname)
return
#do we have power over this channel?
if not channel.controlled_by(source_object):
source_object.emit_to("You don't have that power in channel '%s'." % cname)
return
#mux specification requires an * before player objects.
player_boot = False
if objname[0] == '*':
player_boot = True
objname = objname[1:]
bootobj = source_object.search_for_object(objname)
if not bootobj:
source_object.emit_to("Object '%s' not found." % objname)
return
if bootobj.is_player() and not player_boot:
source_object.emit_to("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
membership = bootobj.channel_membership_set.filter(channel__name__iexact=cname)
if not membership:
source_object.emit_to("'%s' is not on channel '%s'." % (objname,cname))
return
#announce to channel
if not 'quiet' in switches:
comsys.send_cmessage(cname, "%s boots %s from channel." % \
(source_object.get_name(show_dbref=False), objname))
#all is set, boot the object by removing all its aliases from the channel.
for mship in membership:
alias = mship.user_alias
comsys.plr_del_channel(bootobj, alias)
GLOBAL_CMD_TABLE.add_command("@cboot", cmd_cboot)
def cmd_cemit(command):
"""
@ -363,3 +419,4 @@ def cmd_cchown(command):
"""
# TODO: Implement cmd_cchown.
pass

View file

@ -432,7 +432,7 @@ def cmd_create(command):
Creates a new object. If parent is given, the object is created as a child of this
parent. The parent script is assumed to be located under game/gamesrc/parents
and any further directory structure is given in Python notation. So if you
have a correct parent object defined in parents/examples/red_button.py, you could
have a correct parent object defined in parents/examples/red_button.py, you would
load create a new object inheriting from this parent like this:
@create button:examples.red_button
"""
@ -779,11 +779,6 @@ def cmd_dig(command):
if not roomname:
source_object.emit_to("You must supply a new room name.")
else:
# Create and set the object up.
#odat = {"name": roomname,
# "type": defines_global.OTYPE_ROOM,
# "location": None,
# "owner": source_object}
new_room = Object.objects.create_object(roomname,
defines_global.OTYPE_ROOM,
None,
@ -801,12 +796,6 @@ def cmd_dig(command):
if destination and not destination.is_exit():
location = source_object.get_location()
#create an exit from here to the new room.
#odat = {"name": exits[0].strip(),
# "type": defines_global.OTYPE_EXIT,
# "location": location,
# "owner": source_object,
# "home": destination}
new_object = Object.objects.create_object(exits[0].strip(),
defines_global.OTYPE_EXIT,
location,
@ -815,12 +804,6 @@ def cmd_dig(command):
source_object.emit_to("Created exit from %s to %s named '%s'." % (location,destination,new_object))
if len(exits)>1:
#create exit back to this room
#odat = {"name": exits[1].strip(),
# "type": defines_global.OTYPE_EXIT,
# "location": destination,
# "owner": source_object,
# "home": location}
new_object = Object.objects.create_object(exits[1].strip(),
defines_global.OTYPE_EXIT,
destination,

View file

@ -147,7 +147,7 @@ def plr_add_channel(source_object, alias, channel):
listening: (bool) A True or False value to determine listening status.
"""
membership = CommChannelMembership(channel=channel, listener=source_object,
user_alias=alias)
user_alias=alias)
membership.save()
sessions = session_mgr.sessions_from_object(source_object)

View file

@ -200,23 +200,13 @@ class SessionProtocol(StatefulTelnetProtocol):
Adds the player to the default channels.
"""
# Add the default channels.
if self.pobject.is_superuser():
"Have the super users join these too."
chan = CommChannel.objects(name=settings.COMMCHAN_MUD_INFO)
chan_alias = 'info'
src.comsys.plr_set_channel(self, chan_alias, chan.name, True)
chan = CommChannel.objects(name=settings.COMMCHAN_MUD_CONNECTIONS)
chan_alias = 'conns'
src.comsys.plr_set_channel(self, chan_alias, chan.name, True)
for chan in CommChannel.objects.filter(is_joined_by_default=True):
logger.log_infomsg("ADDING BY DEFAULT %s" % chan)
chan_alias = chan.get_default_chan_alias()
#logger.log_infomsg("ADDING BY DEFAULT %s" % chan)
chan_alias = chan.get_default_chan_alias()
membership = CommChannelMembership(channel=chan,
listener=self.get_pobject(),
user_alias=chan_alias)
membership.save()
membership.save()
comsys.plr_set_channel_listening(self, chan_alias, True)
def __str__(self):