]> git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Add nick changing support.
authorantzucaro <azucaro@gmail.com>
Mon, 10 Oct 2011 19:15:59 +0000 (15:15 -0400)
committerantzucaro <azucaro@gmail.com>
Mon, 10 Oct 2011 19:15:59 +0000 (15:15 -0400)
xonstat/views/submission.py

index 7102fee3feb242b2ff394d5131cb0b0d4b482765..ce15d67520afa94dbf9df691886391dd1c0d42da 100755 (executable)
@@ -121,12 +121,16 @@ def get_or_create_player(session=None, hashkey=None, nick=None):
                 player.player_id, hashkey.hashkey))\r
         except:\r
             player = Player()\r
+            session.add(player)\r
+            session.flush()\r
 \r
+           # if nick is given to us, use it. If not, use "Anonymous Player"\r
+            # with a suffix added for uniqueness.\r
             if nick:\r
                 player.nick = nick\r
+           else:\r
+                player.nick = "Anonymous Player #{0}".format(player.player_id)\r
 \r
-            session.add(player)\r
-            session.flush()\r
             hashkey = Hashkey(player_id=player.player_id, hashkey=hashkey)\r
             session.add(hashkey)\r
             log.debug("Created player {0} with hashkey {1}.".format(\r
@@ -192,6 +196,12 @@ def create_player_game_stat(session=None, player=None,
     if pgstat.nick == None:\r
         pgstat.nick = player.nick\r
 \r
+    # if the nick we end up with is different from the one in the\r
+    # player record, change the nick to reflect the new value\r
+    if pgstat.nick != player.nick:\r
+        player.nick = pgstat.nick\r
+        session.add(player)\r
+\r
     session.add(pgstat)\r
     session.flush()\r
 \r