From 4426f776fd5285db4ca07a5c10a445ac105d517f Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Thu, 26 Mar 2009 14:12:30 +0000 Subject: [PATCH] Fixed an annoying problem with player creation. It only affected the first player created after the server was started for the first time. --- src/objects/managers/object.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/objects/managers/object.py b/src/objects/managers/object.py index 29263a4e3b..ead676dda1 100644 --- a/src/objects/managers/object.py +++ b/src/objects/managers/object.py @@ -14,6 +14,7 @@ from src.config.models import ConfigValue from src.objects.exceptions import ObjectNotExist from src.objects.util import object as util_object from src import defines_global +from src import logger class ObjectManager(models.Manager): def num_total_players(self): @@ -311,18 +312,22 @@ class ObjectManager(models.Manager): # pluck the user ID from it. if not str(uid).isdigit(): uid = uid.id + logger.log_infomsg('Next usable object ID is %d. (recycled)' % uid) + else: + logger.log_infomsg('Next usable object ID is %d. (new)' % uid) user = User.objects.create_user(uname, email, password) # It stinks to have to do this but it's the only trivial way now. user.save() - # Update the session to use the newly created User object's ID. - command.session.uid = user.id - # We can't use the user model to change the id because of the way keys # are handled, so we actually need to fall back to raw SQL. Boo hiss. cursor = connection.cursor() cursor.execute("UPDATE auth_user SET id=%d WHERE id=%d" % (uid, user.id)) + # Update the session to use the newly created User object's ID. + command.session.uid = uid + logger.log_infomsg('User created with id %d.' % command.session.uid) + # Grab the user object again since we've changed it and the old reference # is no longer valid. user = User.objects.get(id=uid)