diff --git a/Controls/TransparentLabel.cs b/Controls/TransparentLabel.cs index 35a5fa268..c9e2a34c5 100644 --- a/Controls/TransparentLabel.cs +++ b/Controls/TransparentLabel.cs @@ -163,7 +163,7 @@ private float GetFontSizeFactor() { (Stats.CurrentLanguage == 4 || Stats.CurrentLanguage == 5) ? (this.TextRight.Length > 17 ? (1f - (((this.TextRight.Length * 3.3f) - 68 + (this.Text.Length * 3.3f)) / 100f)) : 1f) : 1f; break; case "lblFastest": - factor = (Stats.CurrentLanguage == 0 || Stats.CurrentLanguage == 1) ? (this.TextRight.Length > 7 ? (1f - (((this.TextRight.Length * 3.3f) - 63 + (this.Text.Length * 3.3f)) / 100f)) : 1f) : + factor = (Stats.CurrentLanguage == 0 || Stats.CurrentLanguage == 1) ? (this.TextRight.Length > 7 || this.Text.Length > 15 ? (1f - (((this.TextRight.Length * 3.3f) - 79 + (this.Text.Length * 3.3f)) / 100f)) : 1f) : (Stats.CurrentLanguage == 2 || Stats.CurrentLanguage == 3) ? (this.TextRight.Length > 7 ? (1f - (((this.TextRight.Length * 3.3f) - 49 + (this.Text.Length * 3.3f)) / 100f)) : 1f) : (Stats.CurrentLanguage == 4 || Stats.CurrentLanguage == 5) ? (this.TextRight.Length > 7 ? (1f - (((this.TextRight.Length * 3.3f) - 46 + (this.Text.Length * 3.3f)) / 100f)) : 1f) : 1f; break; diff --git a/Entities/LogFileWatcher.cs b/Entities/LogFileWatcher.cs index e4f766a26..403a5d9ed 100644 --- a/Entities/LogFileWatcher.cs +++ b/Entities/LogFileWatcher.cs @@ -471,20 +471,17 @@ private void SetCountryCodeByIP(string ip) { if (this.toggleCountryInfoApi || !Stats.IsClientRunning()) { return; } this.toggleCountryInfoApi = true; Stats.LastCountryAlpha2Code = string.Empty; + Stats.LastCountryRegion = string.Empty; try { string countryInfo = this.StatsForm.GetIpToCountryCode(ip); string alpha2Code = countryInfo.Split(';')[0].ToLower(); string region = countryInfo.Split(';').Length > 1 ? countryInfo.Split(';')[1] : string.Empty; Stats.LastCountryAlpha2Code = alpha2Code; - if (this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(alpha2Code)) { - // this.StatsForm.ShowNotification(Multilingual.GetWord("message_connected_to_server_caption"), - // $"{Multilingual.GetWord("message_connected_to_server_prefix")}{Multilingual.GetCountryName(alpha2Code)}{(countryInfo.Split(';').Length > 1 ? $", {countryInfo.Split(';')[1]}" : "")}{Multilingual.GetWord("message_connected_to_server_suffix")}", - // System.Windows.Forms.ToolTipIcon.Info, 2000); - this.OnShowToastNotification?.Invoke(alpha2Code, region); - } + Stats.LastCountryRegion = region; } catch { this.toggleCountryInfoApi = false; Stats.LastCountryAlpha2Code = string.Empty; + Stats.LastCountryRegion = string.Empty; } } @@ -520,6 +517,10 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { } } } else if (line.Line.IndexOf("[StateDisconnectingFromServer] Shutting down game and resetting scene to reconnect", StringComparison.OrdinalIgnoreCase) >= 0) { + ServerConnectionLog serverConnectionLog = this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId); + if (serverConnectionLog != null) { + this.StatsForm.UpsertServerConnectionLog(this.sessionId, this.selectedShowId, Stats.LastServerIp, Stats.ConnectedToServerDate, true, false); + } Stats.InShow = false; Stats.QueuedPlayers = 0; Stats.IsQueued = false; @@ -527,6 +528,7 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { Stats.LastServerPing = 0; Stats.IsBadServerPing = false; Stats.LastCountryAlpha2Code = string.Empty; + Stats.LastCountryRegion = string.Empty; this.toggleCountryInfoApi = false; this.toggleFgdbCreativeApi = false; } else if (line.Line.IndexOf("[StateMatchmaking] Begin", StringComparison.OrdinalIgnoreCase) >= 0 @@ -566,11 +568,28 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { this.useShareCode = false; } } else if ((index = line.Line.IndexOf("[HandleSuccessfulLogin] Session: ", StringComparison.OrdinalIgnoreCase)) >= 0) { - //Store SessionID to prevent duplicates (for fallalytics) this.sessionId = line.Line.Substring(index + 33); - if (!this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId) && (DateTime.UtcNow - Stats.ConnectedToServerDate).TotalMinutes <= 40) { - this.serverPingWatcher.Start(); - this.SetCountryCodeByIP(Stats.LastServerIp); + if ((DateTime.UtcNow - Stats.ConnectedToServerDate).TotalMinutes <= 40) { + ServerConnectionLog serverConnectionLog = this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId); + if (serverConnectionLog != null) { + if (!serverConnectionLog.IsNotify) { + if (this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(Stats.LastCountryAlpha2Code)) { + this.OnShowToastNotification?.Invoke(Stats.LastCountryAlpha2Code, Stats.LastCountryRegion); + } + } + + if (serverConnectionLog.IsPlaying) { + this.serverPingWatcher.Start(); + this.SetCountryCodeByIP(Stats.LastServerIp); + } + } else { + this.StatsForm.UpsertServerConnectionLog(this.sessionId, this.selectedShowId, Stats.LastServerIp, Stats.ConnectedToServerDate, true, true); + this.serverPingWatcher.Start(); + this.SetCountryCodeByIP(Stats.LastServerIp); + if (this.StatsForm.CurrentSettings.NotifyServerConnected && !string.IsNullOrEmpty(Stats.LastCountryAlpha2Code)) { + this.OnShowToastNotification?.Invoke(Stats.LastCountryAlpha2Code, Stats.LastCountryRegion); + } + } } } else if ((index = line.Line.IndexOf("[StateGameLoading] Loading game level scene", StringComparison.OrdinalIgnoreCase)) >= 0) { if (line.Date > Stats.LastRoundLoad) { @@ -582,11 +601,10 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { Stats.IsLastPlayedRoundStillPlaying = false; Stats.LastPlayedRoundStart = null; Stats.LastPlayedRoundEnd = null; - - if (!this.StatsForm.SelectServerConnectionLog(this.sessionId, this.selectedShowId) && (DateTime.UtcNow - Stats.ConnectedToServerDate).TotalMinutes <= 40) { + + if ((DateTime.UtcNow - Stats.ConnectedToServerDate).TotalMinutes <= 40) { this.gameStateWatcher.Start(); } - this.StatsForm.UpsertServerConnectionLog(this.sessionId, this.selectedShowId, Stats.LastServerIp, Stats.ConnectedToServerDate); } logRound.Info = new RoundInfo { ShowNameId = this.selectedShowId, SessionId = this.sessionId, UseShareCode = this.useShareCode }; @@ -735,6 +753,7 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { Stats.LastServerPing = 0; Stats.IsBadServerPing = false; Stats.LastCountryAlpha2Code = string.Empty; + Stats.LastCountryRegion = string.Empty; Stats.IsClientHasBeenClosed = false; this.AddLineAfterClientShutdown(); @@ -745,6 +764,7 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { Stats.LastServerPing = 0; Stats.IsBadServerPing = false; Stats.LastCountryAlpha2Code = string.Empty; + Stats.LastCountryRegion = string.Empty; this.toggleCountryInfoApi = false; this.toggleFgdbCreativeApi = false; @@ -801,6 +821,7 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { } round[i].ShowEnd = showEnd; } + this.StatsForm.UpsertServerConnectionLog(logRound.Info.SessionId, logRound.Info.ShowNameId, Stats.LastServerIp, Stats.ConnectedToServerDate, true, false); logRound.Info = null; Stats.InShow = false; Stats.EndedShow = true; @@ -914,6 +935,7 @@ private bool ParseLine(LogLine line, List round, LogRound logRound) { logRound.GetCurrentPlayerID = false; logRound.FindingPosition = false; } + this.StatsForm.UpsertServerConnectionLog(logRound.Info.SessionId, logRound.Info.ShowNameId, Stats.LastServerIp, Stats.ConnectedToServerDate, true, false); logRound.Info = null; return true; } diff --git a/Entities/ServerConnectionLog.cs b/Entities/ServerConnectionLog.cs index 02aec916c..6e2d01949 100644 --- a/Entities/ServerConnectionLog.cs +++ b/Entities/ServerConnectionLog.cs @@ -12,5 +12,7 @@ public class ServerConnectionLog { public int OnlineServiceType { get; set; } public string OnlineServiceId { get; set; } public string OnlineServiceNickname { get; set; } + public bool IsNotify { get; set; } + public bool IsPlaying { get; set; } } } \ No newline at end of file diff --git a/EunmaToast.dll b/EunmaToast.dll index 0a0fc0101..9371a5442 100644 Binary files a/EunmaToast.dll and b/EunmaToast.dll differ diff --git a/Views/Stats.cs b/Views/Stats.cs index 8a352fb89..94de14c1f 100644 --- a/Views/Stats.cs +++ b/Views/Stats.cs @@ -146,6 +146,7 @@ public static bool IsClientRunning() { public static DateTime ConnectedToServerDate = DateTime.MinValue; public static string LastServerIp = string.Empty; public static string LastCountryAlpha2Code = string.Empty; + public static string LastCountryRegion = string.Empty; public static long LastServerPing = 0; public static bool IsBadServerPing = false; @@ -3135,20 +3136,31 @@ private void LogFile_OnParsedLogLines(List round) { } } - public bool SelectServerConnectionLog(string sessionId, string showId) { - if (string.IsNullOrEmpty(sessionId) || string.IsNullOrEmpty(showId)) return true; + public bool ExistsServerConnectionLog(string sessionId, string showId) { + if (string.IsNullOrEmpty(sessionId) || string.IsNullOrEmpty(showId)) return false; BsonExpression condition = Query.And( Query.EQ("_id", sessionId), Query.EQ("ShowId", showId) ); return this.ServerConnectionLog.Exists(condition); } + + public ServerConnectionLog SelectServerConnectionLog(string sessionId, string showId) { + // Console.WriteLine($"{sessionId} / {showId}"); + BsonExpression condition = Query.And( + Query.EQ("_id", sessionId), + Query.EQ("ShowId", showId) + ); + return this.ServerConnectionLog.FindOne(condition); + } - public void UpsertServerConnectionLog(string sessionId, string showNameId, string serverIp, DateTime connectionDate) { + public void UpsertServerConnectionLog(string sessionId, string showNameId, string serverIp, DateTime connectionDate, bool isNotify, bool isPlaying) { lock (this.StatsDB) { this.StatsDB.BeginTrans(); this.ServerConnectionLog.Upsert(new ServerConnectionLog { SessionId = sessionId, ShowId = showNameId, ServerIp = serverIp, ConnectionDate = connectionDate, - CountryCode = HostCountryCode, OnlineServiceType = (int)OnlineServiceType, OnlineServiceId = OnlineServiceId, OnlineServiceNickname = OnlineServiceNickname }); + CountryCode = HostCountryCode, OnlineServiceType = (int)OnlineServiceType, OnlineServiceId = OnlineServiceId, OnlineServiceNickname = OnlineServiceNickname, + IsNotify = isNotify, IsPlaying = isPlaying + }); this.StatsDB.Commit(); } }