Work on the comsys. @cwho is working now.

This commit is contained in:
Greg Taylor 2009-01-22 03:19:40 +00:00
parent 8909b9d2c0
commit 4c562cd6ce
4 changed files with 61 additions and 6 deletions

View file

@ -76,6 +76,7 @@ GLOBAL_CMD_TABLE.add_command("@ccreate", commands.comsys.cmd_ccreate,
GLOBAL_CMD_TABLE.add_command("@cdestroy", commands.comsys.cmd_cdestroy,
priv_tuple=("objects.delete_commchannel")),
GLOBAL_CMD_TABLE.add_command("@chown", commands.objmanip.cmd_chown),
GLOBAL_CMD_TABLE.add_command("@cwho", commands.comsys.cmd_cwho),
GLOBAL_CMD_TABLE.add_command("@chzone", commands.objmanip.cmd_chzone),
GLOBAL_CMD_TABLE.add_command("@cemit", commands.comsys.cmd_cemit),
GLOBAL_CMD_TABLE.add_command("@clist", commands.comsys.cmd_clist),

View file

@ -149,8 +149,13 @@ def cmd_cdestroy(command):
if not name_matches:
session.msg("Could not find channel %s." % (cname,))
else:
session.msg("Channel %s destroyed." % (name_matches[0],))
name_matches.delete()
is_controlled_by_plr = name_matches[0].controlled_by(pobject)
if is_controlled_by_plr:
session.msg("Channel %s destroyed." % (name_matches[0],))
name_matches.delete()
else:
session.msg("Permission denied.")
return
def cmd_cset(command):
"""
@ -252,8 +257,34 @@ def cmd_cwho(command):
Adding /all after the channel name will list disconnected players
as well.
"""
# TODO: Implement cmd_cwho
pass
session = command.session
pobject = session.get_pobject()
if not command.command_argument:
session.msg("You must specify a channel name.")
return
channel_name = command.command_argument
if channel_name.strip() == '':
session.msg("You must specify a channel name.")
return
name_matches = src.comsys.cname_search(channel_name, exact=True)
if name_matches:
# Check to make sure the user has permission to use @cwho.
is_channel_admin = pobject.user_has_perm("objects.channel_admin")
is_controlled_by_plr = name_matches[0].controlled_by(pobject)
if is_controlled_by_plr or is_channel_admin:
src.comsys.msg_cwho(session, channel_name)
else:
session.msg("Permission denied.")
return
else:
session.msg("No channel with that name was found.")
return
def cmd_ccreate(command):
"""
@ -269,6 +300,10 @@ def cmd_ccreate(command):
session.msg("You must supply a name!")
return
if not pobject.user_has_perm("objects.channel_admin"):
session.msg("Permission denied.")
return
cname = command.command_argument
name_matches = src.comsys.cname_search(cname, exact=True)

View file

@ -107,7 +107,7 @@ def plr_has_channel(session, cname, alias_search=False, return_muted=False):
chan_list = plr_get_cdict(session).values()
for chan in chan_list:
# Check for a name match
if cname == chan[0]:
if cname.lower() == chan[0].lower():
has_channel = True
# If channel status is taken into consideration, see if the user

View file

@ -914,7 +914,8 @@ class CommChannel(models.Model):
class Meta:
ordering = ['-name']
permissions = (
("emit_commchannel", "May @cemit over channels."),
('emit_commchannel', 'May @cemit over channels.'),
('channel_admin', 'May administer comm channels.')
)
def get_name(self):
@ -957,6 +958,24 @@ class CommChannel(models.Model):
"""
self.owner = new_owner
self.save()
def controlled_by(self, pobject):
"""
Use this to see if another object controls the channel. This is means
that the specified object either owns the channel or has special
permissions to control it.
pobject: (Object) Player object to check for control.
"""
if pobject.is_superuser():
return True
if self.owner and self.owner.id == pobject.id:
# If said object owns the target, then give it the green.
return True
# They've failed to meet any of the above conditions.
return False
class CommChannelAdmin(admin.ModelAdmin):
list_display = ('name', 'owner')