예제 #1
0
        private void UpdatePlayerHistory()
        {
            string accountId = ChosenPlayer.accountId;

            bool fileExists = File.Exists(FilePaths.PLAYER_HISTORY(accountId, Server));

            if (fileExists)
            {
                History savedHistory = DataManager.LoadPlayerHistory(accountId, Server);

                if (savedHistory.LastGameId == -1)
                {
                    Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created.");
                }
                else
                {
                    Instant lastMatch = Instant.FromEpochSeconds(savedHistory.matches[0].timestamp / 1000);
                    Console.WriteLine($"Player {ChosenPlayer.name} has a history saved," +
                                      $" with the last game played on {lastMatch.ToString("dddd, MMMM d, yyyy - HH:mm")}." +
                                      $" Their history will now be updated.");
                }

                savedHistory = UpdateHistoryFromApi(savedHistory, ChosenPlayer, Server);
                DataManager.SavePlayerHistory(savedHistory, accountId, Server);
            }
            else
            {
                Console.WriteLine($"Player {ChosenPlayer.name} has no history saved. A new one will be created.");
                History history = GetFullHistoryFromApi(ChosenPlayer, Server);
                DataManager.SavePlayerHistory(history, accountId, Server);
            }
        }
예제 #2
0
        public static History LoadPlayerHistory(string accountId, string server)
        {
            string sJson = File.ReadAllText(FilePaths.PLAYER_HISTORY(accountId, server));

            if (string.IsNullOrEmpty(sJson))
            {
                return(null);
            }
            else
            {
                return(JsonConvert.DeserializeObject <History>(sJson));
            }
        }
예제 #3
0
        //private JsonSerializer json = new JsonSerializer() { Formatting = Formatting.Indented };

        public static List <Player> LoadPlayerList(string server)
        {
            string sJson = File.ReadAllText(FilePaths.PLAYER_KEYS(server));

            if (string.IsNullOrEmpty(sJson))
            {
                return(null);
            }
            else
            {
                return(JsonConvert.DeserializeObject <List <Player> >(sJson));
            }
        }
예제 #4
0
        public static void SavePlayerHistory(History history, string accountId, string server)
        {
            string sJson = JsonConvert.SerializeObject(history, Formatting.Indented);

            File.WriteAllText(FilePaths.PLAYER_HISTORY(accountId, server), sJson);
        }