diff --git a/evennia/trunk/TODO b/evennia/trunk/TODO index 7bf1c4c736..ddbc5ef245 100644 --- a/evennia/trunk/TODO +++ b/evennia/trunk/TODO @@ -19,7 +19,6 @@ High Priority Tasks functions in functions_db.py. * Implement player to player paging/telling. * Implement a global comsys of some sort. Use MUX2's commands and stuff. -* Implement @newpass and @password. Medium Priority Tasks --------------------- diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index b3dbdde871..2c6c80639a 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -114,6 +114,36 @@ class Object(models.Model): else: 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): """ Sets an object's home. @@ -135,6 +165,14 @@ class Object(models.Model): pobject.name = new_name 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): """ Returns an object's name. diff --git a/evennia/trunk/cmdhandler.py b/evennia/trunk/cmdhandler.py index 0a21d00616..e947c8f4c4 100755 --- a/evennia/trunk/cmdhandler.py +++ b/evennia/trunk/cmdhandler.py @@ -70,17 +70,19 @@ def handle(cdat): cmd(cdat) return - pobject = session.get_pobject() - exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted'])) - if exit_matches: - exit = exit_matches[0] - if exit.get_home(): - cdat['uinput'] = parsed_input - pobject.move_to(exit.get_home()) - commands_general.cmd_look(cdat) - else: - session.msg("That exit leads to nowhere.") - return + if session.logged_in: + # If we're not logged in, don't check exits. + pobject = session.get_pobject() + exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted'])) + if exit_matches: + exit = exit_matches[0] + if exit.get_home(): + cdat['uinput'] = parsed_input + pobject.move_to(exit.get_home()) + commands_general.cmd_look(cdat) + else: + session.msg("That exit leads to nowhere.") + return # If we reach this point, we haven't matched anything. raise UnknownCommand diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 5c182622d1..1ccddaa29e 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -4,6 +4,7 @@ import commands_general import cmdhandler import session_mgr import ansi +from django.contrib.auth.models import User from apps.objects.models import Object """ 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,)) 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 = + """ + 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): """ Handle naming an object.