Made so the default add_default_cmdset script also removes the added cmdset when stopped. Fixed the function of @delplayer command.

This commit is contained in:
Griatch 2010-09-05 18:20:39 +00:00
parent 212061abb6
commit e125763ea5
5 changed files with 86 additions and 36 deletions

View file

@ -12,7 +12,7 @@ from src.scripts.models import ScriptDB
from src.objects.models import ObjectDB from src.objects.models import ObjectDB
from src.permissions.models import PermissionGroup from src.permissions.models import PermissionGroup
from src.utils import reloads, create, logger, utils from src.utils import reloads, create, logger, utils
from src.permissions.permissions import has_perm from src.permissions.permissions import has_perm, has_perm_string
from game.gamesrc.commands.default.muxcommand import MuxCommand from game.gamesrc.commands.default.muxcommand import MuxCommand
@ -437,41 +437,76 @@ class CmdDelPlayer(MuxCommand):
if ':' in args: if ':' in args:
args, reason = [arg.strip() for arg in args.split(':', 1)] args, reason = [arg.strip() for arg in args.split(':', 1)]
# Search for the object connected to this user (this is done by # We use player_search since we want to be sure to find also players
# adding a * to the beginning of the search criterion) # that lack characters.
pobj = caller.search("*%s" % args, global_search=True) players = PlayerDB.objects.filter(db_key=args)
if not pobj: if not players:
# if we cannot find an object connected to this user, try:
# try a more direct approach players = PlayerDB.objects.filter(id=args)
except ValueError:
pass
if not players:
# try to find a user instead of a Player
try: try:
user = User.objects.get(id=args) user = User.objects.get(id=args)
except Exception: except Exception:
try: try:
user = User.objects.get(name__iexact=args) user = User.objects.get(username__iexact=args)
except Exception: except Exception:
caller.msg("Could not find user/id '%s'." % args) string = "No Player nor User found matching '%s'." % args
caller.msg(string)
return return
uprofile = user.get_profile try:
else: player = user.get_profile()
user = pobj.user except Exception:
uprofile = pobj.user_profile player = None
if not has_perm(caller, uprofile, 'manage_players'): if not has_perm_string(caller, 'manage_players'):
string = "You don't have the permissions to delete this player."
caller.msg(string)
return
string = ""
name = user.username
user.delete()
if player:
name = player.name
player.delete()
string = "Player %s was deleted." % name
else:
string += "The User %s was deleted, but had no Player associated with it." % name
caller.msg(string)
return
elif len(players) > 1:
string = "There where multiple matches:"
for player in players:
string += "\n %s %s" % (player.id, player.key)
return
else:
# one single match
player = players[0]
user = player.user
character = player.character
if not has_perm(caller, player, 'manage_players'):
string = "You don't have the permissions to delete that player." string = "You don't have the permissions to delete that player."
caller.msg(string) caller.msg(string)
return return
uname = user.username uname = user.username
# boot the player then delete # boot the player then delete
if pobj and pobj.has_user: if character and character.has_player:
caller.msg("Booting and informing player ...") caller.msg("Booting and informing player ...")
msg = "\nYour account '%s' is being *permanently* deleted.\n" % uname string = "\nYour account '%s' is being *permanently* deleted.\n" % uname
if reason: if reason:
msg += " Reason given:\n '%s'" % reason string += " Reason given:\n '%s'" % reason
pobj.msg(msg) character.msg(string)
caller.execute_cmd("@boot %s" % uname) caller.execute_cmd("@boot %s" % uname)
uprofile.delete() player.delete()
user.delete() user.delete()
caller.msg("Player %s was successfully deleted." % uname) caller.msg("Player %s was successfully deleted." % uname)

View file

@ -307,7 +307,7 @@ class CmdSetHandler(object):
the last cmdset in the stack is removed. Whenever the last cmdset in the stack is removed. Whenever
the cmdset_stack changes, the cmdset is updated. the cmdset_stack changes, the cmdset is updated.
The default cmdset (first entry in stack) is never The default cmdset (first entry in stack) is never
removed - set it to an empty set with add_default instead. removed - remove it explicitly with delete_default.
key_or_class - a specific cmdset key or a cmdset class (in key_or_class - a specific cmdset key or a cmdset class (in
the latter case, *all* cmdsets of this class the latter case, *all* cmdsets of this class
@ -339,6 +339,11 @@ class CmdSetHandler(object):
# re-sync the cmdsethandler. # re-sync the cmdsethandler.
self.update() self.update()
def delete_default(self):
"This explicitly deletes the default cmdset. It's the only command that can."
self.cmdset_stack[0] = CmdSet(cmdsetobj=self.obj, key="Empty")
self.update()
def all(self): def all(self):
""" """
Returns the list of cmdsets. Mostly useful to check if stack if empty or not. Returns the list of cmdsets. Mostly useful to check if stack if empty or not.

View file

@ -301,3 +301,13 @@ class AddCmdSet(Script):
else: else:
self.obj.cmdset.add(cmdset) self.obj.cmdset.add(cmdset)
def at_stop(self):
"""
This removes the cmdset when the script stops
"""
cmdset = self.db.cmdset
if cmdset:
if self.db.add_default:
self.obj.cmdset.delete_default()
else:
self.obj.cmdset.delete(cmdset)

View file

@ -417,7 +417,7 @@ def create_player(name, email, password,
new_user = User.objects.create_user(name, email, password) new_user = User.objects.create_user(name, email, password)
# create the associated Player for this User, and tie them together # create the associated Player for this User, and tie them together
new_player = PlayerDB(user=new_user) new_player = PlayerDB(db_key=name, user=new_user)
new_player.save() new_player.save()
# assign mud permissions # assign mud permissions