Exemple #1
0
        public static async Task <KillEventRecord> Parse(JsonObject json)
        {
            KillEventRecord record            = new KillEventRecord();
            JsonString      characterId       = json["character_id"] as JsonString;
            JsonString      attackerId        = json["attacker_character_id"] as JsonString;
            JsonString      attackerVehicleId = json["attacker_vehicle_id"] as JsonString;
            JsonString      attackerLoadoutId = json["attacker_loadout_id"] as JsonString;
            JsonString      victimLoadoutId   = json["character_loadout_id"] as JsonString;
            JsonString      attackerWeaponId  = json["attacker_weapon_id"] as JsonString;
            JsonString      headshot          = json["is_headshot"] as JsonString;
            JsonString      timestamp         = json["timestamp"] as JsonString;
            var             characterTask     = PS2APIUtils.GetCharacterName(characterId);
            var             attackerTask      = PS2APIUtils.GetCharacterName(attackerId);

            record.attackerVehicle     = PS2APIUtils.GetVehicleName(attackerVehicleId);
            record.attackerLoadoutName = PS2APIUtils.GetLoadoutName(attackerLoadoutId);
            record.victimLoadoutName   = PS2APIUtils.GetLoadoutName(victimLoadoutId);
            record.weaponName          = PS2APIUtils.GetWeaponName(attackerWeaponId);

            long ts;

            if (timestamp == null || !long.TryParse(timestamp.InnerString, out ts))
            {
                ts = 0;
            }
            record.timestamp = ts;

            await Task.WhenAll(characterTask, attackerTask);

            record.victim   = await characterTask;
            record.attacker = await attackerTask;
            record.headshot = headshot == null ? false : headshot.InnerString != "0";
            return(record);
        }
Exemple #2
0
        async Task <KillEventRecord> ProcessDeathRecord(JsonObject payload)
        {
            KillEventRecord killRecord = await KillEventRecord.Parse(payload);

            foreach (var handler in handlers)
            {
                handlersLock.EnterReadLock();
                try
                {
                    handler.Handle(killRecord);
                } finally
                {
                    handlersLock.ExitReadLock();
                }
            }
            return(killRecord);
        }