mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-17 18:39:07 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d83783b7af | ||
|
|
8e7b4a2d40 | ||
|
|
e0fce7a4b4 | ||
|
|
8f0e8a0a63 | ||
|
|
eb6cdfc98d | ||
|
|
56537971ad |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
.vs/
|
||||
bin/
|
||||
obj/
|
||||
.test/
|
||||
|
||||
55
Commands.cs
55
Commands.cs
@@ -8,29 +8,26 @@ namespace WeaponPaints
|
||||
{
|
||||
private void OnCommandRefresh(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.CommandWpEnabled || !Config.Additional.SkinEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Config.AdditionalSetting.CommandWpEnabled || !Config.AdditionalSetting.SkinEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
if (player == null || player.Index <= 0) return;
|
||||
int playerIndex = (int)player!.Index;
|
||||
if (player == null || !player.IsValid || player.UserId == null || player.Index <= 0 || player.IsBot) return;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (player == null || player.UserId == null) return;
|
||||
|
||||
if (!commandsCooldown.TryGetValue((int)player.UserId, out DateTime cooldownEndTime) ||
|
||||
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.GetWeaponPaintsFromDatabase(playerInfo));
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
if (Config.AdditionalSetting.KnifeEnabled)
|
||||
{
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.GetKnifeFromDatabase(playerInfo));
|
||||
@@ -51,7 +48,7 @@ namespace WeaponPaints
|
||||
|
||||
private void OnCommandWS(CCSPlayerController? player, CommandInfo command)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
if (!Config.AdditionalSetting.SkinEnabled) return;
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_info_website"]))
|
||||
@@ -62,7 +59,7 @@ namespace WeaponPaints
|
||||
{
|
||||
player!.Print(Localizer["wp_info_refresh"]);
|
||||
}
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
if (!Config.AdditionalSetting.KnifeEnabled) return;
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_info_knife"]))
|
||||
{
|
||||
player!.Print(Localizer["wp_info_knife"]);
|
||||
@@ -71,19 +68,19 @@ namespace WeaponPaints
|
||||
|
||||
private void RegisterCommands()
|
||||
{
|
||||
AddCommand($"css_{Config.Additional.CommandSkin}", "Skins info", (player, info) =>
|
||||
AddCommand($"css_{Config.AdditionalSetting.CommandSkin}", "Skins info", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
OnCommandWS(player, info);
|
||||
});
|
||||
AddCommand($"css_{Config.Additional.CommandRefresh}", "Skins refresh", (player, info) =>
|
||||
AddCommand($"css_{Config.AdditionalSetting.CommandRefresh}", "Skins refresh", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
OnCommandRefresh(player, info);
|
||||
});
|
||||
if (Config.Additional.CommandKillEnabled)
|
||||
if (Config.AdditionalSetting.CommandKillEnabled)
|
||||
{
|
||||
AddCommand($"css_{Config.Additional.CommandKill}", "kill yourself", (player, info) =>
|
||||
AddCommand($"css_{Config.AdditionalSetting.CommandKill}", "kill yourself", (player, info) =>
|
||||
{
|
||||
if (player == null || !Utility.IsPlayerValid(player) || player.PlayerPawn.Value == null || !player!.PlayerPawn.IsValid) return;
|
||||
|
||||
@@ -94,7 +91,7 @@ namespace WeaponPaints
|
||||
|
||||
private void SetupKnifeMenu()
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
if (!Config.AdditionalSetting.KnifeEnabled || !g_bCommandsAllowed) return;
|
||||
|
||||
var knivesOnly = weaponList
|
||||
.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet"))
|
||||
@@ -115,7 +112,7 @@ namespace WeaponPaints
|
||||
player!.Print(Localizer["wp_knife_menu_select", knifeName]);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.Additional.CommandKillEnabled)
|
||||
if (!string.IsNullOrEmpty(Localizer["wp_knife_menu_kill"]) && Config.AdditionalSetting.CommandKillEnabled)
|
||||
{
|
||||
player!.Print(Localizer["wp_knife_menu_kill"]);
|
||||
}
|
||||
@@ -124,7 +121,7 @@ namespace WeaponPaints
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
@@ -145,7 +142,7 @@ namespace WeaponPaints
|
||||
{
|
||||
giveItemMenu.AddMenuOption(knifePair.Value, handleGive);
|
||||
}
|
||||
AddCommand($"css_{Config.Additional.CommandKnife}", "Knife Menu", (player, info) =>
|
||||
AddCommand($"css_{Config.AdditionalSetting.CommandKnife}", "Knife Menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player) || !g_bCommandsAllowed) return;
|
||||
|
||||
@@ -212,25 +209,25 @@ namespace WeaponPaints
|
||||
if (firstSkin != null &&
|
||||
firstSkin.TryGetValue("weapon_defindex", out var weaponDefIndexObj) &&
|
||||
weaponDefIndexObj != null &&
|
||||
int.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||
int.TryParse(selectedPaintID, out var paintID))
|
||||
ushort.TryParse(weaponDefIndexObj.ToString(), out var weaponDefIndex) &&
|
||||
ushort.TryParse(selectedPaintID, out var paintID))
|
||||
{
|
||||
p!.Print(Localizer["wp_skin_menu_select", selectedSkin]);
|
||||
|
||||
if (!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
||||
}
|
||||
if (!gPlayerWeaponsInfo[playerIndex].TryGetValue(weaponDefIndex, out _))
|
||||
{
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex] = new WeaponInfo();
|
||||
}
|
||||
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.01f;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Paint = paintID;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Wear = 0.00001f;
|
||||
gPlayerWeaponsInfo[playerIndex][weaponDefIndex].Seed = 0;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64,
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
@@ -238,7 +235,7 @@ namespace WeaponPaints
|
||||
if (!Config.GlobalShare)
|
||||
{
|
||||
if (weaponSync != null)
|
||||
Task.Run(async () => await weaponSync.SyncWeaponPaintsToDatabase(playerInfo));
|
||||
Task.Run(async () => await weaponSync.SyncWeaponPaintToDatabase(playerInfo, weaponDefIndex));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -273,7 +270,7 @@ namespace WeaponPaints
|
||||
weaponSelectionMenu.AddMenuOption(weaponName, handleWeaponSelection);
|
||||
}
|
||||
// Command to open the weapon selection menu for players
|
||||
AddCommand($"css_{Config.Additional.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||
AddCommand($"css_{Config.AdditionalSetting.CommandSkinSelection}", "Skins selection menu", (player, info) =>
|
||||
{
|
||||
if (!Utility.IsPlayerValid(player)) return;
|
||||
|
||||
|
||||
22
Config.cs
22
Config.cs
@@ -3,9 +3,13 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
public class Additional
|
||||
public class AdditionalSetting
|
||||
{
|
||||
[JsonPropertyName("SkinVisibilityFix")]
|
||||
|
||||
[JsonPropertyName("UseMetamodAlwaysLegacyModel")]
|
||||
public bool UseMetamodAlwaysLegacyModel { get; set; } = false;
|
||||
|
||||
[JsonPropertyName("SkinVisibilityFix")]
|
||||
public bool SkinVisibilityFix { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("KnifeEnabled")]
|
||||
@@ -14,7 +18,13 @@ namespace WeaponPaints
|
||||
[JsonPropertyName("SkinEnabled")]
|
||||
public bool SkinEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("CommandWpEnabled")]
|
||||
[JsonPropertyName("MusicKitEnabled")]
|
||||
public bool MusicKitEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("NameTagEnabled")]
|
||||
public bool NameTagEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("CommandWpEnabled")]
|
||||
public bool CommandWpEnabled { get; set; } = true;
|
||||
|
||||
[JsonPropertyName("CommandKillEnabled")]
|
||||
@@ -46,7 +56,7 @@ namespace WeaponPaints
|
||||
|
||||
public class WeaponPaintsConfig : BasePluginConfig
|
||||
{
|
||||
public override int Version { get; set; } = 4;
|
||||
public override int Version { get; set; } = 5;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
@@ -75,8 +85,8 @@ namespace WeaponPaints
|
||||
[JsonPropertyName("Website")]
|
||||
public string Website { get; set; } = "example.com/skins";
|
||||
|
||||
[JsonPropertyName("Additional")]
|
||||
public Additional Additional { get; set; } = new Additional();
|
||||
[JsonPropertyName("AdditionalSetting")]
|
||||
public AdditionalSetting AdditionalSetting { get; set; } = new AdditionalSetting();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
161
Events.cs
161
Events.cs
@@ -1,5 +1,7 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using System.Numerics;
|
||||
|
||||
namespace WeaponPaints
|
||||
{
|
||||
@@ -13,22 +15,18 @@ namespace WeaponPaints
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player.SteamID.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
SteamId = player.SteamID,
|
||||
Name = player.PlayerName,
|
||||
IpAddress = player.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || weaponSync == null) return;
|
||||
|
||||
Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Config.Additional.SkinEnabled)
|
||||
await weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
await weaponSync.GetPlayerDatabaseIndex(playerInfo);
|
||||
});
|
||||
|
||||
//if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
//_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
@@ -36,16 +34,19 @@ namespace WeaponPaints
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.UserId == null) return;
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersDatabaseIndex.TryRemove((int)player.Index, out _);
|
||||
if (Config.AdditionalSetting.KnifeEnabled)
|
||||
g_playersKnife.TryRemove((int)player.Index, out _);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
if (Config.AdditionalSetting.SkinEnabled)
|
||||
{
|
||||
if (gPlayerWeaponsInfo.TryRemove((int)player.Index, out var innerDictionary))
|
||||
{
|
||||
innerDictionary.Clear();
|
||||
}
|
||||
}
|
||||
if (commandsCooldown.ContainsKey((int)player.UserId))
|
||||
if (Config.AdditionalSetting.MusicKitEnabled)
|
||||
g_playersMusicKit.TryRemove((int)player.Index, out _);
|
||||
if (commandsCooldown.ContainsKey((int)player.UserId))
|
||||
{
|
||||
commandsCooldown.Remove((int)player.UserId);
|
||||
}
|
||||
@@ -53,7 +54,7 @@ namespace WeaponPaints
|
||||
|
||||
private void OnEntityCreated(CEntityInstance entity)
|
||||
{
|
||||
if (!Config.Additional.SkinEnabled) return;
|
||||
if (!Config.AdditionalSetting.SkinEnabled) return;
|
||||
if (entity == null || !entity.IsValid || string.IsNullOrEmpty(entity.DesignerName)) return;
|
||||
string designerName = entity.DesignerName;
|
||||
if (!weaponList.ContainsKey(designerName)) return;
|
||||
@@ -93,42 +94,41 @@ namespace WeaponPaints
|
||||
if (player == null || !player.IsValid) return HookResult.Continue;
|
||||
|
||||
/*
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||
AddTimer(0.2f, () => RefreshSkins(player));
|
||||
*/
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||
return HookResult.Continue;
|
||||
/*
|
||||
private HookResult OnItemPickup(EventItemPickup @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Defindex == 42 || @event.Defindex == 59)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
if (player == null || !player.IsValid || !g_knifePickupCount.ContainsKey((int)player.Index) || player.IsBot || !g_playersKnife.ContainsKey((int)player.Index))
|
||||
return HookResult.Continue;
|
||||
|
||||
|
||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||
if (g_knifePickupCount[(int)player.Index] >= 2) return HookResult.Continue;
|
||||
|
||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||
&&
|
||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
if (g_playersKnife.ContainsKey((int)player.Index)
|
||||
&&
|
||||
g_playersKnife[(int)player.Index] != "weapon_knife")
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
|
||||
RemovePlayerKnife(player, true);
|
||||
RemovePlayerKnife(player, true);
|
||||
|
||||
if (!PlayerHasKnife(player) && Config.Additional.GiveKnifeAfterRemove)
|
||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
}
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
if (!PlayerHasKnife(player) && Config.AdditionalSetting.GiveKnifeAfterRemove)
|
||||
AddTimer(0.3f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
}
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
|
||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||
public HookResult OnPickup(CEntityIOOutput output, string name, CEntityInstance activator, CEntityInstance caller, CVariant value, float delay)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetEntityFromIndex<CCSPlayerPawn>((int)activator.Index).OriginalController.Value;
|
||||
|
||||
@@ -150,55 +150,53 @@ namespace WeaponPaints
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index]++;
|
||||
player.RemoveItemByDesignerName(weapon.DesignerName);
|
||||
if (Config.Additional.GiveKnifeAfterRemove)
|
||||
if (Config.AdditionalSetting.GiveKnifeAfterRemove)
|
||||
AddTimer(0.2f, () => GiveKnifeToPlayer(player));
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnMapStart(string mapName)
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
if (!Config.Additional.KnifeEnabled) return;
|
||||
// TODO
|
||||
// needed for now
|
||||
AddTimer(2.0f, () =>
|
||||
if (!Config.AdditionalSetting.KnifeEnabled) return;
|
||||
// TODO
|
||||
// needed for now
|
||||
AddTimer(2.0f, () =>
|
||||
{
|
||||
|
||||
NativeAPI.IssueServerCommand("mp_t_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_ct_default_melee \"\"");
|
||||
NativeAPI.IssueServerCommand("mp_equipment_reset_rounds 0");
|
||||
|
||||
if (Config.GlobalShare)
|
||||
if (Config.GlobalShare)
|
||||
GlobalShareConnect();
|
||||
|
||||
weaponSync = new WeaponSynchronization(DatabaseConnectionString, Config, GlobalShareApi, GlobalShareServerId);
|
||||
});
|
||||
|
||||
/*
|
||||
g_hTimerCheckSkinsData = AddTimer(10.0f, () =>
|
||||
{
|
||||
List<CCSPlayerController> players = Utilities.GetPlayers();
|
||||
|
||||
foreach (CCSPlayerController player in players)
|
||||
HashSet<int> playerIndexes = new HashSet<int>(gPlayerWeaponsInfo.Keys);
|
||||
foreach (CCSPlayerController player in players)
|
||||
{
|
||||
if (player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||
//if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||
if (playerIndexes.Contains((int)player.Index)) continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.SteamID.ToString(),
|
||||
SteamId = player?.SteamID,
|
||||
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);
|
||||
}
|
||||
if (weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerInfo);
|
||||
}
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE | CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT);
|
||||
*/
|
||||
}
|
||||
|
||||
private HookResult OnPlayerConnectFull(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
@@ -211,22 +209,19 @@ namespace WeaponPaints
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.SteamID.ToString(),
|
||||
SteamId = player?.SteamID,
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
|
||||
if (!gPlayerWeaponsInfo.ContainsKey((int)player!.Index))
|
||||
if (!g_playersDatabaseIndex.ContainsKey((int)player!.Index))
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
await weaponSync.GetPlayerDatabaseIndex(playerInfo);
|
||||
});
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
@@ -239,7 +234,7 @@ namespace WeaponPaints
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled && !PlayerHasKnife(player))
|
||||
if (Config.AdditionalSetting.KnifeEnabled && !PlayerHasKnife(player))
|
||||
{
|
||||
g_knifePickupCount[(int)player.Index] = 0;
|
||||
GiveKnifeToPlayer(player);
|
||||
@@ -247,7 +242,7 @@ namespace WeaponPaints
|
||||
}
|
||||
|
||||
/*
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||
{
|
||||
AddTimer(0.3f, () => RefreshSkins(player));
|
||||
}
|
||||
@@ -279,7 +274,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);
|
||||
|
||||
@@ -298,11 +293,11 @@ namespace WeaponPaints
|
||||
if (
|
||||
viewModel.Value.CBodyComponent != null
|
||||
&& viewModel.Value.CBodyComponent.SceneNode != null
|
||||
)
|
||||
&& weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2
|
||||
)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(viewModel.Value.CBodyComponent.SceneNode);
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
|
||||
Utilities.SetStateChanged(viewModel.Value, "CBaseEntity", "m_CBodyComponent");
|
||||
}
|
||||
@@ -318,16 +313,18 @@ namespace WeaponPaints
|
||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
RegisterListener<Listeners.OnTick>(OnTick);
|
||||
|
||||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
if (!Config.AdditionalSetting.UseMetamodAlwaysLegacyModel)
|
||||
RegisterListener<Listeners.OnTick>(OnTick);
|
||||
|
||||
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnectFull);
|
||||
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart, HookMode.Pre);
|
||||
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
|
||||
RegisterEventHandler<EventItemPurchase>(OnEventItemPurchasePost);
|
||||
//RegisterEventHandler<EventItemPickup>(OnItemPickup);
|
||||
HookEntityOutput("weapon_knife", "OnPlayerPickup", OnPickup, HookMode.Pre);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* WORKAROUND FOR CLIENTS WITHOUT STEAMID ON AUTHORIZATION */
|
||||
@@ -338,15 +335,15 @@ namespace WeaponPaints
|
||||
if (player == null || !player.IsValid || !player.EntityIndex.HasValue || player.IsHLTV) return HookResult.Continue;
|
||||
|
||||
int playerIndex = (int)player.EntityIndex.Value.Value;
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
if (Config.AdditionalSetting.SkinEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetWeaponPaintsFromDatabase(playerIndex);
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
if (Config.AdditionalSetting.KnifeEnabled && weaponSync != null)
|
||||
_ = weaponSync.GetKnifeFromDatabase(playerIndex);
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Config.Additional.SkinEnabled && weaponSync != null)
|
||||
if (Config.Additional.KnifeEnabled && weaponSync != null)
|
||||
if (Config.AdditionalSetting.SkinEnabled && weaponSync != null)
|
||||
if (Config.AdditionalSetting.KnifeEnabled && weaponSync != null)
|
||||
});
|
||||
|
||||
return HookResult.Continue;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public string? SteamId { get; set; }
|
||||
public ulong? SteamId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? IpAddress { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
README.md
10
README.md
@@ -10,7 +10,7 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
|
||||
## Features
|
||||
- Changes only paint, seed and wear on weapons and knives
|
||||
- MySQL based or global website, so you dont need MySQL/Website
|
||||
- MySQL(min. ver 5.6.5) based or global website, so you dont need MySQL/Website
|
||||
- Data syncs on player connect
|
||||
- Added command **`!wp`** to refresh skins ***(with cooldown in seconds can be configured)***
|
||||
- Added command **`!ws`** to show website
|
||||
@@ -23,7 +23,8 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
## CS2 Server
|
||||
- Have working CounterStrikeSharp (**with RUNTIME!**)
|
||||
- Download from Release and copy plugin to plugins
|
||||
- Setup `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
||||
- Run server with plugin, it will generate config if installed correctly
|
||||
- Edit `addons/counterstrikesharp/configs/`**`plugins/WeaponPaints/WeaponPaints.json`** set **`GlobalShare`** to **`true`** for global, or include database credentials
|
||||
- In `addons/counterstrikesharp/configs/`**`core.json`** set **FollowCS2ServerGuidelines** to **`false`**
|
||||
|
||||
## Plugin Configuration
|
||||
@@ -73,8 +74,9 @@ Unfinished, unoptimized and not fully functional ugly demo weapon paints plugin
|
||||
</details>
|
||||
|
||||
## Web install
|
||||
Disregard if the config is **`GlobalShare = true`**
|
||||
- Requires PHP >= 7.4 ***(Tested on php ver **`8.2.3`** and nginx webserver)***
|
||||
Ignore this section if you have in config **`GlobalShare = true`**
|
||||
- Minimum PHP version 5.5 (needs testing)
|
||||
- Minimum MySQL version 5.6.5
|
||||
- **Before using website, make sure the plugin is correctly loaded in cs2 server!** Mysql tables are created by plugin not by website.
|
||||
- Copy website to web server ***(Folder `img` not needed)***
|
||||
- Get [Steam API Key](https://steamcommunity.com/dev/apikey)
|
||||
|
||||
24
Utility.cs
24
Utility.cs
@@ -27,8 +27,7 @@ namespace WeaponPaints
|
||||
|
||||
return builder.ConnectionString;
|
||||
}
|
||||
|
||||
internal static async void CheckDatabaseTables()
|
||||
internal static async void CheckDatabaseTables()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -37,15 +36,22 @@ namespace WeaponPaints
|
||||
|
||||
using var transaction = await connection.BeginTransactionAsync();
|
||||
|
||||
try
|
||||
// Minimal version for MySQL 5.6.5
|
||||
string[] sqlCommands = new string[]
|
||||
{
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users` (`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `steamid` BIGINT UNSIGNED NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `unique_steamid` (`steamid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_items` (`user_id` INT UNSIGNED NOT NULL, `weapon` SMALLINT UNSIGNED NOT NULL, `paint` SMALLINT UNSIGNED NOT NULL, `wear` FLOAT NOT NULL DEFAULT 0.00001, `seed` SMALLINT UNSIGNED NOT NULL DEFAULT 0, `nametag` VARCHAR(20) DEFAULT NULL, `stattrack` INT UNSIGNED NOT NULL DEFAULT 0, `stattrack_enabled` SMALLINT NOT NULL DEFAULT 0, `quality` SMALLINT UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (`user_id`,`weapon`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_knife` (`user_id` INT UNSIGNED NOT NULL, `knife` VARCHAR(32) DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
|
||||
"CREATE TABLE IF NOT EXISTS `wp_users_music` (`user_id` INT UNSIGNED NOT NULL, `music` SMALLINT UNSIGNED DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
|
||||
};
|
||||
try
|
||||
{
|
||||
string createTable1 = "CREATE TABLE IF NOT EXISTS `wp_player_skins` (`steamid` varchar(64) NOT NULL, `weapon_defindex` int(6) NOT NULL, `weapon_paint_id` int(6) NOT NULL, `weapon_wear` float NOT NULL DEFAULT 0.000001, `weapon_seed` int(16) NOT NULL DEFAULT 0) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci";
|
||||
string createTable2 = "CREATE TABLE IF NOT EXISTS `wp_player_knife` (`steamid` varchar(64) NOT NULL, `knife` varchar(64) NOT NULL, UNIQUE (`steamid`)) ENGINE = InnoDB";
|
||||
foreach (string command in sqlCommands)
|
||||
{
|
||||
await connection.ExecuteAsync(command, transaction: transaction);
|
||||
}
|
||||
|
||||
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
||||
await connection.ExecuteAsync(createTable2, transaction: transaction);
|
||||
|
||||
await transaction.CommitAsync();
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
@@ -19,15 +19,14 @@ namespace WeaponPaints
|
||||
|
||||
if (isKnife && !g_playersKnife.ContainsKey(playerIndex) || isKnife && g_playersKnife[playerIndex] == "weapon_knife") return;
|
||||
|
||||
int weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||
|
||||
ushort weaponDefIndex = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||
|
||||
if (isKnife)
|
||||
{
|
||||
weapon.AttributeManager.Item.EntityQuality = 3;
|
||||
}
|
||||
|
||||
if (_config.Additional.GiveRandomSkin &&
|
||||
if (_config.AdditionalSetting.GiveRandomSkin &&
|
||||
!gPlayerWeaponsInfo[playerIndex].ContainsKey(weaponDefIndex))
|
||||
{
|
||||
// Random skins
|
||||
@@ -36,13 +35,12 @@ namespace WeaponPaints
|
||||
weapon.AttributeManager.Item.ItemIDHigh = weapon.AttributeManager.Item.ItemIDLow >> 32;
|
||||
weapon.FallbackPaintKit = GetRandomPaint(weaponDefIndex);
|
||||
weapon.FallbackSeed = 0;
|
||||
weapon.FallbackWear = 0.000001f;
|
||||
weapon.FallbackWear = 0.00001f;
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||
if (skeleton.ModelState.MeshGroupMask != 2)
|
||||
if (weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2)
|
||||
{
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -58,25 +56,25 @@ namespace WeaponPaints
|
||||
weapon.FallbackSeed = weaponInfo.Seed;
|
||||
weapon.FallbackWear = weaponInfo.Wear;
|
||||
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
if (!isKnife && weapon.CBodyComponent != null && weapon.CBodyComponent.SceneNode != null)
|
||||
{
|
||||
var skeleton = GetSkeletonInstance(weapon.CBodyComponent.SceneNode);
|
||||
if (skeleton.ModelState.MeshGroupMask != 2)
|
||||
if (weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask != 2)
|
||||
{
|
||||
skeleton.ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
weapon.CBodyComponent!.SceneNode!.GetSkeletonInstance().ModelState.MeshGroupMask = 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static void GiveKnifeToPlayer(CCSPlayerController? player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled || player == null || !player.IsValid) return;
|
||||
if (!_config.AdditionalSetting.KnifeEnabled || player == null || !player.IsValid) return;
|
||||
|
||||
if (g_playersKnife.TryGetValue((int)player.Index, out var knife))
|
||||
{
|
||||
player.GiveNamedItem(knife);
|
||||
}
|
||||
else if (_config.Additional.GiveRandomKnife)
|
||||
else if (_config.AdditionalSetting.GiveRandomKnife)
|
||||
{
|
||||
var knifeTypes = weaponList.Where(pair => pair.Key.StartsWith("weapon_knife") || pair.Key.StartsWith("weapon_bayonet")).ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
|
||||
@@ -95,7 +93,7 @@ namespace WeaponPaints
|
||||
|
||||
internal static bool PlayerHasKnife(CCSPlayerController? player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return false;
|
||||
if (!_config.AdditionalSetting.KnifeEnabled) return false;
|
||||
|
||||
if (player == null || !player.IsValid || player.PlayerPawn == null || !player.PlayerPawn.IsValid || !player.PawnIsAlive)
|
||||
{
|
||||
@@ -177,7 +175,7 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
internal void RefreshSkins(CCSPlayerController? player)
|
||||
{
|
||||
return;
|
||||
@@ -187,8 +185,8 @@ namespace WeaponPaints
|
||||
AddTimer(0.25f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot2"));
|
||||
AddTimer(0.38f, () => NativeAPI.IssueClientCommand((int)player.Index - 1, "slot1"));
|
||||
}
|
||||
|
||||
internal void RefreshWeapons(CCSPlayerController? player)
|
||||
*/
|
||||
internal void RefreshWeapons(CCSPlayerController? player)
|
||||
{
|
||||
if (player == null || !player.IsValid || player.PlayerPawn.Value == null || !player.PawnIsAlive) return;
|
||||
if (player.PlayerPawn.Value.WeaponServices == null || player.PlayerPawn.Value.ItemServices == null) return;
|
||||
@@ -213,13 +211,13 @@ namespace WeaponPaints
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!weaponDefindex.ContainsKey(weapon.Value.AttributeManager.Item.ItemDefinitionIndex)) continue;
|
||||
if (!WeaponDefindex.ContainsKey(weapon.Value.AttributeManager.Item.ItemDefinitionIndex)) continue;
|
||||
int clip1, reservedAmmo;
|
||||
|
||||
clip1 = weapon.Value.Clip1;
|
||||
reservedAmmo = weapon.Value.ReserveAmmo[0];
|
||||
|
||||
string weaponByDefindex = weaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||
string weaponByDefindex = WeaponDefindex[weapon.Value.AttributeManager.Item.ItemDefinitionIndex];
|
||||
player.RemoveItemByDesignerName(weapon.Value.DesignerName, true);
|
||||
CBasePlayerWeapon newWeapon = new(player.GiveNamedItem(weaponByDefindex));
|
||||
|
||||
@@ -246,7 +244,7 @@ namespace WeaponPaints
|
||||
}
|
||||
|
||||
/*
|
||||
if (Config.Additional.SkinVisibilityFix)
|
||||
if (Config.AdditionalSetting.SkinVisibilityFix)
|
||||
RefreshSkins(player);
|
||||
*/
|
||||
}
|
||||
@@ -321,13 +319,6 @@ namespace WeaponPaints
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static CSkeletonInstance GetSkeletonInstance(CGameSceneNode node)
|
||||
{
|
||||
Func<nint, nint> GetSkeletonInstance = VirtualFunction.Create<nint, nint>(node.Handle, 8);
|
||||
return new CSkeletonInstance(GetSkeletonInstance(node.Handle));
|
||||
}
|
||||
|
||||
private static unsafe CHandle<CBaseViewModel>[]? GetPlayerViewModels(CCSPlayerController player)
|
||||
{
|
||||
if (player.PlayerPawn.Value == null || player.PlayerPawn.Value.ViewModelServices == null) return null;
|
||||
@@ -348,6 +339,5 @@ namespace WeaponPaints
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,12 @@
|
||||
{
|
||||
public class WeaponInfo
|
||||
{
|
||||
public int Paint { get; set; }
|
||||
public int Seed { get; set; }
|
||||
public ushort Paint { get; set; }
|
||||
public ushort Seed { get; set; }
|
||||
public float Wear { get; set; }
|
||||
}
|
||||
public string? NameTag { get; set; }
|
||||
public ushort Quality { get; set; }
|
||||
public uint StatTrack { get; set; }
|
||||
public bool StatTrackEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
184
WeaponPaints.cs
184
WeaponPaints.cs
@@ -9,7 +9,7 @@ using System.Collections.Concurrent;
|
||||
|
||||
namespace WeaponPaints;
|
||||
|
||||
[MinimumApiVersion(144)]
|
||||
[MinimumApiVersion(155)]
|
||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
{
|
||||
internal static readonly Dictionary<string, string> weaponList = new()
|
||||
@@ -69,12 +69,70 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
{ "weapon_knife_outdoor", "Nomad Knife" },
|
||||
{ "weapon_knife_skeleton", "Skeleton Knife" }
|
||||
};
|
||||
public static Dictionary<int, string> WeaponDefindex { get; } = new Dictionary<int, string>
|
||||
{
|
||||
{ 1, "weapon_deagle" },
|
||||
{ 2, "weapon_elite" },
|
||||
{ 3, "weapon_fiveseven" },
|
||||
{ 4, "weapon_glock" },
|
||||
{ 7, "weapon_ak47" },
|
||||
{ 8, "weapon_aug" },
|
||||
{ 9, "weapon_awp" },
|
||||
{ 10, "weapon_famas" },
|
||||
{ 11, "weapon_g3sg1" },
|
||||
{ 13, "weapon_galilar" },
|
||||
{ 14, "weapon_m249" },
|
||||
{ 16, "weapon_m4a1" },
|
||||
{ 17, "weapon_mac10" },
|
||||
{ 19, "weapon_p90" },
|
||||
{ 23, "weapon_mp5sd" },
|
||||
{ 24, "weapon_ump45" },
|
||||
{ 25, "weapon_xm1014" },
|
||||
{ 26, "weapon_bizon" },
|
||||
{ 27, "weapon_mag7" },
|
||||
{ 28, "weapon_negev" },
|
||||
{ 29, "weapon_sawedoff" },
|
||||
{ 30, "weapon_tec9" },
|
||||
{ 32, "weapon_hkp2000" },
|
||||
{ 33, "weapon_mp7" },
|
||||
{ 34, "weapon_mp9" },
|
||||
{ 35, "weapon_nova" },
|
||||
{ 36, "weapon_p250" },
|
||||
{ 38, "weapon_scar20" },
|
||||
{ 39, "weapon_sg556" },
|
||||
{ 40, "weapon_ssg08" },
|
||||
{ 60, "weapon_m4a1_silencer" },
|
||||
{ 61, "weapon_usp_silencer" },
|
||||
{ 63, "weapon_cz75a" },
|
||||
{ 64, "weapon_revolver" },
|
||||
{ 500, "weapon_bayonet" },
|
||||
{ 503, "weapon_knife_css" },
|
||||
{ 505, "weapon_knife_flip" },
|
||||
{ 506, "weapon_knife_gut" },
|
||||
{ 507, "weapon_knife_karambit" },
|
||||
{ 508, "weapon_knife_m9_bayonet" },
|
||||
{ 509, "weapon_knife_tactical" },
|
||||
{ 512, "weapon_knife_falchion" },
|
||||
{ 514, "weapon_knife_survival_bowie" },
|
||||
{ 515, "weapon_knife_butterfly" },
|
||||
{ 516, "weapon_knife_push" },
|
||||
{ 517, "weapon_knife_cord" },
|
||||
{ 518, "weapon_knife_canis" },
|
||||
{ 519, "weapon_knife_ursus" },
|
||||
{ 520, "weapon_knife_gypsy_jackknife" },
|
||||
{ 521, "weapon_knife_outdoor" },
|
||||
{ 522, "weapon_knife_stiletto" },
|
||||
{ 523, "weapon_knife_widowmaker" },
|
||||
{ 525, "weapon_knife_skeleton" }
|
||||
};
|
||||
|
||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||
internal static WeaponPaintsConfig _config = new WeaponPaintsConfig();
|
||||
internal static IStringLocalizer? _localizer;
|
||||
internal static Dictionary<int, int> g_knifePickupCount = new Dictionary<int, int>();
|
||||
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||
internal static ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<int, WeaponInfo>>();
|
||||
internal static ConcurrentDictionary<int, int> g_playersDatabaseIndex = new ConcurrentDictionary<int, int>();
|
||||
internal static ConcurrentDictionary<int, string> g_playersKnife = new ConcurrentDictionary<int, string>();
|
||||
internal static ConcurrentDictionary<int, int?> g_playersMusicKit = new ConcurrentDictionary<int, int?>();
|
||||
internal static ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>> gPlayerWeaponsInfo = new ConcurrentDictionary<int, ConcurrentDictionary<ushort, WeaponInfo>>();
|
||||
internal static List<JObject> skinsList = new List<JObject>();
|
||||
internal static WeaponSynchronization? weaponSync;
|
||||
internal bool g_bCommandsAllowed = true;
|
||||
@@ -83,69 +141,12 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
internal int GlobalShareServerId = 0;
|
||||
internal static Dictionary<int, DateTime> commandsCooldown = new Dictionary<int, DateTime>();
|
||||
private string DatabaseConnectionString = string.Empty;
|
||||
private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||
public static Dictionary<int, string> weaponDefindex { get; } = new Dictionary<int, string>
|
||||
{
|
||||
{ 1, "weapon_deagle" },
|
||||
{ 2, "weapon_elite" },
|
||||
{ 3, "weapon_fiveseven" },
|
||||
{ 4, "weapon_glock" },
|
||||
{ 7, "weapon_ak47" },
|
||||
{ 8, "weapon_aug" },
|
||||
{ 9, "weapon_awp" },
|
||||
{ 10, "weapon_famas" },
|
||||
{ 11, "weapon_g3sg1" },
|
||||
{ 13, "weapon_galilar" },
|
||||
{ 14, "weapon_m249" },
|
||||
{ 16, "weapon_m4a1" },
|
||||
{ 17, "weapon_mac10" },
|
||||
{ 19, "weapon_p90" },
|
||||
{ 23, "weapon_mp5sd" },
|
||||
{ 24, "weapon_ump45" },
|
||||
{ 25, "weapon_xm1014" },
|
||||
{ 26, "weapon_bizon" },
|
||||
{ 27, "weapon_mag7" },
|
||||
{ 28, "weapon_negev" },
|
||||
{ 29, "weapon_sawedoff" },
|
||||
{ 30, "weapon_tec9" },
|
||||
{ 32, "weapon_hkp2000" },
|
||||
{ 33, "weapon_mp7" },
|
||||
{ 34, "weapon_mp9" },
|
||||
{ 35, "weapon_nova" },
|
||||
{ 36, "weapon_p250" },
|
||||
{ 38, "weapon_scar20" },
|
||||
{ 39, "weapon_sg556" },
|
||||
{ 40, "weapon_ssg08" },
|
||||
{ 60, "weapon_m4a1_silencer" },
|
||||
{ 61, "weapon_usp_silencer" },
|
||||
{ 63, "weapon_cz75a" },
|
||||
{ 64, "weapon_revolver" },
|
||||
{ 500, "weapon_bayonet" },
|
||||
{ 503, "weapon_knife_css" },
|
||||
{ 505, "weapon_knife_flip" },
|
||||
{ 506, "weapon_knife_gut" },
|
||||
{ 507, "weapon_knife_karambit" },
|
||||
{ 508, "weapon_knife_m9_bayonet" },
|
||||
{ 509, "weapon_knife_tactical" },
|
||||
{ 512, "weapon_knife_falchion" },
|
||||
{ 514, "weapon_knife_survival_bowie" },
|
||||
{ 515, "weapon_knife_butterfly" },
|
||||
{ 516, "weapon_knife_push" },
|
||||
{ 517, "weapon_knife_cord" },
|
||||
{ 518, "weapon_knife_canis" },
|
||||
{ 519, "weapon_knife_ursus" },
|
||||
{ 520, "weapon_knife_gypsy_jackknife" },
|
||||
{ 521, "weapon_knife_outdoor" },
|
||||
{ 522, "weapon_knife_stiletto" },
|
||||
{ 523, "weapon_knife_widowmaker" },
|
||||
{ 525, "weapon_knife_skeleton" }
|
||||
};
|
||||
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
//private CounterStrikeSharp.API.Modules.Timers.Timer? g_hTimerCheckSkinsData = null;
|
||||
public WeaponPaintsConfig Config { get; set; } = new();
|
||||
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.4b";
|
||||
public override string ModuleVersion => "1.5.0";
|
||||
|
||||
public static WeaponPaintsConfig GetWeaponPaintsConfig()
|
||||
{
|
||||
@@ -169,23 +170,21 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
foreach (CCSPlayerController player in players)
|
||||
{
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.SteamID.ToString() == "") continue;
|
||||
if (gPlayerWeaponsInfo.ContainsKey((int)player.Index)) continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
if (g_playersDatabaseIndex.ContainsKey((int)player.Index)) continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.SteamID.ToString(),
|
||||
SteamId = player?.SteamID,
|
||||
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);
|
||||
|
||||
g_knifePickupCount[(int)player!.Index] = 0;
|
||||
if (weaponSync != null)
|
||||
{
|
||||
_ = weaponSync!.GetPlayerDatabaseIndex(playerInfo);
|
||||
}
|
||||
g_knifePickupCount[(int)player!.Index] = 0;
|
||||
}
|
||||
/*
|
||||
RegisterListeners();
|
||||
@@ -193,9 +192,9 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
*/
|
||||
}
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
if (Config.AdditionalSetting.KnifeEnabled)
|
||||
SetupKnifeMenu();
|
||||
if (Config.Additional.SkinEnabled)
|
||||
if (Config.AdditionalSetting.SkinEnabled)
|
||||
SetupSkinsMenu();
|
||||
|
||||
RegisterListeners();
|
||||
@@ -210,16 +209,37 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
{
|
||||
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!");
|
||||
}
|
||||
// maybe more spam to get attention?
|
||||
for (int i = 1; i <= 30; i++)
|
||||
{
|
||||
Console.WriteLine("[WeaponPaints] You need to setup Database credentials in config!");
|
||||
}
|
||||
Logger.LogError("You need to setup Database credentials in config!");
|
||||
throw new Exception("[WeaponPaints] You need to setup Database credentials in config!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// maybe more spam to get attention?
|
||||
for (int i = 1; i <= 30; i++)
|
||||
{
|
||||
Console.WriteLine("[WeaponPaints] GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||
}
|
||||
Logger.LogError("GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||
throw new Exception("[WeaponPaints] GLOBAL SHARE IS NOT SUPPORTED NOW !!");
|
||||
}
|
||||
|
||||
Config = config;
|
||||
_config = config;
|
||||
_localizer = Localizer;
|
||||
|
||||
Utility.Config = config;
|
||||
/*
|
||||
* GLOBAL SHARE IS NOT SUPPORTED NOW!
|
||||
*/
|
||||
if (Config.GlobalShare)
|
||||
Config.GlobalShare = false;
|
||||
|
||||
Utility.Config = config;
|
||||
Utility.ShowAd(ModuleVersion);
|
||||
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
||||
}
|
||||
@@ -253,7 +273,7 @@ public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig
|
||||
Task<string> responseBodyTask = response.Content.ReadAsStringAsync();
|
||||
responseBodyTask.Wait();
|
||||
string responseBody = responseBodyTask.Result;
|
||||
GlobalShareServerId = Int32.Parse(responseBody);
|
||||
GlobalShareServerId = int.Parse(responseBody);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Dapper;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using Dapper;
|
||||
using MySqlConnector;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -19,21 +21,64 @@ namespace WeaponPaints
|
||||
_globalShareApi = globalShareApi;
|
||||
_globalShareServerId = globalShareServerId;
|
||||
}
|
||||
|
||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
internal async Task GetPlayerDatabaseIndex(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
|
||||
try
|
||||
{
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
string query = "SELECT `id` FROM `wp_users` WHERE `steamid` = @steamid";
|
||||
int? databaseIndex = await connection.QueryFirstOrDefaultAsync<int?>(query, new { steamid = player.SteamId });
|
||||
if (databaseIndex != null)
|
||||
{
|
||||
WeaponPaints.g_playersDatabaseIndex[player.Index] = (int)databaseIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
string insertQuery = "INSERT INTO `wp_users` (`steamid`) VALUES (@steamid)";
|
||||
await connection.ExecuteAsync(insertQuery, new { steamid = player.SteamId });
|
||||
Console.WriteLine("SQL Insert Query: " + insertQuery);
|
||||
databaseIndex = await connection.QueryFirstOrDefaultAsync<int?>(query, new { steamid = player.SteamId });
|
||||
WeaponPaints.g_playersDatabaseIndex[(int)player.Index] = (int)databaseIndex;
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
|
||||
if (databaseIndex != null)
|
||||
{
|
||||
if (_config.AdditionalSetting.SkinEnabled)
|
||||
await GetWeaponPaintsFromDatabase(player);
|
||||
if (_config.AdditionalSetting.KnifeEnabled)
|
||||
await GetKnifeFromDatabase(player);
|
||||
if (_config.AdditionalSetting.MusicKitEnabled)
|
||||
await GetMusicKitFromDatabase(player);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log("GetPlayerDatabaseIndex: " + e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
internal async Task GetKnifeFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.AdditionalSetting.KnifeEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
try
|
||||
{
|
||||
if (_config.GlobalShare)
|
||||
{
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", player.SteamId },
|
||||
{ "knife", "1" }
|
||||
};
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", player.SteamId.ToString()! },
|
||||
{ "knife", "1" }
|
||||
};
|
||||
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||
@@ -64,13 +109,17 @@ namespace WeaponPaints
|
||||
return;
|
||||
}
|
||||
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
string query = "SELECT `knife` FROM `wp_player_knife` WHERE `steamid` = @steamid";
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (PlayerKnife != null)
|
||||
string query = "SELECT `knife` FROM `wp_users_knife` WHERE `user_id` = @userId";
|
||||
string? PlayerKnife = await connection.QueryFirstOrDefaultAsync<string>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||
if (PlayerKnife != null)
|
||||
{
|
||||
WeaponPaints.g_playersKnife[player.Index] = PlayerKnife;
|
||||
}
|
||||
@@ -83,30 +132,63 @@ namespace WeaponPaints
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log(e.Message);
|
||||
Utility.Log("GetKnifeFromDatabase: " + e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
internal async Task GetMusicKitFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.AdditionalSetting.MusicKitEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
string query = "SELECT `music` FROM `wp_users_music` WHERE `user_id` = @userId";
|
||||
int? PlayerMusitKit = await connection.QueryFirstOrDefaultAsync<int?>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||
if (PlayerMusitKit != null)
|
||||
{
|
||||
WeaponPaints.g_playersMusicKit[player.Index] = PlayerMusitKit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log("GetMusicKitFromDatabase: " + e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
internal async Task GetWeaponPaintsFromDatabase(PlayerInfo player)
|
||||
{
|
||||
if (!_config.Additional.SkinEnabled) return;
|
||||
if (!_config.AdditionalSetting.SkinEnabled) return;
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||
{
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<int, WeaponInfo>();
|
||||
}
|
||||
try
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out _))
|
||||
{
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index] = new ConcurrentDictionary<ushort, WeaponInfo>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_config.GlobalShare)
|
||||
{
|
||||
var values = new Dictionary<string, string>
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", player.SteamId },
|
||||
{ "skins", "1" }
|
||||
};
|
||||
{
|
||||
{ "server_id", _globalShareServerId.ToString() },
|
||||
{ "steamid", player.SteamId.ToString()! },
|
||||
{ "skins", "1" }
|
||||
};
|
||||
UriBuilder builder = new UriBuilder(_globalShareApi);
|
||||
builder.Query = string.Join("&", values.Select(p => $"{Uri.EscapeDataString(p.Key)}={Uri.EscapeDataString(p.Value)}"));
|
||||
|
||||
@@ -124,19 +206,20 @@ namespace WeaponPaints
|
||||
{
|
||||
foreach (var weapon in jsonArray)
|
||||
{
|
||||
int? weaponDefIndex = weapon["weapon_defindex"]?.Value<int>();
|
||||
int? weaponPaintId = weapon["weapon_paint_id"]?.Value<int>();
|
||||
ushort? weaponDefIndex = weapon["weapon_defindex"]?.Value<ushort>();
|
||||
ushort? weaponPaintId = weapon["weapon_paint_id"]?.Value<ushort>();
|
||||
float? weaponWear = weapon["weapon_wear"]?.Value<float>();
|
||||
int? weaponSeed = weapon["weapon_seed"]?.Value<int>();
|
||||
ushort? weaponSeed = weapon["weapon_seed"]?.Value<ushort>();
|
||||
|
||||
if (weaponDefIndex != null && weaponPaintId != null && weaponWear != null && weaponSeed != null)
|
||||
if (weaponDefIndex != null && weaponPaintId != null && weaponWear != null && weaponSeed != null)
|
||||
{
|
||||
WeaponInfo weaponInfo = new WeaponInfo
|
||||
{
|
||||
Paint = weaponPaintId.Value,
|
||||
Seed = weaponSeed.Value,
|
||||
Wear = weaponWear.Value
|
||||
};
|
||||
Wear = weaponWear.Value,
|
||||
NameTag = null
|
||||
};
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex.Value] = weaponInfo;
|
||||
}
|
||||
}
|
||||
@@ -150,28 +233,33 @@ namespace WeaponPaints
|
||||
}
|
||||
}
|
||||
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var connection = new MySqlConnection(_databaseConnectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
|
||||
string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid";
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { steamid = player.SteamId });
|
||||
|
||||
if (PlayerSkins != null && PlayerSkins.AsList().Count > 0)
|
||||
string query = "SELECT `weapon`, `paint`, `wear`, `seed`, `nametag` FROM `wp_users_items` WHERE `user_id` = @userId";
|
||||
IEnumerable<dynamic> PlayerSkins = await connection.QueryAsync<dynamic>(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index] });
|
||||
if (PlayerSkins != null && PlayerSkins.Any())
|
||||
{
|
||||
PlayerSkins.ToList().ForEach(row =>
|
||||
PlayerSkins.ToList().ForEach(row =>
|
||||
{
|
||||
int weaponDefIndex = row.weapon_defindex ?? default(int);
|
||||
int weaponPaintId = row.weapon_paint_id ?? default(int);
|
||||
float weaponWear = row.weapon_wear ?? default(float);
|
||||
int weaponSeed = row.weapon_seed ?? default(int);
|
||||
ushort weaponDefIndex = row.weapon ?? default(ushort);
|
||||
ushort weaponPaintId = row.paint ?? default(ushort);
|
||||
float weaponWear = row.wear ?? default(float);
|
||||
ushort weaponSeed = row.seed ?? default(ushort);
|
||||
string weaponNameTag = row.nametag;
|
||||
|
||||
WeaponInfo weaponInfo = new WeaponInfo
|
||||
WeaponInfo weaponInfo = new WeaponInfo
|
||||
{
|
||||
Paint = weaponPaintId,
|
||||
Seed = weaponSeed,
|
||||
Wear = weaponWear
|
||||
};
|
||||
Wear = weaponWear,
|
||||
NameTag = weaponNameTag
|
||||
};
|
||||
WeaponPaints.gPlayerWeaponsInfo[player.Index][weaponDefIndex] = weaponInfo;
|
||||
});
|
||||
}
|
||||
@@ -184,22 +272,24 @@ namespace WeaponPaints
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utility.Log(e.Message);
|
||||
Utility.Log("GetWeaponPaintsFromDatabase: " + e.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task SyncKnifeToDatabase(PlayerInfo player, string knife)
|
||||
{
|
||||
if (!_config.Additional.KnifeEnabled) return;
|
||||
try
|
||||
if (!_config.AdditionalSetting.KnifeEnabled) return;
|
||||
if(player == null || player.Index <= 0) return;
|
||||
try
|
||||
{
|
||||
if (player.SteamId == null || player.Index == 0) return;
|
||||
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out _))
|
||||
return;
|
||||
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
string query = "INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(@steamid, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||
await connection.ExecuteAsync(query, new { steamid = player.SteamId, newKnife = knife });
|
||||
string query = "INSERT INTO `wp_users_knife` (`user_id`, `knife`) VALUES(@userId, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||
await connection.ExecuteAsync(query, new { userId = WeaponPaints.g_playersDatabaseIndex[player.Index], newKnife = knife });
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -208,42 +298,34 @@ namespace WeaponPaints
|
||||
return;
|
||||
}
|
||||
}
|
||||
internal async Task SyncWeaponPaintsToDatabase(PlayerInfo player)
|
||||
internal async Task SyncWeaponPaintToDatabase(PlayerInfo player, ushort weaponDefIndex)
|
||||
{
|
||||
if (player == null || player.Index <= 0 || player.SteamId == null) return;
|
||||
if (!_config.AdditionalSetting.SkinEnabled) return;
|
||||
if (player == null || player.Index <= 0) return;
|
||||
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
if (!WeaponPaints.g_playersDatabaseIndex.TryGetValue(player.Index, out var playerDatabaseIndex))
|
||||
return;
|
||||
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.TryGetValue(player.Index, out var playerSavedWeapons))
|
||||
return;
|
||||
|
||||
if (!playerSavedWeapons.TryGetValue(weaponDefIndex, out var weaponInfo))
|
||||
return;
|
||||
|
||||
if (!WeaponPaints.gPlayerWeaponsInfo.ContainsKey(player.Index))
|
||||
return;
|
||||
|
||||
foreach (var weaponInfoPair in WeaponPaints.gPlayerWeaponsInfo[player.Index])
|
||||
{
|
||||
int weaponDefIndex = weaponInfoPair.Key;
|
||||
WeaponInfo weaponInfo = weaponInfoPair.Value;
|
||||
|
||||
int paintId = weaponInfo.Paint;
|
||||
float wear = weaponInfo.Wear;
|
||||
int seed = weaponInfo.Seed;
|
||||
|
||||
string updateSql = "UPDATE `wp_player_skins` SET `weapon_paint_id` = @paintId, " +
|
||||
"`weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid " +
|
||||
"AND `weapon_defindex` = @weaponDefIndex";
|
||||
|
||||
var updateParams = new { paintId, wear, seed, steamid = player.SteamId, weaponDefIndex };
|
||||
int rowsAffected = await connection.ExecuteAsync(updateSql, updateParams);
|
||||
|
||||
if (rowsAffected == 0)
|
||||
{
|
||||
string insertSql = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, " +
|
||||
"`weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||
"VALUES (@steamid, @weaponDefIndex, @paintId, @wear, @seed)";
|
||||
|
||||
await connection.ExecuteAsync(insertSql, updateParams);
|
||||
}
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
using var connection = new MySqlConnection(_databaseConnectionString);
|
||||
string querySql = @"
|
||||
INSERT INTO `wp_users_items`
|
||||
(`user_id`, `weapon`, `paint`, `wear`, `seed`)
|
||||
VALUES
|
||||
(@userId, @weaponDefIndex, @paintId, @wear, @seed)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
paint = @paintId,
|
||||
wear = @wear,
|
||||
seed = @seed";
|
||||
var queryParams = new { weaponDefIndex, userId = playerDatabaseIndex, paintId = weaponInfo.Paint, wear = weaponInfo.Wear, seed = weaponInfo.Seed };
|
||||
await connection.ExecuteAsync(querySql, queryParams);
|
||||
await connection.CloseAsync();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Class DataBase
|
||||
*
|
||||
* This class handles database operations using PDO.
|
||||
*/
|
||||
class DataBase {
|
||||
|
||||
/**
|
||||
* @var PDO The PDO instance for database connection.
|
||||
*/
|
||||
private $PDO;
|
||||
|
||||
/**
|
||||
* Constructor method to initialize the database connection.
|
||||
*/
|
||||
public function __construct() {
|
||||
try {
|
||||
$this->PDO = new PDO("mysql:host=".DB_HOST."; port=".DB_PORT."; dbname=".DB_NAME, DB_USER, DB_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
|
||||
// Establish a connection to the database using PDO
|
||||
$this->PDO = new PDO(
|
||||
"mysql:host=".DB_HOST.";port=".DB_PORT.";dbname=".DB_NAME,
|
||||
DB_USER,
|
||||
DB_PASS
|
||||
);
|
||||
// Set the connection to use utf8 encoding
|
||||
$this->PDO->exec("SET NAMES utf8");
|
||||
}
|
||||
catch(PDOException $ex)
|
||||
{
|
||||
catch(PDOException $ex) {
|
||||
// Display error message if connection fails
|
||||
echo "<div style='display: flex; flex-direction: column;align-items: center;justify-content: center;text-align: center;'><h2>Problem with database!</h2>";
|
||||
die("<pre style='padding: 10px;text-wrap: balance; border: 2px solid #ed6bd3;background: #252525; color: #ed6bd3; width: 50%;'>" . $ex . "</pre>");
|
||||
}
|
||||
}
|
||||
public function select($query, $bindings = []) {
|
||||
|
||||
/**
|
||||
* Perform a SELECT query on the database.
|
||||
*
|
||||
* @param string $query The SQL query to execute.
|
||||
* @param array $bindings An associative array of parameters and their values.
|
||||
* @return array|false Returns an array of rows as associative arrays or false if no results are found.
|
||||
*/
|
||||
public function select($query, $bindings = array()) {
|
||||
// Prepare and execute the SQL query
|
||||
$STH = $this->PDO->prepare($query);
|
||||
$STH->execute($bindings);
|
||||
|
||||
// Fetch the results as associative arrays
|
||||
$result = $STH->fetchAll(PDO::FETCH_ASSOC);
|
||||
$result ??= false;
|
||||
return $result;
|
||||
if ($result === false) {
|
||||
$result = array(); // Set $result to an empty array if no results found
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function query($query, $bindings = []){
|
||||
/**
|
||||
* Perform a non-query SQL statement on the database.
|
||||
*
|
||||
* @param string $query The SQL query to execute.
|
||||
* @param array $bindings An associative array of parameters and their values.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function query($query, $bindings = array()) {
|
||||
// Prepare and execute the SQL query
|
||||
$STH = $this->PDO->prepare($query);
|
||||
return $STH->execute($bindings);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
71
website/class/header.php
Normal file
71
website/class/header.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// Set security headers to enhance security
|
||||
header("X-Frame-Options: SAMEORIGIN");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("Referrer-Policy: no-referrer-when-downgrade");
|
||||
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net https://code.jquery.com; style-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; img-src 'self' data: https://cdn.jsdelivr.net https://steamcommunity-a.akamaihd.net https://raw.githubusercontent.com;");
|
||||
|
||||
|
||||
// Include necessary classes and files
|
||||
require 'class/config.php';
|
||||
require 'class/database.php';
|
||||
require 'steamauth/steamauth.php';
|
||||
require 'class/utils.php';
|
||||
|
||||
// Create a database instance
|
||||
$db = new DataBase();
|
||||
|
||||
// Check if the user is logged in
|
||||
if (isset($_SESSION['steamid'])) {
|
||||
// Insert or update user's Steam ID in the database
|
||||
$steamid = $_SESSION['steamid'];
|
||||
$db->query("INSERT INTO `wp_users` (`steamid`) VALUES ('{$steamid}') ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP");
|
||||
|
||||
// Get user's database index
|
||||
$userInfoQuery = $db->select("SELECT `id` FROM `wp_users` WHERE `steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$_SESSION['userDbIndex'] = $userDbIndex = (int)$userInfoQuery[0]['id'];
|
||||
|
||||
// Get weapons and skins information
|
||||
$weapons = UtilsClass::getWeaponsFromArray();
|
||||
$skins = UtilsClass::skinsFromJson();
|
||||
|
||||
// Retrieve user's selected skins and knife
|
||||
$querySelected = $db->select("SELECT `weapon`, `paint`, `wear`, `seed`, `nametag` FROM `wp_users_items` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]);
|
||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||
$selectedKnifeResult = $db->select("SELECT `knife` FROM `wp_users_knife` WHERE `user_id` = :user_id", ["user_id" => $userDbIndex]);
|
||||
|
||||
// Determine user's selected knife or set default knife
|
||||
if (!empty($selectedKnifeResult)) {
|
||||
$selectedKnife = $selectedKnifeResult[0]['knife'];
|
||||
} else {
|
||||
$selectedKnife = "weapon_knife";
|
||||
}
|
||||
$knifes = UtilsClass::getKnifeTypes();
|
||||
|
||||
// Handle form submission
|
||||
if (isset($_POST['forma'])) {
|
||||
$ex = explode("-", $_POST['forma']);
|
||||
|
||||
// Handle knife selection
|
||||
if ($ex[0] == "knife") {
|
||||
$db->query("INSERT INTO `wp_users_knife` (`user_id`, `knife`) VALUES(:user_id, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["user_id" => $userDbIndex, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||
} else {
|
||||
// Handle skin selection
|
||||
if (array_key_exists($ex[1], $skins[$ex[0]]) && isset($_POST['wear']) && $_POST['wear'] >= 0.00 && $_POST['wear'] <= 1.00 && isset($_POST['seed'])) {
|
||||
$wear = floatval($_POST['wear']); // wear
|
||||
$seed = intval($_POST['seed']); // seed
|
||||
|
||||
// Check if the skin is already selected and update or insert accordingly
|
||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||
$db->query("UPDATE wp_users_items SET paint = :weapon_paint_id, wear = :weapon_wear, seed = :weapon_seed WHERE user_id = :user_id AND weapon = :weapon_defindex", ["user_id" => $userDbIndex, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
} else {
|
||||
$db->query("INSERT INTO wp_users_items (`user_id`, `weapon`, `paint`, `wear`, `seed`) VALUES (:user_id, :weapon_defindex, :weapon_paint_id, :weapon_wear, :weapon_seed)", ["user_id" => $userDbIndex, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Redirect to the same page after form submission
|
||||
header("Location: {$_SERVER['PHP_SELF']}");
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,98 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Class UtilsClass
|
||||
*
|
||||
* Provides utility methods for handling skin and weapon data.
|
||||
*/
|
||||
class UtilsClass
|
||||
{
|
||||
public static function skinsFromJson(): array
|
||||
/**
|
||||
* Retrieve skins data from the JSON file.
|
||||
*
|
||||
* @return array An associative array containing skin data.
|
||||
*/
|
||||
public static function skinsFromJson()
|
||||
{
|
||||
$skins = [];
|
||||
$json = json_decode(file_get_contents(__DIR__ . "/../data/skins.json"), true);
|
||||
$skins = array();
|
||||
$jsonFilePath = __DIR__ . "/../data/skins.json";
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
|
||||
'weapon_name' => $skin['weapon_name'],
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
];
|
||||
if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) {
|
||||
$json = json_decode(file_get_contents($jsonFilePath), true);
|
||||
|
||||
foreach ($json as $skin) {
|
||||
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = array(
|
||||
'weapon_name' => $skin['weapon_name'],
|
||||
'paint_name' => $skin['paint_name'],
|
||||
'image_url' => $skin['image'],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Handle file not found or unreadable error
|
||||
// You can throw an exception or log an error message
|
||||
}
|
||||
|
||||
return $skins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve weapons data from the skin data array.
|
||||
*
|
||||
* @return array An associative array containing weapon data.
|
||||
*/
|
||||
public static function getWeaponsFromArray()
|
||||
{
|
||||
$weapons = [];
|
||||
$temp = self::skinsFromJson();
|
||||
$weapons = array();
|
||||
$skinsData = self::skinsFromJson();
|
||||
|
||||
foreach ($temp as $key => $value) {
|
||||
if (key_exists($key, $weapons))
|
||||
continue;
|
||||
|
||||
$weapons[$key] = [
|
||||
foreach ($skinsData as $key => $value) {
|
||||
$weapons[$key] = array(
|
||||
'weapon_name' => $value[0]['weapon_name'],
|
||||
'paint_name' => $value[0]['paint_name'],
|
||||
'image_url' => $value[0]['image_url'],
|
||||
];
|
||||
);
|
||||
}
|
||||
|
||||
return $weapons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve knife types from the weapon data array.
|
||||
*
|
||||
* @return array An associative array containing knife types data.
|
||||
*/
|
||||
public static function getKnifeTypes()
|
||||
{
|
||||
$knifes = [];
|
||||
$temp = self::getWeaponsFromArray();
|
||||
$knifes = array();
|
||||
$weaponsData = self::getWeaponsFromArray();
|
||||
|
||||
foreach ($temp as $key => $weapon) {
|
||||
if (
|
||||
!in_array($key, [
|
||||
500,
|
||||
503,
|
||||
505,
|
||||
506,
|
||||
507,
|
||||
508,
|
||||
509,
|
||||
512,
|
||||
514,
|
||||
515,
|
||||
516,
|
||||
517,
|
||||
518,
|
||||
519,
|
||||
520,
|
||||
521,
|
||||
522,
|
||||
523,
|
||||
525
|
||||
])
|
||||
)
|
||||
continue;
|
||||
$allowedKnifeKeys = array(
|
||||
500, 503, 505, 506, 507, 508, 509, 512, 514, 515,
|
||||
516, 517, 518, 519, 520, 521, 522, 523, 525
|
||||
);
|
||||
|
||||
$knifes[$key] = [
|
||||
'weapon_name' => $weapon['weapon_name'],
|
||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||
'image_url' => $weapon['image_url'],
|
||||
];
|
||||
$knifes[0] = [
|
||||
'weapon_name' => "weapon_knife",
|
||||
'paint_name' => "Default knife",
|
||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||
];
|
||||
foreach ($weaponsData as $key => $weapon) {
|
||||
if (in_array($key, $allowedKnifeKeys)) {
|
||||
$knifes[$key] = array(
|
||||
'weapon_name' => $weapon['weapon_name'],
|
||||
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
|
||||
'image_url' => $weapon['image_url'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add default knife
|
||||
$knifes[0] = array(
|
||||
'weapon_name' => "weapon_knife",
|
||||
'paint_name' => "Default knife",
|
||||
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
|
||||
);
|
||||
|
||||
ksort($knifes);
|
||||
return $knifes;
|
||||
}
|
||||
|
||||
public static function getSelectedSkins(array $temp)
|
||||
/**
|
||||
* Retrieve selected skins data from the database result.
|
||||
*
|
||||
* @param array $temp An array containing the selected skins data.
|
||||
* @return array An associative array containing selected skins data.
|
||||
*/
|
||||
public static function getSelectedSkins($temp)
|
||||
{
|
||||
$selected = [];
|
||||
$selected = array();
|
||||
|
||||
foreach ($temp as $weapon) {
|
||||
$selected[$weapon['weapon_defindex']] = [
|
||||
'weapon_paint_id' => $weapon['weapon_paint_id'],
|
||||
'weapon_seed' => $weapon['weapon_seed'],
|
||||
'weapon_wear' => $weapon['weapon_wear'],
|
||||
];
|
||||
$selected[$weapon['weapon']] = array(
|
||||
'weapon_paint_id' => $weapon['paint'],
|
||||
'weapon_seed' => $weapon['seed'],
|
||||
'weapon_wear' => $weapon['wear'],
|
||||
);
|
||||
}
|
||||
|
||||
return $selected;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,261 +1,36 @@
|
||||
<?php
|
||||
require_once 'class/config.php';
|
||||
require_once 'class/database.php';
|
||||
require_once 'steamauth/steamauth.php';
|
||||
require_once 'class/utils.php';
|
||||
|
||||
$db = new DataBase();
|
||||
if (isset($_SESSION['steamid'])) {
|
||||
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
$weapons = UtilsClass::getWeaponsFromArray();
|
||||
$skins = UtilsClass::skinsFromJson();
|
||||
$querySelected = $db->select("SELECT `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed` FROM `wp_player_skins` WHERE `wp_player_skins`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$selectedSkins = UtilsClass::getSelectedSkins($querySelected);
|
||||
$selectedKnife = $db->select("SELECT * FROM `wp_player_knife` WHERE `wp_player_knife`.`steamid` = :steamid", ["steamid" => $steamid]);
|
||||
$knifes = UtilsClass::getKnifeTypes();
|
||||
|
||||
if (isset($_POST['forma'])) {
|
||||
$ex = explode("-", $_POST['forma']);
|
||||
|
||||
if ($ex[0] == "knife") {
|
||||
$db->query("INSERT INTO `wp_player_knife` (`steamid`, `knife`) VALUES(:steamid, :knife) ON DUPLICATE KEY UPDATE `knife` = :knife", ["steamid" => $steamid, "knife" => $knifes[$ex[1]]['weapon_name']]);
|
||||
} else {
|
||||
if (array_key_exists($ex[1], $skins[$ex[0]]) && isset($_POST['wear']) && $_POST['wear'] >= 0.00 && $_POST['wear'] <= 1.00 && isset($_POST['seed'])) {
|
||||
$wear = floatval($_POST['wear']); // wear
|
||||
$seed = intval($_POST['seed']); // seed
|
||||
if (array_key_exists($ex[0], $selectedSkins)) {
|
||||
$db->query("UPDATE wp_player_skins SET weapon_paint_id = :weapon_paint_id, weapon_wear = :weapon_wear, weapon_seed = :weapon_seed WHERE steamid = :steamid AND weapon_defindex = :weapon_defindex", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
} else {
|
||||
$db->query("INSERT INTO wp_player_skins (`steamid`, `weapon_defindex`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) VALUES (:steamid, :weapon_defindex, :weapon_paint_id, :weapon_wear, :weapon_seed)", ["steamid" => $steamid, "weapon_defindex" => $ex[0], "weapon_paint_id" => $ex[1], "weapon_wear" => $wear, "weapon_seed" => $seed]);
|
||||
}
|
||||
}
|
||||
}
|
||||
header("Location: {$_SERVER['PHP_SELF']}");
|
||||
}
|
||||
}
|
||||
require 'class/header.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"<?php if(WEB_STYLE_DARK) echo 'data-bs-theme="dark"'?>>
|
||||
|
||||
<html lang="en" <?php if (WEB_STYLE_DARK) echo 'data-bs-theme="dark"' ?>>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>CS2 Simple Weapon Paints</title>
|
||||
<meta charset="utf-8">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
|
||||
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>CS2 Simple Weapon Paints</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<?php
|
||||
if (!isset($_SESSION['steamid'])) {
|
||||
echo "<div class='bg-primary'><h2>To choose weapon paints loadout, you need to ";
|
||||
loginbutton("rectangle");
|
||||
echo "</h2></div>";
|
||||
} else {
|
||||
echo "<div class='bg-primary'><h2>Your current weapon skin loadout <a class='btn btn-danger' href='{$_SERVER['PHP_SELF']}?logout'>Logout</a></h2> </div>";
|
||||
echo "<div class='card-group mt-2'>";
|
||||
?>
|
||||
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3 border border-primary">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
$actualKnife = $knifes[0];
|
||||
if ($selectedKnife != null)
|
||||
{
|
||||
foreach ($knifes as $knife) {
|
||||
if ($selectedKnife[0]['knife'] == $knife['weapon_name']) {
|
||||
$actualKnife = $knife;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select knife</option>
|
||||
<?php
|
||||
foreach ($knifes as $knifeKey => $knife) {
|
||||
if ($selectedKnife[0]['knife'] == $knife['weapon_name'])
|
||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
foreach ($weapons as $defindex => $default) { ?>
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||
} else {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select skin</option>
|
||||
<?php
|
||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br></br>
|
||||
<?php
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
if ($selectedSkinInfo) :
|
||||
?>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||
Settings
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<button type="button" class="btn btn-primary" onclick="showSkinSelectionAlert()">
|
||||
Settings
|
||||
</button>
|
||||
<script>
|
||||
function showSkinSelectionAlert() {
|
||||
alert("You need to select a skin first.");
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// wear value
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||
|
||||
// seed value
|
||||
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||
?>
|
||||
|
||||
|
||||
<div class="modal fade" id="weaponModal<?php echo $defindex ?>" tabindex="-1" role="dialog" aria-labelledby="weaponModalLabel<?php echo $defindex ?>" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class='card-title item-name'>
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||
} else {
|
||||
echo "{$default["paint_name"]} Settings";
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<select class="form-select" id="wearSelect<?php echo $defindex ?>" name="wearSelect" onchange="updateWearValue<?php echo $defindex ?>(this.value)">
|
||||
<option disabled>Select Wear</option>
|
||||
<option value="0.00" <?php echo ($initialWearValue == 0.00) ? 'selected' : ''; ?>>Factory New</option>
|
||||
<option value="0.07" <?php echo ($initialWearValue == 0.07) ? 'selected' : ''; ?>>Minimal Wear</option>
|
||||
<option value="0.15" <?php echo ($initialWearValue == 0.15) ? 'selected' : ''; ?>>Field-Tested</option>
|
||||
<option value="0.38" <?php echo ($initialWearValue == 0.38) ? 'selected' : ''; ?>>Well-Worn</option>
|
||||
<option value="0.45" <?php echo ($initialWearValue == 0.45) ? 'selected' : ''; ?>>Battle-Scarred</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="wear">Wear:</label>
|
||||
<input type="text" value="<?php echo $initialWearValue; ?>" class="form-control" id="wear<?php echo $defindex ?>" name="wear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="seed">Seed:</label>
|
||||
<input type="text" value="<?php echo $initialSeedValue; ?>" class="form-control" id="seed<?php echo $defindex ?>" name="seed" oninput="validateSeed(this)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-danger">Use</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// wear
|
||||
function updateWearValue<?php echo $defindex ?>(selectedValue) {
|
||||
var wearInputElement = document.getElementById("wear<?php echo $defindex ?>");
|
||||
wearInputElement.value = selectedValue;
|
||||
}
|
||||
|
||||
function validateWear(inputElement) {
|
||||
inputElement.value = inputElement.value.replace(/[^0-9]/g, '');
|
||||
}
|
||||
// seed
|
||||
function validateSeed(input) {
|
||||
// Check entered value
|
||||
var inputValue = input.value.replace(/[^0-9]/g, ''); // Just get the numbers
|
||||
|
||||
if (inputValue === "") {
|
||||
input.value = 0; // Set to 0 if empty or no numbers
|
||||
} else {
|
||||
var numericValue = parseInt(inputValue);
|
||||
numericValue = Math.min(1000, Math.max(1, numericValue)); // Interval control
|
||||
|
||||
input.value = numericValue;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||
<div class="col-md-4 d-flex align-items-center">
|
||||
<span class="mb-3 mb-md-0 text-body-secondary">© 2023 <a href="https://github.com/Nereziel/cs2-WeaponPaints">Nereziel/cs2-WeaponPaints</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
<?php if (!isset($_SESSION['steamid'])) : ?>
|
||||
<div class='bg-primary'><h2>To choose weapon paints loadout, you need to <?php loginbutton("rectangle"); ?></h2></div>
|
||||
<?php else : ?>
|
||||
<div class='bg-primary'><h2>Your current weapon skin loadout <a class='btn btn-danger' href='<?php echo $_SERVER['PHP_SELF']; ?>?logout'>Logout</a></h2> </div>
|
||||
<div class='card-group mt-2'>
|
||||
<!-- Display user's selected knife -->
|
||||
<?php require_once 'view/display_knife.php'; ?>
|
||||
<!-- Display user's selected skins for different weapons -->
|
||||
<?php require_once 'view/display_weapons.php'; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<!-- Footer section -->
|
||||
<div class="container">
|
||||
<footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
|
||||
<div class="col-md-4 d-flex align-items-center">
|
||||
<span class="mb-3 mb-md-0 text-body-secondary">© 2024 <a href="https://github.com/Nereziel/cs2-WeaponPaints">Nereziel/cs2-WeaponPaints</a></span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
21
website/steamauth/licence.txt
Normal file
21
website/steamauth/licence.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Benjamin Smith
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
ob_start();
|
||||
session_start();
|
||||
//ob_start();
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
function logoutbutton() {
|
||||
echo "<form action='' method='get'><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
||||
echo "<form><button class='btn btn-secondary' name='logout' type='submit'>Logout</button></form>"; //logout button
|
||||
}
|
||||
|
||||
function loginbutton($buttonstyle = "square") {
|
||||
|
||||
@@ -7,7 +7,6 @@ if (empty($_SESSION['steam_uptodate']) or empty($_SESSION['steam_personaname']))
|
||||
$_SESSION['steam_communityvisibilitystate'] = $content['response']['players'][0]['communityvisibilitystate'];
|
||||
$_SESSION['steam_profilestate'] = $content['response']['players'][0]['profilestate'];
|
||||
$_SESSION['steam_personaname'] = $content['response']['players'][0]['personaname'];
|
||||
$_SESSION['steam_lastlogoff'] = $content['response']['players'][0]['lastlogoff'];
|
||||
$_SESSION['steam_profileurl'] = $content['response']['players'][0]['profileurl'];
|
||||
$_SESSION['steam_avatar'] = $content['response']['players'][0]['avatar'];
|
||||
$_SESSION['steam_avatarmedium'] = $content['response']['players'][0]['avatarmedium'];
|
||||
@@ -27,7 +26,6 @@ $steamprofile['steamid'] = $_SESSION['steam_steamid'];
|
||||
$steamprofile['communityvisibilitystate'] = $_SESSION['steam_communityvisibilitystate'];
|
||||
$steamprofile['profilestate'] = $_SESSION['steam_profilestate'];
|
||||
$steamprofile['personaname'] = $_SESSION['steam_personaname'];
|
||||
$steamprofile['lastlogoff'] = $_SESSION['steam_lastlogoff'];
|
||||
$steamprofile['profileurl'] = $_SESSION['steam_profileurl'];
|
||||
$steamprofile['avatar'] = $_SESSION['steam_avatar'];
|
||||
$steamprofile['avatarmedium'] = $_SESSION['steam_avatarmedium'];
|
||||
|
||||
42
website/view/display_knife.php
Normal file
42
website/view/display_knife.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3 border border-primary">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// Determine the user's selected knife
|
||||
$actualKnife = $knifes[0];
|
||||
if ($selectedKnife != null) {
|
||||
foreach ($knifes as $knife) {
|
||||
if ($selectedKnife == $knife['weapon_name']) {
|
||||
$actualKnife = $knife;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display user's selected knife information
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h6 class='card-title item-name'>Knife type</h6>";
|
||||
echo "<h5 class='card-title item-name'>{$actualKnife["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$actualKnife["image_url"]}' class='skin-image'>";
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<!-- Form for selecting user's knife -->
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select knife</option>
|
||||
<?php
|
||||
// Display options for selecting different knives
|
||||
foreach ($knifes as $knifeKey => $knife) {
|
||||
if ($selectedKnife == $knife['weapon_name'])
|
||||
echo "<option selected value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"knife-{$knifeKey}\">{$knife['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
154
website/view/display_weapons.php
Normal file
154
website/view/display_weapons.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// Display user's selected skins for different weapons
|
||||
foreach ($weapons as $defindex => $default) {
|
||||
?>
|
||||
<div class="col-sm-2">
|
||||
<div class="card text-center mb-3">
|
||||
<div class="card-body">
|
||||
<?php
|
||||
// Determine the skin to display for the current weapon
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]['image_url']}' class='skin-image'>";
|
||||
} else {
|
||||
echo "<div class='card-header'>";
|
||||
echo "<h5 class='card-title item-name'>{$default["paint_name"]}</h5>";
|
||||
echo "</div>";
|
||||
echo "<img src='{$default["image_url"]}' class='skin-image'>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<!-- Form for selecting user's skin and settings -->
|
||||
<form action="" method="POST">
|
||||
<select name="forma" class="form-control select" onchange="this.form.submit()" class="SelectWeapon">
|
||||
<option disabled>Select skin</option>
|
||||
<?php
|
||||
// Display options for selecting different skins
|
||||
foreach ($skins[$defindex] as $paintKey => $paint) {
|
||||
if (array_key_exists($defindex, $selectedSkins) && $selectedSkins[$defindex]['weapon_paint_id'] == $paintKey)
|
||||
echo "<option selected value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
else
|
||||
echo "<option value=\"{$defindex}-{$paintKey}\">{$paint['paint_name']}</option>";
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br></br>
|
||||
<?php
|
||||
// Display settings button for selected skin
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]) ? $selectedSkins[$defindex] : null;
|
||||
$steamid = $_SESSION['steamid'];
|
||||
|
||||
if ($selectedSkinInfo) :
|
||||
?>
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#weaponModal<?php echo $defindex ?>">
|
||||
Settings
|
||||
</button>
|
||||
<?php else : ?>
|
||||
<!-- Display message if skin is not selected -->
|
||||
<button type="button" class="btn btn-primary" onclick="showSkinSelectionAlert()">
|
||||
Settings
|
||||
</button>
|
||||
<script>
|
||||
function showSkinSelectionAlert() {
|
||||
alert("You need to select a skin first.");
|
||||
}
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Display modal for adjusting wear and seed values
|
||||
$selectedSkinInfo = isset($selectedSkins[$defindex]['weapon_paint_id']) ? $selectedSkins[$defindex] : null;
|
||||
$queryWear = $selectedSkins[$defindex]['weapon_wear'] ?? 1.0;
|
||||
$initialWearValue = isset($selectedSkinInfo['weapon_wear']) ? $selectedSkinInfo['weapon_wear'] : (isset($queryWear[0]['weapon_wear']) ? $queryWear[0] : 0.0);
|
||||
$querySeed = $selectedSkins[$defindex]['weapon_seed'] ?? 0;
|
||||
$initialSeedValue = isset($selectedSkinInfo['weapon_seed']) ? $selectedSkinInfo['weapon_seed'] : 0;
|
||||
?>
|
||||
|
||||
<!-- Modal for adjusting wear and seed values -->
|
||||
<div class="modal fade" id="weaponModal<?php echo $defindex ?>" tabindex="-1" role="dialog" aria-labelledby="weaponModalLabel<?php echo $defindex ?>" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<!-- Modal header -->
|
||||
<div class="modal-header">
|
||||
<h5 class='card-title item-name'>
|
||||
<?php
|
||||
if (array_key_exists($defindex, $selectedSkins)) {
|
||||
echo "{$skins[$defindex][$selectedSkins[$defindex]['weapon_paint_id']]["paint_name"]} Settings";
|
||||
} else {
|
||||
echo "{$default["paint_name"]} Settings";
|
||||
}
|
||||
?>
|
||||
</h5>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
<div class="modal-body">
|
||||
<!-- Form for adjusting wear and seed values -->
|
||||
<div class="form-group">
|
||||
<select class="form-select" id="wearSelect<?php echo $defindex ?>" name="wearSelect" onchange="updateWearValue<?php echo $defindex ?>(this.value)">
|
||||
<option disabled>Select Wear</option>
|
||||
<option value="0.00" <?php echo ($initialWearValue == 0.00) ? 'selected' : ''; ?>>Factory New</option>
|
||||
<option value="0.07" <?php echo ($initialWearValue == 0.07) ? 'selected' : ''; ?>>Minimal Wear</option>
|
||||
<option value="0.15" <?php echo ($initialWearValue == 0.15) ? 'selected' : ''; ?>>Field-Tested</option>
|
||||
<option value="0.38" <?php echo ($initialWearValue == 0.38) ? 'selected' : ''; ?>>Well-Worn</option>
|
||||
<option value="0.45" <?php echo ($initialWearValue == 0.45) ? 'selected' : ''; ?>>Battle-Scarred</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="wear">Wear:</label>
|
||||
<input type="text" value="<?php echo $initialWearValue; ?>" class="form-control" id="wear<?php echo $defindex ?>" name="wear">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label for="seed">Seed:</label>
|
||||
<input type="text" value="<?php echo $initialSeedValue; ?>" class="form-control" id="seed<?php echo $defindex ?>" name="seed" oninput="validateSeed(this)">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal footer -->
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
||||
<button type="submit" class="btn btn-danger">Use</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- JavaScript functions for updating wear and seed values -->
|
||||
<script>
|
||||
// wear
|
||||
function updateWearValue<?php echo $defindex ?>(selectedValue) {
|
||||
var wearInputElement = document.getElementById("wear<?php echo $defindex ?>");
|
||||
wearInputElement.value = selectedValue;
|
||||
}
|
||||
|
||||
function validateWear(inputElement) {
|
||||
inputElement.value = inputElement.value.replace(/[^0-9]/g, '');
|
||||
}
|
||||
// seed
|
||||
function validateSeed(input) {
|
||||
// Check entered value
|
||||
var inputValue = input.value.replace(/[^0-9]/g, ''); // Just get the numbers
|
||||
|
||||
if (inputValue === "") {
|
||||
input.value = 0; // Set to 0 if empty or no numbers
|
||||
} else {
|
||||
var numericValue = parseInt(inputValue);
|
||||
numericValue = Math.min(1000, Math.max(1, numericValue)); // Interval control
|
||||
|
||||
input.value = numericValue;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user