Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qubqub committed Oct 26, 2023
1 parent 0e78a04 commit 1762827
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Controls/TransparentLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 35 additions & 13 deletions Entities/LogFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -520,13 +517,18 @@ private bool ParseLine(LogLine line, List<RoundInfo> 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;
Stats.ToggleServerInfo = false;
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
Expand Down Expand Up @@ -566,11 +568,28 @@ private bool ParseLine(LogLine line, List<RoundInfo> 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) {
Expand All @@ -582,11 +601,10 @@ private bool ParseLine(LogLine line, List<RoundInfo> 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 };
Expand Down Expand Up @@ -735,6 +753,7 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
Stats.LastServerPing = 0;
Stats.IsBadServerPing = false;
Stats.LastCountryAlpha2Code = string.Empty;
Stats.LastCountryRegion = string.Empty;

Stats.IsClientHasBeenClosed = false;
this.AddLineAfterClientShutdown();
Expand All @@ -745,6 +764,7 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
Stats.LastServerPing = 0;
Stats.IsBadServerPing = false;
Stats.LastCountryAlpha2Code = string.Empty;
Stats.LastCountryRegion = string.Empty;
this.toggleCountryInfoApi = false;
this.toggleFgdbCreativeApi = false;

Expand Down Expand Up @@ -801,6 +821,7 @@ private bool ParseLine(LogLine line, List<RoundInfo> 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;
Expand Down Expand Up @@ -914,6 +935,7 @@ private bool ParseLine(LogLine line, List<RoundInfo> 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;
}
Expand Down
2 changes: 2 additions & 0 deletions Entities/ServerConnectionLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Binary file modified EunmaToast.dll
Binary file not shown.
20 changes: 16 additions & 4 deletions Views/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -3135,20 +3136,31 @@ private void LogFile_OnParsedLogLines(List<RoundInfo> 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();
}
}
Expand Down

0 comments on commit 1762827

Please sign in to comment.