mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-03-16 10:39:31 +00:00
Compare commits
4 Commits
04c4de9a31
...
build-408
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e59456c9f | ||
|
|
1f03e1c4f0 | ||
|
|
129b34f5c0 | ||
|
|
fbf473b893 |
@@ -91,12 +91,6 @@ namespace WeaponPaints
|
|||||||
[JsonPropertyName("DatabaseName")]
|
[JsonPropertyName("DatabaseName")]
|
||||||
public string DatabaseName { get; set; } = "";
|
public string DatabaseName { get; set; } = "";
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseType")]
|
|
||||||
public string DatabaseType { get; set; } = "mysql";
|
|
||||||
|
|
||||||
[JsonPropertyName("DatabasePath")]
|
|
||||||
public string DatabasePath { get; set; } = "weaponpaints.db";
|
|
||||||
|
|
||||||
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
[JsonPropertyName("CmdRefreshCooldownSeconds")]
|
||||||
public int CmdRefreshCooldownSeconds { get; set; } = 3;
|
public int CmdRefreshCooldownSeconds { get; set; } = 3;
|
||||||
|
|
||||||
|
|||||||
34
Database.cs
34
Database.cs
@@ -1,21 +1,23 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
namespace WeaponPaints
|
namespace WeaponPaints
|
||||||
{
|
{
|
||||||
public class Database
|
public class Database(string dbConnectionString)
|
||||||
{
|
{
|
||||||
private readonly Func<IDatabaseConnection> _connectionFactory;
|
public async Task<MySqlConnection> GetConnectionAsync()
|
||||||
|
{
|
||||||
public Database(Func<IDatabaseConnection> connectionFactory)
|
try
|
||||||
{
|
{
|
||||||
_connectionFactory = connectionFactory;
|
var connection = new MySqlConnection(dbConnectionString);
|
||||||
}
|
await connection.OpenAsync();
|
||||||
|
return connection;
|
||||||
public async Task<IDatabaseConnection> GetConnectionAsync()
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
var connection = _connectionFactory();
|
{
|
||||||
await connection.OpenAsync();
|
WeaponPaints.Instance.Logger.LogError($"Unable to connect to database: {ex.Message}");
|
||||||
return connection;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
|
||||||
{
|
|
||||||
public interface IDatabaseConnection : IAsyncDisposable, IDisposable
|
|
||||||
{
|
|
||||||
Task OpenAsync();
|
|
||||||
Task CloseAsync();
|
|
||||||
Task<IDbTransaction> BeginTransactionAsync();
|
|
||||||
Task CommitTransactionAsync(IDbTransaction transaction);
|
|
||||||
Task RollbackTransactionAsync(IDbTransaction transaction);
|
|
||||||
IDbConnection GetConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MySqlConnector;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
|
||||||
{
|
|
||||||
public class MySQLConnection : IDatabaseConnection
|
|
||||||
{
|
|
||||||
private readonly MySqlConnection _connection;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
public MySQLConnection(string connectionString, ILogger logger)
|
|
||||||
{
|
|
||||||
_connection = new MySqlConnection(connectionString);
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task OpenAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _connection.OpenAsync();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"Unable to connect to MySQL database: {ex.Message}");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task CloseAsync()
|
|
||||||
{
|
|
||||||
await _connection.CloseAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IDbTransaction> BeginTransactionAsync()
|
|
||||||
{
|
|
||||||
return await _connection.BeginTransactionAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task CommitTransactionAsync(IDbTransaction transaction)
|
|
||||||
{
|
|
||||||
transaction.Commit();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RollbackTransactionAsync(IDbTransaction transaction)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDbConnection GetConnection()
|
|
||||||
{
|
|
||||||
return _connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_connection?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
|
||||||
{
|
|
||||||
await _connection.DisposeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace WeaponPaints
|
|
||||||
{
|
|
||||||
public class SQLiteConnection : IDatabaseConnection
|
|
||||||
{
|
|
||||||
private readonly Microsoft.Data.Sqlite.SqliteConnection _connection;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
public SQLiteConnection(string connectionString, ILogger logger)
|
|
||||||
{
|
|
||||||
_connection = new Microsoft.Data.Sqlite.SqliteConnection(connectionString);
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task OpenAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _connection.OpenAsync();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError($"Unable to connect to SQLite database: {ex.Message}");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task CloseAsync()
|
|
||||||
{
|
|
||||||
await _connection.CloseAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IDbTransaction> BeginTransactionAsync()
|
|
||||||
{
|
|
||||||
return await _connection.BeginTransactionAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task CommitTransactionAsync(IDbTransaction transaction)
|
|
||||||
{
|
|
||||||
transaction.Commit();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RollbackTransactionAsync(IDbTransaction transaction)
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDbConnection GetConnection()
|
|
||||||
{
|
|
||||||
return _connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_connection?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
|
||||||
{
|
|
||||||
await _connection.DisposeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
231
Utility.cs
231
Utility.cs
@@ -20,166 +20,89 @@ namespace WeaponPaints
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await WeaponPaints.Database.GetConnectionAsync();
|
await using var connection = await WeaponPaints.Database.GetConnectionAsync();
|
||||||
string[] createTableQueries = GetCreateTableQueries();
|
await using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
// Log para debug
|
|
||||||
WeaponPaints.Instance.Logger.LogInformation($"[WeaponPaints] Creating {createTableQueries.Length} tables for {Config?.DatabaseType} database");
|
|
||||||
|
|
||||||
foreach (var query in createTableQueries)
|
try
|
||||||
{
|
{
|
||||||
try
|
string[] createTableQueries =
|
||||||
{
|
[
|
||||||
await connection.GetConnection().ExecuteAsync(query);
|
@"
|
||||||
WeaponPaints.Instance.Logger.LogInformation($"[WeaponPaints] Table created successfully");
|
CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
||||||
}
|
`steamid` varchar(18) NOT NULL,
|
||||||
catch (Exception ex)
|
`weapon_team` int(1) NOT NULL,
|
||||||
{
|
`weapon_defindex` int(6) NOT NULL,
|
||||||
WeaponPaints.Instance.Logger.LogError($"[WeaponPaints] Error creating table: {ex.Message}");
|
`weapon_paint_id` int(6) NOT NULL,
|
||||||
WeaponPaints.Instance.Logger.LogError($"[WeaponPaints] Query: {query}");
|
`weapon_wear` float NOT NULL DEFAULT 0.000001,
|
||||||
throw;
|
`weapon_seed` int(16) NOT NULL DEFAULT 0,
|
||||||
}
|
`weapon_nametag` VARCHAR(128) DEFAULT NULL,
|
||||||
}
|
`weapon_stattrak` tinyint(1) NOT NULL DEFAULT 0,
|
||||||
|
`weapon_stattrak_count` int(10) NOT NULL DEFAULT 0,
|
||||||
|
`weapon_sticker_0` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
||||||
|
`weapon_sticker_1` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
||||||
|
`weapon_sticker_2` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
||||||
|
`weapon_sticker_3` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
||||||
|
`weapon_sticker_4` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
||||||
|
`weapon_keychain` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0' COMMENT 'id;x;y;z;seed',
|
||||||
|
UNIQUE (`steamid`, `weapon_team`, `weapon_defindex`) -- Add unique constraint here
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||||
|
|
||||||
WeaponPaints.Instance.Logger.LogInformation("[WeaponPaints] All database tables created successfully");
|
@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
||||||
|
`steamid` varchar(18) NOT NULL,
|
||||||
|
`weapon_team` int(1) NOT NULL,
|
||||||
|
`knife` varchar(64) NOT NULL,
|
||||||
|
UNIQUE (`steamid`, `weapon_team`) -- Unique constraint
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||||
|
|
||||||
|
@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
||||||
|
`steamid` varchar(18) NOT NULL,
|
||||||
|
`weapon_team` int(1) NOT NULL,
|
||||||
|
`weapon_defindex` int(11) NOT NULL,
|
||||||
|
UNIQUE (`steamid`, `weapon_team`) -- Unique constraint
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||||
|
|
||||||
|
@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `wp_player_agents` (
|
||||||
|
`steamid` varchar(18) NOT NULL,
|
||||||
|
`agent_ct` varchar(64) DEFAULT NULL,
|
||||||
|
`agent_t` varchar(64) DEFAULT NULL,
|
||||||
|
UNIQUE (`steamid`) -- Unique constraint
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||||
|
|
||||||
|
@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `wp_player_music` (
|
||||||
|
`steamid` varchar(64) NOT NULL,
|
||||||
|
`weapon_team` int(1) NOT NULL,
|
||||||
|
`music_id` int(11) NOT NULL,
|
||||||
|
UNIQUE (`steamid`, `weapon_team`) -- Unique constraint
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
||||||
|
|
||||||
|
@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `wp_player_pins` (
|
||||||
|
`steamid` varchar(64) NOT NULL,
|
||||||
|
`weapon_team` int(1) NOT NULL,
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
UNIQUE (`steamid`, `weapon_team`) -- Unique constraint
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (var query in createTableQueries)
|
||||||
|
{
|
||||||
|
await connection.ExecuteAsync(query, transaction: transaction);
|
||||||
|
}
|
||||||
|
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
throw new Exception("[WeaponPaints] Unable to create tables!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
WeaponPaints.Instance.Logger.LogError($"[WeaponPaints] Database exception: {ex.Message}");
|
throw new Exception("[WeaponPaints] Unknown MySQL exception! " + ex.Message);
|
||||||
throw new Exception("[WeaponPaints] Unknown database exception! " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string[] GetCreateTableQueries()
|
|
||||||
{
|
|
||||||
if (Config?.DatabaseType?.ToLower() == "sqlite")
|
|
||||||
{
|
|
||||||
return new string[]
|
|
||||||
{
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_skins (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
weapon_team INTEGER NOT NULL,
|
|
||||||
weapon_defindex INTEGER NOT NULL,
|
|
||||||
weapon_paint_id INTEGER NOT NULL,
|
|
||||||
weapon_wear REAL NOT NULL DEFAULT 0.000001,
|
|
||||||
weapon_seed INTEGER NOT NULL DEFAULT 0,
|
|
||||||
weapon_nametag TEXT DEFAULT NULL,
|
|
||||||
weapon_stattrak INTEGER NOT NULL DEFAULT 0,
|
|
||||||
weapon_stattrak_count INTEGER NOT NULL DEFAULT 0,
|
|
||||||
weapon_sticker_0 TEXT NOT NULL DEFAULT '0;0;0;0;0;0;0',
|
|
||||||
weapon_sticker_1 TEXT NOT NULL DEFAULT '0;0;0;0;0;0;0',
|
|
||||||
weapon_sticker_2 TEXT NOT NULL DEFAULT '0;0;0;0;0;0;0',
|
|
||||||
weapon_sticker_3 TEXT NOT NULL DEFAULT '0;0;0;0;0;0;0',
|
|
||||||
weapon_sticker_4 TEXT NOT NULL DEFAULT '0;0;0;0;0;0;0',
|
|
||||||
weapon_keychain TEXT NOT NULL DEFAULT '0;0;0;0;0',
|
|
||||||
UNIQUE (steamid, weapon_team, weapon_defindex)
|
|
||||||
)",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_knife (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
weapon_team INTEGER NOT NULL,
|
|
||||||
knife TEXT NOT NULL,
|
|
||||||
UNIQUE (steamid, weapon_team)
|
|
||||||
)",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_gloves (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
weapon_team INTEGER NOT NULL,
|
|
||||||
weapon_defindex INTEGER NOT NULL,
|
|
||||||
UNIQUE (steamid, weapon_team)
|
|
||||||
)",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_agents (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
agent_ct TEXT DEFAULT NULL,
|
|
||||||
agent_t TEXT DEFAULT NULL,
|
|
||||||
UNIQUE (steamid)
|
|
||||||
)",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_music (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
weapon_team INTEGER NOT NULL,
|
|
||||||
music_id INTEGER NOT NULL,
|
|
||||||
UNIQUE (steamid, weapon_team)
|
|
||||||
)",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS wp_player_pins (
|
|
||||||
steamid TEXT NOT NULL,
|
|
||||||
weapon_team INTEGER NOT NULL,
|
|
||||||
id INTEGER NOT NULL,
|
|
||||||
UNIQUE (steamid, weapon_team)
|
|
||||||
)"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else // MySQL
|
|
||||||
{
|
|
||||||
return new string[]
|
|
||||||
{
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_skins` (
|
|
||||||
`steamid` varchar(18) NOT NULL,
|
|
||||||
`weapon_team` int(1) 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,
|
|
||||||
`weapon_nametag` VARCHAR(128) DEFAULT NULL,
|
|
||||||
`weapon_stattrak` tinyint(1) NOT NULL DEFAULT 0,
|
|
||||||
`weapon_stattrak_count` int(10) NOT NULL DEFAULT 0,
|
|
||||||
`weapon_sticker_0` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
|
||||||
`weapon_sticker_1` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
|
||||||
`weapon_sticker_2` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
|
||||||
`weapon_sticker_3` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
|
||||||
`weapon_sticker_4` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0;0;0' COMMENT 'id;schema;x;y;wear;scale;rotation',
|
|
||||||
`weapon_keychain` VARCHAR(128) NOT NULL DEFAULT '0;0;0;0;0' COMMENT 'id;x;y;z;seed',
|
|
||||||
UNIQUE (`steamid`, `weapon_team`, `weapon_defindex`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_knife` (
|
|
||||||
`steamid` varchar(18) NOT NULL,
|
|
||||||
`weapon_team` int(1) NOT NULL,
|
|
||||||
`knife` varchar(64) NOT NULL,
|
|
||||||
UNIQUE (`steamid`, `weapon_team`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_gloves` (
|
|
||||||
`steamid` varchar(18) NOT NULL,
|
|
||||||
`weapon_team` int(1) NOT NULL,
|
|
||||||
`weapon_defindex` int(11) NOT NULL,
|
|
||||||
UNIQUE (`steamid`, `weapon_team`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_agents` (
|
|
||||||
`steamid` varchar(18) NOT NULL,
|
|
||||||
`agent_ct` varchar(64) DEFAULT NULL,
|
|
||||||
`agent_t` varchar(64) DEFAULT NULL,
|
|
||||||
UNIQUE (`steamid`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_music` (
|
|
||||||
`steamid` varchar(64) NOT NULL,
|
|
||||||
`weapon_team` int(1) NOT NULL,
|
|
||||||
`music_id` int(11) NOT NULL,
|
|
||||||
UNIQUE (`steamid`, `weapon_team`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;",
|
|
||||||
|
|
||||||
@"
|
|
||||||
CREATE TABLE IF NOT EXISTS `wp_player_pins` (
|
|
||||||
`steamid` varchar(64) NOT NULL,
|
|
||||||
`weapon_team` int(1) NOT NULL,
|
|
||||||
`id` int(11) NOT NULL,
|
|
||||||
UNIQUE (`steamid`, `weapon_team`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -332,13 +332,27 @@ namespace WeaponPaints
|
|||||||
if (!PlayerHasKnife(player) && hasKnife)
|
if (!PlayerHasKnife(player) && hasKnife)
|
||||||
{
|
{
|
||||||
var newKnife = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.Knife));
|
var newKnife = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.Knife));
|
||||||
newKnife.AddEntityIOEvent("Kill", newKnife, null, "", 0.01f);
|
|
||||||
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP));
|
var newWeapon = new CBasePlayerWeapon(player.GiveNamedItem(CsItem.USP));
|
||||||
player.GiveNamedItem(CsItem.Knife);
|
player.GiveNamedItem(CsItem.Knife);
|
||||||
player.ExecuteClientCommand("slot3");
|
player.ExecuteClientCommand("slot3");
|
||||||
newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f);
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (newKnife != null && newKnife.IsValid)
|
||||||
|
newKnife.AddEntityIOEvent("Kill", newKnife, null, "", 0.01f);
|
||||||
|
if (newWeapon != null && newWeapon.IsValid)
|
||||||
|
newWeapon.AddEntityIOEvent("Kill", newWeapon, null, "", 0.01f);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning("Error AddEntityIOEvent " + ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach (var entry in weaponsWithAmmo)
|
foreach (var entry in weaponsWithAmmo)
|
||||||
{
|
{
|
||||||
foreach (var ammo in entry.Value)
|
foreach (var ammo in entry.Value)
|
||||||
|
|||||||
267
WeaponPaints.cs
267
WeaponPaints.cs
@@ -13,173 +13,134 @@ namespace WeaponPaints;
|
|||||||
[MinimumApiVersion(338)]
|
[MinimumApiVersion(338)]
|
||||||
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
public partial class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||||
{
|
{
|
||||||
internal static WeaponPaints Instance { get; private set; } = new();
|
internal static WeaponPaints Instance { get; private set; } = new();
|
||||||
|
|
||||||
public WeaponPaintsConfig Config { get; set; } = new();
|
public WeaponPaintsConfig Config { get; set; } = new();
|
||||||
private static WeaponPaintsConfig _config { get; set; } = new();
|
private static WeaponPaintsConfig _config { get; set; } = new();
|
||||||
public override string ModuleAuthor => "Nereziel & daffyy";
|
public override string ModuleAuthor => "Nereziel & daffyy";
|
||||||
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
public override string ModuleDescription => "Skin, gloves, agents and knife selector, standalone and web-based";
|
||||||
public override string ModuleName => "WeaponPaints";
|
public override string ModuleName => "WeaponPaints";
|
||||||
public override string ModuleVersion => "3.2a";
|
public override string ModuleVersion => "3.2a";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
// Hardcoded hotfix needs to be changed later (Not needed 17.09.2025)
|
// Hardcoded hotfix needs to be changed later (Not needed 17.09.2025)
|
||||||
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
//if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
// Patch.PerformPatch("0F 85 ? ? ? ? 31 C0 B9 ? ? ? ? BA ? ? ? ? 66 0F EF C0 31 F6 31 FF 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 0F 29 45 ? 48 C7 45 ? ? ? ? ? C7 45 ? ? ? ? ? 66 89 45 ? E8 ? ? ? ? 41 89 C5 85 C0 0F 8E", "90 90 90 90 90 90");
|
// Patch.PerformPatch("0F 85 ? ? ? ? 31 C0 B9 ? ? ? ? BA ? ? ? ? 66 0F EF C0 31 F6 31 FF 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 48 C7 45 ? ? ? ? ? 0F 29 45 ? 48 C7 45 ? ? ? ? ? C7 45 ? ? ? ? ? 66 89 45 ? E8 ? ? ? ? 41 89 C5 85 C0 0F 8E", "90 90 90 90 90 90");
|
||||||
//else
|
//else
|
||||||
// Patch.PerformPatch("74 ? 48 8D 0D ? ? ? ? FF 15 ? ? ? ? EB ? BA", "EB");
|
// Patch.PerformPatch("74 ? 48 8D 0D ? ? ? ? FF 15 ? ? ? ? EB ? BA", "EB");
|
||||||
|
|
||||||
|
Instance = this;
|
||||||
|
|
||||||
Instance = this;
|
if (hotReload)
|
||||||
|
{
|
||||||
|
OnMapStart(string.Empty);
|
||||||
|
|
||||||
|
GPlayerWeaponsInfo.Clear();
|
||||||
|
GPlayersKnife.Clear();
|
||||||
|
GPlayersGlove.Clear();
|
||||||
|
GPlayersAgent.Clear();
|
||||||
|
GPlayersPin.Clear();
|
||||||
|
GPlayersMusic.Clear();
|
||||||
|
|
||||||
if (hotReload)
|
foreach (var player in Enumerable
|
||||||
{
|
.OfType<CCSPlayerController>(Utilities.GetPlayers().TakeWhile(_ => WeaponSync != null))
|
||||||
OnMapStart(string.Empty);
|
.Where(player => player.IsValid &&
|
||||||
|
!string.IsNullOrEmpty(player.IpAddress) && player is
|
||||||
|
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
|
||||||
|
{
|
||||||
|
var playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Slot = player.Slot,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.SteamID.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
GPlayerWeaponsInfo.Clear();
|
_ = Task.Run(async () =>
|
||||||
GPlayersKnife.Clear();
|
{
|
||||||
GPlayersGlove.Clear();
|
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
|
||||||
GPlayersAgent.Clear();
|
});
|
||||||
GPlayersPin.Clear();
|
}
|
||||||
GPlayersMusic.Clear();
|
}
|
||||||
|
|
||||||
foreach (var player in Enumerable
|
Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
|
||||||
.OfType<CCSPlayerController>(Utilities.GetPlayers().TakeWhile(_ => WeaponSync != null))
|
Utility.LoadGlovesFromFile(ModuleDirectory + $"/data/gloves_{_config.SkinsLanguage}.json", Logger);
|
||||||
.Where(player => player.IsValid &&
|
Utility.LoadAgentsFromFile(ModuleDirectory + $"/data/agents_{_config.SkinsLanguage}.json", Logger);
|
||||||
!string.IsNullOrEmpty(player.IpAddress) && player is
|
Utility.LoadMusicFromFile(ModuleDirectory + $"/data/music_{_config.SkinsLanguage}.json", Logger);
|
||||||
{ IsBot: false, Connected: PlayerConnectedState.PlayerConnected }))
|
Utility.LoadPinsFromFile(ModuleDirectory + $"/data/collectibles_{_config.SkinsLanguage}.json", Logger);
|
||||||
{
|
|
||||||
var playerInfo = new PlayerInfo
|
|
||||||
{
|
|
||||||
UserId = player.UserId,
|
|
||||||
Slot = player.Slot,
|
|
||||||
Index = (int)player.Index,
|
|
||||||
SteamId = player?.SteamID.ToString(),
|
|
||||||
Name = player?.PlayerName,
|
|
||||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
|
||||||
};
|
|
||||||
|
|
||||||
_ = Task.Run(async () =>
|
RegisterListeners();
|
||||||
{
|
}
|
||||||
if (WeaponSync != null) await WeaponSync.GetPlayerData(playerInfo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Utility.LoadSkinsFromFile(ModuleDirectory + $"/data/skins_{_config.SkinsLanguage}.json", Logger);
|
public void OnConfigParsed(WeaponPaintsConfig config)
|
||||||
Utility.LoadGlovesFromFile(ModuleDirectory + $"/data/gloves_{_config.SkinsLanguage}.json", Logger);
|
{
|
||||||
Utility.LoadAgentsFromFile(ModuleDirectory + $"/data/agents_{_config.SkinsLanguage}.json", Logger);
|
Config = config;
|
||||||
Utility.LoadMusicFromFile(ModuleDirectory + $"/data/music_{_config.SkinsLanguage}.json", Logger);
|
_config = config;
|
||||||
Utility.LoadPinsFromFile(ModuleDirectory + $"/data/collectibles_{_config.SkinsLanguage}.json", Logger);
|
|
||||||
|
|
||||||
RegisterListeners();
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
}
|
{
|
||||||
|
Logger.LogError("You need to setup Database credentials in \"configs/plugins/WeaponPaints/WeaponPaints.json\"!");
|
||||||
|
Unload(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnConfigParsed(WeaponPaintsConfig config)
|
if (!File.Exists(Path.GetDirectoryName(Path.GetDirectoryName(ModuleDirectory)) + "/gamedata/weaponpaints.json"))
|
||||||
{
|
{
|
||||||
Config = config;
|
Logger.LogError("You need to upload \"weaponpaints.json\" to \"gamedata directory\"!");
|
||||||
_config = config;
|
Unload(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new MySqlConnectionStringBuilder
|
||||||
|
{
|
||||||
|
Server = config.DatabaseHost,
|
||||||
|
UserID = config.DatabaseUser,
|
||||||
|
Password = config.DatabasePassword,
|
||||||
|
Database = config.DatabaseName,
|
||||||
|
Port = (uint)config.DatabasePort,
|
||||||
|
Pooling = true,
|
||||||
|
MaximumPoolSize = 640,
|
||||||
|
};
|
||||||
|
|
||||||
// Validar configurações de banco de dados
|
Database = new Database(builder.ConnectionString);
|
||||||
if (config.DatabaseType.ToLower() == "mysql")
|
|
||||||
{
|
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
|
||||||
{
|
|
||||||
Logger.LogError("You need to setup MySQL Database credentials in \"configs/plugins/WeaponPaints/WeaponPaints.json\"!");
|
|
||||||
Unload(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (config.DatabaseType.ToLower() == "sqlite")
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(config.DatabasePath))
|
|
||||||
{
|
|
||||||
Logger.LogError("You need to setup SQLite Database path in \"configs/plugins/WeaponPaints/WeaponPaints.json\"!");
|
|
||||||
Unload(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.LogError("Invalid DatabaseType. Use 'mysql' or 'sqlite'.");
|
|
||||||
Unload(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!File.Exists(Path.GetDirectoryName(Path.GetDirectoryName(ModuleDirectory)) + "/gamedata/weaponpaints.json"))
|
_ = Utility.CheckDatabaseTables();
|
||||||
{
|
_localizer = Localizer;
|
||||||
Logger.LogError("You need to upload \"weaponpaints.json\" to \"gamedata directory\"!");
|
|
||||||
Unload(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Criar factory de conexão baseada no tipo de banco
|
Utility.Config = config;
|
||||||
Func<IDatabaseConnection> connectionFactory;
|
Utility.ShowAd(ModuleVersion);
|
||||||
if (config.DatabaseType.ToLower() == "mysql")
|
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
||||||
{
|
}
|
||||||
var builder = new MySqlConnectionStringBuilder
|
|
||||||
{
|
|
||||||
Server = config.DatabaseHost,
|
|
||||||
UserID = config.DatabaseUser,
|
|
||||||
Password = config.DatabasePassword,
|
|
||||||
Database = config.DatabaseName,
|
|
||||||
Port = (uint)config.DatabasePort,
|
|
||||||
Pooling = true,
|
|
||||||
MaximumPoolSize = 640,
|
|
||||||
};
|
|
||||||
connectionFactory = () => new MySQLConnection(builder.ConnectionString, Logger);
|
|
||||||
}
|
|
||||||
else // SQLite
|
|
||||||
{
|
|
||||||
// Garantir que o diretório existe
|
|
||||||
var dbPath = Path.GetFullPath(config.DatabasePath);
|
|
||||||
var dbDirectory = Path.GetDirectoryName(dbPath);
|
|
||||||
if (!string.IsNullOrEmpty(dbDirectory) && !Directory.Exists(dbDirectory))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(dbDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
var connectionString = $"Data Source={dbPath}";
|
public override void OnAllPluginsLoaded(bool hotReload)
|
||||||
Logger.LogInformation($"[WeaponPaints] SQLite database path: {dbPath}");
|
{
|
||||||
|
try
|
||||||
connectionFactory = () => new SQLiteConnection(connectionString, Logger);
|
{
|
||||||
}
|
MenuApi = MenuCapability.Get();
|
||||||
|
|
||||||
Database = new Database(connectionFactory);
|
if (Config.Additional.KnifeEnabled)
|
||||||
|
SetupKnifeMenu();
|
||||||
Utility.Config = config;
|
if (Config.Additional.SkinEnabled)
|
||||||
Task.Run(async () => await Utility.CheckDatabaseTables());
|
SetupSkinsMenu();
|
||||||
_localizer = Localizer;
|
if (Config.Additional.GloveEnabled)
|
||||||
Utility.ShowAd(ModuleVersion);
|
SetupGlovesMenu();
|
||||||
Task.Run(async () => await Utility.CheckVersion(ModuleVersion, Logger));
|
if (Config.Additional.AgentEnabled)
|
||||||
}
|
SetupAgentsMenu();
|
||||||
|
if (Config.Additional.MusicEnabled)
|
||||||
public override void OnAllPluginsLoaded(bool hotReload)
|
SetupMusicMenu();
|
||||||
{
|
if (Config.Additional.PinsEnabled)
|
||||||
try
|
SetupPinsMenu();
|
||||||
{
|
|
||||||
MenuApi = MenuCapability.Get();
|
RegisterCommands();
|
||||||
|
}
|
||||||
if (Config.Additional.KnifeEnabled)
|
catch (Exception)
|
||||||
SetupKnifeMenu();
|
{
|
||||||
if (Config.Additional.SkinEnabled)
|
MenuApi = null;
|
||||||
SetupSkinsMenu();
|
Logger.LogError("Error while loading required plugins");
|
||||||
if (Config.Additional.GloveEnabled)
|
throw;
|
||||||
SetupGlovesMenu();
|
}
|
||||||
if (Config.Additional.AgentEnabled)
|
}
|
||||||
SetupAgentsMenu();
|
|
||||||
if (Config.Additional.MusicEnabled)
|
|
||||||
SetupMusicMenu();
|
|
||||||
if (Config.Additional.PinsEnabled)
|
|
||||||
SetupPinsMenu();
|
|
||||||
|
|
||||||
RegisterCommands();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
MenuApi = null;
|
|
||||||
Logger.LogError("Error while loading required plugins");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,21 +9,20 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.342" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.358" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
<PackageReference Include="MySqlConnector" Version="2.4.0" />
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="gamedata\*.*" CopyToOutputDirectory="PreserveNewest" />
|
<None Update="gamedata\*.*" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="MenuManagerApi">
|
<Reference Include="MenuManagerApi">
|
||||||
<HintPath>3rd_party\MenuManagerApi.dll</HintPath>
|
<HintPath>3rd_party\MenuManagerApi.dll</HintPath>
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"ConfigVersion": 10,
|
|
||||||
"SkinsLanguage": "pt-BR",
|
|
||||||
"DatabaseType": "sqlite",
|
|
||||||
"DatabasePath": "weaponpaints.db",
|
|
||||||
"DatabaseHost": "",
|
|
||||||
"DatabasePort": 3306,
|
|
||||||
"DatabaseUser": "",
|
|
||||||
"DatabasePassword": "",
|
|
||||||
"DatabaseName": "",
|
|
||||||
"CmdRefreshCooldownSeconds": 3,
|
|
||||||
"Website": "example.com/skins",
|
|
||||||
"Additional": {
|
|
||||||
"KnifeEnabled": true,
|
|
||||||
"GloveEnabled": true,
|
|
||||||
"MusicEnabled": true,
|
|
||||||
"AgentEnabled": true,
|
|
||||||
"SkinEnabled": true,
|
|
||||||
"PinsEnabled": true,
|
|
||||||
"CommandWpEnabled": true,
|
|
||||||
"CommandKillEnabled": true,
|
|
||||||
"CommandKnife": ["knife"],
|
|
||||||
"CommandMusic": ["music"],
|
|
||||||
"CommandPin": ["pin", "pins", "coin", "coins"],
|
|
||||||
"CommandGlove": ["gloves"],
|
|
||||||
"CommandAgent": ["agents"],
|
|
||||||
"CommandStattrak": ["stattrak", "st"],
|
|
||||||
"CommandSkin": ["ws"],
|
|
||||||
"CommandSkinSelection": ["skins"],
|
|
||||||
"CommandRefresh": ["wp"],
|
|
||||||
"CommandKill": ["kill"],
|
|
||||||
"GiveRandomKnife": false,
|
|
||||||
"GiveRandomSkin": false,
|
|
||||||
"ShowSkinImage": true
|
|
||||||
},
|
|
||||||
"MenuType": "selectable"
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
|
using MySqlConnector;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Data;
|
|
||||||
|
|
||||||
namespace WeaponPaints;
|
namespace WeaponPaints;
|
||||||
|
|
||||||
@@ -24,17 +24,17 @@ internal class WeaponSynchronization
|
|||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
if (_config.Additional.KnifeEnabled)
|
if (_config.Additional.KnifeEnabled)
|
||||||
GetKnifeFromDatabase(player, connection.GetConnection());
|
GetKnifeFromDatabase(player, connection);
|
||||||
if (_config.Additional.GloveEnabled)
|
if (_config.Additional.GloveEnabled)
|
||||||
GetGloveFromDatabase(player, connection.GetConnection());
|
GetGloveFromDatabase(player, connection);
|
||||||
if (_config.Additional.AgentEnabled)
|
if (_config.Additional.AgentEnabled)
|
||||||
GetAgentFromDatabase(player, connection.GetConnection());
|
GetAgentFromDatabase(player, connection);
|
||||||
if (_config.Additional.MusicEnabled)
|
if (_config.Additional.MusicEnabled)
|
||||||
GetMusicFromDatabase(player, connection.GetConnection());
|
GetMusicFromDatabase(player, connection);
|
||||||
if (_config.Additional.SkinEnabled)
|
if (_config.Additional.SkinEnabled)
|
||||||
GetWeaponPaintsFromDatabase(player, connection.GetConnection());
|
GetWeaponPaintsFromDatabase(player, connection);
|
||||||
if (_config.Additional.PinsEnabled)
|
if (_config.Additional.PinsEnabled)
|
||||||
GetPinsFromDatabase(player, connection.GetConnection());
|
GetPinsFromDatabase(player, connection);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -43,16 +43,14 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetKnifeFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetKnifeFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player?.SteamId))
|
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT `knife`, `weapon_team` FROM `wp_player_knife` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
||||||
? "SELECT knife, weapon_team FROM wp_player_knife WHERE steamid = @steamid ORDER BY weapon_team ASC"
|
|
||||||
: "SELECT `knife`, `weapon_team` FROM `wp_player_knife` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
|
||||||
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
||||||
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
@@ -61,14 +59,14 @@ internal class WeaponSynchronization
|
|||||||
if (string.IsNullOrEmpty(row.knife)) continue;
|
if (string.IsNullOrEmpty(row.knife)) continue;
|
||||||
|
|
||||||
// Determine the weapon team based on the query result
|
// Determine the weapon team based on the query result
|
||||||
CsTeam weaponTeam = Convert.ToInt32(row.weapon_team) switch
|
CsTeam weaponTeam = (int)row.weapon_team switch
|
||||||
{
|
{
|
||||||
2 => CsTeam.Terrorist,
|
2 => CsTeam.Terrorist,
|
||||||
3 => CsTeam.CounterTerrorist,
|
3 => CsTeam.CounterTerrorist,
|
||||||
_ => CsTeam.None,
|
_ => CsTeam.None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get or create entries for the player's slot
|
// Get or create entries for the player’s slot
|
||||||
var playerKnives = WeaponPaints.GPlayersKnife.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, string>());
|
var playerKnives = WeaponPaints.GPlayersKnife.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, string>());
|
||||||
|
|
||||||
if (weaponTeam == CsTeam.None)
|
if (weaponTeam == CsTeam.None)
|
||||||
@@ -90,16 +88,14 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetGloveFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetGloveFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player?.SteamId))
|
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT `weapon_defindex`, `weapon_team` FROM `wp_player_gloves` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
||||||
? "SELECT weapon_defindex, weapon_team FROM wp_player_gloves WHERE steamid = @steamid ORDER BY weapon_team ASC"
|
|
||||||
: "SELECT `weapon_defindex`, `weapon_team` FROM `wp_player_gloves` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
|
||||||
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
||||||
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
@@ -108,7 +104,7 @@ internal class WeaponSynchronization
|
|||||||
if (row.weapon_defindex == null) continue;
|
if (row.weapon_defindex == null) continue;
|
||||||
// Determine the weapon team based on the query result
|
// Determine the weapon team based on the query result
|
||||||
var playerGloves = WeaponPaints.GPlayersGlove.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
var playerGloves = WeaponPaints.GPlayersGlove.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
||||||
CsTeam weaponTeam = Convert.ToInt32(row.weapon_team) switch
|
CsTeam weaponTeam = (int)row.weapon_team switch
|
||||||
{
|
{
|
||||||
2 => CsTeam.Terrorist,
|
2 => CsTeam.Terrorist,
|
||||||
3 => CsTeam.CounterTerrorist,
|
3 => CsTeam.CounterTerrorist,
|
||||||
@@ -120,13 +116,13 @@ internal class WeaponSynchronization
|
|||||||
if (weaponTeam == CsTeam.None)
|
if (weaponTeam == CsTeam.None)
|
||||||
{
|
{
|
||||||
// Assign glove ID to both teams if weaponTeam is None
|
// Assign glove ID to both teams if weaponTeam is None
|
||||||
playerGloves[CsTeam.Terrorist] = Convert.ToUInt16(row.weapon_defindex);
|
playerGloves[CsTeam.Terrorist] = (ushort)row.weapon_defindex;
|
||||||
playerGloves[CsTeam.CounterTerrorist] = Convert.ToUInt16(row.weapon_defindex);
|
playerGloves[CsTeam.CounterTerrorist] = (ushort)row.weapon_defindex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assign glove ID to the specific team
|
// Assign glove ID to the specific team
|
||||||
playerGloves[weaponTeam] = Convert.ToUInt16(row.weapon_defindex);
|
playerGloves[weaponTeam] = (ushort)row.weapon_defindex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,16 +132,14 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetAgentFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetAgentFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_config.Additional.AgentEnabled || string.IsNullOrEmpty(player?.SteamId))
|
if (!_config.Additional.AgentEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT `agent_ct`, `agent_t` FROM `wp_player_agents` WHERE `steamid` = @steamid";
|
||||||
? "SELECT agent_ct, agent_t FROM wp_player_agents WHERE steamid = @steamid"
|
|
||||||
: "SELECT `agent_ct`, `agent_t` FROM `wp_player_agents` WHERE `steamid` = @steamid";
|
|
||||||
var agentData = connection.QueryFirstOrDefault<(string, string)>(query, new { steamid = player.SteamId });
|
var agentData = connection.QueryFirstOrDefault<(string, string)>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
if (agentData == default) return;
|
if (agentData == default) return;
|
||||||
@@ -166,7 +160,7 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetWeaponPaintsFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetWeaponPaintsFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -178,22 +172,20 @@ internal class WeaponSynchronization
|
|||||||
|
|
||||||
// var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
// var weaponInfos = new ConcurrentDictionary<int, WeaponInfo>();
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
||||||
? "SELECT * FROM wp_player_skins WHERE steamid = @steamid ORDER BY weapon_team ASC"
|
|
||||||
: "SELECT * FROM `wp_player_skins` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
|
||||||
var playerSkins = connection.Query<dynamic>(query, new { steamid = player.SteamId });
|
var playerSkins = connection.Query<dynamic>(query, new { steamid = player.SteamId });
|
||||||
|
|
||||||
foreach (var row in playerSkins)
|
foreach (var row in playerSkins)
|
||||||
{
|
{
|
||||||
int weaponDefIndex = Convert.ToInt32(row.weapon_defindex ?? 0);
|
int weaponDefIndex = row.weapon_defindex ?? 0;
|
||||||
int weaponPaintId = Convert.ToInt32(row.weapon_paint_id ?? 0);
|
int weaponPaintId = row.weapon_paint_id ?? 0;
|
||||||
float weaponWear = Convert.ToSingle(row.weapon_wear ?? 0f);
|
float weaponWear = row.weapon_wear ?? 0f;
|
||||||
int weaponSeed = Convert.ToInt32(row.weapon_seed ?? 0);
|
int weaponSeed = row.weapon_seed ?? 0;
|
||||||
string weaponNameTag = row.weapon_nametag?.ToString() ?? "";
|
string weaponNameTag = row.weapon_nametag ?? "";
|
||||||
bool weaponStatTrak = Convert.ToBoolean(row.weapon_stattrak ?? false);
|
bool weaponStatTrak = row.weapon_stattrak ?? false;
|
||||||
int weaponStatTrakCount = Convert.ToInt32(row.weapon_stattrak_count ?? 0);
|
int weaponStatTrakCount = row.weapon_stattrak_count ?? 0;
|
||||||
|
|
||||||
CsTeam weaponTeam = Convert.ToInt32(row.weapon_team) switch
|
CsTeam weaponTeam = row.weapon_team switch
|
||||||
{
|
{
|
||||||
2 => CsTeam.Terrorist,
|
2 => CsTeam.Terrorist,
|
||||||
3 => CsTeam.CounterTerrorist,
|
3 => CsTeam.CounterTerrorist,
|
||||||
@@ -303,16 +295,14 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetMusicFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetMusicFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!_config.Additional.MusicEnabled || string.IsNullOrEmpty(player?.SteamId))
|
if (!_config.Additional.MusicEnabled || string.IsNullOrEmpty(player?.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT `music_id`, `weapon_team` FROM `wp_player_music` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
||||||
? "SELECT music_id, weapon_team FROM wp_player_music WHERE steamid = @steamid ORDER BY weapon_team ASC"
|
|
||||||
: "SELECT `music_id`, `weapon_team` FROM `wp_player_music` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
|
||||||
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
||||||
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
@@ -321,26 +311,26 @@ internal class WeaponSynchronization
|
|||||||
if (row.music_id == null) continue;
|
if (row.music_id == null) continue;
|
||||||
|
|
||||||
// Determine the weapon team based on the query result
|
// Determine the weapon team based on the query result
|
||||||
CsTeam weaponTeam = Convert.ToInt32(row.weapon_team) switch
|
CsTeam weaponTeam = (int)row.weapon_team switch
|
||||||
{
|
{
|
||||||
2 => CsTeam.Terrorist,
|
2 => CsTeam.Terrorist,
|
||||||
3 => CsTeam.CounterTerrorist,
|
3 => CsTeam.CounterTerrorist,
|
||||||
_ => CsTeam.None,
|
_ => CsTeam.None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get or create entries for the player's slot
|
// Get or create entries for the player’s slot
|
||||||
var playerMusic = WeaponPaints.GPlayersMusic.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
var playerMusic = WeaponPaints.GPlayersMusic.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
||||||
|
|
||||||
if (weaponTeam == CsTeam.None)
|
if (weaponTeam == CsTeam.None)
|
||||||
{
|
{
|
||||||
// Assign music ID to both teams if weaponTeam is None
|
// Assign music ID to both teams if weaponTeam is None
|
||||||
playerMusic[CsTeam.Terrorist] = Convert.ToUInt16(row.music_id);
|
playerMusic[CsTeam.Terrorist] = (ushort)row.music_id;
|
||||||
playerMusic[CsTeam.CounterTerrorist] = Convert.ToUInt16(row.music_id);
|
playerMusic[CsTeam.CounterTerrorist] = (ushort)row.music_id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assign music ID to the specific team
|
// Assign music ID to the specific team
|
||||||
playerMusic[weaponTeam] = Convert.ToUInt16(row.music_id);
|
playerMusic[weaponTeam] = (ushort)row.music_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -350,16 +340,14 @@ internal class WeaponSynchronization
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetPinsFromDatabase(PlayerInfo? player, IDbConnection connection)
|
private void GetPinsFromDatabase(PlayerInfo? player, MySqlConnection connection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(player?.SteamId))
|
if (string.IsNullOrEmpty(player?.SteamId))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "SELECT `id`, `weapon_team` FROM `wp_player_pins` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
||||||
? "SELECT id, weapon_team FROM wp_player_pins WHERE steamid = @steamid ORDER BY weapon_team ASC"
|
|
||||||
: "SELECT `id`, `weapon_team` FROM `wp_player_pins` WHERE `steamid` = @steamid ORDER BY `weapon_team` ASC";
|
|
||||||
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
var rows = connection.Query<dynamic>(query, new { steamid = player.SteamId }); // Retrieve all records for the player
|
||||||
|
|
||||||
foreach (var row in rows)
|
foreach (var row in rows)
|
||||||
@@ -368,26 +356,26 @@ internal class WeaponSynchronization
|
|||||||
if (row.id == null) continue;
|
if (row.id == null) continue;
|
||||||
|
|
||||||
// Determine the weapon team based on the query result
|
// Determine the weapon team based on the query result
|
||||||
CsTeam weaponTeam = Convert.ToInt32(row.weapon_team) switch
|
CsTeam weaponTeam = (int)row.weapon_team switch
|
||||||
{
|
{
|
||||||
2 => CsTeam.Terrorist,
|
2 => CsTeam.Terrorist,
|
||||||
3 => CsTeam.CounterTerrorist,
|
3 => CsTeam.CounterTerrorist,
|
||||||
_ => CsTeam.None,
|
_ => CsTeam.None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get or create entries for the player's slot
|
// Get or create entries for the player’s slot
|
||||||
var playerPins = WeaponPaints.GPlayersPin.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
var playerPins = WeaponPaints.GPlayersPin.GetOrAdd(player.Slot, _ => new ConcurrentDictionary<CsTeam, ushort>());
|
||||||
|
|
||||||
if (weaponTeam == CsTeam.None)
|
if (weaponTeam == CsTeam.None)
|
||||||
{
|
{
|
||||||
// Assign pin ID to both teams if weaponTeam is None
|
// Assign pin ID to both teams if weaponTeam is None
|
||||||
playerPins[CsTeam.Terrorist] = Convert.ToUInt16(row.id);
|
playerPins[CsTeam.Terrorist] = (ushort)row.id;
|
||||||
playerPins[CsTeam.CounterTerrorist] = Convert.ToUInt16(row.id);
|
playerPins[CsTeam.CounterTerrorist] = (ushort)row.id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Assign pin ID to the specific team
|
// Assign pin ID to the specific team
|
||||||
playerPins[weaponTeam] = Convert.ToUInt16(row.id);
|
playerPins[weaponTeam] = (ushort)row.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,9 +389,7 @@ internal class WeaponSynchronization
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player.SteamId) || string.IsNullOrEmpty(knife) || teams.Length == 0) return;
|
if (!_config.Additional.KnifeEnabled || string.IsNullOrEmpty(player.SteamId) || string.IsNullOrEmpty(knife) || teams.Length == 0) return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "INSERT INTO `wp_player_knife` (`steamid`, `weapon_team`, `knife`) VALUES(@steamid, @team, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
||||||
? "INSERT OR REPLACE INTO wp_player_knife (steamid, weapon_team, knife) VALUES(@steamid, @team, @newKnife)"
|
|
||||||
: "INSERT INTO `wp_player_knife` (`steamid`, `weapon_team`, `knife`) VALUES(@steamid, @team, @newKnife) ON DUPLICATE KEY UPDATE `knife` = @newKnife";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -412,7 +398,7 @@ internal class WeaponSynchronization
|
|||||||
// Loop through each team and insert/update accordingly
|
// Loop through each team and insert/update accordingly
|
||||||
foreach (var team in teams)
|
foreach (var team in teams)
|
||||||
{
|
{
|
||||||
await connection.GetConnection().ExecuteAsync(query, new { steamid = player.SteamId, team, newKnife = knife });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, team, newKnife = knife });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -427,9 +413,8 @@ internal class WeaponSynchronization
|
|||||||
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player.SteamId) || teams.Length == 0)
|
if (!_config.Additional.GloveEnabled || string.IsNullOrEmpty(player.SteamId) || teams.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = @"
|
||||||
? "INSERT OR REPLACE INTO wp_player_gloves (steamid, weapon_team, weapon_defindex) VALUES(@steamid, @team, @gloveDefIndex)"
|
INSERT INTO `wp_player_gloves` (`steamid`, `weapon_team`, `weapon_defindex`)
|
||||||
: @"INSERT INTO `wp_player_gloves` (`steamid`, `weapon_team`, `weapon_defindex`)
|
|
||||||
VALUES(@steamid, @team, @gloveDefIndex)
|
VALUES(@steamid, @team, @gloveDefIndex)
|
||||||
ON DUPLICATE KEY UPDATE `weapon_defindex` = @gloveDefIndex";
|
ON DUPLICATE KEY UPDATE `weapon_defindex` = @gloveDefIndex";
|
||||||
|
|
||||||
@@ -442,7 +427,7 @@ internal class WeaponSynchronization
|
|||||||
foreach (var team in teams)
|
foreach (var team in teams)
|
||||||
{
|
{
|
||||||
// Execute the SQL command for each team
|
// Execute the SQL command for each team
|
||||||
await connection.GetConnection().ExecuteAsync(query, new {
|
await connection.ExecuteAsync(query, new {
|
||||||
steamid = player.SteamId,
|
steamid = player.SteamId,
|
||||||
team = (int)team, // Cast the CsTeam enum to int for insertion
|
team = (int)team, // Cast the CsTeam enum to int for insertion
|
||||||
gloveDefIndex
|
gloveDefIndex
|
||||||
@@ -460,14 +445,18 @@ internal class WeaponSynchronization
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.AgentEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
if (!_config.Additional.AgentEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = """
|
||||||
? "INSERT OR REPLACE INTO wp_player_agents (steamid, agent_ct, agent_t) VALUES(@steamid, @agent_ct, @agent_t)"
|
INSERT INTO `wp_player_agents` (`steamid`, `agent_ct`, `agent_t`)
|
||||||
: "INSERT INTO `wp_player_agents` (`steamid`, `agent_ct`, `agent_t`) VALUES(@steamid, @agent_ct, @agent_t) ON DUPLICATE KEY UPDATE `agent_ct` = @agent_ct, `agent_t` = @agent_t";
|
VALUES(@steamid, @agent_ct, @agent_t)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
`agent_ct` = @agent_ct,
|
||||||
|
`agent_t` = @agent_t
|
||||||
|
""";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
await connection.GetConnection().ExecuteAsync(query, new { steamid = player.SteamId, agent_ct = WeaponPaints.GPlayersAgent[player.Slot].CT, agent_t = WeaponPaints.GPlayersAgent[player.Slot].T });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, agent_ct = WeaponPaints.GPlayersAgent[player.Slot].CT, agent_t = WeaponPaints.GPlayersAgent[player.Slot].T });
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -494,11 +483,9 @@ internal class WeaponSynchronization
|
|||||||
var seed = weaponInfo.Seed;
|
var seed = weaponInfo.Seed;
|
||||||
|
|
||||||
// Prepare the queries to check and update/insert weapon skin data
|
// Prepare the queries to check and update/insert weapon skin data
|
||||||
string queryCheckExistence = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string queryCheckExistence = "SELECT COUNT(*) FROM `wp_player_skins` WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex AND `weapon_team` = @weaponTeam";
|
||||||
? "SELECT COUNT(*) FROM wp_player_skins WHERE steamid = @steamid AND weapon_defindex = @weaponDefIndex AND weapon_team = @weaponTeam"
|
|
||||||
: "SELECT COUNT(*) FROM `wp_player_skins` WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex AND `weapon_team` = @weaponTeam";
|
|
||||||
|
|
||||||
var existingRecordCount = await connection.GetConnection().ExecuteScalarAsync<int>(
|
var existingRecordCount = await connection.ExecuteScalarAsync<int>(
|
||||||
queryCheckExistence,
|
queryCheckExistence,
|
||||||
new { steamid = player.SteamId, weaponDefIndex, weaponTeam = teamId }
|
new { steamid = player.SteamId, weaponDefIndex, weaponTeam = teamId }
|
||||||
);
|
);
|
||||||
@@ -509,21 +496,19 @@ internal class WeaponSynchronization
|
|||||||
if (existingRecordCount > 0)
|
if (existingRecordCount > 0)
|
||||||
{
|
{
|
||||||
// Update existing record
|
// Update existing record
|
||||||
query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
query = "UPDATE `wp_player_skins` SET `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed " +
|
||||||
? "UPDATE wp_player_skins SET weapon_paint_id = @paintId, weapon_wear = @wear, weapon_seed = @seed WHERE steamid = @steamid AND weapon_defindex = @weaponDefIndex AND weapon_team = @weaponTeam"
|
"WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex AND `weapon_team` = @weaponTeam";
|
||||||
: "UPDATE `wp_player_skins` SET `weapon_paint_id` = @paintId, `weapon_wear` = @wear, `weapon_seed` = @seed WHERE `steamid` = @steamid AND `weapon_defindex` = @weaponDefIndex AND `weapon_team` = @weaponTeam";
|
|
||||||
parameters = new { steamid = player.SteamId, weaponDefIndex, weaponTeam = (int)teamId, paintId, wear, seed };
|
parameters = new { steamid = player.SteamId, weaponDefIndex, weaponTeam = (int)teamId, paintId, wear, seed };
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Insert new record
|
// Insert new record
|
||||||
query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
query = "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_team`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) " +
|
||||||
? "INSERT INTO wp_player_skins (steamid, weapon_defindex, weapon_team, weapon_paint_id, weapon_wear, weapon_seed) VALUES (@steamid, @weaponDefIndex, @weaponTeam, @paintId, @wear, @seed)"
|
"VALUES (@steamid, @weaponDefIndex, @weaponTeam, @paintId, @wear, @seed)";
|
||||||
: "INSERT INTO `wp_player_skins` (`steamid`, `weapon_defindex`, `weapon_team`, `weapon_paint_id`, `weapon_wear`, `weapon_seed`) VALUES (@steamid, @weaponDefIndex, @weaponTeam, @paintId, @wear, @seed)";
|
|
||||||
parameters = new { steamid = player.SteamId, weaponDefIndex, weaponTeam = (int)teamId, paintId, wear, seed };
|
parameters = new { steamid = player.SteamId, weaponDefIndex, weaponTeam = (int)teamId, paintId, wear, seed };
|
||||||
}
|
}
|
||||||
|
|
||||||
await connection.GetConnection().ExecuteAsync(query, parameters);
|
await connection.ExecuteAsync(query, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -537,9 +522,7 @@ internal class WeaponSynchronization
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.MusicEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
if (!_config.Additional.MusicEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "INSERT INTO `wp_player_music` (`steamid`, `weapon_team`, `music_id`) VALUES(@steamid, @team, @newMusic) ON DUPLICATE KEY UPDATE `music_id` = @newMusic";
|
||||||
? "INSERT OR REPLACE INTO wp_player_music (steamid, weapon_team, music_id) VALUES(@steamid, @team, @newMusic)"
|
|
||||||
: "INSERT INTO `wp_player_music` (`steamid`, `weapon_team`, `music_id`) VALUES(@steamid, @team, @newMusic) ON DUPLICATE KEY UPDATE `music_id` = @newMusic";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -548,7 +531,7 @@ internal class WeaponSynchronization
|
|||||||
// Loop through each team and insert/update accordingly
|
// Loop through each team and insert/update accordingly
|
||||||
foreach (var team in teams)
|
foreach (var team in teams)
|
||||||
{
|
{
|
||||||
await connection.GetConnection().ExecuteAsync(query, new { steamid = player.SteamId, team, newMusic = music });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, team, newMusic = music });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -561,9 +544,7 @@ internal class WeaponSynchronization
|
|||||||
{
|
{
|
||||||
if (!_config.Additional.PinsEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
if (!_config.Additional.PinsEnabled || string.IsNullOrEmpty(player.SteamId)) return;
|
||||||
|
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = "INSERT INTO `wp_player_pins` (`steamid`, `weapon_team`, `id`) VALUES(@steamid, @team, @newPin) ON DUPLICATE KEY UPDATE `id` = @newPin";
|
||||||
? "INSERT OR REPLACE INTO wp_player_pins (steamid, weapon_team, id) VALUES(@steamid, @team, @newPin)"
|
|
||||||
: "INSERT INTO `wp_player_pins` (`steamid`, `weapon_team`, `id`) VALUES(@steamid, @team, @newPin) ON DUPLICATE KEY UPDATE `id` = @newPin";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -572,7 +553,7 @@ internal class WeaponSynchronization
|
|||||||
// Loop through each team and insert/update accordingly
|
// Loop through each team and insert/update accordingly
|
||||||
foreach (var team in teams)
|
foreach (var team in teams)
|
||||||
{
|
{
|
||||||
await connection.GetConnection().ExecuteAsync(query, new { steamid = player.SteamId, team, newPin = pin });
|
await connection.ExecuteAsync(query, new { steamid = player.SteamId, team, newPin = pin });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -590,7 +571,7 @@ internal class WeaponSynchronization
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
using var transaction = await connection.BeginTransactionAsync();
|
await using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
|
||||||
// Check if player's slot exists in GPlayerWeaponsInfo
|
// Check if player's slot exists in GPlayerWeaponsInfo
|
||||||
if (!WeaponPaints.GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamWeaponsInfo))
|
if (!WeaponPaints.GPlayerWeaponsInfo.TryGetValue(player.Slot, out var teamWeaponsInfo))
|
||||||
@@ -618,9 +599,8 @@ internal class WeaponSynchronization
|
|||||||
// Sync StatTrak values for the current team
|
// Sync StatTrak values for the current team
|
||||||
foreach (var (defindex, (statTrak, statTrakCount)) in statTrakWeapons)
|
foreach (var (defindex, (statTrak, statTrakCount)) in statTrakWeapons)
|
||||||
{
|
{
|
||||||
string query = Utility.Config?.DatabaseType?.ToLower() == "sqlite"
|
const string query = @"
|
||||||
? "UPDATE wp_player_skins SET weapon_stattrak = @StatTrak, weapon_stattrak_count = @StatTrakCount WHERE steamid = @steamid AND weapon_defindex = @weaponDefIndex AND weapon_team = @weaponTeam"
|
UPDATE `wp_player_skins`
|
||||||
: @"UPDATE `wp_player_skins`
|
|
||||||
SET `weapon_stattrak` = @StatTrak,
|
SET `weapon_stattrak` = @StatTrak,
|
||||||
`weapon_stattrak_count` = @StatTrakCount
|
`weapon_stattrak_count` = @StatTrakCount
|
||||||
WHERE `steamid` = @steamid
|
WHERE `steamid` = @steamid
|
||||||
@@ -636,11 +616,11 @@ internal class WeaponSynchronization
|
|||||||
weaponTeam
|
weaponTeam
|
||||||
};
|
};
|
||||||
|
|
||||||
await connection.GetConnection().ExecuteAsync(query, parameters, transaction);
|
await connection.ExecuteAsync(query, parameters, transaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await connection.CommitTransactionAsync(transaction);
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user