From 6132f18ccad967c8ad3ce007bd3634db1e15a447 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Tue, 27 May 2014 20:38:33 -0400 Subject: [PATCH] Add anticheat logging. --- xonstat/models.py | 15 +++++++++++++++ xonstat/views/submission.py | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/xonstat/models.py b/xonstat/models.py index a8be324..6cf94b8 100644 --- a/xonstat/models.py +++ b/xonstat/models.py @@ -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 "" % (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) diff --git a/xonstat/views/submission.py b/xonstat/views/submission.py index b304085..1a3630c 100644 --- a/xonstat/views/submission.py +++ b/xonstat/views/submission.py @@ -666,6 +666,29 @@ def create_game_stat(session, game_meta, game, server, gmap, player, events): return pgstat +def create_anticheats(session, pgstat, game, player, events): + """Anticheats handler for all game types""" + + anticheats = [] + + # all anticheat events are prefixed by "anticheat" + for (key,value) in events.items(): + if key.startswith("anticheat"): + try: + ac = PlayerGameAnticheat( + player.player_id, + game.game_id, + key, + float(value) + ) + anticheats.append(ac) + session.add(ac) + except Exception as e: + log.debug("Could not parse value for key %s. Ignoring." % key) + + return anticheats + + def create_default_team_stat(session, game_type_cd): """Creates a blanked-out teamstat record for the given game type""" @@ -852,6 +875,10 @@ def submit_stats(request): pgstat = create_game_stat(session, game_meta, game, server, gmap, player, events) + if player.player_id > 1: + anticheats = create_anticheats(session, pgstat, game, player, + events) + if should_do_weapon_stats(game_type_cd) and player.player_id > 1: pwstats = create_weapon_stats(session, game_meta, game, player, pgstat, events) -- 2.39.2