Implemented @password and @newpass.
This commit is contained in:
parent
121e8cf7c1
commit
959be95e42
4 changed files with 121 additions and 12 deletions
|
|
@ -19,7 +19,6 @@ High Priority Tasks
|
||||||
functions in functions_db.py.
|
functions in functions_db.py.
|
||||||
* Implement player to player paging/telling.
|
* Implement player to player paging/telling.
|
||||||
* Implement a global comsys of some sort. Use MUX2's commands and stuff.
|
* Implement a global comsys of some sort. Use MUX2's commands and stuff.
|
||||||
* Implement @newpass and @password.
|
|
||||||
|
|
||||||
Medium Priority Tasks
|
Medium Priority Tasks
|
||||||
---------------------
|
---------------------
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,36 @@ class Object(models.Model):
|
||||||
else:
|
else:
|
||||||
return profile[0].is_superuser
|
return profile[0].is_superuser
|
||||||
|
|
||||||
|
def owns_other(self, other_obj):
|
||||||
|
"""
|
||||||
|
See if the envoked object owns another object.
|
||||||
|
other_obj: (Object) Reference for object to check ownership of.
|
||||||
|
"""
|
||||||
|
return self.id == other_obj.get_owner().id
|
||||||
|
|
||||||
|
def controls_other(self, other_obj):
|
||||||
|
"""
|
||||||
|
See if the envoked object controls another object.
|
||||||
|
other_obj: (Object) Reference for object to check dominance of.
|
||||||
|
"""
|
||||||
|
if self == other_obj:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.is_superuser():
|
||||||
|
# Don't allow superusers to dominate other superusers.
|
||||||
|
if not other_obj.is_superuser():
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self.owns_other(other_obj):
|
||||||
|
# If said object owns the target, then give it the green.
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
# Still pending more stuff here, for now assume we have
|
||||||
|
# dominance. Bad assumption.
|
||||||
|
return True
|
||||||
|
|
||||||
def set_home(self, new_home):
|
def set_home(self, new_home):
|
||||||
"""
|
"""
|
||||||
Sets an object's home.
|
Sets an object's home.
|
||||||
|
|
@ -135,6 +165,14 @@ class Object(models.Model):
|
||||||
pobject.name = new_name
|
pobject.name = new_name
|
||||||
pobject.save()
|
pobject.save()
|
||||||
|
|
||||||
|
def get_user_account(self):
|
||||||
|
"""
|
||||||
|
Returns the player object's account object.
|
||||||
|
"""
|
||||||
|
if not self.is_player():
|
||||||
|
return False
|
||||||
|
return User.objects.get(id=self.id)
|
||||||
|
|
||||||
def get_name(self, fullname=False):
|
def get_name(self, fullname=False):
|
||||||
"""
|
"""
|
||||||
Returns an object's name.
|
Returns an object's name.
|
||||||
|
|
|
||||||
|
|
@ -70,17 +70,19 @@ def handle(cdat):
|
||||||
cmd(cdat)
|
cmd(cdat)
|
||||||
return
|
return
|
||||||
|
|
||||||
pobject = session.get_pobject()
|
if session.logged_in:
|
||||||
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
# If we're not logged in, don't check exits.
|
||||||
if exit_matches:
|
pobject = session.get_pobject()
|
||||||
exit = exit_matches[0]
|
exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted']))
|
||||||
if exit.get_home():
|
if exit_matches:
|
||||||
cdat['uinput'] = parsed_input
|
exit = exit_matches[0]
|
||||||
pobject.move_to(exit.get_home())
|
if exit.get_home():
|
||||||
commands_general.cmd_look(cdat)
|
cdat['uinput'] = parsed_input
|
||||||
else:
|
pobject.move_to(exit.get_home())
|
||||||
session.msg("That exit leads to nowhere.")
|
commands_general.cmd_look(cdat)
|
||||||
return
|
else:
|
||||||
|
session.msg("That exit leads to nowhere.")
|
||||||
|
return
|
||||||
|
|
||||||
# If we reach this point, we haven't matched anything.
|
# If we reach this point, we haven't matched anything.
|
||||||
raise UnknownCommand
|
raise UnknownCommand
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import commands_general
|
||||||
import cmdhandler
|
import cmdhandler
|
||||||
import session_mgr
|
import session_mgr
|
||||||
import ansi
|
import ansi
|
||||||
|
from django.contrib.auth.models import User
|
||||||
from apps.objects.models import Object
|
from apps.objects.models import Object
|
||||||
"""
|
"""
|
||||||
Staff commands may be a bad description for this file, but it'll do for
|
Staff commands may be a bad description for this file, but it'll do for
|
||||||
|
|
@ -93,6 +94,75 @@ def cmd_description(cdat):
|
||||||
session.msg("%s - DESCRIPTION set." % (target_obj,))
|
session.msg("%s - DESCRIPTION set." % (target_obj,))
|
||||||
target_obj.set_description(new_desc)
|
target_obj.set_description(new_desc)
|
||||||
|
|
||||||
|
def cmd_newpassword(cdat):
|
||||||
|
"""
|
||||||
|
Set a player's password.
|
||||||
|
"""
|
||||||
|
session = cdat['session']
|
||||||
|
pobject = session.get_pobject()
|
||||||
|
args = cdat['uinput']['splitted'][1:]
|
||||||
|
eq_args = ' '.join(args).split('=')
|
||||||
|
searchstring = ''.join(eq_args[0])
|
||||||
|
newpass = ''.join(eq_args[1:])
|
||||||
|
|
||||||
|
if len(args) == 0:
|
||||||
|
session.msg("What player's password do you want to change")
|
||||||
|
return
|
||||||
|
if len(newpass) == 0:
|
||||||
|
session.msg("You must supply a new password.")
|
||||||
|
return
|
||||||
|
|
||||||
|
results = functions_db.local_and_global_search(pobject, searchstring)
|
||||||
|
|
||||||
|
|
||||||
|
if len(results) > 1:
|
||||||
|
session.msg("More than one match found (please narrow target):")
|
||||||
|
for result in results:
|
||||||
|
session.msg(" %s" % (result,))
|
||||||
|
elif len(results) == 0:
|
||||||
|
session.msg("I don't see that here.")
|
||||||
|
elif not pobject.controls_other(results[0]):
|
||||||
|
session.msg("You do not control %s." % (results[0],))
|
||||||
|
else:
|
||||||
|
uaccount = results[0].get_user_account()
|
||||||
|
if len(newpass) == 0:
|
||||||
|
uaccount.set_password()
|
||||||
|
else:
|
||||||
|
uaccount.set_password(newpass)
|
||||||
|
uaccount.save()
|
||||||
|
session.msg("%s - PASSWORD set." % (results[0],))
|
||||||
|
results[0].emit_to("%s has changed your password." % (pobject,))
|
||||||
|
|
||||||
|
def cmd_password(cdat):
|
||||||
|
"""
|
||||||
|
Changes your own password.
|
||||||
|
|
||||||
|
@newpass <Oldpass>=<Newpass>
|
||||||
|
"""
|
||||||
|
session = cdat['session']
|
||||||
|
pobject = session.get_pobject()
|
||||||
|
args = cdat['uinput']['splitted'][1:]
|
||||||
|
eq_args = ' '.join(args).split('=')
|
||||||
|
oldpass = ''.join(eq_args[0])
|
||||||
|
newpass = ''.join(eq_args[1:])
|
||||||
|
|
||||||
|
if len(oldpass) == 0:
|
||||||
|
session.msg("You must provide your old password.")
|
||||||
|
elif len(newpass) == 0:
|
||||||
|
session.msg("You must provide your new password.")
|
||||||
|
else:
|
||||||
|
uaccount = User.objects.get(id=pobject.id)
|
||||||
|
|
||||||
|
if not uaccount.check_password(oldpass):
|
||||||
|
session.msg("The specified old password isn't correct.")
|
||||||
|
elif len(newpass) < 3:
|
||||||
|
session.msg("Passwords must be at least three characters long.")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
uaccount.set_password(newpass)
|
||||||
|
uaccount.save()
|
||||||
|
session.msg("Password changed.")
|
||||||
|
|
||||||
def cmd_name(cdat):
|
def cmd_name(cdat):
|
||||||
"""
|
"""
|
||||||
Handle naming an object.
|
Handle naming an object.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue