- Implemented permission system management inside the game
- changed @chperm to @setperm to avoid confusion with channel commands - added @setgroup command for adding user group permissions - Moved permissions/group setup into settings file to allow admins to tweak without going into evennia engine. - Add all new players to default permission group (defined in settings) - Defined a basic group hierarchy, removed permission 'genperms.builder' in favour of a group named builders instead, containing all relevant permissions. - Filtered out all django's automatic permissions in @setperm/list to make permission system more controlled by admin. - Probably fixed bug that caused new users to not be signed up to channels (more testing needed) - Added Exception handler in unloggedin method create, this was killing tracebacks upon user creation. /Griatch
This commit is contained in:
parent
77f2186d9a
commit
7f7306a6e4
23 changed files with 341 additions and 214 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
Models for the help system.
|
Models for the help system.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src.ansi import parse_ansi
|
from src.ansi import parse_ansi
|
||||||
|
|
@ -22,10 +23,7 @@ class CommChannel(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['-name']
|
ordering = ['-name']
|
||||||
permissions = (
|
permissions = settings.PERM_CHANNELS
|
||||||
('emit_commchannel', 'May @cemit over channels.'),
|
|
||||||
('channel_admin', 'May administer comm channels.')
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -113,8 +111,9 @@ class CommChannelMessage(models.Model):
|
||||||
message = models.TextField()
|
message = models.TextField()
|
||||||
date_sent = models.DateTimeField(editable=False, auto_now_add=True)
|
date_sent = models.DateTimeField(editable=False, auto_now_add=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['-date_sent']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s: %s" % (self.channel.name, self.message)
|
return "%s: %s" % (self.channel.name, self.message)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['-date_sent']
|
|
||||||
|
|
@ -175,7 +175,7 @@ def cmd_batchprocess(command):
|
||||||
|
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
|
|
||||||
#check permissions
|
#check permissions; this is a superuser only command.
|
||||||
if not source_object.is_superuser():
|
if not source_object.is_superuser():
|
||||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,6 @@ from src import ansi
|
||||||
from src.util import functions_general
|
from src.util import functions_general
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src.cmdtable import GLOBAL_CMD_TABLE
|
from src.cmdtable import GLOBAL_CMD_TABLE
|
||||||
#from src.imc2.models import IMC2ChannelMapping
|
|
||||||
#from src.imc2.packets import IMC2PacketIceMsgBroadcasted
|
|
||||||
#from src.irc.models import IRCChannelMapping
|
|
||||||
#from src.irc.connection import IRC_CHANNELS
|
|
||||||
|
|
||||||
def cmd_addcom(command):
|
def cmd_addcom(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -85,9 +81,7 @@ def cmd_addcom(command):
|
||||||
except CommChannel.DoesNotExist:
|
except CommChannel.DoesNotExist:
|
||||||
# Failed to match iexact on channel's 'name' attribute.
|
# Failed to match iexact on channel's 'name' attribute.
|
||||||
source_object.emit_to("Could not find channel %s." % chan_name)
|
source_object.emit_to("Could not find channel %s." % chan_name)
|
||||||
|
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("addcom", cmd_addcom),
|
|
||||||
|
|
||||||
def cmd_delcom(command):
|
def cmd_delcom(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -275,14 +269,13 @@ def cmd_cdestroy(command):
|
||||||
source_object.emit_to("Could not find channel %s." % (cname,))
|
source_object.emit_to("Could not find channel %s." % (cname,))
|
||||||
else:
|
else:
|
||||||
is_controlled_by_plr = name_matches[0].controlled_by(source_object)
|
is_controlled_by_plr = name_matches[0].controlled_by(source_object)
|
||||||
if is_controlled_by_plr:
|
if is_controlled_by_plr or source_object.has_perm("channels.channel_admin"):
|
||||||
source_object.emit_to("Channel %s destroyed." % (name_matches[0],))
|
source_object.emit_to("Channel %s destroyed." % (name_matches[0],))
|
||||||
name_matches.delete()
|
name_matches.delete()
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("Permission denied.")
|
source_object.emit_to("Permission denied.")
|
||||||
return
|
return
|
||||||
GLOBAL_CMD_TABLE.add_command("@cdestroy", cmd_cdestroy,
|
GLOBAL_CMD_TABLE.add_command("@cdestroy", cmd_cdestroy)
|
||||||
priv_tuple=("objects.delete_commchannel")),
|
|
||||||
|
|
||||||
def cmd_cset(command):
|
def cmd_cset(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -327,7 +320,7 @@ def cmd_cboot(command):
|
||||||
return
|
return
|
||||||
|
|
||||||
#do we have power over this channel?
|
#do we have power over this channel?
|
||||||
if not channel.controlled_by(source_object):
|
if not channel.controlled_by(source_object) or source_object.has_perm("channels.channel_admin"):
|
||||||
source_object.emit_to("You don't have that power in channel '%s'." % cname)
|
source_object.emit_to("You don't have that power in channel '%s'." % cname)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -432,7 +425,7 @@ def cmd_cemit(command):
|
||||||
#pipe to external channels (IRC, IMC) eventually mapped to this channel
|
#pipe to external channels (IRC, IMC) eventually mapped to this channel
|
||||||
comsys.send_cexternal(cname_parsed, cmessage, caller=source_object)
|
comsys.send_cexternal(cname_parsed, cmessage, caller=source_object)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit),
|
GLOBAL_CMD_TABLE.add_command("@cemit", cmd_cemit,priv_tuple=("channels.emit_commchannel",))
|
||||||
|
|
||||||
def cmd_cwho(command):
|
def cmd_cwho(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -503,8 +496,7 @@ def cmd_ccreate(command):
|
||||||
# Create and set the object up.
|
# Create and set the object up.
|
||||||
new_chan = comsys.create_channel(cname, source_object)
|
new_chan = comsys.create_channel(cname, source_object)
|
||||||
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
|
source_object.emit_to("Channel %s created." % (new_chan.get_name(),))
|
||||||
GLOBAL_CMD_TABLE.add_command("@ccreate", cmd_ccreate,
|
GLOBAL_CMD_TABLE.add_command("@ccreate", cmd_ccreate)
|
||||||
priv_tuple=("objects.add_commchannel",))
|
|
||||||
|
|
||||||
def cmd_cchown(command):
|
def cmd_cchown(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -526,7 +518,7 @@ def cmd_cchown(command):
|
||||||
source_object.emit_to("Channel '%s' not found." % cname)
|
source_object.emit_to("Channel '%s' not found." % cname)
|
||||||
return
|
return
|
||||||
#check so we have ownership to give away.
|
#check so we have ownership to give away.
|
||||||
if not channel.controlled_by(source_object):
|
if not channel.controlled_by(source_object) and not source_object.has_perm("channels.channel_admin"):
|
||||||
source_object.emit_to("You don't control this channel.")
|
source_object.emit_to("You don't control this channel.")
|
||||||
return
|
return
|
||||||
#find the new owner
|
#find the new owner
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ now.
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from src.config.models import ConfigValue
|
from src.config.models import ConfigValue
|
||||||
from src.helpsys.models import HelpEntry
|
from src.helpsys.models import HelpEntry
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
|
|
@ -334,7 +335,7 @@ def cmd_examine(command):
|
||||||
# Send it all
|
# Send it all
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("examine", cmd_examine)
|
GLOBAL_CMD_TABLE.add_command("examine", cmd_examine,priv_tuple=("objects.info",))
|
||||||
|
|
||||||
def cmd_quit(command):
|
def cmd_quit(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -452,6 +453,31 @@ def cmd_pose(command):
|
||||||
source_object.get_location().emit_to_contents(sent_msg)
|
source_object.get_location().emit_to_contents(sent_msg)
|
||||||
GLOBAL_CMD_TABLE.add_command("pose", cmd_pose)
|
GLOBAL_CMD_TABLE.add_command("pose", cmd_pose)
|
||||||
|
|
||||||
|
def cmd_group(command):
|
||||||
|
"""@group
|
||||||
|
Usage:
|
||||||
|
@group
|
||||||
|
|
||||||
|
This command shows you which user permission groups you are a member of, if any.
|
||||||
|
"""
|
||||||
|
source_object = command.source_object
|
||||||
|
user = User.objects.get(username=source_object.get_name(show_dbref=False,no_ansi=True))
|
||||||
|
s = ""
|
||||||
|
if source_object.is_superuser():
|
||||||
|
s += "\n This is a SUPERUSER account! Group membership does not matter."
|
||||||
|
if not user.is_active:
|
||||||
|
s += "\n ACCOUNT NOT ACTIVE."
|
||||||
|
for g in user.groups.all():
|
||||||
|
s += "\n -- %s" % g
|
||||||
|
for p in g.permissions.all():
|
||||||
|
s += "\n --- %s" % p.name
|
||||||
|
if not s:
|
||||||
|
s = "You are not a member of any groups." % source_object.get_name(show_dbref=False)
|
||||||
|
else:
|
||||||
|
s = "\nYour (%s's) group memberships: %s" % (source_object.get_name(show_dbref=False),s)
|
||||||
|
source_object.emit_to(s)
|
||||||
|
GLOBAL_CMD_TABLE.add_command("@group", cmd_group,auto_help=True)
|
||||||
|
|
||||||
|
|
||||||
def cmd_help(command):
|
def cmd_help(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -539,8 +565,8 @@ def cmd_help(command):
|
||||||
|
|
||||||
if 'add' in switches:
|
if 'add' in switches:
|
||||||
#try to add/replace help text for a command
|
#try to add/replace help text for a command
|
||||||
if not source_object.is_staff():
|
if not source_object.has_perm("helpsys.add_help"):
|
||||||
source_object.emit_to("Only staff can add new help entries.")
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
spl = (topicstr.split(':',1))
|
spl = (topicstr.split(':',1))
|
||||||
if len(spl) != 2:
|
if len(spl) != 2:
|
||||||
|
|
@ -559,11 +585,11 @@ def cmd_help(command):
|
||||||
|
|
||||||
elif 'append' in switches or 'app' in switches:
|
elif 'append' in switches or 'app' in switches:
|
||||||
#append text to a help entry
|
#append text to a help entry
|
||||||
if not source_object.is_staff():
|
if not source_object.has_perm("helpsys.add_help"):
|
||||||
source_object.emit_to("Only staff can append to help entries.")
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
spl = (topicstr.split(':',1))
|
spl = (topicstr.split(':',1))
|
||||||
if len(spl) != 2:
|
if len(spl) != 2:
|
||||||
source_object.emit_to("""Format is help/append <topic>:<text to add>
|
source_object.emit_to("""Format is help/append <topic>:<text to add>
|
||||||
Use the /newline switch to make a new paragraph.""")
|
Use the /newline switch to make a new paragraph.""")
|
||||||
return
|
return
|
||||||
|
|
@ -582,8 +608,8 @@ def cmd_help(command):
|
||||||
|
|
||||||
elif 'del' in switches or 'delete' in switches:
|
elif 'del' in switches or 'delete' in switches:
|
||||||
#delete a help entry
|
#delete a help entry
|
||||||
if not source_object.is_staff():
|
if not source_object.has_perm("helpsys.del_help"):
|
||||||
source_object.emit_to("Only staff can add delete help entries.")
|
source_object.emit_to(defines_global.NOPERMS_MSG)
|
||||||
return
|
return
|
||||||
topics = edit_help.del_help(source_object,topicstr)
|
topics = edit_help.del_help(source_object,topicstr)
|
||||||
if type(topics) != type(list()):
|
if type(topics) != type(list()):
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,8 @@ def cmd_imcstatus(command):
|
||||||
retval += '-' * 50
|
retval += '-' * 50
|
||||||
|
|
||||||
source_object.emit_to(retval)
|
source_object.emit_to(retval)
|
||||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus,
|
||||||
|
priv_tuple=('imc2.admin_imc_channels',))
|
||||||
|
|
||||||
|
|
||||||
def cmd_IMC2chan(command):
|
def cmd_IMC2chan(command):
|
||||||
|
|
@ -179,5 +180,5 @@ def cmd_IMC2chan(command):
|
||||||
source_object.emit_to(outstring)
|
source_object.emit_to(outstring)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@imc2chan",cmd_IMC2chan,auto_help=True,staff_help=True,
|
GLOBAL_CMD_TABLE.add_command("@imc2chan",cmd_IMC2chan,auto_help=True,staff_help=True,
|
||||||
priv_tuple=("objects.add_commchannel",))
|
priv_tuple=("imc2.admin_imc_channels",))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ def cmd_list(command):
|
||||||
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
|
source_object.emit_to("Flags: "+" ".join(flags.SERVER_FLAGS))
|
||||||
else:
|
else:
|
||||||
source_object.emit_to(msg_invalid)
|
source_object.emit_to(msg_invalid)
|
||||||
GLOBAL_CMD_TABLE.add_command("@list", cmd_list),
|
GLOBAL_CMD_TABLE.add_command("@list", cmd_list,priv_tuple=("genperms.game_info",)),
|
||||||
|
|
||||||
def cmd_ps(command):
|
def cmd_ps(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -131,4 +131,4 @@ def cmd_stats(command):
|
||||||
stats_dict["things"],
|
stats_dict["things"],
|
||||||
stats_dict["players"],
|
stats_dict["players"],
|
||||||
stats_dict["garbage"]))
|
stats_dict["garbage"]))
|
||||||
GLOBAL_CMD_TABLE.add_command("@stats", cmd_stats),
|
GLOBAL_CMD_TABLE.add_command("@stats", cmd_stats, priv_tuple=("genperms.game_info",)),
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ def cmd_IRC2chan(command):
|
||||||
source_object.emit_to(outstring)
|
source_object.emit_to(outstring)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@irc2chan",cmd_IRC2chan,auto_help=True,staff_help=True,
|
GLOBAL_CMD_TABLE.add_command("@irc2chan",cmd_IRC2chan,auto_help=True,staff_help=True,
|
||||||
priv_tuple=("objects.add_commchannel",))
|
priv_tuple=("irc.admin_irc_channels",))
|
||||||
|
|
||||||
def cmd_IRCjoin(command):
|
def cmd_IRCjoin(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -101,7 +101,7 @@ def cmd_IRCjoin(command):
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,auto_help=True,
|
GLOBAL_CMD_TABLE.add_command("@ircjoin",cmd_IRCjoin,auto_help=True,
|
||||||
staff_help=True,
|
staff_help=True,
|
||||||
priv_tuple=("objects.add_commchannel",))
|
priv_tuple=("irc.admin_irc_channels",))
|
||||||
|
|
||||||
def cmd_IRCchanlist(command):
|
def cmd_IRCchanlist(command):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ def cmd_teleport(command):
|
||||||
|
|
||||||
source_object.move_to(target_obj, quiet=tel_quietly)
|
source_object.move_to(target_obj, quiet=tel_quietly)
|
||||||
GLOBAL_CMD_TABLE.add_command("@teleport", cmd_teleport,
|
GLOBAL_CMD_TABLE.add_command("@teleport", cmd_teleport,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("objects.teleport",))
|
||||||
|
|
||||||
def cmd_alias(command):
|
def cmd_alias(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -165,7 +165,7 @@ def cmd_wipe(command):
|
||||||
target_obj.clear_attribute(attr.get_name())
|
target_obj.clear_attribute(attr.get_name())
|
||||||
source_object.emit_to("%s - %d attributes wiped." % (target_obj.get_name(),
|
source_object.emit_to("%s - %d attributes wiped." % (target_obj.get_name(),
|
||||||
len(attr_matches)))
|
len(attr_matches)))
|
||||||
GLOBAL_CMD_TABLE.add_command("@wipe", cmd_wipe)
|
GLOBAL_CMD_TABLE.add_command("@wipe", cmd_wipe,priv_tuple=("objects.wipe",))
|
||||||
|
|
||||||
def cmd_set(command):
|
def cmd_set(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -250,7 +250,7 @@ def cmd_set(command):
|
||||||
s += '\nFlag %s=%s set.' % (target_name, flag.upper())
|
s += '\nFlag %s=%s set.' % (target_name, flag.upper())
|
||||||
target.set_flag(flag, True)
|
target.set_flag(flag, True)
|
||||||
source_object.emit_to(s[1:])
|
source_object.emit_to(s[1:])
|
||||||
GLOBAL_CMD_TABLE.add_command("@set", cmd_set)
|
GLOBAL_CMD_TABLE.add_command("@set", cmd_set, priv_tuple=("objects.modify_attributes",))
|
||||||
|
|
||||||
def cmd_cpattr(command):
|
def cmd_cpattr(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -332,7 +332,7 @@ def cmd_cpattr(command):
|
||||||
to_objname, to_attr)
|
to_objname, to_attr)
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
GLOBAL_CMD_TABLE.add_command("@cpattr", cmd_cpattr,
|
GLOBAL_CMD_TABLE.add_command("@cpattr", cmd_cpattr,
|
||||||
priv_tuple=("genperms.builder",))
|
priv_tuple=("objects.modify_attributes",))
|
||||||
|
|
||||||
|
|
||||||
def cmd_mvattr(command):
|
def cmd_mvattr(command):
|
||||||
|
|
@ -394,7 +394,7 @@ def cmd_mvattr(command):
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@mvattr", cmd_mvattr,
|
GLOBAL_CMD_TABLE.add_command("@mvattr", cmd_mvattr,
|
||||||
priv_tuple=("genperms.builder",))
|
priv_tuple=("objects.modify_attributes",))
|
||||||
|
|
||||||
def cmd_find(command):
|
def cmd_find(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -420,7 +420,7 @@ def cmd_find(command):
|
||||||
else:
|
else:
|
||||||
source_object.emit_to("No name matches found for: %s" % (searchstring,))
|
source_object.emit_to("No name matches found for: %s" % (searchstring,))
|
||||||
GLOBAL_CMD_TABLE.add_command("@find", cmd_find,
|
GLOBAL_CMD_TABLE.add_command("@find", cmd_find,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("objects.info",))
|
||||||
|
|
||||||
def cmd_create(command):
|
def cmd_create(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -474,7 +474,7 @@ def cmd_create(command):
|
||||||
|
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@create", cmd_create,
|
GLOBAL_CMD_TABLE.add_command("@create", cmd_create,
|
||||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||||
|
|
||||||
def cmd_copy(command):
|
def cmd_copy(command):
|
||||||
"""Usage:
|
"""Usage:
|
||||||
|
|
@ -539,7 +539,7 @@ def cmd_copy(command):
|
||||||
reset_text = " (using default attrs/flags)"
|
reset_text = " (using default attrs/flags)"
|
||||||
source_object.emit_to("Copied object '%s'%s%s%s." % (objname,name_text,loc_text,reset_text))
|
source_object.emit_to("Copied object '%s'%s%s%s." % (objname,name_text,loc_text,reset_text))
|
||||||
GLOBAL_CMD_TABLE.add_command("@copy", cmd_copy,
|
GLOBAL_CMD_TABLE.add_command("@copy", cmd_copy,
|
||||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -552,7 +552,7 @@ def cmd_nextfree(command):
|
||||||
nextfree = Object.objects.get_nextfree_dbnum()
|
nextfree = Object.objects.get_nextfree_dbnum()
|
||||||
command.source_object.emit_to("Next free object number: #%s" % nextfree)
|
command.source_object.emit_to("Next free object number: #%s" % nextfree)
|
||||||
GLOBAL_CMD_TABLE.add_command("@nextfree", cmd_nextfree,
|
GLOBAL_CMD_TABLE.add_command("@nextfree", cmd_nextfree,
|
||||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
priv_tuple=("objects.info",),auto_help=True,staff_help=True)
|
||||||
|
|
||||||
def cmd_open(command):
|
def cmd_open(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -625,7 +625,7 @@ def cmd_open(command):
|
||||||
None)
|
None)
|
||||||
source_object.emit_to("You open an unlinked exit - %s" % new_object)
|
source_object.emit_to("You open an unlinked exit - %s" % new_object)
|
||||||
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
GLOBAL_CMD_TABLE.add_command("@open", cmd_open,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("objects.dig",))
|
||||||
|
|
||||||
def cmd_chown(command):
|
def cmd_chown(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -655,7 +655,7 @@ def cmd_chown(command):
|
||||||
if not target_obj:
|
if not target_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not source_object.controls_other(target_obj):
|
if not source_object.controls_other(target_obj) and not source_object.has_perm("objects.admin_ownership"):
|
||||||
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
source_object.emit_to(defines_global.NOCONTROL_MSG)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -676,7 +676,7 @@ def cmd_chown(command):
|
||||||
# We haven't provided a target.
|
# We haven't provided a target.
|
||||||
source_object.emit_to("Who should be the new owner of the object?")
|
source_object.emit_to("Who should be the new owner of the object?")
|
||||||
return
|
return
|
||||||
GLOBAL_CMD_TABLE.add_command("@chown", cmd_chown)
|
GLOBAL_CMD_TABLE.add_command("@chown", cmd_chown, priv_tuple=("objects.modify_attributes","objects.admin_ownership"))
|
||||||
|
|
||||||
def cmd_chzone(command):
|
def cmd_chzone(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -728,7 +728,7 @@ def cmd_chzone(command):
|
||||||
# We haven't provided a target zone.
|
# We haven't provided a target zone.
|
||||||
source_object.emit_to("What should the object's zone be set to?")
|
source_object.emit_to("What should the object's zone be set to?")
|
||||||
return
|
return
|
||||||
GLOBAL_CMD_TABLE.add_command("@chzone", cmd_chzone)
|
GLOBAL_CMD_TABLE.add_command("@chzone", cmd_chzone, priv_tuple=("objects.dig",))
|
||||||
|
|
||||||
def cmd_link(command):
|
def cmd_link(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -780,7 +780,7 @@ def cmd_link(command):
|
||||||
source_object.emit_to("You must provide a destination to link to.")
|
source_object.emit_to("You must provide a destination to link to.")
|
||||||
return
|
return
|
||||||
GLOBAL_CMD_TABLE.add_command("@link", cmd_link,
|
GLOBAL_CMD_TABLE.add_command("@link", cmd_link,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("objects.dig",))
|
||||||
|
|
||||||
def cmd_unlink(command):
|
def cmd_unlink(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -806,7 +806,7 @@ def cmd_unlink(command):
|
||||||
target_obj.set_home(None)
|
target_obj.set_home(None)
|
||||||
source_object.emit_to("You have unlinked %s." % target_obj.get_name())
|
source_object.emit_to("You have unlinked %s." % target_obj.get_name())
|
||||||
GLOBAL_CMD_TABLE.add_command("@unlink", cmd_unlink,
|
GLOBAL_CMD_TABLE.add_command("@unlink", cmd_unlink,
|
||||||
priv_tuple=("genperms.builder"))
|
priv_tuple=("objects.dig",))
|
||||||
|
|
||||||
def cmd_dig(command):
|
def cmd_dig(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -933,7 +933,7 @@ def cmd_dig(command):
|
||||||
source_object.move_to(new_room)
|
source_object.move_to(new_room)
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@dig", cmd_dig,
|
GLOBAL_CMD_TABLE.add_command("@dig", cmd_dig,
|
||||||
priv_tuple=("genperms.builder"),)
|
priv_tuple=("objects.dig",))
|
||||||
|
|
||||||
def cmd_name(command):
|
def cmd_name(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1080,7 +1080,7 @@ def cmd_recover(command):
|
||||||
|
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@recover", cmd_recover,
|
GLOBAL_CMD_TABLE.add_command("@recover", cmd_recover,
|
||||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||||
|
|
||||||
def cmd_destroy(command):
|
def cmd_destroy(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1157,4 +1157,4 @@ def cmd_destroy(command):
|
||||||
source_object.emit_to("You schedule %s for destruction." % target_obj.get_name())
|
source_object.emit_to("You schedule %s for destruction." % target_obj.get_name())
|
||||||
|
|
||||||
GLOBAL_CMD_TABLE.add_command("@destroy", cmd_destroy,
|
GLOBAL_CMD_TABLE.add_command("@destroy", cmd_destroy,
|
||||||
priv_tuple=("genperms.builder"),auto_help=True,staff_help=True)
|
priv_tuple=("objects.create",),auto_help=True,staff_help=True)
|
||||||
|
|
|
||||||
|
|
@ -127,4 +127,4 @@ def cmd_page(command):
|
||||||
# Now set the LASTPAGED attribute
|
# Now set the LASTPAGED attribute
|
||||||
source_object.set_attribute("LASTPAGED", ','.join(
|
source_object.set_attribute("LASTPAGED", ','.join(
|
||||||
["#%d" % (x.id) for x in targets]))
|
["#%d" % (x.id) for x in targets]))
|
||||||
GLOBAL_CMD_TABLE.add_command("page", cmd_page),
|
GLOBAL_CMD_TABLE.add_command("page", cmd_page, priv_tuple=('channels.page',))
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,7 @@ This file contains commands that require special permissions to use. These
|
||||||
are generally @-prefixed commands, but there are exceptions.
|
are generally @-prefixed commands, but there are exceptions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib.auth.models import Permission
|
from django.contrib.auth.models import Permission, Group, User
|
||||||
from django.contrib.auth.models import Group
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
|
|
@ -133,7 +131,7 @@ def cmd_newpassword(command):
|
||||||
newpass = eq_args[1]
|
newpass = eq_args[1]
|
||||||
|
|
||||||
if not command.command_argument or len(searchstring) == 0:
|
if not command.command_argument or len(searchstring) == 0:
|
||||||
source_object.emit_to("What player's password do you want to change")
|
source_object.emit_to("What player's password do you want to change?")
|
||||||
return
|
return
|
||||||
if len(newpass) == 0:
|
if len(newpass) == 0:
|
||||||
source_object.emit_to("You must supply a new password.")
|
source_object.emit_to("You must supply a new password.")
|
||||||
|
|
@ -256,17 +254,30 @@ def cmd_shutdown(command):
|
||||||
GLOBAL_CMD_TABLE.add_command("@shutdown", cmd_shutdown,
|
GLOBAL_CMD_TABLE.add_command("@shutdown", cmd_shutdown,
|
||||||
priv_tuple=("genperms.process_control",))
|
priv_tuple=("genperms.process_control",))
|
||||||
|
|
||||||
def cmd_chperm(command):
|
# permission administration
|
||||||
"""@chperm
|
|
||||||
|
# Django automatically creates a host of permissions that we don't want to
|
||||||
|
# mess with, but which are not very useful from inside the game. While these
|
||||||
|
# permissions are ok to use, we only show the permissions that we have defined
|
||||||
|
# in our settings file in order to give better control.
|
||||||
|
APPS_NOSHOW = ("news","admin","auth","config","contentypes",
|
||||||
|
"flatpages","news","sessions","sites")
|
||||||
|
SETTINGS_PERM_NAMES = []
|
||||||
|
for apps in settings.PERM_ALL_DEFAULTS + settings.PERM_ALL_CUSTOM:
|
||||||
|
for permtuples in apps:
|
||||||
|
SETTINGS_PERM_NAMES.append(permtuples[1])
|
||||||
|
|
||||||
|
def cmd_setperm(command):
|
||||||
|
"""@setperm
|
||||||
Usage:
|
Usage:
|
||||||
@chperm[/switch] [<user>] = [<permission>]
|
@setperm[/switch] [<user>] = [<permission>]
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
add : add a permission from <user>
|
add : add a permission from <user>
|
||||||
del : delete a permission from <user>
|
del : delete a permission from <user>
|
||||||
list : list all permissions, or those set on <user>
|
list : list all permissions, or those set on <user>
|
||||||
|
|
||||||
@chperm (change permission) sets/clears individual permission bits on a user.
|
This command sets/clears individual permission bits on a user.
|
||||||
Use /list without any arguments to see all available permissions or those
|
Use /list without any arguments to see all available permissions or those
|
||||||
defined on the <user> argument.
|
defined on the <user> argument.
|
||||||
"""
|
"""
|
||||||
|
|
@ -276,32 +287,31 @@ def cmd_chperm(command):
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
if "list" not in switches:
|
if "list" not in switches:
|
||||||
source_object.emit_to("Usage: @chperm[/switch] [user] = [permission]")
|
source_object.emit_to("Usage: @setperm[/switch] [user] = [permission]")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
#just print all available permissions
|
#just print all available permissions
|
||||||
s = "\n---Permission name %s ---Description" % (24 * " ")
|
s = "\n---Permission name %s ---Description" % (24 * " ")
|
||||||
for p in Permission.objects.all():
|
permlist = [perm for perm in Permission.objects.all() if perm.content_type.app_label not in APPS_NOSHOW and
|
||||||
|
perm.name in SETTINGS_PERM_NAMES]
|
||||||
|
for p in permlist:
|
||||||
app = p.content_type.app_label
|
app = p.content_type.app_label
|
||||||
s += "\n%s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
if app not in APPS_NOSHOW:
|
||||||
|
s += "\n%s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
return
|
return
|
||||||
#we have command arguments.
|
#we have command arguments.
|
||||||
arglist = args.split('=',1)
|
arglist = args.split('=',1)
|
||||||
obj_name = arglist[0].strip()
|
obj_name = arglist[0].strip()
|
||||||
if not obj_name:
|
if not obj_name:
|
||||||
source_object.emit_to("Usage: @chperm[/switch] [user] [= permission]")
|
source_object.emit_to("Usage: @setperm[/switch] [user] [= permission]")
|
||||||
return
|
return
|
||||||
obj = source_object.search_for_object(obj_name)
|
obj = source_object.search_for_object(obj_name)
|
||||||
if not obj:
|
if not obj:
|
||||||
return
|
return
|
||||||
if not obj.is_player():
|
user = obj.get_user_account()
|
||||||
source_object.emit_to("Only players may have permissions.")
|
if not user:
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
user = User.objects.get(username=obj.get_name(show_dbref=False,no_ansi=True))
|
|
||||||
except:
|
|
||||||
raise
|
|
||||||
if len(arglist) == 1:
|
if len(arglist) == 1:
|
||||||
#if we didn't have any =, we list the permissions set on <object>.
|
#if we didn't have any =, we list the permissions set on <object>.
|
||||||
s = ""
|
s = ""
|
||||||
|
|
@ -312,16 +322,18 @@ def cmd_chperm(command):
|
||||||
if obj.is_staff():
|
if obj.is_staff():
|
||||||
s += "\n Member of staff (can enter Admin interface)"
|
s += "\n Member of staff (can enter Admin interface)"
|
||||||
aperms = user.get_all_permissions()
|
aperms = user.get_all_permissions()
|
||||||
if aperms:
|
gperms = user.get_group_permissions()
|
||||||
s += "\n Extra User permissions:"
|
uperms = [perm for perm in aperms if perm not in gperms]
|
||||||
gperms = user.get_group_permissions()
|
if gperms:
|
||||||
for p in aperms:
|
s += "\n Group-inherited Permissions:"
|
||||||
if p in gperms:
|
for p in gperms:
|
||||||
s += "\n --- %s (from group)" % p
|
s += "\n --- %s" % p
|
||||||
else:
|
if uperms:
|
||||||
s += "\n ---- %s (custom assigned)" % p
|
s += "\n Individually granted Permisssions:"
|
||||||
|
for p in uperms:
|
||||||
|
s += "\n ---- %s" % p
|
||||||
if not s:
|
if not s:
|
||||||
s = "User %s has no extra permissions." % obj.get_name()
|
s = "User %s has no permissions." % obj.get_name()
|
||||||
else:
|
else:
|
||||||
s = "\nPermissions for user %s: %s" % (obj.get_name(),s)
|
s = "\nPermissions for user %s: %s" % (obj.get_name(),s)
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
|
|
@ -338,11 +350,11 @@ def cmd_chperm(command):
|
||||||
except Permission.DoesNotExist:
|
except Permission.DoesNotExist:
|
||||||
source_object.emit_to("Permission type '%s' is not a valid permission.\nUse @chperm/list for help with valid permission strings." % perm_string)
|
source_object.emit_to("Permission type '%s' is not a valid permission.\nUse @chperm/list for help with valid permission strings." % perm_string)
|
||||||
return
|
return
|
||||||
|
if not switches:
|
||||||
|
source_object.emit_to("You must supply a switch /add or /del.")
|
||||||
|
return
|
||||||
if "add" in switches:
|
if "add" in switches:
|
||||||
#add the permission to this user
|
#add the permission to this user
|
||||||
if not source_object.has_perm("auth.add_permission"):
|
|
||||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
|
||||||
return
|
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
source_object.emit_to("As a superuser you always have all permissions.")
|
source_object.emit_to("As a superuser you always have all permissions.")
|
||||||
return
|
return
|
||||||
|
|
@ -350,16 +362,12 @@ def cmd_chperm(command):
|
||||||
source_object.emit_to("User already has this permission.")
|
source_object.emit_to("User already has this permission.")
|
||||||
return
|
return
|
||||||
user.user_permissions.add(permission)
|
user.user_permissions.add(permission)
|
||||||
user.save()
|
user.save();obj.save()
|
||||||
obj.save()
|
|
||||||
source_object.emit_to("%s gained the permission '%s'." % (obj.get_name(), permission.name))
|
source_object.emit_to("%s gained the permission '%s'." % (obj.get_name(), permission.name))
|
||||||
obj.emit_to("%s gave you the permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
obj.emit_to("%s gave you the permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||||
permission.name))
|
permission.name))
|
||||||
if "del" in switches:
|
if "del" in switches:
|
||||||
#delete the permission from this user
|
#delete the permission from this user
|
||||||
if not source_object.has_perm("auth.delete_permission"):
|
|
||||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
|
||||||
return
|
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
source_object.emit_to("As a superuser you always have all permissions.")
|
source_object.emit_to("As a superuser you always have all permissions.")
|
||||||
return
|
return
|
||||||
|
|
@ -367,25 +375,24 @@ def cmd_chperm(command):
|
||||||
source_object.emit_to("User is already lacking this permission.")
|
source_object.emit_to("User is already lacking this permission.")
|
||||||
return
|
return
|
||||||
user.user_permissions.remove(permission)
|
user.user_permissions.remove(permission)
|
||||||
user.save()
|
user.save();obj.save()
|
||||||
obj.save()
|
|
||||||
source_object.emit_to("%s lost the permission '%s'." % (obj.get_name(), permission.name))
|
source_object.emit_to("%s lost the permission '%s'." % (obj.get_name(), permission.name))
|
||||||
obj.emit_to("%s removed your permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
obj.emit_to("%s removed your permission '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||||
permission.name))
|
permission.name))
|
||||||
GLOBAL_CMD_TABLE.add_command("@chperm", cmd_chperm,
|
GLOBAL_CMD_TABLE.add_command("@setperm", cmd_setperm,
|
||||||
priv_tuple=("auth.change_permission",), auto_help=True, staff_help=True)
|
priv_tuple=("auth.change_permission","genperms.admin_perm"), auto_help=True, staff_help=True)
|
||||||
|
|
||||||
def cmd_chgroup(command):
|
def cmd_setgroup(command):
|
||||||
"""@chgroup
|
"""@setgroup
|
||||||
Usage:
|
Usage:
|
||||||
@chgroup[/switch] [<user>] [= <group>]
|
@setgroup[/switch] [<user>] [= <group>]
|
||||||
|
|
||||||
switches
|
switches
|
||||||
add : add user to a group
|
add : add user to a group
|
||||||
del : remove user from a group
|
del : remove user from a group
|
||||||
list : list all groups a user is part of, or list all available groups if no user is given
|
list : list all groups a user is part of, or list all available groups if no user is given
|
||||||
|
|
||||||
Changes the group membership of a user.
|
Changes and views the group membership of a user.
|
||||||
"""
|
"""
|
||||||
source_object = command.source_object
|
source_object = command.source_object
|
||||||
args = command.command_argument
|
args = command.command_argument
|
||||||
|
|
@ -393,7 +400,7 @@ def cmd_chgroup(command):
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
if "list" not in switches:
|
if "list" not in switches:
|
||||||
source_object.emit_to("Usage: @chgroup[/switch] [user] [= permission]")
|
source_object.emit_to("Usage: @setgroup[/switch] [user] [= permission]")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
#just print all available permissions
|
#just print all available permissions
|
||||||
|
|
@ -402,14 +409,15 @@ def cmd_chgroup(command):
|
||||||
s += "\n %s" % g.name
|
s += "\n %s" % g.name
|
||||||
for p in g.permissions.all():
|
for p in g.permissions.all():
|
||||||
app = p.content_type.app_label
|
app = p.content_type.app_label
|
||||||
s += "\n --- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
if app not in APPS_NOSHOW:
|
||||||
|
s += "\n --- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||||
source_object.emit_to(s)
|
source_object.emit_to(s)
|
||||||
return
|
return
|
||||||
#we have command arguments.
|
#we have command arguments.
|
||||||
arglist = args.split('=',1)
|
arglist = args.split('=',1)
|
||||||
obj_name = arglist[0].strip()
|
obj_name = arglist[0].strip()
|
||||||
if not obj_name:
|
if not obj_name:
|
||||||
source_object.emit_to("Usage: @chgroup[/switch] [user] = [permission]")
|
source_object.emit_to("Usage: @setgroup[/switch] [user] = [permission]")
|
||||||
return
|
return
|
||||||
obj = source_object.search_for_object(obj_name)
|
obj = source_object.search_for_object(obj_name)
|
||||||
if not obj:
|
if not obj:
|
||||||
|
|
@ -417,10 +425,9 @@ def cmd_chgroup(command):
|
||||||
if not obj.is_player():
|
if not obj.is_player():
|
||||||
source_object.emit_to("Only players may be members of permission groups.")
|
source_object.emit_to("Only players may be members of permission groups.")
|
||||||
return
|
return
|
||||||
try:
|
user = obj.get_user_account()
|
||||||
user = User.objects.get(username=obj.get_name(show_dbref=False,no_ansi=True))
|
if not user:
|
||||||
except:
|
return
|
||||||
raise
|
|
||||||
if len(arglist) == 1:
|
if len(arglist) == 1:
|
||||||
#if we didn't have any =, we list the groups this user is member of
|
#if we didn't have any =, we list the groups this user is member of
|
||||||
s = ""
|
s = ""
|
||||||
|
|
@ -429,7 +436,10 @@ def cmd_chgroup(command):
|
||||||
if not user.is_active:
|
if not user.is_active:
|
||||||
s += "\n ACCOUNT NOT ACTIVE."
|
s += "\n ACCOUNT NOT ACTIVE."
|
||||||
for g in user.groups.all():
|
for g in user.groups.all():
|
||||||
s += "\n --- %s" % g
|
s += "\n --- %s" % g
|
||||||
|
for p in g.permissions.all():
|
||||||
|
app = p.content_type.app_label
|
||||||
|
s += "\n -- %s.%s%s\t%s" % (app, p.codename, (35 - len(app) - len(p.codename)) * " ", p.name)
|
||||||
if not s:
|
if not s:
|
||||||
s = "User %s is not a member of any groups." % obj.get_name()
|
s = "User %s is not a member of any groups." % obj.get_name()
|
||||||
else:
|
else:
|
||||||
|
|
@ -439,15 +449,15 @@ def cmd_chgroup(command):
|
||||||
# we supplied an argument on the form obj = group
|
# we supplied an argument on the form obj = group
|
||||||
group_string = arglist[1].strip()
|
group_string = arglist[1].strip()
|
||||||
try:
|
try:
|
||||||
group = Group.objects.get(name=group_string)
|
group = Group.objects.get(name=group_string)
|
||||||
except Group.DoesNotExist:
|
except Group.DoesNotExist:
|
||||||
source_object.emit_to("Group '%s' is not a valid group. Remember that the name is case-sensitive.\nUse @chperm/list for help with valid group names." % group_string)
|
source_object.emit_to("Group '%s' is not a valid group. Remember that the name is case-sensitive.\nUse @chperm/list for help with valid group names." % group_string)
|
||||||
return
|
return
|
||||||
|
if not switches:
|
||||||
|
source_object.emit_to("You must supply a switch /add or /del.")
|
||||||
|
return
|
||||||
if "add" in switches:
|
if "add" in switches:
|
||||||
#add the user to this group
|
#add the user to this group
|
||||||
if not source_object.has_perm("auth.add_group"):
|
|
||||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
|
||||||
return
|
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
source_object.emit_to("As a superuser, group access does not matter.")
|
source_object.emit_to("As a superuser, group access does not matter.")
|
||||||
return
|
return
|
||||||
|
|
@ -455,16 +465,12 @@ def cmd_chgroup(command):
|
||||||
source_object.emit_to("User is already a member of this group.")
|
source_object.emit_to("User is already a member of this group.")
|
||||||
return
|
return
|
||||||
user.groups.add(group)
|
user.groups.add(group)
|
||||||
user.save()
|
user.save(); obj.save()
|
||||||
obj.save()
|
|
||||||
source_object.emit_to("%s added to group '%s'." % (obj.get_name(), group.name))
|
source_object.emit_to("%s added to group '%s'." % (obj.get_name(), group.name))
|
||||||
obj.emit_to("%s added you to the group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
obj.emit_to("%s added you to the group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||||
group.name))
|
group.name))
|
||||||
if "del" in switches:
|
if "del" in switches:
|
||||||
#delete the permission from this user
|
#delete the permission from this user
|
||||||
if not source_object.has_perm("auth.delete_group"):
|
|
||||||
source_object.emit_to(defines_global.NOPERMS_MSG)
|
|
||||||
return
|
|
||||||
if user.is_superuser:
|
if user.is_superuser:
|
||||||
source_object.emit_to("As a superuser, group access does not matter.")
|
source_object.emit_to("As a superuser, group access does not matter.")
|
||||||
return
|
return
|
||||||
|
|
@ -473,10 +479,10 @@ def cmd_chgroup(command):
|
||||||
return
|
return
|
||||||
|
|
||||||
user.groups.remove(group)
|
user.groups.remove(group)
|
||||||
user.save()
|
user.save(); obj.save()
|
||||||
obj.save()
|
|
||||||
source_object.emit_to("%s was removed from group '%s'." % (obj.get_name(), group.name))
|
source_object.emit_to("%s was removed from group '%s'." % (obj.get_name(), group.name))
|
||||||
obj.emit_to("%s removed you from group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
obj.emit_to("%s removed you from group '%s'." % (source_object.get_name(show_dbref=False,no_ansi=True),
|
||||||
group.name))
|
group.name))
|
||||||
GLOBAL_CMD_TABLE.add_command("@chgroup", cmd_chgroup,
|
GLOBAL_CMD_TABLE.add_command("@setgroup", cmd_setgroup,
|
||||||
priv_tuple=("auth.change_group",), auto_help=True, staff_help=True)
|
priv_tuple=("auth.change_group","genperms.admin_group"), auto_help=True, staff_help=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,4 +232,4 @@ def cmd_search(command):
|
||||||
|
|
||||||
display_results(source_object, search_query)
|
display_results(source_object, search_query)
|
||||||
GLOBAL_CMD_TABLE.add_command("@search", cmd_search,
|
GLOBAL_CMD_TABLE.add_command("@search", cmd_search,
|
||||||
priv_tuple=("genperms.builder")),
|
priv_tuple=("objects.info")),
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
"""
|
"""
|
||||||
Commands that are available from the connect screen.
|
Commands that are available from the connect screen.
|
||||||
"""
|
"""
|
||||||
|
import traceback
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from src.objects.models import Attribute, Object
|
from src.objects.models import Attribute, Object
|
||||||
from src import defines_global
|
from src import defines_global
|
||||||
from src.util import functions_general
|
from src.util import functions_general
|
||||||
from src.cmdtable import GLOBAL_UNCON_CMD_TABLE
|
from src.cmdtable import GLOBAL_UNCON_CMD_TABLE
|
||||||
|
from src.logger import log_errmsg
|
||||||
|
|
||||||
def cmd_connect(command):
|
def cmd_connect(command):
|
||||||
"""
|
"""
|
||||||
|
|
@ -104,7 +105,14 @@ def cmd_create(command):
|
||||||
elif len(password) < 3:
|
elif len(password) < 3:
|
||||||
session.msg("Your password must be at least 3 characters or longer.\n\rFor best security, make it at least 8 characters long, avoid making it a real word and mix numbers into it.")
|
session.msg("Your password must be at least 3 characters or longer.\n\rFor best security, make it at least 8 characters long, avoid making it a real word and mix numbers into it.")
|
||||||
else:
|
else:
|
||||||
Object.objects.create_user(command, uname, email, password)
|
try:
|
||||||
|
Object.objects.create_user(command, uname, email, password)
|
||||||
|
except:
|
||||||
|
# we have to handle traceback ourself at this point, if we don't errors will givo no feedback.
|
||||||
|
session.msg("This is a bug. Please e-mail an admin if the problem persists.\n%s" % traceback.format_exc())
|
||||||
|
log_errmsg(traceback.format_exc())
|
||||||
|
raise
|
||||||
|
|
||||||
GLOBAL_UNCON_CMD_TABLE.add_command("create", cmd_create)
|
GLOBAL_UNCON_CMD_TABLE.add_command("create", cmd_create)
|
||||||
|
|
||||||
def cmd_quit(command):
|
def cmd_quit(command):
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ def send_cexternal(cname, cmessage, caller=None, from_external=None):
|
||||||
|
|
||||||
# Look for IMC2 channel maps. If one is found, send an ice-msg-b
|
# Look for IMC2 channel maps. If one is found, send an ice-msg-b
|
||||||
# packet to the network.
|
# packet to the network.
|
||||||
print "caller found: %s (%s). Msg: %s" % (caller,from_external,cmessage)
|
#logger.msg_infomsg("caller found: %s (%s). Msg: %s" % (caller,from_external,cmessage))
|
||||||
|
|
||||||
imccaller = caller
|
imccaller = caller
|
||||||
imccmessage = cmessage
|
imccmessage = cmessage
|
||||||
|
|
@ -349,7 +349,7 @@ def send_cexternal(cname, cmessage, caller=None, from_external=None):
|
||||||
imccaller, imccmessage = cmessage.split("@",1)
|
imccaller, imccmessage = cmessage.split("@",1)
|
||||||
#throw away IRC channel name; IMC users need not know it
|
#throw away IRC channel name; IMC users need not know it
|
||||||
imccmessage = (imccmessage.split(":",1)[1]).strip()
|
imccmessage = (imccmessage.split(":",1)[1]).strip()
|
||||||
print "caller: %s cmessage: %s" % (imccaller, imccmessage)
|
#logger.msg_infomsg("caller: %s cmessage: %s" % (imccaller, imccmessage))
|
||||||
else:
|
else:
|
||||||
imccaller = "*"
|
imccaller = "*"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,40 +66,122 @@ DATABASE_HOST = ''
|
||||||
# Empty string defaults to localhost. Not used with sqlite3.
|
# Empty string defaults to localhost. Not used with sqlite3.
|
||||||
DATABASE_PORT = ''
|
DATABASE_PORT = ''
|
||||||
|
|
||||||
|
## Permissions
|
||||||
|
## The variables in this section are used by each evennia subsystem to tell which permissions to define.
|
||||||
|
## These variables are called by the respective subsystem ('application' in django lingo) of Evennia. The final
|
||||||
|
## look of the permission will be 'app.permission', e.g. 'irc.admin.irc_channels'.
|
||||||
|
## Note that beyond what is listed here, django automatically creates 3 add/change/delete permissions
|
||||||
|
## for each model defined in each appliction. These are however not used by any default commands in
|
||||||
|
## game and are filtered out in e.g. @adminperm/list in order to give the admin more overview.
|
||||||
|
## Note that all variables here must be proper nested tuples of tuples. ( (),(), )
|
||||||
|
|
||||||
# Communication channels in-game
|
# irc permissions
|
||||||
|
PERM_IRC = (
|
||||||
|
('admin_irc_channels', 'May administer IRC channels.'),)
|
||||||
|
# imc2 permissions
|
||||||
|
PERM_IMC2 = (
|
||||||
|
('admin_imc_channels', 'May administer IMC channels.'),)
|
||||||
|
# general channel permissions
|
||||||
|
PERM_CHANNELS = (
|
||||||
|
('emit_commchannel', 'May @cemit over channels.'),
|
||||||
|
('channel_admin', 'May administer comm channels.'),
|
||||||
|
('page','May page other users.'),)
|
||||||
|
# help system access permissions
|
||||||
|
PERM_HELPSYS = (
|
||||||
|
("staff_help", "May see staff help topics."),
|
||||||
|
("add_help", "May add or append to help entries"),
|
||||||
|
("del_help", "May delete help entries"),)
|
||||||
|
# object manipulation/information permissions
|
||||||
|
PERM_OBJECTS = (
|
||||||
|
("teleport","May teleport an object to any location."),
|
||||||
|
("wipe","May wipe all attributes on an object."),
|
||||||
|
("modify_attributes","May modify/delete/add attributes to an object."),
|
||||||
|
("info","May search for and examine objects."),
|
||||||
|
("create", "May create, copy and destroy objects."),
|
||||||
|
("dig", "May dig new rooms, open new exits and link them."),
|
||||||
|
("admin_ownership", "May change ownership of any object."),
|
||||||
|
("see_dbref","May see an object's dbref."),)
|
||||||
|
# misc general and admin permissions
|
||||||
|
PERM_GENPERMS = (
|
||||||
|
("announce", "May make announcements to everyone."),
|
||||||
|
("admin_perm", "Can modify individual permissions."),
|
||||||
|
("admin_group", "Can manage membership in groups."),
|
||||||
|
("process_control", "May shutdown/restart/reload the game"),
|
||||||
|
("manage_players", "Can change passwords, siteban, etc."),
|
||||||
|
("game_info", "Can review game metadata"),)
|
||||||
|
|
||||||
"""
|
## These permissions are not yet used in the default engine.
|
||||||
Your names of various default comm channels for emitting
|
## ("boot", "May use @boot to kick players"),
|
||||||
debug- or informative messages.
|
## ("chown_all", "Can @chown anything to anyone."),
|
||||||
"""
|
## ("free_money", "Has infinite money"),
|
||||||
|
## ("long_fingers", "May get/look/examine etc. from a distance"),
|
||||||
|
## ("steal", "May give negative money"),
|
||||||
|
## ("set_hide", "May set themself invisible"),
|
||||||
|
## ("tel_anywhere", "May @teleport anywhere"),
|
||||||
|
## ("tel_anyone", "May @teleport anything"),
|
||||||
|
## ("see_session_data", "May see detailed player session data"),)
|
||||||
|
|
||||||
|
# Gathering of all permission tuple groups. This is used by e.g. @adminperm to only show these permissions.
|
||||||
|
PERM_ALL_DEFAULTS = (PERM_IRC, PERM_IMC2, PERM_CHANNELS, PERM_HELPSYS, PERM_OBJECTS, PERM_GENPERMS)
|
||||||
|
# If you defined your own tuple groups, add them below.
|
||||||
|
PERM_ALL_CUSTOM = ()
|
||||||
|
|
||||||
|
## Permission Groups
|
||||||
|
## Permission groups clump the permissions into larger chunks for quick assigning to
|
||||||
|
## a user (e.g. a builder). Each permission is written on the form app.permission,
|
||||||
|
## e.g. 'helpsys.view_staff_help'. Each group can contain an arbitrary number of
|
||||||
|
## permissions. A user is added to a group with the default @admingroup command.
|
||||||
|
## Superusers are automatically members of all groups.
|
||||||
|
|
||||||
|
# A dict defining the groups, on the form {group_name:(perm1,perm2,...),...}
|
||||||
|
PERM_GROUPS = \
|
||||||
|
{"Immortals":('irc.admin_irc_channels','imc2.admin_imc_channels','channels.emit_commchannel',
|
||||||
|
'channels.channel_admin','channels.page','helpsys.staff_help','helpsys.add_help',
|
||||||
|
'helpsys.del_help','objects.teleport','objects.wipe','objects.modify_attributes',
|
||||||
|
'objects.info','objects.create','objects.dig','objects.see_dbref','objects.admin_ownership',
|
||||||
|
'genperms.announce','genperms.admin_perm','genperms.admin_group','genperms.process_control',
|
||||||
|
'genperms.manage_players','genperms.game_info'),
|
||||||
|
"Wizards": ('irc.admin_irc_channels','imc2.admin_imc_channels','channels.emit_commchannel',
|
||||||
|
'channels.channel_admin','channels.page','helpsys.staff_help','helpsys.add_help',
|
||||||
|
'helpsys.del_help','objects.teleport','objects.wipe','objects.see_dbref',
|
||||||
|
'objects.modify_attributes',
|
||||||
|
'objects.info','objects.create','objects.dig','objects.admin_ownership','genperms.announce',
|
||||||
|
'genperms.game_info'),
|
||||||
|
"Builders":('channels.emit_commchannel','channels.page','helpsys.staff_help','helpsys.add_help',
|
||||||
|
'helpsys.del_help','objects.teleport','objects.wipe','objects.see_dbref',
|
||||||
|
'objects.modify_attributes', 'objects.info','objects.create','objects.dig',
|
||||||
|
'genperms.game_info'),
|
||||||
|
"Player Helpers":('channels.emit_commchannel', 'channels.page', 'helpsys.staff_help',
|
||||||
|
'helpsys.add_help','helpsys.del_help'),
|
||||||
|
"Players":('channels.emit_commchannel','channels.page')
|
||||||
|
}
|
||||||
|
# By defining a default player group, all players may start with some permissions pre-set.
|
||||||
|
PERM_DEFAULT_PLAYER_GROUP = "Players"
|
||||||
|
|
||||||
|
|
||||||
|
# Your names of various default comm channels for emitting debug- or informative messages.
|
||||||
COMMCHAN_MUD_INFO = 'MUDInfo'
|
COMMCHAN_MUD_INFO = 'MUDInfo'
|
||||||
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
|
COMMCHAN_MUD_CONNECTIONS = 'MUDConnections'
|
||||||
COMMCHAN_IMC2_INFO = 'MUDInfo'
|
COMMCHAN_IMC2_INFO = 'MUDInfo'
|
||||||
COMMCHAN_IRC_INFO = 'MUDInfo'
|
COMMCHAN_IRC_INFO = 'MUDInfo'
|
||||||
|
|
||||||
"""
|
## IMC Configuration
|
||||||
IMC Configuration
|
## IMC (Inter-MUD communication) allows for an evennia chat channel that connects
|
||||||
|
## to people on other MUDs also using the IMC. Your evennia server do *not* have
|
||||||
IMC (Inter-MUD communication) allows for an evennia chat channel that connects
|
## to be open to the public to use IMC; it works as a stand-alone chat client.
|
||||||
to people on other MUDs also using the IMC. Your evennia server do *not* have
|
##
|
||||||
to be open to the public to use IMC; it works as a stand-alone chat client.
|
## Copy and paste this section to your game/settings.py file and change the
|
||||||
|
## values to fit your needs.
|
||||||
Copy and paste this section to your game/settings.py file and change the
|
##
|
||||||
values to fit your needs.
|
## Evennia's IMC2 client was developed against MudByte's network. You must
|
||||||
|
## register your MUD on the network before you can use it, go to
|
||||||
Evennia's IMC2 client was developed against MudByte's network. You must
|
## http://www.mudbytes.net/imc2-intermud-join-network.
|
||||||
register your MUD on the network before you can use it, go to
|
##
|
||||||
http://www.mudbytes.net/imc2-intermud-join-network.
|
## Choose 'Other unsupported IMC2 version' from the choices and
|
||||||
|
## and enter your information there. You have to enter the same
|
||||||
Choose 'Other unsupported IMC2 version' from the choices and
|
## 'short mud name', 'client password' and 'server password' as you
|
||||||
and enter your information there. You have to enter the same
|
## define in this file.
|
||||||
'short mud name', 'client password' and 'server password' as you
|
## The Evennia discussion channel is on server02.mudbytes.net:9000.
|
||||||
define in this file.
|
|
||||||
|
|
||||||
The Evennia discussion channel is on server02.mudbytes.net:9000.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Change to True if you want IMC active at all.
|
# Change to True if you want IMC active at all.
|
||||||
IMC2_ENABLED = False
|
IMC2_ENABLED = False
|
||||||
|
|
@ -120,12 +202,10 @@ IMC2_DEBUG = False
|
||||||
# This isn't something you should generally change.
|
# This isn't something you should generally change.
|
||||||
IMC2_PROTOCOL_VERSION = '2'
|
IMC2_PROTOCOL_VERSION = '2'
|
||||||
|
|
||||||
"""
|
## IRC config. This allows your evennia channels to connect to an external IRC
|
||||||
IRC config. This allows your evennia channels to connect to an external IRC
|
## channel. Evennia will connect under a nickname that then echoes what is
|
||||||
channel. Evennia will connect under a nickname that then echoes what is
|
## said on the channel to IRC and vice versa.
|
||||||
said on the channel to IRC and vice versa.
|
## Obs - make sure the IRC network allows bots.
|
||||||
Obs - make sure the IRC network allows bots.
|
|
||||||
"""
|
|
||||||
|
|
||||||
#Activate the IRC bot.
|
#Activate the IRC bot.
|
||||||
IRC_ENABLED = False
|
IRC_ENABLED = False
|
||||||
|
|
@ -138,8 +218,6 @@ IRC_CHANNEL = ""
|
||||||
#Under what nickname should Evennia connect to the channel
|
#Under what nickname should Evennia connect to the channel
|
||||||
IRC_NICKNAME = ""
|
IRC_NICKNAME = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Local time zone for this installation. All choices can be found here:
|
# Local time zone for this installation. All choices can be found here:
|
||||||
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
||||||
TIME_ZONE = 'America/New_York'
|
TIME_ZONE = 'America/New_York'
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
class GenericPerm(models.Model):
|
class GenericPerm(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
@ -6,19 +7,4 @@ class GenericPerm(models.Model):
|
||||||
fit under a particular module.
|
fit under a particular module.
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
|
permissions = settings.PERM_GENPERMS
|
||||||
permissions = (
|
|
||||||
("announce", "May use @wall to make announcements"),
|
|
||||||
("boot", "May use @boot to kick players"),
|
|
||||||
("builder", "Can build and modify objects"),
|
|
||||||
("chown_all", "Can @chown anything to anyone."),
|
|
||||||
("free_money", "Has infinite money"),
|
|
||||||
("long_fingers", "May get/look/examine etc. from a distance"),
|
|
||||||
("steal", "May give negative money"),
|
|
||||||
("set_hide", "May set themself invisible"),
|
|
||||||
("tel_anywhere", "May @teleport anywhere"),
|
|
||||||
("tel_anyone", "May @teleport anything"),
|
|
||||||
("see_session_data", "May see detailed player session data"),
|
|
||||||
("process_control", "May shutdown/restart/reload the game"),
|
|
||||||
("manage_players", "Can change passwords, siteban, etc."),
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ well as creating auto-docs of commands based on their doc strings.
|
||||||
The system supports help-markup for multiple help entries as well
|
The system supports help-markup for multiple help entries as well
|
||||||
as a dynamically updating help index.
|
as a dynamically updating help index.
|
||||||
"""
|
"""
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from src.helpsys.models import HelpEntry
|
from src.helpsys.models import HelpEntry
|
||||||
from src.ansi import ANSITable
|
from src.ansi import ANSITable
|
||||||
|
|
||||||
|
|
@ -44,7 +45,7 @@ def _create_help(topicstr, entrytext, staff_only=False, force_create=False,
|
||||||
elif pobject:
|
elif pobject:
|
||||||
#checks access rights before searching (this should have been
|
#checks access rights before searching (this should have been
|
||||||
#done already at the command level)
|
#done already at the command level)
|
||||||
if not pobject.is_staff(): return []
|
if not pobject.has_perm("helpsys.add_help"): return []
|
||||||
topic = HelpEntry.objects.find_topicmatch(pobject, topicstr)
|
topic = HelpEntry.objects.find_topicmatch(pobject, topicstr)
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
@ -197,7 +198,8 @@ def get_help_index(pobject,filter=None):
|
||||||
filter='staff' - view only staff-specific help files
|
filter='staff' - view only staff-specific help files
|
||||||
filter='player' - view only those files visible to all
|
filter='player' - view only those files visible to all
|
||||||
"""
|
"""
|
||||||
if pobject.is_staff():
|
|
||||||
|
if pobject.has_perm("helpsys.staff_help"):
|
||||||
if filter == 'staff':
|
if filter == 'staff':
|
||||||
helpentries = HelpEntry.objects.filter(staff_only=True).order_by('topicname')
|
helpentries = HelpEntry.objects.filter(staff_only=True).order_by('topicname')
|
||||||
elif filter == 'player':
|
elif filter == 'player':
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
Models for the help system.
|
Models for the help system.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from src import ansi
|
from src import ansi
|
||||||
from src.helpsys.managers import HelpEntryManager
|
from src.helpsys.managers import HelpEntryManager
|
||||||
|
|
||||||
|
|
@ -18,6 +19,7 @@ class HelpEntry(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = "Help entries"
|
verbose_name_plural = "Help entries"
|
||||||
ordering = ['topicname']
|
ordering = ['topicname']
|
||||||
|
permissions = settings.PERM_HELPSYS
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.topicname
|
return self.topicname
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from src.channels.models import CommChannel
|
from src.channels.models import CommChannel
|
||||||
|
|
||||||
class IMC2ChannelMapping(models.Model):
|
class IMC2ChannelMapping(models.Model):
|
||||||
|
|
@ -14,6 +15,7 @@ class IMC2ChannelMapping(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "IMC2 Channel mapping"
|
verbose_name = "IMC2 Channel mapping"
|
||||||
verbose_name_plural = "IMC2 Channel mappings"
|
verbose_name_plural = "IMC2 Channel mappings"
|
||||||
|
permissions = settings.PERM_IMC2
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s <-> %s" % (self.channel, self.imc2_channel_name)
|
return "%s <-> %s" % (self.channel, self.imc2_channel_name)
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,12 @@ other things.
|
||||||
|
|
||||||
Everything starts at handle_setup()
|
Everything starts at handle_setup()
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group, Permission
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
from src.config.models import ConfigValue, CommandAlias, ConnectScreen
|
from src.config.models import ConfigValue, CommandAlias, ConnectScreen
|
||||||
from src import comsys, defines_global
|
from src import comsys, defines_global, logger
|
||||||
|
|
||||||
def get_god_user():
|
def get_god_user():
|
||||||
"""
|
"""
|
||||||
Returns the initially created 'god' User object.
|
Returns the initially created 'god' User object.
|
||||||
|
|
@ -54,13 +53,21 @@ def create_objects():
|
||||||
|
|
||||||
def create_groups():
|
def create_groups():
|
||||||
"""
|
"""
|
||||||
Creates the default permissions groups.
|
Creates the default permissions groups and assign permissions to each as defined in settings.
|
||||||
"""
|
"""
|
||||||
groups = ("Immortals", "Wizards", "Builders", "Player Helpers")
|
for group_name, perm_tuple in settings.PERM_GROUPS.items():
|
||||||
for group in groups:
|
|
||||||
newgroup = Group()
|
newgroup = Group()
|
||||||
newgroup.name = group
|
newgroup.name = group_name
|
||||||
newgroup.save()
|
newgroup.save()
|
||||||
|
for perm_string in perm_tuple:
|
||||||
|
#assign permissions to the group
|
||||||
|
app_label, codename = perm_string.split(".",1)
|
||||||
|
try:
|
||||||
|
permission = Permission.objects.filter(content_type__app_label=app_label).get(codename=codename)
|
||||||
|
except Permission.DoesNotExist:
|
||||||
|
logger.log_errmsg("Initial_setup: Permission %s is not defined." % perm_string)
|
||||||
|
continue
|
||||||
|
newgroup.permissions.add(permission)
|
||||||
|
|
||||||
def create_channels():
|
def create_channels():
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.conf import settings
|
||||||
from src.channels.models import CommChannel
|
from src.channels.models import CommChannel
|
||||||
|
|
||||||
class IRCChannelMapping(models.Model):
|
class IRCChannelMapping(models.Model):
|
||||||
|
|
@ -13,8 +14,9 @@ class IRCChannelMapping(models.Model):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "IRC Channel mapping"
|
verbose_name = "IRC Channel mapping"
|
||||||
verbose_name_plural = "IRC Channel mappings"
|
verbose_name_plural = "IRC Channel mappings"
|
||||||
|
permissions = settings.PERM_IRC
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s <-> %s (%s)" % (self.channel, self.irc_channel_name,
|
return "%s <-> %s (%s)" % (self.channel, self.irc_channel_name,
|
||||||
self.irc_server_name)
|
self.irc_server_name)
|
||||||
|
|
|
||||||
|
|
@ -242,8 +242,7 @@ class ObjectManager(models.Manager):
|
||||||
if match_type == "exact":
|
if match_type == "exact":
|
||||||
return [prospect for prospect in searchlist
|
return [prospect for prospect in searchlist
|
||||||
if ostring == str(prospect.get_attribute_value(attribute_name))]
|
if ostring == str(prospect.get_attribute_value(attribute_name))]
|
||||||
else:
|
else:
|
||||||
print [type(p) for p in searchlist]
|
|
||||||
return [prospect for prospect in searchlist
|
return [prospect for prospect in searchlist
|
||||||
if ostring in str(prospect.get_attribute_value(attribute_name))]
|
if ostring in str(prospect.get_attribute_value(attribute_name))]
|
||||||
else:
|
else:
|
||||||
|
|
@ -466,9 +465,7 @@ class ObjectManager(models.Manager):
|
||||||
# pluck the user ID from it.
|
# pluck the user ID from it.
|
||||||
if not str(uid).isdigit():
|
if not str(uid).isdigit():
|
||||||
uid = uid.id
|
uid = uid.id
|
||||||
logger.log_infomsg('Next usable object ID is %d. (recycled)' % uid)
|
logger.log_infomsg('Create_user: Recycling object ID %d.' % uid)
|
||||||
else:
|
|
||||||
logger.log_infomsg('Next usable object ID is %d. (new)' % uid)
|
|
||||||
|
|
||||||
user = User.objects.create_user(uname, email, password)
|
user = User.objects.create_user(uname, email, password)
|
||||||
# It stinks to have to do this but it's the only trivial way now.
|
# It stinks to have to do this but it's the only trivial way now.
|
||||||
|
|
@ -480,7 +477,6 @@ class ObjectManager(models.Manager):
|
||||||
|
|
||||||
# Update the session to use the newly created User object's ID.
|
# Update the session to use the newly created User object's ID.
|
||||||
command.session.uid = uid
|
command.session.uid = uid
|
||||||
logger.log_infomsg('User created with id %d.' % command.session.uid)
|
|
||||||
|
|
||||||
# Grab the user object again since we've changed it and the old reference
|
# Grab the user object again since we've changed it and the old reference
|
||||||
# is no longer valid.
|
# is no longer valid.
|
||||||
|
|
@ -495,16 +491,20 @@ class ObjectManager(models.Manager):
|
||||||
# The User and player Object are ready, do anything needed by the
|
# The User and player Object are ready, do anything needed by the
|
||||||
# game to further prepare things.
|
# game to further prepare things.
|
||||||
user_object.scriptlink.at_player_creation()
|
user_object.scriptlink.at_player_creation()
|
||||||
|
|
||||||
# Activate the player's session and set them loose.
|
|
||||||
command.session.login(user, first_login=True)
|
|
||||||
|
|
||||||
logger.log_infomsg('Registration: %s' % user_object.get_name())
|
|
||||||
|
|
||||||
# Add the user to all of the CommChannel objects that are flagged
|
# Add the user to all of the CommChannel objects that are flagged
|
||||||
# is_joined_by_default.
|
# is_joined_by_default.
|
||||||
command.session.add_default_channels()
|
command.session.add_default_channels()
|
||||||
|
|
||||||
|
# Add user to the default permission group, if defined set in preferences.
|
||||||
|
command.session.add_default_group()
|
||||||
|
|
||||||
|
logger.log_infomsg("Registered new user: %s" % user_object.get_name())
|
||||||
|
|
||||||
|
# Activate the player's session and set them loose.
|
||||||
|
command.session.login(user, first_login=True)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# ObjectManager Copy method
|
# ObjectManager Copy method
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,10 @@ class Object(models.Model):
|
||||||
#state system can set a particular command table to be used (not persistent).
|
#state system can set a particular command table to be used (not persistent).
|
||||||
state = None
|
state = None
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['-date_created', 'id']
|
||||||
|
permissions = settings.PERM_OBJECTS
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
"""
|
"""
|
||||||
Used to figure out if one object is the same as another.
|
Used to figure out if one object is the same as another.
|
||||||
|
|
@ -136,9 +140,6 @@ class Object(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s" % (self.get_name(no_ansi=True),)
|
return "%s" % (self.get_name(no_ansi=True),)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['-date_created', 'id']
|
|
||||||
|
|
||||||
def dbref(self):
|
def dbref(self):
|
||||||
"""Returns the object's dbref id on the form #NN, directly
|
"""Returns the object's dbref id on the form #NN, directly
|
||||||
usable by Object.objects.dbref_search()
|
usable by Object.objects.dbref_search()
|
||||||
|
|
@ -206,8 +207,8 @@ class Object(models.Model):
|
||||||
if self.is_player():
|
if self.is_player():
|
||||||
return session_mgr.sessions_from_object(self)
|
return session_mgr.sessions_from_object(self)
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def emit_to(self, message):
|
def emit_to(self, message):
|
||||||
"""
|
"""
|
||||||
Emits something to any sessions attached to the object.
|
Emits something to any sessions attached to the object.
|
||||||
|
|
@ -291,7 +292,7 @@ class Object(models.Model):
|
||||||
looker_user = self.get_user_account()
|
looker_user = self.get_user_account()
|
||||||
if looker_user:
|
if looker_user:
|
||||||
# Builders see dbrefs
|
# Builders see dbrefs
|
||||||
return looker_user.has_perm('genperms.builder')
|
return looker_user.has_perm('objects.see_dbref')
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -300,7 +301,9 @@ class Object(models.Model):
|
||||||
Checks to see whether a user has the specified permission or is a super
|
Checks to see whether a user has the specified permission or is a super
|
||||||
user.
|
user.
|
||||||
|
|
||||||
perm: (string) A string representing the desired permission.
|
perm: (string) A string representing the desired permission. This
|
||||||
|
is on the form app.perm , e.g. 'objects.see_dbref' as
|
||||||
|
defined in the settings file.
|
||||||
"""
|
"""
|
||||||
if not self.is_player():
|
if not self.is_player():
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.auth.models import Group
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from util import functions_general
|
from util import functions_general
|
||||||
from src.objects.models import Object
|
from src.objects.models import Object
|
||||||
|
|
@ -202,15 +203,27 @@ class SessionProtocol(StatefulTelnetProtocol):
|
||||||
Adds the player to the default channels.
|
Adds the player to the default channels.
|
||||||
"""
|
"""
|
||||||
# Add the default channels.
|
# Add the default channels.
|
||||||
for chan in CommChannel.objects.filter(is_joined_by_default=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()
|
||||||
chan_alias = chan.get_default_chan_alias()
|
comsys.plr_add_channel(self.get_pobject(), chan_alias, chan)
|
||||||
membership = CommChannelMembership(channel=chan,
|
|
||||||
listener=self.get_pobject(),
|
|
||||||
user_alias=chan_alias)
|
|
||||||
membership.save()
|
|
||||||
comsys.plr_set_channel_listening(self, chan_alias, True)
|
comsys.plr_set_channel_listening(self, chan_alias, True)
|
||||||
|
|
||||||
|
def add_default_group(self):
|
||||||
|
default_group = settings.PERM_DEFAULT_PLAYER_GROUP.strip()
|
||||||
|
if not default_group:
|
||||||
|
logger.log_infomsg("settings.DEFAULT_PLAYER_GROUP is not set. Using no group.")
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
group = Group.objects.get(name=default_group)
|
||||||
|
except Group.DoesNotExist:
|
||||||
|
logger.log_errmsg("settings.DEFAULT_PLAYER_GROUP = %s is not a valid group. Using no group." % default_group)
|
||||||
|
return
|
||||||
|
pobj = self.get_pobject()
|
||||||
|
user = User.objects.get(username=pobj.get_name(show_dbref=False,no_ansi=True))
|
||||||
|
user.groups.add(group)
|
||||||
|
logger.log_infomsg("Added new player to default permission group '%s'." % default_group)
|
||||||
|
user.save(); pobj.save()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
String representation of the user session class. We use
|
String representation of the user session class. We use
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue