mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-01 13:52:14 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
643beaad46 | ||
|
|
6d44e582be | ||
|
|
813a9abcc8 | ||
|
|
b0790729be | ||
|
|
74a6dff114 | ||
|
|
e37f111f1b | ||
|
|
5e6286b667 |
51
Commands.cs
51
Commands.cs
@@ -1,5 +1,7 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
||||||
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
@@ -13,29 +15,39 @@ namespace WeaponPaints
|
|||||||
string temp = "";
|
string temp = "";
|
||||||
if (player == null || player.Index <= 0) return;
|
if (player == null || player.Index <= 0) return;
|
||||||
int playerIndex = (int)player!.Index;
|
int playerIndex = (int)player!.Index;
|
||||||
|
|
||||||
|
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 (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
if (playerIndex != 0 && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CmdRefreshCooldownSeconds))
|
||||||
{
|
{
|
||||||
commandCooldown[playerIndex] = DateTime.UtcNow;
|
commandCooldown[playerIndex] = DateTime.UtcNow;
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerIndex));
|
Task.Run(async () => await weaponSync.GetWeaponPaintsFromDatabase(playerInfo));
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
{
|
{
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerIndex));
|
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||||
|
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
if (!string.IsNullOrEmpty(Config.Messages.SuccessRefreshCommand))
|
||||||
{
|
{
|
||||||
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
temp = $" {Config.Prefix} {Config.Messages.SuccessRefreshCommand}";
|
||||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
if (!string.IsNullOrEmpty(Config.Messages.CooldownRefreshCommand))
|
||||||
{
|
{
|
||||||
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
temp = $" {Config.Prefix} {Config.Messages.CooldownRefreshCommand}";
|
||||||
player.PrintToChat(Utility.ReplaceTags(temp));
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +111,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (Utility.IsPlayerValid(player))
|
if (Utility.IsPlayerValid(player))
|
||||||
{
|
{
|
||||||
|
if (player == null) return;
|
||||||
var knifeName = option.Text;
|
var knifeName = option.Text;
|
||||||
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
var knifeKey = knivesOnly.FirstOrDefault(x => x.Value == knifeName).Key;
|
||||||
if (!string.IsNullOrEmpty(knifeKey))
|
if (!string.IsNullOrEmpty(knifeKey))
|
||||||
@@ -117,14 +130,24 @@ namespace WeaponPaints
|
|||||||
player!.PrintToChat(Utility.ReplaceTags(temp));
|
player!.PrintToChat(Utility.ReplaceTags(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
g_playersKnife[(int)player!.Index] = knifeKey;
|
g_playersKnife[(int)player!.Index] = knifeKey;
|
||||||
|
|
||||||
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
if (player!.PawnIsAlive && g_bCommandsAllowed)
|
||||||
{
|
{
|
||||||
RefreshWeapons(player);
|
RefreshWeapons(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (weaponSync != null)
|
if (weaponSync != null)
|
||||||
Task.Run(() => weaponSync.SyncKnifeToDatabase((int)player.Index, knifeKey));
|
Task.Run(async () => await weaponSync.SyncKnifeToDatabase(playerInfo, knifeKey));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -210,16 +233,22 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
|
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.0f;
|
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f;
|
||||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
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 (!Config.GlobalShare)
|
||||||
{
|
{
|
||||||
if (weaponSync == null) return;
|
if (weaponSync != null)
|
||||||
Task.Run(async () =>
|
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||||
{
|
|
||||||
await weaponSync.SyncWeaponPaintsToDatabase(p);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
69
Events.cs
69
Events.cs
@@ -12,12 +12,25 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
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.Additional.SkinEnabled && weaponSync != null)
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
Task.Run(async () =>
|
||||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
{
|
||||||
|
if (Config.Additional.SkinEnabled)
|
||||||
|
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
//if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
//_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
@@ -82,7 +95,7 @@ namespace WeaponPaints
|
|||||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
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)
|
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||||
&&
|
&&
|
||||||
@@ -92,7 +105,6 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
RemovePlayerKnife(player, true);
|
RemovePlayerKnife(player, true);
|
||||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -111,6 +123,8 @@ namespace WeaponPaints
|
|||||||
|
|
||||||
if (Config.GlobalShare)
|
if (Config.GlobalShare)
|
||||||
GlobalShareConnect();
|
GlobalShareConnect();
|
||||||
|
|
||||||
|
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||||
});
|
});
|
||||||
|
|
||||||
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||||
@@ -122,27 +136,49 @@ namespace WeaponPaints
|
|||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
||||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
|
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.Additional.SkinEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
}
|
}
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return HookResult.Continue;
|
|
||||||
|
|
||||||
if (!gPlayerWeaponsInfo.ContainsKey((int)player.Index))
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return HookResult.Continue;
|
||||||
|
|
||||||
|
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 (!gPlayerWeaponsInfo.ContainsKey((int)player!.Index))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
|
Console.WriteLine($"[WeaponPaints] Retrying to retrieve player {player.PlayerName} skins");
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
Task.Run(async () =>
|
||||||
_ = weaponSync.GetWeaponPaintsFromDatabase((int)player.Index);
|
{
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
if (Config.Additional.SkinEnabled)
|
||||||
_ = weaponSync.GetKnifeFromDatabase((int)player.Index);
|
await weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||||
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -171,6 +207,7 @@ namespace WeaponPaints
|
|||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||||
{
|
{
|
||||||
g_bCommandsAllowed = false;
|
g_bCommandsAllowed = false;
|
||||||
|
|||||||
11
PlayerInfo.cs
Normal file
11
PlayerInfo.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace WeaponPaints
|
||||||
|
{
|
||||||
|
public class PlayerInfo
|
||||||
|
{
|
||||||
|
public int Index { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
|
public string? SteamId { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? IpAddress { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Utility.cs
40
Utility.cs
@@ -5,6 +5,7 @@ using MySqlConnector;
|
|||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -107,6 +108,45 @@ namespace WeaponPaints
|
|||||||
return message;
|
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)
|
internal static void ShowAd(string moduleVersion)
|
||||||
{
|
{
|
||||||
Console.WriteLine(" ");
|
Console.WriteLine(" ");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Memory;
|
using CounterStrikeSharp.API.Modules.Memory;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
@@ -81,7 +82,7 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return false;
|
if (!_config.Additional.KnifeEnabled) return false;
|
||||||
|
|
||||||
if (player == null || !player.IsValid || !player.PlayerPawn.IsValid)
|
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -221,6 +222,7 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Logger.LogWarning("Refreshing weapons exception");
|
||||||
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
Console.WriteLine("[WeaponPaints] Refreshing weapons exception");
|
||||||
Console.WriteLine(ex.Message);
|
Console.WriteLine(ex.Message);
|
||||||
}
|
}
|
||||||
@@ -240,6 +242,7 @@ namespace WeaponPaints
|
|||||||
if (weapons != null && weapons.Count > 0)
|
if (weapons != null && weapons.Count > 0)
|
||||||
{
|
{
|
||||||
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
CCSPlayer_ItemServices service = new CCSPlayer_ItemServices(player.PlayerPawn.Value.ItemServices.Handle);
|
||||||
|
//var dropWeapon = VirtualFunction.CreateVoid<nint, nint>(service.Handle, GameData.GetOffset("CCSPlayer_ItemServices_DropActivePlayerWeapon"));
|
||||||
|
|
||||||
foreach (var weapon in weapons)
|
foreach (var weapon in weapons)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ using CounterStrikeSharp.API.Core;
|
|||||||
using CounterStrikeSharp.API.Core.Attributes;
|
using CounterStrikeSharp.API.Core.Attributes;
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(90)]
|
[MinimumApiVersion(101)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
|
internal static ILogger? logger;
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
{
|
{
|
||||||
{"weapon_deagle", "Desert Eagle"},
|
{"weapon_deagle", "Desert Eagle"},
|
||||||
@@ -76,7 +78,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
//internal static List<int> g_changedKnife = new();
|
//internal static List<int> g_changedKnife = new();
|
||||||
internal bool g_bCommandsAllowed = true;
|
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;
|
internal int GlobalShareServerId = 0;
|
||||||
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
private DateTime[] commandCooldown = new DateTime[Server.MaxPlayers];
|
||||||
private string DatabaseConnectionString = string.Empty;
|
private string DatabaseConnectionString = string.Empty;
|
||||||
@@ -142,7 +144,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "1.3c";
|
public override string ModuleVersion => "1.3f";
|
||||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||||
{
|
{
|
||||||
return _config;
|
return _config;
|
||||||
@@ -156,22 +158,34 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
Utility.TestDatabaseConnection();
|
Utility.TestDatabaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
|
||||||
|
|
||||||
if (hotReload)
|
if (hotReload)
|
||||||
{
|
{
|
||||||
OnMapStart(string.Empty);
|
OnMapStart(string.Empty);
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
for (int i = 1; i <= Server.MaxPlayers; i++)
|
|
||||||
{
|
|
||||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
|
||||||
await weaponSync.GetWeaponPaintsFromDatabase(i);
|
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||||
await weaponSync.GetKnifeFromDatabase(i);
|
|
||||||
}
|
foreach (CCSPlayerController player in players)
|
||||||
});
|
{
|
||||||
|
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.AuthorizedSteamID == null) continue;
|
||||||
|
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||||
|
|
||||||
|
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.Additional.SkinEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetWeaponPaintsFromDatabase(playerInfo);
|
||||||
|
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||||
|
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterListeners();
|
||||||
|
RegisterCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.Additional.KnifeEnabled)
|
if (Config.Additional.KnifeEnabled)
|
||||||
@@ -191,6 +205,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
{
|
{
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
{
|
{
|
||||||
|
Logger.LogError("You need to setup Database credentials in config!");
|
||||||
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,6 +214,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
_config = config;
|
_config = config;
|
||||||
Utility.Config = config;
|
Utility.Config = config;
|
||||||
Utility.ShowAd(ModuleVersion);
|
Utility.ShowAd(ModuleVersion);
|
||||||
|
Task.Run(async () => await Utility.CheckVersion(ModuleVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Unload(bool hotReload)
|
public override void Unload(bool hotReload)
|
||||||
@@ -234,9 +250,12 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger.LogError("Unable to retrieve serverid from GlobalShare!");
|
||||||
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogInformation("GlobalShare ONLINE!");
|
||||||
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
Console.WriteLine("[WeaponPaints] GlobalShare ONLINE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,24 +21,21 @@ namespace WeaponPaints
|
|||||||
_globalShareServerId = globalShareServerId;
|
_globalShareServerId = globalShareServerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task GetKnifeFromDatabase(int playerIndex)
|
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
if (!_config.Additional.KnifeEnabled) return;
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
if (player.AuthorizedSteamID == null) return;
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
|
|
||||||
if (_config.GlobalShare)
|
if (_config.GlobalShare)
|
||||||
{
|
{
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
{ "steamid", steamId },
|
{ "steamid", player.SteamId },
|
||||||
{ "knife", "1" }
|
{ "knife", "1" }
|
||||||
};
|
};
|
||||||
|
|
||||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||||
|
|
||||||
@@ -53,7 +50,7 @@ namespace WeaponPaints
|
|||||||
string result = await response.Content.ReadAsStringAsync();
|
string result = await response.Content.ReadAsStringAsync();
|
||||||
if (!string.IsNullOrEmpty(result))
|
if (!string.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
WeaponPaints.g_playersKnife[playerIndex] = result;
|
WeaponPaints.g_playersKnife[player.Index] = result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -72,10 +69,11 @@ namespace WeaponPaints
|
|||||||
{
|
{
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = steamId });
|
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
if (PlayerKnife != null)
|
if (PlayerKnife != null)
|
||||||
{
|
{
|
||||||
WeaponPaints.g_playersKnife[playerIndex] = PlayerKnife;
|
WeaponPaints.g_playersKnife[player.Index] = PlayerKnife;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -91,20 +89,14 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task GetWeaponPaintsFromDatabase(int playerIndex)
|
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.SkinEnabled) return;
|
if (!_config.Additional.SkinEnabled) return;
|
||||||
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
|
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||||
if (!Utility.IsPlayerValid(player)) return;
|
|
||||||
|
|
||||||
if (player.AuthorizedSteamID == null) return;
|
|
||||||
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(playerIndex, out _))
|
|
||||||
{
|
{
|
||||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex] = new Dictionary<int, WeaponInfo>();
|
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new Dictionary<int, WeaponInfo>();
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -113,7 +105,7 @@ namespace WeaponPaints
|
|||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "server_id", _globalShareServerId.ToString() },
|
{ "server_id", _globalShareServerId.ToString() },
|
||||||
{ "steamid", steamId },
|
{ "steamid", player.SteamId },
|
||||||
{ "skins", "1" }
|
{ "skins", "1" }
|
||||||
};
|
};
|
||||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||||
@@ -146,7 +138,7 @@ namespace WeaponPaints
|
|||||||
Seed = weaponSeed.Value,
|
Seed = weaponSeed.Value,
|
||||||
Wear = weaponWear.Value
|
Wear = weaponWear.Value
|
||||||
};
|
};
|
||||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex.Value] = weaponInfo;
|
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +156,7 @@ namespace WeaponPaints
|
|||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|
||||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = steamId });
|
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||||
{
|
{
|
||||||
@@ -181,7 +173,7 @@ namespace WeaponPaints
|
|||||||
Seed = weaponSeed,
|
Seed = weaponSeed,
|
||||||
Wear = weaponWear
|
Wear = weaponWear
|
||||||
};
|
};
|
||||||
WeaponPaints.gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = weaponInfo;
|
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex] = weaponInfo;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -198,20 +190,17 @@ namespace WeaponPaints
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task SyncKnifeToDatabase(int playerIndex, string knife)
|
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled) return;
|
if (!_config.Additional.KnifeEnabled) return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CCSPlayerController player = Utilities.GetPlayerFromIndex(playerIndex);
|
if (player.SteamId == null || player.Index == 0) return;
|
||||||
if (player == null || !player.IsValid) return;
|
|
||||||
if (player.AuthorizedSteamID == null) return;
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
|
|
||||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||||
await connection.ExecuteAsync(query, new { steamid = steamId, newKnife = knife });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newKnife = knife });
|
||||||
await connection.CloseAsync();
|
await connection.CloseAsync();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -220,21 +209,17 @@ namespace WeaponPaints
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal async Task SyncWeaponPaintsToDatabase(CCSPlayerController? player)
|
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (player == null || !Utility.IsPlayerValid(player)) return;
|
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
||||||
|
|
||||||
int playerIndex = (int)player.Index;
|
|
||||||
if (player.AuthorizedSteamID == null) return;
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
|
|
||||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|
||||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(playerIndex))
|
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[playerIndex])
|
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index])
|
||||||
{
|
{
|
||||||
int weaponDefIndex = weaponInfoPair.Key;
|
int weaponDefIndex = weaponInfoPair.Key;
|
||||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||||
@@ -247,7 +232,7 @@ namespace WeaponPaints
|
|||||||
"`weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid " +
|
"`weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid " +
|
||||||
"AND `weapon_defindex` = @weaponDefIndex";
|
"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);
|
int rowsAffected = await connection.ExecuteAsync(updateSql, updateParams);
|
||||||
|
|
||||||
if (rowsAffected == 0)
|
if (rowsAffected == 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user