diff --git a/src/cmdtable.py b/src/cmdtable.py index 4cab99c7b2..4198b100b9 100644 --- a/src/cmdtable.py +++ b/src/cmdtable.py @@ -75,6 +75,7 @@ GLOBAL_CMD_TABLE.add_command("@ccreate", commands.comsys.cmd_ccreate, priv_tuple=("objects.add_commchannel")), GLOBAL_CMD_TABLE.add_command("@cdestroy", commands.comsys.cmd_cdestroy, priv_tuple=("objects.delete_commchannel")), +GLOBAL_CMD_TABLE.add_command("@chown", commands.objmanip.cmd_chown), GLOBAL_CMD_TABLE.add_command("@cemit", commands.comsys.cmd_cemit), GLOBAL_CMD_TABLE.add_command("@clist", commands.comsys.cmd_clist), GLOBAL_CMD_TABLE.add_command("@create", commands.objmanip.cmd_create, diff --git a/src/commands/objmanip.py b/src/commands/objmanip.py index 720c1cb0a7..d8d94168c1 100644 --- a/src/commands/objmanip.py +++ b/src/commands/objmanip.py @@ -368,6 +368,59 @@ def cmd_open(command): new_object = Object.objects.create_object(odat) session.msg("You open an unlinked exit - %s" % (new_object,)) + +def cmd_chown(command): + """ + Changes the ownership of an object. The new owner specified must be a + player object. + + Forms: + @chown = + """ + session = command.session + pobject = session.get_pobject() + + if not command.command_argument: + session.msg("Change the ownership of what?") + return + + eq_args = command.command_argument.split('=', 1) + target_name = eq_args[0] + owner_name = eq_args[1] + + if len(target_name) == 0: + session.msg("Change the ownership of what?") + return + + if len(eq_args) > 1: + target_obj = Object.objects.standard_plr_objsearch(session, target_name) + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not target_obj: + return + + if not pobject.controls_other(target_obj): + session.msg(defines_global.NOCONTROL_MSG) + return + + owner_obj = Object.objects.standard_plr_objsearch(session, owner_name) + # Use standard_plr_objsearch to handle duplicate/nonexistant results. + if not owner_obj: + return + + if not owner_obj.is_player(): + session.msg("Only players may own objects.") + return + if target_obj.is_player(): + session.msg("You may not change the ownership of player objects.") + return + + target_obj.set_owner(owner_obj) + session.msg("%s now owns %s." % (owner_obj, target_obj)) + + else: + # We haven't provided a target. + session.msg("Who should be the new owner of the object?") + return def cmd_link(command): """ diff --git a/src/objects/models.py b/src/objects/models.py index ec9f91d3cc..d2ba688fd8 100755 --- a/src/objects/models.py +++ b/src/objects/models.py @@ -304,6 +304,13 @@ class Object(models.Model): """ self.home = new_home self.save() + + def set_owner(self, new_owner): + """ + Sets an object's owner. + """ + self.owner = new_owner + self.save() def set_name(self, new_name): """