mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-07 07:31:11 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74a6dff114 | ||
|
|
e37f111f1b | ||
|
|
5e6286b667 |
18
Commands.cs
18
Commands.cs
@@ -13,29 +13,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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
66
Events.cs
66
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)
|
||||||
@@ -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;
|
||||||
|
|||||||
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq;
|
|||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
[MinimumApiVersion(90)]
|
[MinimumApiVersion(101)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
internal static readonly Dictionary<string, string> weaponList = new()
|
internal static readonly Dictionary<string, string> weaponList = new()
|
||||||
@@ -156,22 +156,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)
|
||||||
@@ -237,6 +249,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
|||||||
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
throw new Exception("[WeaponPaints] Unable to retrieve serverid from GlobalShare!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user