public static async Task <List <SServers> > UpdateServers() { List <SServers> servers = new List <SServers>(); string data; // all squad oblit servers string url = //"http://battlelog.battlefield.com/bf4/servers/pc/?filtered=1&expand=1&settings=&useLocation=1&useAdvanced=1&gameexpansions=-1&slots=16&slots=1&slots=2&slots=4&q=&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&mapRotation=-1&modeRotation=-1&password=-1®ions=64&osls=-1&vvsa=-1&vffi=-1&vaba=-1&vkca=-1&v3ca=-1&v3sp=-1&vmsp=-1&vrhe=-1&vhud=-1&vmin=-1&vnta=-1&vbdm-min=1&vbdm-max=300&vprt-min=1&vprt-max=300&vshe-min=1&vshe-max=300&vtkk-min=1&vtkk-max=99&vnit-min=30&vnit-max=86400&vtkc-min=1&vtkc-max=99&vvsd-min=0&vvsd-max=500&vgmc-min=0&vgmc-max=500"; "http://battlelog.battlefield.com/bf4/servers/pc/?filtered=1&expand=1&settings=&useLocation=1&useAdvanced=1&gameexpansions=-1&slots=16&slots=1&slots=2&slots=4&q=&serverTypes=8&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&gameexpansions=-1&mapRotation=-1&modeRotation=-1&password=-1&osls=-1&vvsa=-1&vffi=-1&vaba=-1&vkca=-1&v3ca=-1&v3sp=-1&vmsp=-1&vrhe=-1&vhud=-1&vmin=-1&vnta=-1&vbdm-min=1&vbdm-max=300&vprt-min=1&vprt-max=300&vshe-min=1&vshe-max=300&vtkk-min=1&vtkk-max=99&vnit-min=30&vnit-max=86400&vtkc-min=1&vtkc-max=99&vvsd-min=0&vvsd-max=500&vgmc-min=0&vgmc-max=500"; data = await HttpAsync.GetUrlAsync(url); //convert string to dynamic dynamic serverList = JsonConvert.DeserializeObject <dynamic>(data); //get the servers dynamic serverGuidList = serverList["globalContext"]["servers"]; serverList = null; data = null; //Add guid and guid names to list if (serverGuidList != null) { foreach (var guid in serverGuidList) { Guid serverGuid = Guid.Parse(guid["guid"].ToString()); string serverName = guid["name"].ToString(); int tickRate = Convert.ToInt32(guid["tickRate"]); string mapID = guid["map"].ToString(); int playerCount = Convert.ToInt32(guid["slots"]["2"]["current"]); string countryInfo = guid["country"].ToString(); //limit for playercount if wanted if (playerCount >= 0) { servers.Add(new SServers { _ServerGuid = serverGuid, _ServerName = serverName, _MapID = mapID, _TickRate = tickRate, _PlayerSlots = playerCount, _Location = countryInfo, LastUpdate = DateTime.Now }); } } } return(servers); }
public async Task <CustomSnapshotRoot> getKeeperInfo(string guid) { string keeperData = ""; getNumPlayersOnServer playersOnServerData = getNumPlayersOnServerInfo(guid); SnapshotRoot snapshotData = null; CustomSnapshotRoot snapshotSend = null; List <playersData> team0Data = new List <playersData>(); List <playersData> team1Data = new List <playersData>(); List <playersData> team2Data = new List <playersData>(); playersData empty = new playersData { name = "No players on the server" }; try { keeperData = await HttpAsync.GetUrlAsync(keeperURL + guid); } catch (Exception) { CLogging.AddLog("The server crashed or was never available: " + guid); } snapshotData = JsonConvert.DeserializeObject <SnapshotRoot>(keeperData); if (snapshotData == null) { return(null); } if (!snapshotData.snapshot.status.Equals("SUCCESS", StringComparison.OrdinalIgnoreCase)) { return(null); } //run update code and return null if (snapshotData.snapshot.teamInfo.Team0 != null) { var team0 = snapshotData.snapshot.teamInfo.Team0; foreach (KeyValuePair <string, JToken> x in team0.players) { TeamPlayer playerInfo = x.Value.ToObject <TeamPlayer>(); team0Data.Add( new playersData { playerId = ulong.Parse(x.Key.ToString()), name = playerInfo.Name, kills = playerInfo.kills, deaths = playerInfo.deaths, score = playerInfo.score, tag = playerInfo.tag, squad = playerInfo.squad, role = playerInfo.role }); } } if (snapshotData.snapshot.teamInfo.Team1 != null) { var team1 = snapshotData.snapshot.teamInfo.Team1; foreach (KeyValuePair <string, JToken> x in team1.players) { TeamPlayer playerInfo = x.Value.ToObject <TeamPlayer>(); team1Data.Add( new playersData { playerId = ulong.Parse(x.Key.ToString()), name = playerInfo.Name, kills = playerInfo.kills, deaths = playerInfo.deaths, score = playerInfo.score, tag = playerInfo.tag, squad = playerInfo.squad, role = playerInfo.role }); } } else { team1Data.Add(empty); } if (snapshotData.snapshot.teamInfo.Team2 != null) { var team2 = snapshotData.snapshot.teamInfo.Team2; foreach (KeyValuePair <string, JToken> x in team2.players) { TeamPlayer playerInfo = x.Value.ToObject <TeamPlayer>(); team2Data.Add( new playersData { playerId = ulong.Parse(x.Key.ToString()), name = playerInfo.Name, kills = playerInfo.kills, deaths = playerInfo.deaths, score = playerInfo.score, tag = playerInfo.tag, squad = playerInfo.squad, role = playerInfo.role }); } } else { team2Data.Add(empty); } //SORT TEAM DATA BY SCORE team1Data = team1Data.OrderByDescending(x => x.score).ToList(); team2Data = team2Data.OrderByDescending(x => x.score).ToList(); //Copy snapshotData to snapshotSend //--------------COPY--------------- //repackage all data into CustomSnapshotRoot int team1Tickets = 0; int team2Tickets = 0; int team1TicketsMax = 0; int team2TicketsMax = 0; if (snapshotData.snapshot.Conquest != null) { team1Tickets = snapshotData.snapshot.Conquest.Team1.tickets; team1TicketsMax = snapshotData.snapshot.Conquest.Team1.ticketsMax; team2Tickets = snapshotData.snapshot.Conquest.Team2.tickets; team2TicketsMax = snapshotData.snapshot.Conquest.Team2.ticketsMax; } else if (snapshotData.snapshot.Deathmatch != null) { team1Tickets = snapshotData.snapshot.Deathmatch.Team1.Kills; team1TicketsMax = snapshotData.snapshot.Deathmatch.Team1.KillsMax; team2Tickets = snapshotData.snapshot.Deathmatch.Team2.Kills; team2TicketsMax = snapshotData.snapshot.Deathmatch.Team2.KillsMax; } try { snapshotSend = new CustomSnapshotRoot { lastUpdated = snapshotData.lastUpdated, snapshot = new CustomSnapshot { status = snapshotData.snapshot.status, gameId = snapshotData.snapshot.gameId, currentMap = snapshotData.snapshot.currentMap, maxPlayers = snapshotData.snapshot.maxPlayers, waitingPlayers = snapshotData.snapshot.waitingPlayers, roundTime = snapshotData.snapshot.roundTime, gameMode = snapshotData.snapshot.gameMode, mapId = playersOnServerData.map, modeId = playersOnServerData.mapMode, team1Tickets = new modeCounter { tickets = team1Tickets, ticketsMax = team1TicketsMax }, team2Tickets = new modeCounter { tickets = team2Tickets, ticketsMax = team2TicketsMax }, teamInfo = new CustomSnapshotTeamInfo { team0 = new CustomSnapshotTeam { faction = snapshotData.snapshot.teamInfo.Team0.faction, player = team0Data }, team1 = new CustomSnapshotTeam { faction = snapshotData.snapshot.teamInfo.Team1.faction, player = team1Data }, team2 = new CustomSnapshotTeam { faction = snapshotData.snapshot.teamInfo.Team2.faction, player = team2Data } } } }; } catch (Exception ex) { CLogging.AddLog(ex.ToString()); } if ((team0Data.Count + team1Data.Count + team2Data.Count) < 1) { return(null); } return(snapshotSend); }