mirror of
https://github.com/Nereziel/cs2-WeaponPaints.git
synced 2026-02-18 10:43:22 +00:00
Merge pull request #42 from daffyyyy/enhancement/mysql-wrapper
Creating tables fix
This commit is contained in:
@@ -127,29 +127,29 @@ public class WeaponPaints : BasePlugin, IPluginConfig<WeaponPaintsConfig>
|
||||
CheckDatabaseTables();
|
||||
}
|
||||
|
||||
private void CheckDatabaseTables()
|
||||
async private void CheckDatabaseTables()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = new MySqlConnection(DatabaseConnectionString);
|
||||
connection.OpenAsync();
|
||||
using var connection = new MySqlConnection(DatabaseConnectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
using var transaction = connection.BeginTransaction();
|
||||
using var transaction = await connection.BeginTransactionAsync();
|
||||
|
||||
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.0001, `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;";
|
||||
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.0001, `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";
|
||||
|
||||
connection.ExecuteAsync(createTable1);
|
||||
connection.ExecuteAsync(createTable2);
|
||||
await connection.ExecuteAsync(createTable1, transaction: transaction);
|
||||
await connection.ExecuteAsync(createTable2, transaction: transaction);
|
||||
|
||||
transaction.Commit();
|
||||
await transaction.CommitAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
transaction.RollbackAsync();
|
||||
throw new Exception("Unable to create tables!");
|
||||
await transaction.RollbackAsync();
|
||||
throw new Exception("Unable to create tables!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -220,12 +220,12 @@ public override void Unload(bool hotReload)
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
CCSPlayerController player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
// TODO: Clean up after player
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersKnife.Remove(playerSlot+1);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
||||
|
||||
if (!player.IsValid || player.IsBot) return;
|
||||
|
||||
if (Config.Additional.KnifeEnabled)
|
||||
g_playersKnife.Remove(playerSlot+1);
|
||||
if (Config.Additional.SkinEnabled)
|
||||
gPlayerWeaponPaints.Remove(new SteamID(player.SteamID).SteamId64);
|
||||
}
|
||||
|
||||
private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
|
||||
|
||||
Reference in New Issue
Block a user