mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
!skins thread-safe and checking version
This commit is contained in:
20
Commands.cs
20
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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
40
Utility.cs
40
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(" ");
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace WeaponPaints;
|
||||
[MinimumApiVersion(101)]
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
internal static ILogger? logger;
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
{
|
||||
{"weapon_deagle", "Desert Eagle"},
|
||||
@@ -77,7 +78,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
//internal static List<int> 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<WeaponPaintsConfig
|
||||
public override string ModuleAuthor => "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<WeaponPaintsConfig
|
||||
_config = config;
|
||||
Utility.Config = config;
|
||||
Utility.ShowAd(ModuleVersion);
|
||||
Task.Run(async () => await Utility.CheckVersion(ModuleVersion));
|
||||
}
|
||||
|
||||
public override void Unload(bool hotReload)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user