Disallow re-naming and re-aliasing duplicates.

This commit is contained in:
Greg Taylor 2009-04-06 22:24:49 +00:00
parent 899136760e
commit 65d8ac8bdc
2 changed files with 11 additions and 6 deletions

View file

@ -6,6 +6,7 @@ from src.objects.models import Object, Attribute
import src.flags import src.flags
from src import ansi from src import ansi
from src.cmdtable import GLOBAL_CMD_TABLE from src.cmdtable import GLOBAL_CMD_TABLE
from src import defines_global
def cmd_teleport(command): def cmd_teleport(command):
""" """
@ -95,7 +96,8 @@ def cmd_alias(command):
source_object.emit_to("Aliases must be alphanumeric.") source_object.emit_to("Aliases must be alphanumeric.")
return return
old_alias = target.get_attribute_value('ALIAS') old_alias = target.get_attribute_value('ALIAS', default='')
print "ALIAS", old_alias
duplicates = Object.objects.player_alias_search(source_object, new_alias) duplicates = Object.objects.player_alias_search(source_object, new_alias)
if not duplicates or old_alias.lower() == new_alias.lower(): if not duplicates or old_alias.lower() == new_alias.lower():
# Either no duplicates or just changing the case of existing alias. # Either no duplicates or just changing the case of existing alias.
@ -668,6 +670,12 @@ def cmd_name(command):
return return
ansi_name = ansi.parse_ansi(new_name, strip_formatting=True) ansi_name = ansi.parse_ansi(new_name, strip_formatting=True)
if Object.objects.filter(name__iexact=new_name,
type=defines_global.OTYPE_PLAYER):
source_object.emit_to("There is already a player with that name.")
return
source_object.emit_to("You have renamed %s to %s." % (target_obj, source_object.emit_to("You have renamed %s to %s." % (target_obj,
ansi_name)) ansi_name))
target_obj.set_name(new_name) target_obj.set_name(new_name)

View file

@ -793,7 +793,7 @@ class Object(models.Model):
self.script_parent = parent_str.strip() self.script_parent = parent_str.strip()
self.save() self.save()
def get_attribute_value(self, attrib, default=False): def get_attribute_value(self, attrib, default=None):
""" """
Returns the value of an attribute on an object. You may need to Returns the value of an attribute on an object. You may need to
type cast the returned value from this function! type cast the returned value from this function!
@ -804,10 +804,7 @@ class Object(models.Model):
attrib = Attribute.objects.filter(attr_object=self).filter(attr_name=attrib) attrib = Attribute.objects.filter(attr_object=self).filter(attr_name=attrib)
return attrib[0].attr_value return attrib[0].attr_value
else: else:
if default: return default
return default
else:
return False
def get_attribute_obj(self, attrib): def get_attribute_obj(self, attrib):
""" """