示例#1
0
        public static async Task <ReviveEventRecord> Parse(JsonObject json, bool squad)
        {
            ReviveEventRecord record = new ReviveEventRecord();

            record.squad = squad;
            JsonString characterId   = json["character_id"] as JsonString;
            JsonString otherId       = json["other_id"] as JsonString;
            JsonString timestamp     = json["timestamp"] as JsonString;
            var        characterTask = PS2APIUtils.GetCharacterName(characterId);
            var        otherTask     = PS2APIUtils.GetCharacterName(otherId);

            long ts;

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

            await Task.WhenAll(characterTask, otherTask);

            record.reviver = await characterTask;
            record.revived = await otherTask;
            return(record);
        }
        /// <summary>
        /// Get the player info from game's databse
        /// </summary>
        static private async Task <NameOutfitFactionRecord> FetchPlayerInfo(JsonString id)
        {
            JsonObject json;
            int        retry = 0;

            // try to resolve player info from database at most 3 times before returning unresolved record
            do
            {
                string uri = $@"http://census.daybreakgames.com/s:{PS2APIConstants.ServiceId}/get/ps2/character_name/?character_id={id.InnerString}&c:join=character^inject_at:character^show:faction_id(outfit_member_extended^inject_at:outfit^show:alias%27name)";
                json = await PS2APIUtils.RestAPIRequestClient(uri);
            } while (json == null && ++retry < 3);

            NameOutfitFactionRecord record = new NameOutfitFactionRecord();

            if ((record.Name = (json?["character_name_list"]?[0]?["name"]?["first"] as JsonString)?.InnerString) == null)
            {
                record.Name = $"<Character:{id.InnerString}>";
            }
            if ((record.Faction = (json?["character_name_list"]?[0]?["character"]?["faction_id"] as JsonString)?.InnerString) == null)
            {
                record.Faction = $"<CharacterFaction:{id.InnerString}>";
            }
            // no outfit is possible value
            record.Outfit = (json?["character_name_list"]?[0]?["character"]?["outfit"]?["alias"] as JsonString)?.InnerString;
            record.Id     = id;

            return(record);
        }
        static VehicleCache()
        {
            Console.WriteLine("Vehicle cache loading...");
            // get all vehicles' info and save them to dictionary
            string     allVehiclesRequest = $@"https://census.daybreakgames.com/s:{PS2APIConstants.ServiceId}/get/ps2/vehicle/?c:limit=100&c:show=vehicle_id,type_id,name";
            JsonObject json     = PS2APIUtils.RestAPIRequest(allVehiclesRequest).GetAwaiter().GetResult();
            var        vehicles = json?["vehicle_list"] as JsonArray;

            if (vehicles == null)
            {
                return;
            }
            for (int i = 0; i < vehicles.Length; i++)
            {
                JsonString vehicleId = vehicles[i]?["vehicle_id"] as JsonString;
                JsonString name      = vehicles[i]?["name"]?["en"] as JsonString;
                JsonString typeId    = vehicles[i]?["type_id"] as JsonString;
                if (vehicleId == null || name == null)
                {
                    continue;
                }
                VehicleIdToName.Add(vehicleId, new VehicleRecord()
                {
                    Name = name?.InnerString, Id = vehicleId, Type = typeId
                });
            }
            Console.WriteLine("Vehicle cache loaded!");
        }
示例#4
0
        public static async Task <MinorExperienceEventRecord> Parse(JsonObject json)
        {
            MinorExperienceEventRecord record = new MinorExperienceEventRecord();
            JsonString characterId            = json["character_id"] as JsonString;
            JsonString otherId       = json["other_id"] as JsonString;
            JsonString loadoutId     = json["loadout_id"] as JsonString;
            JsonString experienceId  = json["experience_id"] as JsonString;
            JsonString timestamp     = json["timestamp"] as JsonString;
            var        characterTask = PS2APIUtils.GetCharacterName(characterId);
            var        otherTask     = PS2APIUtils.GetCharacterName(otherId);

            record.characterLoadout = PS2APIUtils.GetLoadoutName(loadoutId);

            long ts;

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

            await Task.WhenAll(characterTask, otherTask);

            record.character = await characterTask;
            record.other     = await otherTask;
            return(record);
        }
示例#5
0
        public static async Task <VehicleDestroyedEventRecord> Parse(JsonObject json)
        {
            VehicleDestroyedEventRecord record = new VehicleDestroyedEventRecord();
            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 attackerWeaponId  = json["attacker_weapon_id"] as JsonString;
            JsonString vehicleId         = json["vehicle_id"] as JsonString;
            JsonString timestamp         = json["timestamp"] as JsonString;
            var        characterTask     = PS2APIUtils.GetCharacterName(characterId);
            var        attackerTask      = PS2APIUtils.GetCharacterName(attackerId);

            record.attackerVehicle     = PS2APIUtils.GetVehicleName(attackerVehicleId);
            record.destroyedVehicle    = PS2APIUtils.GetVehicleName(vehicleId);
            record.attackerLoadoutName = PS2APIUtils.GetLoadoutName(attackerLoadoutId);
            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;
            return(record);
        }
