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):
"""
We stove away the character when logging off, otherwise they will remain where
they are, 'headless', so to say.
We stove away the character when logging off, otherwise the character object will
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.db.prelogout_location = self.location
self.location = None
@ -120,9 +120,14 @@ class Character(BaseCharacter):
This recovers the character again after having been "stoved away" at disconnect.
"""
if self.db.prelogout_location:
# try to recover
self.location = self.db.prelogout_location
else:
if self.location == None:
# 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.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_location=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
# character safety features

View file

@ -397,6 +397,7 @@ def create_player(name, email, password,
else:
new_user = User.objects.create_user(name, email, password)
try:
if not typeclass:
typeclass = settings.BASE_PLAYER_TYPECLASS
elif isinstance(typeclass, PlayerDB):
@ -442,8 +443,26 @@ def create_player(name, email, password,
# 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,
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