From b45d8db2365fa492be864c0b4f45ab38e7d555dd Mon Sep 17 00:00:00 2001 From: antzucaro Date: Mon, 10 Oct 2011 15:15:59 -0400 Subject: [PATCH] Add nick changing support. --- xonstat/views/submission.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index 7102fee..ce15d67 100755 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -121,12 +121,16 @@ def get_or_create_player(session=None, hashkey=None, nick=None): player.player_id, hashkey.hashkey)) except: player = Player() + session.add(player) + session.flush() + # if nick is given to us, use it. If not, use "Anonymous Player" + # with a suffix added for uniqueness. if nick: player.nick = nick + else: + player.nick = "Anonymous Player #{0}".format(player.player_id) - session.add(player) - session.flush() hashkey = Hashkey(player_id=player.player_id, hashkey=hashkey) session.add(hashkey) log.debug("Created player {0} with hashkey {1}.".format( @@ -192,6 +196,12 @@ def create_player_game_stat(session=None, player=None, if pgstat.nick == None: pgstat.nick = player.nick + # if the nick we end up with is different from the one in the + # player record, change the nick to reflect the new value + if pgstat.nick != player.nick: + player.nick = pgstat.nick + session.add(player) + session.add(pgstat) session.flush() -- 2.39.2