diff --git a/Database.cs b/Database.cs deleted file mode 100644 index 95302db2..00000000 --- a/Database.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CounterStrikeSharp.API; -using MySqlConnector; -using WeaponPaints; - -namespace WeaponPaints -{ - internal class Database - { - private static readonly MySqlConnectionStringBuilder connection = new() - { - Server = Cfg.config.DatabaseHost, - Port = Cfg.config.DatabasePort, - UserID = Cfg.config.DatabaseUser, - Password = Cfg.config.DatabasePassword, - Database = Cfg.config.DatabaseName - }; - - public static MySqlConnection GetConnection() - { - return new MySqlConnection(connection.ConnectionString); - } - } - internal class Queries - { - public static int GetPlayersWeaponPaint(string steamId, int weaponDefIndex) - { - try - { - using MySqlConnection connection = Database.GetConnection(); - using MySqlCommand command = connection.CreateCommand(); - command.CommandText = "SELECT weapon_paint_id FROM wp_player_skins WHERE steamid = @steamId AND weapon_defindex = @weaponDefIndex;"; - command.Parameters.AddWithValue("@steamId", steamId); - command.Parameters.AddWithValue("@weaponDefIndex", weaponDefIndex); - - connection.Open(); - using var reader = command.ExecuteReader(); - - int weaponPaint = 0; - while (reader.Read()) - { - weaponPaint = reader.GetInt32("weapon_paint_id"); - } - connection.Close(); - return weaponPaint; - } - catch (Exception) - { - return 0; - } - } - } -} \ No newline at end of file diff --git a/WeaponPaints.cs b/WeaponPaints.cs index fa321edd..b68fb235 100644 --- a/WeaponPaints.cs +++ b/WeaponPaints.cs @@ -1,18 +1,23 @@ using CounterStrikeSharp.API.Core; +using MySqlConnector; +using Nexd.MySQL; namespace WeaponPaints; public class WeaponPaints : BasePlugin { public override string ModuleName => "WeaponPaints"; - - public override string ModuleVersion => "0.0.1"; + public override string ModuleDescription => "Connector for web-based player chosen wepaon paints."; + public override string ModuleAuthor => "Nereziel"; + public override string ModuleVersion => "0.2"; + MySqlDb? MySql = null; public override void Load(bool hotReload) { new Cfg().CheckConfig(ModuleDirectory); + MySql = new MySqlDb(Cfg.config.DatabaseHost!, Cfg.config.DatabaseUser!, Cfg.config.DatabasePassword!, Cfg.config.DatabaseName!, (int)Cfg.config.DatabasePort); RegisterListener(OnEntitySpawned); - } + private void OnEntitySpawned(CEntityInstance entity) { var designerName = entity.DesignerName; @@ -27,7 +32,7 @@ public class WeaponPaints : BasePlugin //Log($"AccountID {weapon.AttributeManager.Item.AccountID}"); //Log($"playerSteam {playerId}"); var playerId = ConvertToSteam64(weapon.AttributeManager.Item.AccountID); - int weaponPaint = Queries.GetPlayersWeaponPaint(playerId.ToString(), weapon.AttributeManager.Item.ItemDefinitionIndex); + int weaponPaint = GetPlayersWeaponPaint(playerId.ToString(), weapon.AttributeManager.Item.ItemDefinitionIndex); if (playerId == 0) return; if (weaponPaint == 0) return; weapon.AttributeManager.Item.AccountID = unchecked((uint)271098320); @@ -50,4 +55,21 @@ public class WeaponPaints : BasePlugin Console.WriteLine(message); Console.ResetColor(); } + public int GetPlayersWeaponPaint(string steamId, int weaponDefIndex) + { + try + { + MySqlQueryCondition conditions = new MySqlQueryCondition() + .Add("steamid", "=", steamId) + .Add("weapon_defindex", "=", weaponDefIndex); + + MySqlQueryResult result = MySql!.Table("wp_player_skins").Where(conditions).Select(); + int weaponPaint = result.Get(0, "weapon_paint_id"); + return weaponPaint; + } + catch (Exception) + { + return 0; + } + } } \ No newline at end of file diff --git a/WeaponPaints.csproj b/WeaponPaints.csproj index 27c6a4db..b8461566 100644 --- a/WeaponPaints.csproj +++ b/WeaponPaints.csproj @@ -4,15 +4,17 @@ net7.0 enable enable + true + + + + deps\CounterStrikeSharp.API.dll - - deps\MySqlConnector.dll - diff --git a/deps/MySqlConnector.dll b/deps/MySqlConnector.dll deleted file mode 100644 index ee6062d1..00000000 Binary files a/deps/MySqlConnector.dll and /dev/null differ