Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 71 additions & 50 deletions Entities/LogFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class LogFileWatcher {
public event Action<List<RoundInfo>> OnParsedLogLinesCurrent;
public event Action<DateTime> OnNewLogFileDate;
public event Action OnServerConnectionNotification;
public event Action<string, string, TimeSpan, TimeSpan> OnPersonalBestNotification;
public event Action<string, string, double, double> OnPersonalBestNotification;
public event Action<string> OnError;

private readonly ServerPingWatcher serverPingWatcher = new ServerPingWatcher();
Expand Down Expand Up @@ -762,65 +762,86 @@ private void ResetMainLocalVariables() {
}

private void UpdateServerConnectionLog(string session, string show) {
if (!this.StatsForm.ExistsServerConnectionLog(session)) {
this.StatsForm.InsertServerConnectionLog(session, show, Stats.LastServerIp, Stats.ConnectedToServerDate, true, true);
this.serverPingWatcher.Start();
this.SetCountryCodeByIp(Stats.LastServerIp);
if (!Stats.IsClientHasBeenClosed && this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(Stats.LastCountryAlpha2Code)) {
this.OnServerConnectionNotification?.Invoke();
}
} else {
ServerConnectionLog serverConnectionLog = this.StatsForm.SelectServerConnectionLog(session);
if (!serverConnectionLog.IsNotify) {
lock (this.StatsForm.ServerConnectionLogCache) {
if (!this.StatsForm.ExistsServerConnectionLog(session)) {
this.StatsForm.InsertServerConnectionLog(session, show, Stats.LastServerIp, Stats.ConnectedToServerDate, true, true);
this.serverPingWatcher.Start();
this.SetCountryCodeByIp(Stats.LastServerIp);
if (!Stats.IsClientHasBeenClosed && this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(Stats.LastCountryAlpha2Code)) {
this.OnServerConnectionNotification?.Invoke();
}
}
} else {
ServerConnectionLog serverConnectionLog = this.StatsForm.SelectServerConnectionLog(session);
if (!serverConnectionLog.IsNotify) {
if (!Stats.IsClientHasBeenClosed && this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(Stats.LastCountryAlpha2Code)) {
this.OnServerConnectionNotification?.Invoke();
}
}

if (serverConnectionLog.IsPlaying) {
this.serverPingWatcher.Start();
this.SetCountryCodeByIp(Stats.LastServerIp);
if (serverConnectionLog.IsPlaying) {
this.serverPingWatcher.Start();
this.SetCountryCodeByIp(Stats.LastServerIp);
}
}
}
}

private void UpdatePersonalBestLog(RoundInfo info) {
if (string.IsNullOrEmpty(info.SessionId) || info.PrivateLobby || (!info.IsCasualShow && info.UseShareCode) || !info.Finish.HasValue) return;

if (info.IsCasualShow) {
if (string.IsNullOrEmpty(info.Name) || !string.Equals(info.CreativeGameModeId, "GAMEMODE_GAUNTLET", StringComparison.OrdinalIgnoreCase)) return;

if (!this.StatsForm.ExistsPersonalBestLog(info.Finish.Value)) {
string levelName = !string.IsNullOrEmpty(info.CreativeTitle) ? info.CreativeTitle : this.StatsForm.GetUserCreativeLevelTitle(info.Name);
List<RoundInfo> roundInfoList = this.StatsForm.AllStats.FindAll(r => r.PrivateLobby == false && r.Finish.HasValue && !string.IsNullOrEmpty(r.ShowNameId) && !string.IsNullOrEmpty(r.SessionId) && string.Equals(r.Name, info.Name));

TimeSpan currentRecord = info.Finish.Value - info.Start;
TimeSpan existingRecord = roundInfoList.Count > 0 ? roundInfoList.Min(r => r.Finish.Value - r.Start) : TimeSpan.MaxValue;

this.StatsForm.InsertPersonalBestLog(info.Finish.Value, info.SessionId, "casual_show", info.Name, currentRecord.TotalMilliseconds, currentRecord < existingRecord);
if (this.StatsForm.CurrentSettings.NotifyPersonalBest && currentRecord < existingRecord) {
this.OnPersonalBestNotification?.Invoke("casual_show", levelName, existingRecord, currentRecord);
}
}
} else {
string levelId = info.VerifiedName();
if (!this.StatsForm.StatLookup.TryGetValue(levelId, out LevelStats currentLevel) || currentLevel.Type != LevelType.Race) return;

if (!this.StatsForm.ExistsPersonalBestLog(info.Finish.Value)) {
List<RoundInfo> roundInfoList = new List<RoundInfo>();
if (currentLevel.IsCreative && !string.IsNullOrEmpty(currentLevel.ShareCode)) {
string[] ids = this.StatsForm.StatDetails.Where(l => string.Equals(l.ShareCode, currentLevel.ShareCode)).Select(l => l.Id).ToArray();
roundInfoList = this.StatsForm.AllStats.FindAll(r => r.PrivateLobby == false && r.Finish.HasValue && !string.IsNullOrEmpty(r.ShowNameId) && !string.IsNullOrEmpty(r.SessionId) && ids.Contains(r.Name));
} else {
roundInfoList = this.StatsForm.AllStats.FindAll(r => r.PrivateLobby == false && r.Finish.HasValue && !string.IsNullOrEmpty(r.ShowNameId) && !string.IsNullOrEmpty(r.SessionId) && string.Equals(r.Name, levelId));
lock (this.StatsForm.PersonalBestLogCache) {
if (string.IsNullOrEmpty(info.SessionId) || info.PrivateLobby || (!info.IsCasualShow && info.UseShareCode) || !info.Finish.HasValue) return;

if (info.IsCasualShow && this.StatsForm.IsCreativeShow(info.ShowNameId)) {
if (string.IsNullOrEmpty(info.Name) || (!string.Equals(info.CreativeGameModeId, "GAMEMODE_GAUNTLET", StringComparison.OrdinalIgnoreCase)
&& !string.Equals(info.CreativeGameModeId, "GAMEMODE_POINTS", StringComparison.OrdinalIgnoreCase))) return;

if (!this.StatsForm.ExistsPersonalBestLog(info.Finish.Value)) {
List<RoundInfo> roundInfoList = this.StatsForm.AllStats.FindAll(r => !r.PrivateLobby &&
!string.IsNullOrEmpty(r.ShowNameId) &&
!string.IsNullOrEmpty(r.SessionId) &&
r.IsCasualShow &&
string.Equals(r.Name, info.Name) &&
r.Finish.HasValue);

double currentPb = roundInfoList.Count > 0 ? roundInfoList.Min(r => (r.Finish.Value - r.Start).TotalMilliseconds) : 0;
double currentRecord = (info.Finish.Value - info.Start).TotalMilliseconds;
bool isNewPb = currentPb == 0 || currentRecord < currentPb;

this.StatsForm.InsertPersonalBestLog(info.Finish.Value, info.SessionId, "casual_show", info.Name, currentRecord, isNewPb);
if (this.StatsForm.CurrentSettings.NotifyPersonalBest && isNewPb) {
string levelName = !string.IsNullOrEmpty(info.CreativeTitle) ? info.CreativeTitle : this.StatsForm.GetUserCreativeLevelTitle(info.Name);
this.OnPersonalBestNotification?.Invoke("casual_show", levelName, currentPb, currentRecord);
}
}

TimeSpan currentRecord = info.Finish.Value - info.Start;
TimeSpan existingRecord = roundInfoList.Count > 0 ? roundInfoList.Min(r => r.Finish.Value - r.Start) : TimeSpan.MaxValue;

this.StatsForm.InsertPersonalBestLog(info.Finish.Value, info.SessionId, info.ShowNameId, levelId, currentRecord.TotalMilliseconds, currentRecord < existingRecord);
if (this.StatsForm.CurrentSettings.NotifyPersonalBest && currentRecord < existingRecord) {
this.OnPersonalBestNotification?.Invoke(info.ShowNameId, levelId, existingRecord, currentRecord);
} else {
string levelId = info.VerifiedName();
if (!this.StatsForm.StatLookup.TryGetValue(levelId, out LevelStats currentLevel) || (currentLevel.BestRecordType != BestRecordType.Fastest)) return;

if (!this.StatsForm.ExistsPersonalBestLog(info.Finish.Value)) {
List<RoundInfo> roundInfoList = new List<RoundInfo>();
if (!info.IsCasualShow) {
roundInfoList = this.StatsForm.AllStats.FindAll(r => !r.PrivateLobby &&
!string.IsNullOrEmpty(r.ShowNameId) &&
!string.IsNullOrEmpty(r.SessionId) &&
string.Equals(r.ShowNameId, info.ShowNameId) &&
string.Equals(r.Name, levelId) &&
r.Finish.HasValue);
} else {
roundInfoList = this.StatsForm.AllStats.FindAll(r => !r.PrivateLobby &&
!string.IsNullOrEmpty(r.ShowNameId) &&
!string.IsNullOrEmpty(r.SessionId) &&
r.IsCasualShow &&
string.Equals(r.Name, levelId) &&
r.Finish.HasValue);
}
double currentPb = roundInfoList.Count > 0 ? roundInfoList.Min(r => (r.Finish.Value - r.Start).TotalMilliseconds) : 0;
double currentRecord = (info.Finish.Value - info.Start).TotalMilliseconds;
bool isNewPb = currentPb == 0 || currentRecord < currentPb;

string showId = !info.IsCasualShow ? info.ShowNameId : "casual_show";
this.StatsForm.InsertPersonalBestLog(info.Finish.Value, info.SessionId, showId, levelId, currentRecord, isNewPb);
if (this.StatsForm.CurrentSettings.NotifyPersonalBest && isNewPb) {
this.OnPersonalBestNotification?.Invoke(showId, levelId, currentPb, currentRecord);
}
}
}
}
Expand Down
40 changes: 24 additions & 16 deletions Views/LevelDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,15 +1050,19 @@ private void DeleteShow() {
List<RoundInfo> ri = this.StatsForm.AllStats.FindAll(r => r.ShowID == bi.ShowID);
foreach (RoundInfo r in ri) {
if (r.Finish.HasValue) {
PersonalBestLog pbLog = this.StatsForm.PersonalBestLogCache.Find(l => l.PbDate == r.Finish);
if (pbLog != null) {
this.StatsForm.PersonalBestLog.Delete(r.Finish);
this.StatsForm.PersonalBestLogCache.Remove(pbLog);
lock (this.StatsForm.PersonalBestLogCache) {
PersonalBestLog pbLog = this.StatsForm.PersonalBestLogCache.Find(l => l.PbDate == r.Finish);
if (pbLog != null) {
this.StatsForm.PersonalBestLog.Delete(r.Finish);
this.StatsForm.PersonalBestLogCache.Remove(pbLog);
}
}
FallalyticsPbLog fPbLog = this.StatsForm.FallalyticsPbLogCache.Find(l => l.PbDate == r.Finish);
if (fPbLog != null) {
this.StatsForm.FallalyticsPbLog.Delete(fPbLog.PbId);
this.StatsForm.FallalyticsPbLogCache.Remove(fPbLog);
lock (this.StatsForm.FallalyticsPbLogCache) {
FallalyticsPbLog fPbLog = this.StatsForm.FallalyticsPbLogCache.Find(l => l.PbDate == r.Finish);
if (fPbLog != null) {
this.StatsForm.FallalyticsPbLog.Delete(fPbLog.PbId);
this.StatsForm.FallalyticsPbLogCache.Remove(fPbLog);
}
}
}
}
Expand Down Expand Up @@ -1160,15 +1164,19 @@ private void deleteFinishTime_Click(object sender, EventArgs e) {
Task.Run(() => {
Task deleteFinishTimeTask = new Task(() => {
this.StatsForm.StatsDB.BeginTrans();
PersonalBestLog pbLog = this.StatsForm.PersonalBestLogCache.Find(l => l.PbDate == ri.Finish);
if (pbLog != null) {
this.StatsForm.PersonalBestLog.Delete(ri.Finish);
this.StatsForm.PersonalBestLogCache.Remove(pbLog);
lock (this.StatsForm.PersonalBestLogCache) {
PersonalBestLog pbLog = this.StatsForm.PersonalBestLogCache.Find(l => l.PbDate == ri.Finish);
if (pbLog != null) {
this.StatsForm.PersonalBestLog.Delete(ri.Finish);
this.StatsForm.PersonalBestLogCache.Remove(pbLog);
}
}
FallalyticsPbLog fPbLog = this.StatsForm.FallalyticsPbLogCache.Find(l => l.PbDate == ri.Finish);
if (fPbLog != null) {
this.StatsForm.FallalyticsPbLog.Delete(fPbLog.PbId);
this.StatsForm.FallalyticsPbLogCache.Remove(fPbLog);
lock (this.StatsForm.FallalyticsPbLogCache) {
FallalyticsPbLog fPbLog = this.StatsForm.FallalyticsPbLogCache.Find(l => l.PbDate == ri.Finish);
if (fPbLog != null) {
this.StatsForm.FallalyticsPbLog.Delete(fPbLog.PbId);
this.StatsForm.FallalyticsPbLogCache.Remove(fPbLog);
}
}
ri.Finish = null;
this.StatsForm.RoundDetails.Update(ri);
Expand Down
8 changes: 5 additions & 3 deletions Views/Overlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,9 +1231,11 @@ private void UpdateInfo() {
this.startedPlaying = this.lastRound.Playing;
}

this.levelTimeLimit = this.lastRound.IsCasualShow && (this.levelType == LevelType.CreativeRace || this.levelType == LevelType.CreativeHunt) ? 1800 :
this.lastRound.UseShareCode ? this.lastRound.CreativeTimeLimitSeconds :
this.StatsForm.LevelTimeLimitCache.Find(l => string.Equals(l.LevelId, this.lastRound.RoundId ?? this.lastRound.Name))?.Duration ?? 0;
lock (this.StatsForm.LevelTimeLimitCache) {
this.levelTimeLimit = this.lastRound.IsCasualShow && (this.levelType == LevelType.CreativeRace || this.levelType == LevelType.CreativeHunt) ? 1800 :
this.lastRound.UseShareCode ? this.lastRound.CreativeTimeLimitSeconds :
this.StatsForm.LevelTimeLimitCache.Find(l => string.Equals(l.LevelId, this.lastRound.RoundId ?? this.lastRound.Name))?.Duration ?? 0;
}

this.SetDurationLabel(this.levelTimeLimit, currentUtc, overlaySetting);
this.SetFinishLabel(this.levelSummary, this.levelType, this.levelId, this.recordType, currentUtc, overlaySetting);
Expand Down
Loading