public static StatsDataEntry GetOrCreateStats(string playerId) { StatsDataEntry stats; if (!PlayerStats.TryGetValue(playerId, out stats)) { stats = new StatsDataEntry(); PlayerStats.Add(playerId, stats); } return(stats); }
public static Dictionary <Players.Player, int> GetInactivePlayers(int days) { var result = new Dictionary <Players.Player, int>(); foreach (Players.Player player in Players.PlayerDatabase.Values) { StatsDataEntry stats = GetOrCreateStats(player.ID.ToStringReadable()); DateTime lastSeen = DateTime.Now; try { lastSeen = DateTime.Parse(stats.lastSeen); } catch (Exception exception) { Log.WriteError($"Unable to parse lastSeen '{stats.lastSeen}': {exception.Message}"); } double inactiveDays = DateTime.Now.Subtract(lastSeen).TotalDays; if (inactiveDays >= days) { result.Add(player, (int)inactiveDays); } } return(result); }