mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-11 08:48:51 +00:00
change mysql
This commit is contained in:
52
Database.cs
52
Database.cs
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using MySqlConnector;
|
||||||
|
using Nexd.MySQL;
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
public class WeaponPaints : BasePlugin
|
public class WeaponPaints : BasePlugin
|
||||||
{
|
{
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
|
public override string ModuleDescription => "Connector for web-based player chosen wepaon paints.";
|
||||||
public override string ModuleVersion => "0.0.1";
|
public override string ModuleAuthor => "Nereziel";
|
||||||
|
public override string ModuleVersion => "0.2";
|
||||||
|
MySqlDb? MySql = null;
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
new Cfg().CheckConfig(ModuleDirectory);
|
new Cfg().CheckConfig(ModuleDirectory);
|
||||||
|
MySql = new MySqlDb(Cfg.config.DatabaseHost!, Cfg.config.DatabaseUser!, Cfg.config.DatabasePassword!, Cfg.config.DatabaseName!, (int)Cfg.config.DatabasePort);
|
||||||
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
RegisterListener<Listeners.OnEntitySpawned>(OnEntitySpawned);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEntitySpawned(CEntityInstance entity)
|
private void OnEntitySpawned(CEntityInstance entity)
|
||||||
{
|
{
|
||||||
var designerName = entity.DesignerName;
|
var designerName = entity.DesignerName;
|
||||||
@@ -27,7 +32,7 @@ public class WeaponPaints : BasePlugin
|
|||||||
//Log($"AccountID {weapon.AttributeManager.Item.AccountID}");
|
//Log($"AccountID {weapon.AttributeManager.Item.AccountID}");
|
||||||
//Log($"playerSteam {playerId}");
|
//Log($"playerSteam {playerId}");
|
||||||
var playerId = ConvertToSteam64(weapon.AttributeManager.Item.AccountID);
|
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 (playerId == 0) return;
|
||||||
if (weaponPaint == 0) return;
|
if (weaponPaint == 0) return;
|
||||||
weapon.AttributeManager.Item.AccountID = unchecked((uint)271098320);
|
weapon.AttributeManager.Item.AccountID = unchecked((uint)271098320);
|
||||||
@@ -50,4 +55,21 @@ public class WeaponPaints : BasePlugin
|
|||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
Console.ResetColor();
|
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<int>(0, "weapon_paint_id");
|
||||||
|
return weaponPaint;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,15 +4,17 @@
|
|||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Nexd.MySQL" Version="1.0.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CounterStrikeSharp.API">
|
<Reference Include="CounterStrikeSharp.API">
|
||||||
<HintPath>deps\CounterStrikeSharp.API.dll</HintPath>
|
<HintPath>deps\CounterStrikeSharp.API.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="MySqlConnector">
|
|
||||||
<HintPath>deps\MySqlConnector.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
BIN
deps/MySqlConnector.dll
vendored
BIN
deps/MySqlConnector.dll
vendored
Binary file not shown.
Reference in New Issue
Block a user