From: antzucaro Date: Mon, 10 Oct 2011 19:15:59 +0000 (-0400) Subject: Add nick changing support. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b45d8db2365fa492be864c0b4f45ab38e7d555dd;p=xonotic%2Fxonstat.git Add nick changing support. --- 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()