public async static void UpdateServerKeeper() { int serversSkipped = 0; int y; for (y = 0; y < Servers.Count - 1; y++) { //SServers item = Servers[y]; KeeperAPI keeper = new KeeperAPI(); CustomSnapshotRoot root = await keeper.getKeeperInfo(Servers[y]._ServerGuid.ToString()); if (root == null) { continue; } if (Servers[y]._Snapshots == null) { Servers[y]._Snapshots = new List <CustomSnapshotRoot>();// new ObservableCollection<CustomSnapshotRoot>(); // CLogging.AddLog("null"); } else { //CLogging.AddLog("not Null"); } int NumPlayers = root.snapshot.teamInfo.team0.player.Count + root.snapshot.teamInfo.team1.player.Count + root.snapshot.teamInfo.team2.player.Count; Servers[y].PlayersPlaying = NumPlayers; //CLogging.AddLog(String.Format("{0} players on server", NumPlayers)); if (root.snapshot.roundTime != 0) { Servers[y]._Snapshots.Add(root); } else { serversSkipped++; } if (Servers[y].Snapshots.Count > 0 && root.snapshot.roundTime == 0) { CLogging.AddLog(String.Format("{0} Saved", Servers[y].ServerGuid)); string output = JsonConvert.SerializeObject(Servers[y]); FileHandler.Save(output, Servers[y].ServerGuid.ToString()); Servers[y].Snapshots.Clear(); } //Servers[y] = item; } CLogging.AddLog(String.Format("{0} servers updated", y), LogType.Update); CheckServersForRemoval(); }
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); }