Gave better error messages when a player typeclass has bugs and thus won't load. Also made a better solution for hiding new characters from the start room when first being created (also makes sure that character.location never starts as being None, recovering back to home in that case).

This commit is contained in:
Griatch 2011-10-09 16:32:55 +02:00
parent 8c6b27b5b3
commit aee147102b
3 changed files with 77 additions and 50 deletions

View file

@ -107,10 +107,10 @@ class Character(BaseCharacter):
def at_disconnect(self): def at_disconnect(self):
""" """
We stove away the character when logging off, otherwise they will remain where We stove away the character when logging off, otherwise the character object will
they are, 'headless', so to say. remain in the room also after the player logged off ("headless", so to say).
""" """
if self.location: # have to check, in case of multiple connections if self.location: # have to check, in case of multiple connections closing
self.location.msg_contents("%s has left the game." % self.name) self.location.msg_contents("%s has left the game." % self.name)
self.db.prelogout_location = self.location self.db.prelogout_location = self.location
self.location = None self.location = None
@ -120,9 +120,14 @@ class Character(BaseCharacter):
This recovers the character again after having been "stoved away" at disconnect. This recovers the character again after having been "stoved away" at disconnect.
""" """
if self.db.prelogout_location: if self.db.prelogout_location:
# try to recover
self.location = self.db.prelogout_location self.location = self.db.prelogout_location
else: if self.location == None:
self.db.prelogout_location = self.location # make sure location is never None (home should always exist)
self.location = self.home
# save location again to be sure
self.db.prelogout_location = self.location
self.location.msg_contents("%s has entered the game." % self.name) self.location.msg_contents("%s has entered the game." % self.name)
self.location.at_object_receive(self, self.location) self.location.at_object_receive(self, self.location)

View file

@ -165,6 +165,9 @@ its and @/./+/-/_ only.") # this echoes the restrictions made by django's auth m
character_typeclass=typeclass, character_typeclass=typeclass,
character_location=default_home, character_location=default_home,
character_home=default_home) character_home=default_home)
if not new_character:
session.msg("There was an error creating the default Character/Player. This error was logged. Contact an admin.")
return
new_player = new_character.player new_player = new_character.player
# character safety features # character safety features

View file

@ -397,53 +397,72 @@ def create_player(name, email, password,
else: else:
new_user = User.objects.create_user(name, email, password) new_user = User.objects.create_user(name, email, password)
if not typeclass: try:
typeclass = settings.BASE_PLAYER_TYPECLASS if not typeclass:
elif isinstance(typeclass, PlayerDB): typeclass = settings.BASE_PLAYER_TYPECLASS
# this is already an objectdb instance, extract its typeclass elif isinstance(typeclass, PlayerDB):
typeclass = typeclass.typeclass.path # this is already an objectdb instance, extract its typeclass
elif isinstance(typeclass, Player) or utils.inherits_from(typeclass, Player): typeclass = typeclass.typeclass.path
# this is already an object typeclass, extract its path elif isinstance(typeclass, Player) or utils.inherits_from(typeclass, Player):
typeclass = typeclass.path # this is already an object typeclass, extract its path
typeclass = typeclass.path
# create new database object # create new database object
new_db_player = PlayerDB(db_key=name, user=new_user) new_db_player = PlayerDB(db_key=name, user=new_user)
new_db_player.save() new_db_player.save()
# assign the typeclass # assign the typeclass
typeclass = utils.to_unicode(typeclass) typeclass = utils.to_unicode(typeclass)
new_db_player.typeclass_path = typeclass new_db_player.typeclass_path = typeclass
# this will either load the typeclass or the default one # this will either load the typeclass or the default one
new_player = new_db_player.typeclass new_player = new_db_player.typeclass
if not object.__getattribute__(new_db_player, "is_typeclass")(typeclass, exact=True): if not object.__getattribute__(new_db_player, "is_typeclass")(typeclass, exact=True):
# this will fail if we gave a typeclass as input and it still gave us a default # this will fail if we gave a typeclass as input and it still gave us a default
SharedMemoryModel.delete(new_db_player) SharedMemoryModel.delete(new_db_player)
return None return None
new_player.basetype_setup() # setup the basic locks and cmdset new_player.basetype_setup() # setup the basic locks and cmdset
# call hook method (may override default permissions) # call hook method (may override default permissions)
new_player.at_player_creation() new_player.at_player_creation()
# custom given arguments potentially overrides the hook # custom given arguments potentially overrides the hook
if permissions: if permissions:
new_player.permissions = permissions new_player.permissions = permissions
elif not new_player.permissions: elif not new_player.permissions:
new_player.permissions = settings.PERMISSION_PLAYER_DEFAULT new_player.permissions = settings.PERMISSION_PLAYER_DEFAULT
if locks: if locks:
new_player.locks.add(locks) new_player.locks.add(locks)
# create *in-game* 'player' object
if create_character:
if not character_typeclass:
character_typeclass = settings.BASE_CHARACTER_TYPECLASS
# creating the object automatically links the player
# and object together by player.obj <-> obj.player
new_character = create_object(character_typeclass, key=name,
location=None, home=character_location,
permissions=permissions,
player=new_player)
return new_character
return new_player
except Exception:
# a failure in creating the character
if not user:
# in there was a failure we clean up everything we can
logger.log_trace()
try:
new_user.delete()
except Exception:
pass
try:
new_player.delete()
except Exception:
pass
try:
del new_character
except Exception:
pass
# create *in-game* 'player' object
if create_character:
if not character_typeclass:
character_typeclass = settings.BASE_CHARACTER_TYPECLASS
# creating the object automatically links the player
# and object together by player.obj <-> obj.player
new_character = create_object(character_typeclass, key=name,
location=character_location, home=character_location,
permissions=permissions,
player=new_player)
return new_character
return new_player