diff --git a/Commands.cs b/Commands.cs index 82bd1248..2760fd1a 100644 --- a/Commands.cs +++ b/Commands.cs @@ -1,5 +1,7 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Entities.Constants; +using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Menu; namespace WeaponPaints @@ -231,16 +233,22 @@ namespace WeaponPaints } gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID; - gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f; + gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f; gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0; + PlayerInfo playerInfo = new PlayerInfo + { + UserId = player.UserId, + Index = (int)player.Index, + SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + if (!Config.GlobalShare) { - if (weaponSync == null) return; - Task.Run(async () => - { - await weaponSync.SyncWeaponPaintsToDatabase(p); - }); + if (weaponSync != null) + Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo)); } } }; diff --git a/Events.cs b/Events.cs index b8836c9f..c863f0b8 100644 --- a/Events.cs +++ b/Events.cs @@ -95,7 +95,7 @@ namespace WeaponPaints if (@event.Defindex == 42 || @event.Defindex == 59) { CCSPlayerController? player = @event.Userid; - if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue; + if (!Utility.IsPlayerValid(player) || !player.PawnIsAlive || g_knifePickupCount[(int)player.Index] >= 1) return HookResult.Continue; if (g_playersKnife.ContainsKey((int)player.Index) && @@ -105,7 +105,6 @@ namespace WeaponPaints RemovePlayerKnife(player, true); AddTimer(0.3f, () => GiveKnifeToPlayer(player)); - } } return HookResult.Continue; diff --git a/Utility.cs b/Utility.cs index 6e7876da..7bf4318b 100644 --- a/Utility.cs +++ b/Utility.cs @@ -5,6 +5,7 @@ using MySqlConnector; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.Reflection; +using Microsoft.Extensions.Logging; namespace WeaponPaints { @@ -107,6 +108,45 @@ namespace WeaponPaints return message; } + internal static async Task CheckVersion(string version) + { + using (HttpClient client = new HttpClient()) + { + try + { + HttpResponseMessage response = await client.GetAsync("https://github.com/Nereziel/cs2-WeaponPaints/blob/main/VERSION"); + + if (response.IsSuccessStatusCode) + { + string remoteVersion = await response.Content.ReadAsStringAsync(); + remoteVersion = remoteVersion.Trim(); + + int comparisonResult = string.Compare(version, remoteVersion); + + if (comparisonResult < 0) + { + WeaponPaints.logger!.LogWarning("Plugin is outdated! Check https://github.com/Nereziel/cs2-WeaponPaints"); + } + else if (comparisonResult > 0) + { + WeaponPaints.logger!.LogInformation("Probably dev version detected"); + } + else + { + WeaponPaints.logger!.LogInformation("Plugin is up to date"); + } + } + else + { + WeaponPaints.logger!.LogWarning("Failed to check version"); + } + } + catch (Exception) + { + } + } + } + internal static void ShowAd(string moduleVersion) { Console.WriteLine(" "); diff --git a/VERSION b/VERSION new file mode 100644 index 00000000..c95270d1 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.3f \ No newline at end of file diff --git a/WeaponPaints.cs b/WeaponPaints.cs index 08158eba..ef4158ad 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -10,6 +10,7 @@ namespace WeaponPaints; [MinimumApiVersion(101)] public partial class WeaponPaints : BasePlugin, IPluginConfig { + internal static ILogger? logger; internal static readonly Dictionary weaponList = new() { {"weapon_deagle", "Desert Eagle"}, @@ -77,7 +78,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig g_changedKnife = new(); internal bool g_bCommandsAllowed = true; - internal Uri GlobalShareApi = new Uri("https://weaponpaints.fun/api.php"); + internal Uri GlobalShareApi = new("https://weaponpaints.fun/api.php"); internal int GlobalShareServerId = 0; private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers]; private string DatabaseConnectionString = string.Empty; @@ -143,7 +144,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.3d"; + public override string ModuleVersion => "1.3f"; public static WeaponPaintsConfig GetWeaponPaintsConfig() { return _config; @@ -213,6 +214,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig await Utility.CheckVersion(ModuleVersion)); } public override void Unload(bool hotReload) diff --git a/WeaponSynchronization.cs b/WeaponSynchronization.cs index 4589d69d..c7b59022 100644 --- a/WeaponSynchronization.cs +++ b/WeaponSynchronization.cs @@ -209,21 +209,17 @@ namespace WeaponPaints return; } } - internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player) + internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player) { - if (player == null || !Utility.IsPlayerValid(player)) return; - - int playerIndex = (int)player.Index; - if (player.AuthorizedSteamID == null) return; - string steamId = player.AuthorizedSteamID.SteamId64.ToString(); + if (player == null || player.Index <= 0 || player.SteamId == null) return; using var connection = new MySqlConnection(_databaseConnectionString); await connection.OpenAsync(); - if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(playerIndex)) + if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index)) return; - foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[playerIndex]) + foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index]) { int weaponDefIndex = weaponInfoPair.Key; WeaponInfo weaponInfo = weaponInfoPair.Value; @@ -236,7 +232,7 @@ namespace WeaponPaints "`weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid " + "AND `weapon_defindex` = @weaponDefIndex"; - var updateParams = new { paintId, wear, seed, steamid = steamId, weaponDefIndex }; + var updateParams = new { paintId, wear, seed, steamid = player.SteamId, weaponDefIndex }; int rowsAffected = await connection.ExecuteAsync(updateSql, updateParams); if (rowsAffected == 0)