示例#6
0
        public static async Task <T> Parse <T>(JsonObject json) where T : PlayerLoggingEventRecord, new()
        {
            T          record        = new T();
            JsonString characterId   = json["character_id"] as JsonString;
            JsonString timestamp     = json["timestamp"] as JsonString;
            var        characterTask = PS2APIUtils.GetCharacterName(characterId);

            long ts;

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

            record.character = await characterTask;
            return(record);
        }
示例#7
0
        static LoadoutCache()
        {
            Console.WriteLine("Loadout cache loading...");
            // get all loadout names and save it to dictionary
            string     allLoadoutsRequest = $@"http://census.daybreakgames.com/s:{PS2APIConstants.ServiceId}/get/ps2/loadout/?c:limit=100&c:show=loadout_id,profile_id&c:join=profile^on:profile_id^show:name^inject_at:profile";
            JsonObject json     = PS2APIUtils.RestAPIRequest(allLoadoutsRequest).GetAwaiter().GetResult();
            var        loadouts = json?["loadout_list"] as JsonArray;

            if (loadouts == null)
            {
                return;
            }
            for (int i = 0; i < loadouts.Length; i++)
            {
                JsonString loadoutId = loadouts[i]?["loadout_id"] as JsonString;
                JsonString name      = loadouts[i]?["profile"]?["name"]?["en"] as JsonString;
                if (loadoutId == null || name == null)
                {
                    continue;
                }
                LoadoutIdToName.Add(loadoutId, name);
            }
            Console.WriteLine("Loadout cache loaded!");
        }
示例#8
0
        static WeaponsCache()
        {
            Console.WriteLine("Weapons cache loading...");
            // get all weapons' names and save them to dictionary
            string     allWeaponsRequest = @"https://census.daybreakgames.com/s:georgik/get/ps2/item_to_weapon/?c:limit=2000&c:join=item^show:name^inject_at:item";
            JsonObject json    = PS2APIUtils.RestAPIRequest(allWeaponsRequest).GetAwaiter().GetResult();
            var        weapons = json?["item_to_weapon_list"] as JsonArray;

            if (weapons == null)
            {
                return;
            }
            for (int i = 0; i < weapons.Length; i++)
            {
                JsonString itemId = weapons[i]?["item_id"] as JsonString;
                JsonString name   = weapons[i]?["item"]?["name"]?["en"] as JsonString;
                if (itemId == null || name == null)
                {
                    continue;
                }
                ItemIdToWeaponName.Add(itemId, name);
            }
            Console.WriteLine("Weapons cache loaded!");
        }
示例#9
0
        public OutfitMembersTracker(string alias, string logfile)
        {
            OutfitAlias = new JsonString(alias);

            token = tokenSource.Token;

            // get information about outfit members
            string outfitQuerry = $@"https://census.daybreakgames.com/s:{PS2APIConstants.ServiceId}/get/ps2/outfit?alias_lower={alias.ToLower()}&c:show=outfit_id,name&c:join=type:outfit_member^on:outfit_id^list:1^inject_at:members^show:character_id%27rank%27rank_ordinal(character^show:name^inject_at:character(characters_online_status^inject_at:onlineStatus^hide:character_id))";

            Console.WriteLine("Outfit data request sent");
            var outfitTask = PS2APIUtils.RestAPIRequestClient(outfitQuerry);

            int onlineCount = 0;

            JsonObject response = outfitTask.GetAwaiter().GetResult();

            if (response == null)
            {
                throw new Exception("Outfit data request failed");
            }
            Console.WriteLine("Outfit data response received");

            try
            {
                JsonArray found = (JsonArray)response["outfit_list"];
                if (found == null)
                {
                    throw new JsonInvalidAccessException("Outfit list wrong format?\n" + response.ToString());
                }

                if (found.Length > 0)
                {
                    var outfit = found[0];
                    OutfitId   = (JsonString)outfit["outfit_id"];
                    OutfitName = (JsonString)outfit["name"];
                    JsonArray members = (JsonArray)outfit["members"];

                    for (int i = 0; i < members.Length; i++)
                    {
                        var id = (JsonString)members?[i]?["character_id"];
                        if (id == null || id.InnerString == "0")
                        {
                            continue;
                        }
                        var name   = (JsonString)members?[i]?["character"]?["name"]?["first"];
                        var rank   = (JsonString)members?[i]?["rank"];
                        var online = (JsonString)members?[i]?["character"]?["onlineStatus"]?["online_status"];

                        Members.Add(new Member()
                        {
                            Name = name, Rank = rank, Id = id
                        });

                        if (online != null && online.InnerString != "0")
                        {
                            onlineCount++;
                        }
                    }
                }
                else
                {
                    throw new Exception($"Outfit with tag '{alias}' not found!");
                }
            }
            catch (InvalidCastException)
            {
                throw new JsonInvalidAccessException("Could not extract outfit info");
            }

            Console.WriteLine($"Outfit ID: {OutfitId}");
            Console.WriteLine($"Outfit Name: {OutfitName}");
            Console.WriteLine($"Total members registered: {Members.Count}");
            Console.WriteLine($"Online members: {onlineCount}");
        }