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:
parent
212061abb6
commit
e125763ea5
5 changed files with 86 additions and 36 deletions
|
|
@ -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,43 +437,78 @@ 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
|
||||||
return
|
caller.msg(string)
|
||||||
uprofile = user.get_profile
|
return
|
||||||
else:
|
try:
|
||||||
user = pobj.user
|
player = user.get_profile()
|
||||||
uprofile = pobj.user_profile
|
except Exception:
|
||||||
|
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 that player."
|
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)
|
caller.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
uname = user.username
|
elif len(players) > 1:
|
||||||
# boot the player then delete
|
string = "There where multiple matches:"
|
||||||
if pobj and pobj.has_user:
|
for player in players:
|
||||||
caller.msg("Booting and informing player ...")
|
string += "\n %s %s" % (player.id, player.key)
|
||||||
msg = "\nYour account '%s' is being *permanently* deleted.\n" % uname
|
return
|
||||||
if reason:
|
|
||||||
msg += " Reason given:\n '%s'" % reason
|
|
||||||
pobj.msg(msg)
|
|
||||||
caller.execute_cmd("@boot %s" % uname)
|
|
||||||
|
|
||||||
uprofile.delete()
|
else:
|
||||||
user.delete()
|
# one single match
|
||||||
caller.msg("Player %s was successfully deleted." % uname)
|
|
||||||
|
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."
|
||||||
|
caller.msg(string)
|
||||||
|
return
|
||||||
|
|
||||||
|
uname = user.username
|
||||||
|
# boot the player then delete
|
||||||
|
if character and character.has_player:
|
||||||
|
caller.msg("Booting and informing player ...")
|
||||||
|
string = "\nYour account '%s' is being *permanently* deleted.\n" % uname
|
||||||
|
if reason:
|
||||||
|
string += " Reason given:\n '%s'" % reason
|
||||||
|
character.msg(string)
|
||||||
|
caller.execute_cmd("@boot %s" % uname)
|
||||||
|
|
||||||
|
player.delete()
|
||||||
|
user.delete()
|
||||||
|
caller.msg("Player %s was successfully deleted." % uname)
|
||||||
|
|
||||||
|
|
||||||
class CmdNewPassword(MuxCommand):
|
class CmdNewPassword(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,10 @@ class CmdCreate(MuxCommand):
|
||||||
permissions = settings.PERMISSION_PLAYER_DEFAULT
|
permissions = settings.PERMISSION_PLAYER_DEFAULT
|
||||||
|
|
||||||
new_character = create.create_player(playername, email, password,
|
new_character = create.create_player(playername, email, password,
|
||||||
permissions=permissions,
|
permissions=permissions,
|
||||||
location=default_home,
|
location=default_home,
|
||||||
typeclass=typeclass,
|
typeclass=typeclass,
|
||||||
home=default_home)
|
home=default_home)
|
||||||
|
|
||||||
# set a default description
|
# set a default description
|
||||||
new_character.db.desc = "This is a Player."
|
new_character.db.desc = "This is a Player."
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue