mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-05-28 02:35:30 +00:00
Added kill feed limit
If we attempt to load every kill a player has ever gotten, this is bad, I've added a limit feature.
This commit is contained in:
parent
75dfb80260
commit
316911ba7d
2 changed files with 59 additions and 9 deletions
AutoTrackR2
|
@ -1,6 +1,7 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace AutoTrackR2;
|
||||
|
||||
|
@ -157,28 +158,70 @@ public class KillHistoryManager
|
|||
});
|
||||
}
|
||||
|
||||
// Apply KillFeedLimit if specified
|
||||
if (ConfigManager.KillFeedLimit.HasValue && ConfigManager.KillFeedLimit.Value > 0)
|
||||
{
|
||||
kills = kills.TakeLast(ConfigManager.KillFeedLimit.Value).ToList();
|
||||
}
|
||||
|
||||
return kills;
|
||||
}
|
||||
|
||||
public List<KillData> GetKillsInCurrentMonth()
|
||||
{
|
||||
string currentMonth = DateTime.Now.ToString("MMM", CultureInfo.InvariantCulture);
|
||||
var kills = GetKills();
|
||||
var kills = new List<KillData>();
|
||||
|
||||
// Because we are not using UTCNOW anymore and users already have kills saved, we need to make sure both formats are compatable. Otherwise people gonna delete their csv.
|
||||
return kills.Where(kill =>
|
||||
// Read all kills directly from file, ignoring KillFeedLimit
|
||||
using var reader = new StreamReader(new FileStream(_killHistoryPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
|
||||
reader.ReadLine(); // Skip headers
|
||||
|
||||
while (reader.Peek() >= 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(kill.KillTime)) return false;
|
||||
var line = reader.ReadLine();
|
||||
|
||||
// Remove extra quotes from CSV data
|
||||
line = line?.Replace("\"", string.Empty);
|
||||
|
||||
var data = line?.Split(',');
|
||||
|
||||
// Check if the kill is from the current month before adding it
|
||||
var killTime = data?[0];
|
||||
if (string.IsNullOrEmpty(killTime)) continue;
|
||||
|
||||
// Try to parse as Unix timestamp first
|
||||
if (long.TryParse(kill.KillTime, out long unixTime))
|
||||
if (long.TryParse(killTime, out long unixTime))
|
||||
{
|
||||
var date = DateTimeOffset.FromUnixTimeSeconds(unixTime);
|
||||
return date.ToString("MMM", CultureInfo.InvariantCulture) == currentMonth;
|
||||
if (date.ToString("MMM", CultureInfo.InvariantCulture) != currentMonth) continue;
|
||||
}
|
||||
else if (!killTime.Contains(currentMonth))
|
||||
{
|
||||
// Fall back to checking if it contains the month name (old format)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fall back to checking if it contains the month name (old format)
|
||||
return kill.KillTime.Contains(currentMonth);
|
||||
}).ToList();
|
||||
kills.Add(new KillData
|
||||
{
|
||||
KillTime = killTime,
|
||||
EnemyPilot = data?[1],
|
||||
EnemyShip = data?[2],
|
||||
Enlisted = data?[3],
|
||||
RecordNumber = data?[4],
|
||||
OrgAffiliation = data?[5],
|
||||
Player = data?[6],
|
||||
Weapon = data?[7],
|
||||
Ship = data?[8],
|
||||
Method = data?[9],
|
||||
Mode = data?[10],
|
||||
GameVersion = data?[11],
|
||||
TrackRver = data?[12],
|
||||
Logged = data?[13],
|
||||
PFP = data?[14],
|
||||
Hash = data?[15]
|
||||
});
|
||||
}
|
||||
|
||||
return kills;
|
||||
}
|
||||
}
|
|
@ -199,6 +199,7 @@ namespace AutoTrackR2
|
|||
public static int StreamlinkEnabled { get; set; }
|
||||
public static int StreamlinkDuration { get; set; } = 30;
|
||||
public static int KillStreakEnabled { get; set; } = 1; // Default to enabled
|
||||
public static int? KillFeedLimit { get; set; } = null; // Default to null (load all)
|
||||
|
||||
static ConfigManager()
|
||||
{
|
||||
|
@ -256,6 +257,11 @@ namespace AutoTrackR2
|
|||
StreamlinkDuration = int.Parse(line.Substring("StreamlinkDuration=".Length).Trim());
|
||||
else if (line.StartsWith("KillStreakEnabled="))
|
||||
KillStreakEnabled = int.Parse(line.Substring("KillStreakEnabled=".Length).Trim());
|
||||
else if (line.StartsWith("KillFeedLimit="))
|
||||
{
|
||||
var value = line.Substring("KillFeedLimit=".Length).Trim();
|
||||
KillFeedLimit = string.IsNullOrEmpty(value) ? null : int.Parse(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,6 +296,7 @@ namespace AutoTrackR2
|
|||
writer.WriteLine($"StreamlinkEnabled={StreamlinkEnabled}");
|
||||
writer.WriteLine($"StreamlinkDuration={StreamlinkDuration}");
|
||||
writer.WriteLine($"KillStreakEnabled={KillStreakEnabled}");
|
||||
writer.WriteLine($"KillFeedLimit={KillFeedLimit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue