Skip to content

Commit

Permalink
Close #388
Browse files Browse the repository at this point in the history
  • Loading branch information
Micdu70 committed Oct 13, 2024
1 parent fc7c49f commit 359af40
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 94 deletions.
6 changes: 3 additions & 3 deletions Entities/LevelStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class RoundInfo : IComparable<RoundInfo> {
public string CreativeGameModeId { get; set; }
public string CreativeLevelThemeId { get; set; }
public DateTime CreativeLastModifiedDate { get; set; } = DateTime.MinValue;
public int CreativePlayCount { get; set; }
public int CreativeLikes { get; set; }
public int CreativeDislikes { get; set; }
public ulong CreativePlayCount { get; set; }
public ulong CreativeLikes { get; set; }
public ulong CreativeDislikes { get; set; }
public int CreativeQualificationPercent { get; set; }
public int CreativeTimeLimitSeconds { get; set; }
public string SessionId { get; set; }
Expand Down
84 changes: 64 additions & 20 deletions Entities/LogFileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ThreadLocalData {
public string sceneName;

public bool toggleCountryInfoApi;
public bool toggleFgdbCreativeApi;
public bool toggleCreativeApi;
public string creativeShareCode;
public string creativeOnlinePlatformId;
public string creativeAuthor;
Expand All @@ -66,9 +66,9 @@ public class ThreadLocalData {
public string creativeGameModeId;
public string creativeLevelThemeId;
public DateTime creativeLastModifiedDate;
public int creativePlayCount;
public int creativeLikes;
public int creativeDislikes;
public ulong creativePlayCount;
public ulong creativeLikes;
public ulong creativeDislikes;
public int creativeQualificationPercent;
public int creativeTimeLimitSeconds;
}
Expand Down Expand Up @@ -470,19 +470,19 @@ private bool IsTeamException(string roundId) {
|| roundId.IndexOf("_squads", StringComparison.OrdinalIgnoreCase) != -1);
}

private void ClearUserCreativeLevelInfo() {
private void SetDefaultUserCreativeLevelInfo() {
this.threadLocalVariable.Value.creativeOnlinePlatformId = string.Empty;
this.threadLocalVariable.Value.creativeAuthor = string.Empty;
this.threadLocalVariable.Value.creativeShareCode = string.Empty;
// this.threadLocalVariable.Value.creativeShareCode = string.Empty;
this.threadLocalVariable.Value.creativeVersion = 0;
this.threadLocalVariable.Value.creativeStatus = string.Empty;
this.threadLocalVariable.Value.creativeTitle = string.Empty;
this.threadLocalVariable.Value.creativeDescription = string.Empty;
this.threadLocalVariable.Value.creativeCreatorTags = string.Empty;
this.threadLocalVariable.Value.creativeMaxPlayer = 0;
this.threadLocalVariable.Value.creativePlatformId = string.Empty;
this.threadLocalVariable.Value.creativeGameModeId = string.Empty;
this.threadLocalVariable.Value.creativeLevelThemeId = string.Empty;
this.threadLocalVariable.Value.creativeGameModeId = "GAMEMODE_GAUNTLET";
this.threadLocalVariable.Value.creativeLevelThemeId = "THEME_VANILLA";
this.threadLocalVariable.Value.creativeLastModifiedDate = DateTime.MinValue;
this.threadLocalVariable.Value.creativePlayCount = 0;
this.threadLocalVariable.Value.creativeLikes = 0;
Expand All @@ -492,11 +492,11 @@ private void ClearUserCreativeLevelInfo() {
}

private void SetCreativeLevelVariable(string shareCode) {
if (this.threadLocalVariable.Value.toggleFgdbCreativeApi) { return; }
if (this.threadLocalVariable.Value.toggleCreativeApi) { return; }
TimeSpan timeDiff = DateTime.UtcNow - Stats.ConnectedToServerDate;
bool isSucceed = false;
if (timeDiff.TotalMinutes <= 15 && Utils.IsInternetConnected()) {
this.threadLocalVariable.Value.toggleFgdbCreativeApi = true;
this.threadLocalVariable.Value.toggleCreativeApi = true;
try {
JsonElement resData = Utils.GetApiData(Utils.FALLGUYSDB_API_URL, $"creative/{shareCode}.json");
if (resData.TryGetProperty("data", out JsonElement je)) {
Expand Down Expand Up @@ -525,16 +525,54 @@ private void SetCreativeLevelVariable(string shareCode) {
this.threadLocalVariable.Value.creativeGameModeId = versionMetadata.GetProperty("game_mode_id").GetString() ?? "GAMEMODE_GAUNTLET";
this.threadLocalVariable.Value.creativeLevelThemeId = versionMetadata.GetProperty("level_theme_id").GetString() ?? "THEME_VANILLA";
this.threadLocalVariable.Value.creativeLastModifiedDate = versionMetadata.GetProperty("last_modified_date").GetDateTime();
this.threadLocalVariable.Value.creativePlayCount = stats.GetProperty("play_count").GetInt32();
this.threadLocalVariable.Value.creativeLikes = stats.GetProperty("likes").GetInt32();
this.threadLocalVariable.Value.creativeDislikes = stats.GetProperty("dislikes").GetInt32();
this.threadLocalVariable.Value.creativePlayCount = stats.GetProperty("play_count").GetUInt64();
this.threadLocalVariable.Value.creativeLikes = stats.GetProperty("likes").GetUInt64();
this.threadLocalVariable.Value.creativeDislikes = stats.GetProperty("dislikes").GetUInt64();
this.threadLocalVariable.Value.creativeQualificationPercent = versionMetadata.GetProperty("qualification_percent").GetInt32();
this.threadLocalVariable.Value.creativeTimeLimitSeconds = versionMetadata.GetProperty("config").TryGetProperty("time_limit_seconds", out JsonElement jeTimeLimitSeconds) ? jeTimeLimitSeconds.GetInt32() : 240;
Task.Run(() => { this.StatsForm.UpdateCreativeLevels(string.Empty, shareCode, snapshot); });
isSucceed = true;
}
} catch {
isSucceed = false;
try {
JsonElement resData = Utils.GetApiData(Utils.CLOUDSEEKER_API_URL, $"creative/?share_code={shareCode}");
if (resData.TryGetProperty("level_data", out JsonElement je)) {
JsonElement level_data = je[0];
JsonElement versionMetadata = level_data.GetProperty("version_metadata");
JsonElement stats = level_data.GetProperty("stats");
string[] onlinePlatformInfo = this.StatsForm.FindUserCreativeAuthor(level_data.GetProperty("author").GetProperty("name_per_platform"));
this.threadLocalVariable.Value.creativeOnlinePlatformId = onlinePlatformInfo[0];
this.threadLocalVariable.Value.creativeAuthor = onlinePlatformInfo[1];
this.threadLocalVariable.Value.creativeShareCode = level_data.GetProperty("share_code").GetString();
this.threadLocalVariable.Value.creativeVersion = versionMetadata.GetProperty("version").GetInt32();
this.threadLocalVariable.Value.creativeStatus = versionMetadata.GetProperty("status").GetString();
this.threadLocalVariable.Value.creativeTitle = versionMetadata.GetProperty("title").GetString();
this.threadLocalVariable.Value.creativeDescription = versionMetadata.GetProperty("description").GetString();
if (versionMetadata.TryGetProperty("creator_tags", out JsonElement creatorTags) && creatorTags.ValueKind == JsonValueKind.Array) {
string temps = string.Empty;
foreach (JsonElement t in creatorTags.EnumerateArray()) {
if (!string.IsNullOrEmpty(temps)) { temps += ";"; }
temps += t.GetString();
}
this.threadLocalVariable.Value.creativeCreatorTags = temps;
}
this.threadLocalVariable.Value.creativeMaxPlayer = versionMetadata.GetProperty("max_player_count").GetInt32();
this.threadLocalVariable.Value.creativeThumbUrl = versionMetadata.GetProperty("thumb_url").GetString();
this.threadLocalVariable.Value.creativePlatformId = versionMetadata.GetProperty("platform_id").GetString();
this.threadLocalVariable.Value.creativeGameModeId = versionMetadata.GetProperty("game_mode_id").GetString() ?? "GAMEMODE_GAUNTLET";
this.threadLocalVariable.Value.creativeLevelThemeId = versionMetadata.GetProperty("level_theme_id").GetString() ?? "THEME_VANILLA";
this.threadLocalVariable.Value.creativeLastModifiedDate = versionMetadata.GetProperty("last_modified_date").GetDateTime();
this.threadLocalVariable.Value.creativePlayCount = stats.GetProperty("play_count").GetUInt64();
this.threadLocalVariable.Value.creativeLikes = stats.GetProperty("likes").GetUInt64();
this.threadLocalVariable.Value.creativeDislikes = stats.GetProperty("dislikes").GetUInt64();
this.threadLocalVariable.Value.creativeQualificationPercent = versionMetadata.GetProperty("qualification_percent").GetInt32();
this.threadLocalVariable.Value.creativeTimeLimitSeconds = versionMetadata.GetProperty("config").TryGetProperty("time_limit_seconds", out JsonElement jeTimeLimitSeconds) ? jeTimeLimitSeconds.GetInt32() : 240;
Task.Run(() => { this.StatsForm.UpdateCreativeLevels(string.Empty, shareCode, level_data); });
isSucceed = true;
}
} catch {
isSucceed = false;
}
}
}

Expand All @@ -559,8 +597,8 @@ private void SetCreativeLevelVariable(string shareCode) {
this.threadLocalVariable.Value.creativeQualificationPercent = ri.CreativeQualificationPercent;
this.threadLocalVariable.Value.creativeTimeLimitSeconds = ri.CreativeTimeLimitSeconds;
} else {
this.threadLocalVariable.Value.toggleFgdbCreativeApi = false;
this.ClearUserCreativeLevelInfo();
this.threadLocalVariable.Value.toggleCreativeApi = false;
this.SetDefaultUserCreativeLevelInfo();
}
}
}
Expand Down Expand Up @@ -624,8 +662,8 @@ private void ResetVariablesUsedForOverlay() {
Stats.LastCountryRegion = string.Empty;
Stats.LastCountryCity = string.Empty;
this.threadLocalVariable.Value.toggleCountryInfoApi = false;
this.threadLocalVariable.Value.toggleFgdbCreativeApi = false;
this.ClearUserCreativeLevelInfo();
this.threadLocalVariable.Value.toggleCreativeApi = false;
this.SetDefaultUserCreativeLevelInfo();
}

private void UpdateServerConnectionLog(string session, string show) {
Expand Down Expand Up @@ -785,7 +823,10 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
};

if (logRound.Info.UseShareCode) {
this.SetCreativeLevelVariable(logRound.Info.IsCasualShow ? this.threadLocalVariable.Value.creativeShareCode : logRound.Info.ShowNameId);
if (line.Date > Stats.LastCreativeRoundLoad) {
Stats.LastCreativeRoundLoad = line.Date;
this.SetCreativeLevelVariable(logRound.Info.IsCasualShow ? this.threadLocalVariable.Value.creativeShareCode : logRound.Info.ShowNameId);
}
logRound.Info.SceneName = this.threadLocalVariable.Value.creativeGameModeId;
} else {
logRound.Info.SceneName = this._sceneNameReplacer.TryGetValue(this.threadLocalVariable.Value.sceneName, out string sceneName)
Expand All @@ -809,7 +850,10 @@ private bool ParseLine(LogLine line, List<RoundInfo> round, LogRound logRound) {
};

if (logRound.Info.UseShareCode) {
this.SetCreativeLevelVariable(logRound.Info.IsCasualShow ? this.threadLocalVariable.Value.creativeShareCode : logRound.Info.ShowNameId);
if (line.Date > Stats.LastCreativeRoundLoad) {
Stats.LastCreativeRoundLoad = line.Date;
this.SetCreativeLevelVariable(logRound.Info.IsCasualShow ? this.threadLocalVariable.Value.creativeShareCode : logRound.Info.ShowNameId);
}
logRound.Info.SceneName = this.threadLocalVariable.Value.creativeGameModeId;
} else {
logRound.Info.SceneName = this._sceneNameReplacer.TryGetValue(this.threadLocalVariable.Value.sceneName, out string sceneName)
Expand Down
Loading

0 comments on commit 359af40

Please sign in to comment.