From 236c79c4b9ab42c69d72c2179bdef7f36bef9b09 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:23:12 +0100 Subject: [PATCH] 1.4c - Minor changes - Better loading skins --- Commands.cs | 40 +++++++++++++++++++++++----------------- Events.cs | 33 +++++++++++++++++++-------------- VERSION | 2 +- WeaponPaints.cs | 10 +++------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Commands.cs b/Commands.cs index 78158223..9fa5aaa7 100644 --- a/Commands.cs +++ b/Commands.cs @@ -10,7 +10,9 @@ namespace WeaponPaints { if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return; if (!Utility.IsPlayerValid(player)) return; - if (player == null || player.Index <= 0) return; + + if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return; + int playerIndex = (int)player!.Index; PlayerInfo playerInfo = new PlayerInfo @@ -22,31 +24,35 @@ namespace WeaponPaints IpAddress = player?.IpAddress?.Split(":")[0] }; - if (player == null || player.UserId == null) return; + if (player == null || !player.IsValid || player.UserId == null || player.IsBot) return; - if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) || - DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) + try { - commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); - if (weaponSync != null) - Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo)); - if (Config.Additional.KnifeEnabled) + if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) || + DateTime.UtcNow >= (commandsCooldown.TryGetValue((int)player.UserId, out cooldownEndTime) ? cooldownEndTime : DateTime.UtcNow)) { + commandsCooldown[(int)player.UserId] = DateTime.UtcNow.AddSeconds(Config.CmdRefreshCooldownSeconds); if (weaponSync != null) - Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo)); + Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo)); + if (Config.Additional.KnifeEnabled) + { + if (weaponSync != null) + Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo)); - RefreshWeapons(player); + RefreshWeapons(player); + } + if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"])) + { + player!.Print(Localizer["wp_command_refresh_done"]); + } + return; } - if (!string.IsNullOrEmpty(Localizer["wp_command_refresh_done"])) + if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"])) { - player!.Print(Localizer["wp_command_refresh_done"]); + player!.Print(Localizer["wp_command_cooldown"]); } - return; - } - if (!string.IsNullOrEmpty(Localizer["wp_command_cooldown"])) - { - player!.Print(Localizer["wp_command_cooldown"]); } + catch (Exception) { } } private void OnCommandWS(CCSPlayerController? player, CommandInfo command) diff --git a/Events.cs b/Events.cs index 583d4b59..a1e2b983 100644 --- a/Events.cs +++ b/Events.cs @@ -9,25 +9,28 @@ namespace WeaponPaints { CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot); + if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null || player.Connected == PlayerConnectedState.PlayerDisconnecting) return; + PlayerInfo playerInfo = new PlayerInfo { UserId = player.UserId, Index = (int)player.Index, SteamId = player.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] + Name = player.PlayerName, + IpAddress = player.IpAddress?.Split(":")[0] }; - if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return; - - Task.Run(async () => + if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index)) { - if (Config.Additional.SkinEnabled) - await weaponSync.GetKnifeFromDatabase(playerInfo); - }); - - //if (Config.Additional.KnifeEnabled && weaponSync != null) - //_ = weaponSync.GetKnifeFromDatabase(playerIndex); + Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins"); + Task.Run(async () => + { + if (Config.Additional.SkinEnabled) + await weaponSync.GetWeaponPaintsFromDatabase(playerInfo); + if (Config.Additional.KnifeEnabled) + await weaponSync.GetKnifeFromDatabase(playerInfo); + }); + } } private void OnClientDisconnect(int playerSlot) @@ -175,6 +178,7 @@ namespace WeaponPaints weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId); }); + /* g_hTimerCheckSkinsData = AddTimer(10.0f, () => { List players = Utilities.GetPlayers(); @@ -199,6 +203,7 @@ namespace WeaponPaints _ = weaponSync.GetKnifeFromDatabase(playerInfo); } }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT); + */ } private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info) @@ -279,7 +284,7 @@ namespace WeaponPaints { try { - if (player == null || !player.IsValid || !player.PawnIsAlive || player.IsBot || player.IsHLTV) continue; + if (player == null || !player.IsValid || !player.PawnIsAlive || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerDisconnecting) continue; var viewModels = GetPlayerViewModels(player); @@ -320,11 +325,11 @@ namespace WeaponPaints RegisterListener(OnMapStart); RegisterListener(OnTick); - RegisterEventHandler(OnPlayerConnectFull); + //RegisterEventHandler(OnPlayerConnectFull); RegisterEventHandler(OnPlayerSpawn); RegisterEventHandler(OnRoundStart, HookMode.Pre); RegisterEventHandler(OnRoundEnd); - RegisterEventHandler(OnEventItemPurchasePost); + //RegisterEventHandler(OnEventItemPurchasePost); //RegisterEventHandler(OnItemPickup); HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre); } diff --git a/VERSION b/VERSION index 4abff1d1..4fceecd5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4b \ No newline at end of file +1.4c \ No newline at end of file diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 7cb447de..0fda45e7 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -83,7 +83,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig commandsCooldown = new Dictionary(); private string DatabaseConnectionString = string.Empty; - private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null; + //private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null; public static Dictionary weaponDefindex { get; } = new Dictionary { { 1, "weapon_deagle" }, @@ -145,7 +145,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig "Nereziel & daffyy"; public override string ModuleDescription => "Skin and knife selector, standalone and web-based"; public override string ModuleName => "WeaponPaints"; - public override string ModuleVersion => "1.4b"; + public override string ModuleVersion => "1.4c"; public static WeaponPaintsConfig GetWeaponPaintsConfig() { @@ -187,10 +187,6 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig responseBodyTask = response.Content.ReadAsStringAsync(); responseBodyTask.Wait(); string responseBody = responseBodyTask.Result; - GlobalShareServerId = Int32.Parse(responseBody); + GlobalShareServerId = int.Parse(responseBody); } else {