Add anticheat logging.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 28 May 2014 00:38:33 +0000 (20:38 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 28 May 2014 00:38:33 +0000 (20:38 -0400)
xonstat/models.py
xonstat/views/submission.py

index a8be324..6cf94b8 100644 (file)
@@ -309,6 +309,19 @@ class TeamGameStat(object):
             return "pink"
 
 
+class PlayerGameAnticheat(object):
+    def __init__(self, player_id=None, game_id=None, key=None,
+            value=None, create_dt=None):
+        self.player_id                = player_id
+        self.game_id                  = game_id
+        self.key                      = key
+        self.value                    = value
+        self.create_dt                = create_dt
+
+    def __repr__(self):
+        return "<PlayerGameAnticheat(%s, %d)>" % (self.key, self.value)
+
+
 def initialize_db(engine=None):
     DBSession.configure(bind=engine)
     Base.metadata.bind = engine
@@ -335,6 +348,7 @@ def initialize_db(engine=None):
     player_captimes_table = MetaData.tables['player_map_captimes']
     summary_stats_table = MetaData.tables['summary_stats']
     team_game_stats_table = MetaData.tables['team_game_stats']
+    player_game_anticheats_table = MetaData.tables['player_game_anticheats']
 
     # now map the tables and the objects together
     mapper(PlayerAchievement, achievements_table)
@@ -354,3 +368,4 @@ def initialize_db(engine=None):
     mapper(PlayerCaptime, player_captimes_table)
     mapper(SummaryStat, summary_stats_table)
     mapper(TeamGameStat, team_game_stats_table)
+    mapper(PlayerGameAnticheat, player_game_anticheats_table)
index b304085..1a3630c 100644 (file)
@@ -666,6 +666,29 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events):
     return pgstat\r
 \r
 \r
+def create_anticheats(session, pgstat, game, player, events):\r
+    """Anticheats handler for all game types"""\r
+\r
+    anticheats = []\r
+\r
+    # all anticheat events are prefixed by "anticheat"\r
+    for (key,value) in events.items():\r
+        if key.startswith("anticheat"):\r
+            try:\r
+                ac = PlayerGameAnticheat(\r
+                    player.player_id,\r
+                    game.game_id,\r
+                    key,\r
+                    float(value)\r
+                )\r
+                anticheats.append(ac)\r
+                session.add(ac)\r
+            except Exception as e:\r
+                log.debug("Could not parse value for key %s. Ignoring." % key)\r
+\r
+    return anticheats\r
+\r
+\r
 def create_default_team_stat(session, game_type_cd):\r
     """Creates a blanked-out teamstat record for the given game type"""\r
 \r
@@ -852,6 +875,10 @@ def submit_stats(request):
             pgstat = create_game_stat(session, game_meta, game, server,\r
                     gmap, player, events)\r
 \r
+            if player.player_id > 1:\r
+                anticheats = create_anticheats(session, pgstat, game, player,\r
+                    events)\r
+\r
             if should_do_weapon_stats(game_type_cd) and player.player_id > 1:\r
                 pwstats = create_weapon_stats(session, game_meta, game, player,\r
                         pgstat, events)\r