From e872fa8897fbb2e9da8f2b0bb1c24a0efc489aa7 Mon Sep 17 00:00:00 2001 From: K4ryuu <104531589+K4ryuu@users.noreply.github.com> Date: Sat, 18 May 2024 18:44:11 +0200 Subject: [PATCH] Patch v4.3.2 --- CHANGELOG | 7 + K4-System/src/Module/Utils/UtilsEvents.cs | 5 +- K4-System/src/Plugin/PluginDatabase.cs | 309 +++++++++++----------- K4-System/src/Plugin/PluginManifest.cs | 2 +- K4-System/src/Plugin/PluginStock.cs | 7 +- 5 files changed, 175 insertions(+), 155 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e533724..0336e70 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +-- 2023.05.17 - V4.3.2 + +- fix: Connect message shown even if its disabled +- fix: Placeholder replaced error logs +- fix: Player top placement is not fetched on join +- fix: Load all player cache is running the query two times + -- 2023.05.17 - V4.3.1 - fix: Connect/Disconnect message parentheses diff --git a/K4-System/src/Module/Utils/UtilsEvents.cs b/K4-System/src/Module/Utils/UtilsEvents.cs index 59ee0ae..be0a3c3 100644 --- a/K4-System/src/Module/Utils/UtilsEvents.cs +++ b/K4-System/src/Module/Utils/UtilsEvents.cs @@ -18,7 +18,10 @@ public void Initialize_Events() if (k4player is null || !k4player.IsValid || !k4player.IsPlayer) return HookResult.Continue; - Server.PrintToChatAll(plugin.ReplacePlaceholders(k4player, plugin.Localizer["k4.announcement.disconnect"])); + string? message = plugin.ReplacePlaceholders(k4player, plugin.Localizer["k4.announcement.disconnect"]); + if (message != null) + Server.PrintToChatAll(message); + return HookResult.Continue; }); } diff --git a/K4-System/src/Plugin/PluginDatabase.cs b/K4-System/src/Plugin/PluginDatabase.cs index 6b94166..4bef73e 100644 --- a/K4-System/src/Plugin/PluginDatabase.cs +++ b/K4-System/src/Plugin/PluginDatabase.cs @@ -262,94 +262,95 @@ private async Task ExecuteTimeUpdateAsync(MySqlTransaction transaction, K4Player public async Task LoadPlayerCacheAsync(K4Player k4player) { string combinedQuery = $@" - INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4ranks` (`name`, `steam_id`, `rank`, `points`, `lastseen`) - VALUES ( - @escapedName, - @steamid, - @noneRankName, - @startPoints, - CURRENT_TIMESTAMP - ) - ON DUPLICATE KEY UPDATE - `name` = @escapedName, - `lastseen` = CURRENT_TIMESTAMP; - - INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4stats` (`name`, `steam_id`, `lastseen`) - VALUES ( - @escapedName, - @steamid, - CURRENT_TIMESTAMP - ) - ON DUPLICATE KEY UPDATE - `name` = @escapedName, - `lastseen` = CURRENT_TIMESTAMP; - - INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4times` (`name`, `steam_id`, `lastseen`) - VALUES ( - @escapedName, - @steamid, - CURRENT_TIMESTAMP - ) - ON DUPLICATE KEY UPDATE - `name` = @escapedName, - `lastseen` = CURRENT_TIMESTAMP; - - SELECT - r.`points`, - s.`kills`, - s.`firstblood`, - s.`deaths`, - s.`assists`, - s.`shoots`, - s.`hits_taken`, - s.`hits_given`, - s.`headshots`, - s.`chest_hits`, - s.`stomach_hits`, - s.`left_arm_hits`, - s.`right_arm_hits`, - s.`left_leg_hits`, - s.`right_leg_hits`, - s.`neck_hits`, - s.`unused_hits`, - s.`gear_hits`, - s.`special_hits`, - s.`grenades`, - s.`mvp`, - s.`round_win`, - s.`round_lose`, - s.`game_win`, - s.`game_lose`, - s.`rounds_overall`, - s.`rounds_ct`, - s.`rounds_t`, - s.`bomb_planted`, - s.`bomb_defused`, - s.`hostage_rescued`, - s.`hostage_killed`, - s.`noscope_kill`, - s.`penetrated_kill`, - s.`thrusmoke_kill`, - s.`flashed_kill`, - s.`dominated_kill`, - s.`revenge_kill`, - s.`assist_flash`, - t.`all`, - t.`ct`, - t.`t`, - t.`spec`, - t.`alive`, - t.`dead` - FROM - `{Config.DatabaseSettings.TablePrefix}k4ranks` AS r - LEFT JOIN - `{Config.DatabaseSettings.TablePrefix}k4stats` AS s ON r.`steam_id` = s.`steam_id` - LEFT JOIN - `{Config.DatabaseSettings.TablePrefix}k4times` AS t ON r.`steam_id` = t.`steam_id` - WHERE - r.`steam_id` = @steamid; - "; - + INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4ranks` (`name`, `steam_id`, `rank`, `points`, `lastseen`) + VALUES ( + @escapedName, + @steamid, + @noneRankName, + @startPoints, + CURRENT_TIMESTAMP + ) + ON DUPLICATE KEY UPDATE + `name` = @escapedName, + `lastseen` = CURRENT_TIMESTAMP; + + INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4stats` (`name`, `steam_id`, `lastseen`) + VALUES ( + @escapedName, + @steamid, + CURRENT_TIMESTAMP + ) + ON DUPLICATE KEY UPDATE + `name` = @escapedName, + `lastseen` = CURRENT_TIMESTAMP; + + INSERT INTO `{Config.DatabaseSettings.TablePrefix}k4times` (`name`, `steam_id`, `lastseen`) + VALUES ( + @escapedName, + @steamid, + CURRENT_TIMESTAMP + ) + ON DUPLICATE KEY UPDATE + `name` = @escapedName, + `lastseen` = CURRENT_TIMESTAMP; + + SELECT + r.`points`, + s.`kills`, + s.`firstblood`, + s.`deaths`, + s.`assists`, + s.`shoots`, + s.`hits_taken`, + s.`hits_given`, + s.`headshots`, + s.`chest_hits`, + s.`stomach_hits`, + s.`left_arm_hits`, + s.`right_arm_hits`, + s.`left_leg_hits`, + s.`right_leg_hits`, + s.`neck_hits`, + s.`unused_hits`, + s.`gear_hits`, + s.`special_hits`, + s.`grenades`, + s.`mvp`, + s.`round_win`, + s.`round_lose`, + s.`game_win`, + s.`game_lose`, + s.`rounds_overall`, + s.`rounds_ct`, + s.`rounds_t`, + s.`bomb_planted`, + s.`bomb_defused`, + s.`hostage_rescued`, + s.`hostage_killed`, + s.`noscope_kill`, + s.`penetrated_kill`, + s.`thrusmoke_kill`, + s.`flashed_kill`, + s.`dominated_kill`, + s.`revenge_kill`, + s.`assist_flash`, + t.`all`, + t.`ct`, + t.`t`, + t.`spec`, + t.`alive`, + t.`dead`, + (SELECT COUNT(*) FROM `{Config.DatabaseSettings.TablePrefix}k4ranks` + WHERE `points` > (SELECT `points` FROM `{Config.DatabaseSettings.TablePrefix}k4ranks` WHERE `steam_id` = @steamid)) AS playerPlace + FROM + `{Config.DatabaseSettings.TablePrefix}k4ranks` AS r + LEFT JOIN + `{Config.DatabaseSettings.TablePrefix}k4stats` AS s ON r.`steam_id` = s.`steam_id` + LEFT JOIN + `{Config.DatabaseSettings.TablePrefix}k4times` AS t ON r.`steam_id` = t.`steam_id` + WHERE + r.`steam_id` = @steamid; + "; try { @@ -378,7 +379,6 @@ LEFT JOIN } } - private void LoadAllPlayersCache() { List players = Utilities.GetPlayers().Where(player => player?.IsValid == true && player.PlayerPawn?.IsValid == true).ToList(); @@ -393,59 +393,61 @@ private void LoadAllPlayersCache() } string combinedQuery = $@"SELECT - r.`points`, - s.`kills`, - s.`firstblood`, - s.`deaths`, - s.`assists`, - s.`shoots`, - s.`hits_taken`, - s.`hits_given`, - s.`headshots`, - s.`chest_hits`, - s.`stomach_hits`, - s.`left_arm_hits`, - s.`right_arm_hits`, - s.`left_leg_hits`, - s.`right_leg_hits`, - s.`neck_hits`, - s.`unused_hits`, - s.`gear_hits`, - s.`special_hits`, - s.`grenades`, - s.`mvp`, - s.`round_win`, - s.`round_lose`, - s.`game_win`, - s.`game_lose`, - s.`rounds_overall`, - s.`rounds_ct`, - s.`rounds_t`, - s.`bomb_planted`, - s.`bomb_defused`, - s.`hostage_rescued`, - s.`hostage_killed`, - s.`noscope_kill`, - s.`penetrated_kill`, - s.`thrusmoke_kill`, - s.`flashed_kill`, - s.`dominated_kill`, - s.`revenge_kill`, - s.`assist_flash`, - t.`all`, - t.`ct`, - t.`t`, - t.`spec`, - t.`alive`, - t.`dead` - FROM - `{Config.DatabaseSettings.TablePrefix}k4ranks` AS r - LEFT JOIN - `{Config.DatabaseSettings.TablePrefix}k4stats` AS s ON r.`steam_id` = s.`steam_id` - LEFT JOIN - `{Config.DatabaseSettings.TablePrefix}k4times` AS t ON r.`steam_id` = t.`steam_id` - WHERE - r.`steam_id` IN (" + string.Join(",", players.Select(player => $"'{player.SteamID}'")) + ");"; + r.`points`, + s.`kills`, + s.`firstblood`, + s.`deaths`, + s.`assists`, + s.`shoots`, + s.`hits_taken`, + s.`hits_given`, + s.`headshots`, + s.`chest_hits`, + s.`stomach_hits`, + s.`left_arm_hits`, + s.`right_arm_hits`, + s.`left_leg_hits`, + s.`right_leg_hits`, + s.`neck_hits`, + s.`unused_hits`, + s.`gear_hits`, + s.`special_hits`, + s.`grenades`, + s.`mvp`, + s.`round_win`, + s.`round_lose`, + s.`game_win`, + s.`game_lose`, + s.`rounds_overall`, + s.`rounds_ct`, + s.`rounds_t`, + s.`bomb_planted`, + s.`bomb_defused`, + s.`hostage_rescued`, + s.`hostage_killed`, + s.`noscope_kill`, + s.`penetrated_kill`, + s.`thrusmoke_kill`, + s.`flashed_kill`, + s.`dominated_kill`, + s.`revenge_kill`, + s.`assist_flash`, + t.`all`, + t.`ct`, + t.`t`, + t.`spec`, + t.`alive`, + t.`dead`, + (SELECT COUNT(*) FROM `{Config.DatabaseSettings.TablePrefix}k4ranks` + WHERE `points` > (SELECT `points` FROM `{Config.DatabaseSettings.TablePrefix}k4ranks` WHERE `steam_id` = r.`steam_id`)) AS playerPlace + FROM + `{Config.DatabaseSettings.TablePrefix}k4ranks` AS r + LEFT JOIN + `{Config.DatabaseSettings.TablePrefix}k4stats` AS s ON r.`steam_id` = s.`steam_id` + LEFT JOIN + `{Config.DatabaseSettings.TablePrefix}k4times` AS t ON r.`steam_id` = t.`steam_id` + WHERE + r.`steam_id` IN (" + string.Join(",", players.Select(player => $"'{player.SteamID}'")) + ");"; Task.Run(() => LoadAllPlayersCacheAsync(combinedQuery)); } @@ -457,16 +459,14 @@ public async Task LoadAllPlayersCacheAsync(string combinedQuery) using (var connection = CreateConnection(Config)) { await connection.OpenAsync(); - var players = await connection.QueryAsync(combinedQuery); + var rows = await connection.QueryAsync(combinedQuery); - foreach (var k4player in K4Players.ToList()) + foreach (var row in rows) { - if (!k4player.IsValid || !k4player.IsPlayer) - continue; - - var rows = await connection.QueryAsync(combinedQuery); + string steamId = row.steam_id; + K4Player? k4player = K4Players.FirstOrDefault(p => p.SteamID == ulong.Parse(steamId)); - foreach (var row in rows) + if (k4player != null && k4player.IsValid && k4player.IsPlayer) { LoadPlayerRowToCache(k4player, row, true); } @@ -494,7 +494,7 @@ public void LoadPlayerRowToCache(K4Player k4player, dynamic row, bool all) RoundPoints = 0, HideAdminTag = false, MuteMessages = false, - TopPlacement = 0 + TopPlacement = (int)row.playerPlace + 1 }; } @@ -555,7 +555,14 @@ public void LoadPlayerRowToCache(K4Player k4player, dynamic row, bool all) if (!all) { K4Players.Add(k4player); - Server.NextWorldUpdate(() => Server.PrintToChatAll(ReplacePlaceholders(k4player, Localizer["k4.announcement.connect"]))); + + if (Config.UtilSettings.ConnectMessageEnable) + { + string? message = ReplacePlaceholders(k4player, Localizer["k4.announcement.connect"]); + + if (message != null) + Server.NextWorldUpdate(() => Server.PrintToChatAll(message)); + } } } } \ No newline at end of file diff --git a/K4-System/src/Plugin/PluginManifest.cs b/K4-System/src/Plugin/PluginManifest.cs index 7bb5afd..fd15b94 100644 --- a/K4-System/src/Plugin/PluginManifest.cs +++ b/K4-System/src/Plugin/PluginManifest.cs @@ -10,7 +10,7 @@ public sealed partial class Plugin : BasePlugin public override string ModuleAuthor => "K4ryuu"; - public override string ModuleVersion => "4.3.1 " + + public override string ModuleVersion => "4.3.2 " + #if RELEASE "(release)"; #else diff --git a/K4-System/src/Plugin/PluginStock.cs b/K4-System/src/Plugin/PluginStock.cs index ad14082..a509542 100644 --- a/K4-System/src/Plugin/PluginStock.cs +++ b/K4-System/src/Plugin/PluginStock.cs @@ -135,14 +135,17 @@ public string GetPlayerCountryCode(CCSPlayerController player) } } - public string ReplacePlaceholders(K4Player k4player, string text) + public string? ReplacePlaceholders(K4Player k4player, string text) { + if (k4player == null) + return text; + Dictionary placeholders = new Dictionary { { "name", k4player.PlayerName }, { "steamid", k4player.SteamID.ToString() }, { "clantag", k4player.ClanTag }, - { "rank", k4player.rankData?.Rank.Name ?? "Unranked" }, + { "rank", k4player.rankData?.Rank?.Name ?? "Unranked" }, { "country", GetPlayerCountryCode(k4player.Controller) }, { "points", k4player.rankData?.Points.ToString() ?? "0" }, { "topplacement", k4player.rankData?.TopPlacement.ToString() ?? "0" },