From cdf0cc6d3fd4a65ac465aef48657f82a8ce5ee16 Mon Sep 17 00:00:00 2001 From: Micdu70 Date: Tue, 7 Oct 2025 13:21:57 +0200 Subject: [PATCH] Bug fix --- Entities/LogFileWatcher.cs | 121 ++++++++++++++++++++++--------------- Views/LevelDetails.cs | 40 +++++++----- Views/Overlay.cs | 8 ++- Views/Stats.cs | 110 +++++++++++++++++++++++---------- 4 files changed, 177 insertions(+), 102 deletions(-) diff --git a/Entities/LogFileWatcher.cs b/Entities/LogFileWatcher.cs index 11f8ec08..7033698f 100644 --- a/Entities/LogFileWatcher.cs +++ b/Entities/LogFileWatcher.cs @@ -94,7 +94,7 @@ public class LogFileWatcher { public event Action> OnParsedLogLinesCurrent; public event Action OnNewLogFileDate; public event Action OnServerConnectionNotification; - public event Action OnPersonalBestNotification; + public event Action OnPersonalBestNotification; public event Action OnError; private readonly ServerPingWatcher serverPingWatcher = new ServerPingWatcher(); @@ -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 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 roundInfoList = new List(); - 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 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 roundInfoList = new List(); + 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); + } } } } diff --git a/Views/LevelDetails.cs b/Views/LevelDetails.cs index 63ae52ab..6adfefc9 100644 --- a/Views/LevelDetails.cs +++ b/Views/LevelDetails.cs @@ -1050,15 +1050,19 @@ private void DeleteShow() { List 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); + } } } } @@ -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); diff --git a/Views/Overlay.cs b/Views/Overlay.cs index 27081ee6..bf0c71d1 100644 --- a/Views/Overlay.cs +++ b/Views/Overlay.cs @@ -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); diff --git a/Views/Stats.cs b/Views/Stats.cs index 627a4548..2ef65260 100644 --- a/Views/Stats.cs +++ b/Views/Stats.cs @@ -1006,8 +1006,8 @@ private string TranslateChangelog(string s) { } private void InitLogData() { - this.ClearServerConnectionLog(5); this.ClearPersonalBestLog(15); + this.ClearServerConnectionLog(5); this.ClearWeeklyCrownLog(15); this.FallalyticsPbLogCache = this.FallalyticsPbLog.FindAll().ToList(); this.FallalyticsCrownLogCache = this.FallalyticsCrownLog.FindAll().ToList(); @@ -1060,7 +1060,7 @@ private Stats() { this.RunDatabaseTask(initUserSettingsTask, false); #if AllowUpdate - this.RemoveUpdateFiles(); + this.RemoveBackupFiles(); #endif this.InitializeComponent(); @@ -1974,7 +1974,7 @@ private void menuProfile_Paint(object sender, PaintEventArgs e) { } #if AllowUpdate - private void RemoveUpdateFiles() { + private void RemoveBackupFiles() { foreach (string file in Directory.EnumerateFiles(CURRENTDIR, "*.bak")) { try { File.SetAttributes(file, FileAttributes.Normal); @@ -5023,10 +5023,10 @@ private void LogFile_OnError(string error) { } } - private void LogFile_OnPersonalBestNotification(string showNameId, string roundId, TimeSpan existingRecord, TimeSpan currentRecord) { + private void LogFile_OnPersonalBestNotification(string showNameId, string roundId, double currentPb, double currentRecord) { string timeDiffContent = string.Empty; - if (existingRecord != TimeSpan.MaxValue) { - TimeSpan timeDiff = existingRecord - currentRecord; + if (currentPb > 0) { + TimeSpan timeDiff = TimeSpan.FromMilliseconds(currentPb - currentRecord); timeDiffContent = timeDiff.Minutes > 0 ? $" ⏱️{Multilingual.GetWord("message_new_personal_best_timediff_by_minute_prefix")}{timeDiff.Minutes}{Multilingual.GetWord("message_new_personal_best_timediff_by_minute_infix")} {timeDiff.Seconds}.{timeDiff.Milliseconds}{Multilingual.GetWord("message_new_personal_best_timediff_by_minute_suffix")}" : $" ⏱️{timeDiff.Seconds}.{timeDiff.Milliseconds}{Multilingual.GetWord("message_new_personal_best_timediff_by_second")}"; } @@ -5335,7 +5335,10 @@ private void LogFile_OnParsedLogLines(List round) { Task.Run(() => this.FallalyticsWeeklyCrown(stat)).ContinueWith(prevTask => this.FallalyticsResendWeeklyCrown()); } - bool existsTransferFailedLogs = this.FallalyticsCrownLogCache.Exists(l => l.IsTransferSuccess == false && l.OnlineServiceType == (int)OnlineServiceType && string.Equals(l.OnlineServiceId, OnlineServiceId)); + bool existsTransferFailedLogs; + lock (this.FallalyticsCrownLogCache) { + existsTransferFailedLogs = this.FallalyticsCrownLogCache.Exists(l => l.IsTransferSuccess == false && l.OnlineServiceType == (int)OnlineServiceType && string.Equals(l.OnlineServiceId, OnlineServiceId)); + } if (existsTransferFailedLogs) { Task.Run(this.FallalyticsResendWeeklyCrown); } @@ -5508,7 +5511,9 @@ public void InsertPersonalBestLog(DateTime finish, string sessionId, string show PbDate = finish, SessionId = sessionId, ShowId = showId, RoundId = roundId, Record = record, IsPb = isPb, CountryCode = HostCountryCode, OnlineServiceType = (int)OnlineServiceType, OnlineServiceId = OnlineServiceId, OnlineServiceNickname = OnlineServiceNickname }; - this.PersonalBestLogCache.Add(log); + lock (this.PersonalBestLogCache) { + this.PersonalBestLogCache.Add(log); + } Task insertPersonalBestTask = new Task(() => { this.StatsDB.BeginTrans(); this.PersonalBestLog.Insert(log); @@ -5531,29 +5536,52 @@ public void InsertPersonalBestLog(DateTime finish, string sessionId, string show // } // } - private void ClearServerConnectionLog(int days) { + // private void ClearUnsavedPersonalBestLog() { + // lock (this.PersonalBestLogCache) { + // bool isCacheUpdated = false; + // List allPbDateLogs = this.PersonalBestLogCache.FindAll(l => l.IsPb).Select(l => l.PbDate).ToList(); + // foreach (DateTime pbDate in allPbDateLogs) { + // if (!this.RoundDetails.Exists(r => r.Finish.HasValue && r.Finish.Value == pbDate)) { + // PersonalBestLog pbLog = this.PersonalBestLogCache.Find(l => l.PbDate == pbDate); + // this.PersonalBestLogCache.Remove(pbLog); + // isCacheUpdated = true; + // } + // } + // if (isCacheUpdated) { + // Task clearUnsavedPersonalBestTask = new Task(() => { + // this.StatsDB.BeginTrans(); + // this.PersonalBestLog.DeleteAll(); + // this.PersonalBestLog.InsertBulk(this.PersonalBestLogCache); + // this.StatsDB.Commit(); + // }); + // this.RunDatabaseTask(clearUnsavedPersonalBestTask, false); + // } + // } + // } + + private void ClearPersonalBestLog(int days) { lock (this.StatsDB) { DateTime daysCond = DateTime.Now.AddDays(days * -1); - BsonExpression condition = Query.LT("ConnectionDate", daysCond); - Task clearServerConnectionTask = new Task(() => { + BsonExpression condition = Query.LT("_id", daysCond); + Task clearPersonalBestTask = new Task(() => { this.StatsDB.BeginTrans(); - this.ServerConnectionLog.DeleteMany(condition); + this.PersonalBestLog.DeleteMany(condition); this.StatsDB.Commit(); }); - this.RunDatabaseTask(clearServerConnectionTask, false); + this.RunDatabaseTask(clearPersonalBestTask, false); } } - private void ClearPersonalBestLog(int days) { + private void ClearServerConnectionLog(int days) { lock (this.StatsDB) { DateTime daysCond = DateTime.Now.AddDays(days * -1); - BsonExpression condition = Query.LT("_id", daysCond); - Task clearPersonalBestTask = new Task(() => { + BsonExpression condition = Query.LT("ConnectionDate", daysCond); + Task clearServerConnectionTask = new Task(() => { this.StatsDB.BeginTrans(); - this.PersonalBestLog.DeleteMany(condition); + this.ServerConnectionLog.DeleteMany(condition); this.StatsDB.Commit(); }); - this.RunDatabaseTask(clearPersonalBestTask, false); + this.RunDatabaseTask(clearServerConnectionTask, false); } } @@ -5610,18 +5638,20 @@ public void InsertServerConnectionLog(string sessionId, string showId, string se } public void UpdateServerConnectionLog(string sessionId, bool isPlaying) { - lock (this.StatsDB) { + lock (this.ServerConnectionLogCache) { ServerConnectionLog log = this.SelectServerConnectionLog(sessionId); if (log != null && !Equals(log.IsPlaying, isPlaying)) { this.ServerConnectionLogCache.Remove(log); log.IsPlaying = isPlaying; this.ServerConnectionLogCache.Add(log); - Task updateServerConnectionTask = new Task(() => { - this.StatsDB.BeginTrans(); - this.ServerConnectionLog.Update(log); - this.StatsDB.Commit(); - }); - this.RunDatabaseTask(updateServerConnectionTask, false); + lock (this.StatsDB) { + Task updateServerConnectionTask = new Task(() => { + this.StatsDB.BeginTrans(); + this.ServerConnectionLog.Update(log); + this.StatsDB.Commit(); + }); + this.RunDatabaseTask(updateServerConnectionTask, false); + } } } } @@ -5641,7 +5671,11 @@ public void UpdateServerConnectionLog(string sessionId, bool isPlaying) { // } private async Task FallalyticsResendWeeklyCrown() { - foreach (FallalyticsCrownLog log in this.FallalyticsCrownLogCache.FindAll(l => l.IsTransferSuccess == false)) { + List transferFailedLogs; + lock (this.FallalyticsCrownLogCache) { + transferFailedLogs = this.FallalyticsCrownLogCache.FindAll(l => !l.IsTransferSuccess); + } + foreach (FallalyticsCrownLog log in transferFailedLogs) { RoundInfo stat = new RoundInfo { SessionId = log.SessionId, ShowNameId = log.ShowId, Name = log.RoundId, End = log.End, OnlineServiceType = log.OnlineServiceType, OnlineServiceId = log.OnlineServiceId, OnlineServiceNickname = log.OnlineServiceNickname }; log.IsTransferSuccess = await FallalyticsReporter.WeeklyCrown(stat, this.CurrentSettings.EnableFallalyticsAnonymous); @@ -5669,7 +5703,9 @@ private async Task FallalyticsWeeklyCrown(RoundInfo stat) { OnlineServiceType = stat.OnlineServiceType.Value, OnlineServiceId = stat.OnlineServiceId, OnlineServiceNickname = stat.OnlineServiceNickname, IsTransferSuccess = isTransferSuccess }; - this.FallalyticsCrownLogCache.Add(log); + lock (this.FallalyticsCrownLogCache) { + this.FallalyticsCrownLogCache.Add(log); + } Task FallalyticsWeeklyCrownTask = new Task(() => { this.StatsDB.BeginTrans(); this.FallalyticsCrownLog.Insert(log); @@ -5686,10 +5722,13 @@ private async Task FallalyticsRegisterPb(RoundInfo stat) { TimeSpan currentRecord = stat.Finish.Value - stat.Start; DateTime currentFinish = stat.Finish.Value; bool isTransferSuccess; + bool existsPbLog; - bool existsPbLog = this.FallalyticsPbLogCache.Exists(l => string.Equals(l.RoundId, currentRoundId) && l.OnlineServiceType == stat.OnlineServiceType.Value && string.Equals(l.OnlineServiceId, stat.OnlineServiceId)); + lock (this.FallalyticsPbLogCache) { + existsPbLog = this.FallalyticsPbLogCache.Exists(l => string.Equals(l.RoundId, currentRoundId) && l.OnlineServiceType == stat.OnlineServiceType.Value && string.Equals(l.OnlineServiceId, stat.OnlineServiceId)); + } if (!existsPbLog) { - // RoundInfo recordInfo = this.AllStats.FindAll(r => r.PrivateLobby == false && r.Finish.HasValue && string.Equals(r.Name, currentRoundId) && !string.IsNullOrEmpty(r.ShowNameId) && !string.IsNullOrEmpty(r.SessionId)).OrderBy(r => r.Finish.Value - r.Start).FirstOrDefault(); + // RoundInfo recordInfo = this.AllStats.FindAll(r => !r.PrivateLobby && r.Finish.HasValue && string.Equals(r.Name, currentRoundId) && !string.IsNullOrEmpty(r.ShowNameId) && !string.IsNullOrEmpty(r.SessionId)).OrderBy(r => r.Finish.Value - r.Start).FirstOrDefault(); // // if (recordInfo != null && currentRecord > recordInfo.Finish.Value - recordInfo.Start) { // currentSessionId = recordInfo.SessionId; @@ -5709,7 +5748,9 @@ private async Task FallalyticsRegisterPb(RoundInfo stat) { OnlineServiceId = stat.OnlineServiceId, OnlineServiceNickname = stat.OnlineServiceNickname, IsTransferSuccess = isTransferSuccess }; - this.FallalyticsPbLogCache.Add(log); + lock (this.FallalyticsPbLogCache) { + this.FallalyticsPbLogCache.Add(log); + } Task FallalyticsRegisterPbTask = new Task(() => { this.StatsDB.BeginTrans(); this.FallalyticsPbLog.Insert(log); @@ -5718,9 +5759,12 @@ private async Task FallalyticsRegisterPb(RoundInfo stat) { this.RunDatabaseTask(FallalyticsRegisterPbTask, false); } } else { - int logIndex = this.FallalyticsPbLogCache.FindIndex(l => string.Equals(l.RoundId, currentRoundId) && l.OnlineServiceType == stat.OnlineServiceType.Value && string.Equals(l.OnlineServiceId, stat.OnlineServiceId)); - if (logIndex != -1) { - FallalyticsPbLog pbLog = this.FallalyticsPbLogCache[logIndex]; + FallalyticsPbLog pbLog; + lock (this.FallalyticsPbLogCache) { + int logIndex = this.FallalyticsPbLogCache.FindIndex(l => string.Equals(l.RoundId, currentRoundId) && l.OnlineServiceType == stat.OnlineServiceType.Value && string.Equals(l.OnlineServiceId, stat.OnlineServiceId)); + pbLog = logIndex != -1 ? this.FallalyticsPbLogCache[logIndex] : null; + } + if (pbLog != null) { TimeSpan existingRecord = TimeSpan.FromMilliseconds(pbLog.Record); // RoundInfo missingInfo = this.AllStats.FindAll(r =>