mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-26 05:04:48 +00:00
1.2.9a - fix
- Fixed native in non-main thread
This commit is contained in:
@@ -59,7 +59,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void OnConfigParsed(CS2_SimpleAdminConfig config)
|
public void OnConfigParsed(CS2_SimpleAdminConfig config)
|
||||||
{
|
{
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
{
|
{
|
||||||
@@ -77,16 +77,19 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
|
|
||||||
dbConnectionString = builder.ConnectionString;
|
dbConnectionString = builder.ConnectionString;
|
||||||
|
|
||||||
try
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
_database = new(dbConnectionString);
|
try
|
||||||
|
|
||||||
using (var connection = _database.GetConnection())
|
|
||||||
{
|
{
|
||||||
using var transaction = await connection.BeginTransactionAsync();
|
|
||||||
try
|
_database = new(dbConnectionString);
|
||||||
|
|
||||||
|
using (var connection = _database.GetConnection())
|
||||||
{
|
{
|
||||||
string sql = @"CREATE TABLE IF NOT EXISTS `sa_bans` (
|
using var transaction = await connection.BeginTransactionAsync();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = @"CREATE TABLE IF NOT EXISTS `sa_bans` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
`player_steamid` VARCHAR(64),
|
`player_steamid` VARCHAR(64),
|
||||||
`player_name` VARCHAR(128),
|
`player_name` VARCHAR(128),
|
||||||
@@ -102,9 +105,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";
|
||||||
|
|
||||||
|
|
||||||
await connection.QueryAsync(sql, transaction: transaction);
|
await connection.QueryAsync(sql, transaction: transaction);
|
||||||
|
|
||||||
sql = @"CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
sql = @"CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`player_steamid` varchar(64) NOT NULL,
|
`player_steamid` varchar(64) NOT NULL,
|
||||||
`player_name` varchar(128) NULL,
|
`player_name` varchar(128) NULL,
|
||||||
@@ -120,9 +123,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci";
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci";
|
||||||
|
|
||||||
await connection.QueryAsync(sql, transaction: transaction);
|
await connection.QueryAsync(sql, transaction: transaction);
|
||||||
|
|
||||||
sql = @"CREATE TABLE IF NOT EXISTS `sa_admins` (
|
sql = @"CREATE TABLE IF NOT EXISTS `sa_admins` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`player_steamid` varchar(64) NOT NULL,
|
`player_steamid` varchar(64) NOT NULL,
|
||||||
`player_name` varchar(128) NOT NULL,
|
`player_name` varchar(128) NOT NULL,
|
||||||
@@ -134,9 +137,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci";
|
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci";
|
||||||
|
|
||||||
await connection.QueryAsync(sql, transaction: transaction);
|
await connection.QueryAsync(sql, transaction: transaction);
|
||||||
|
|
||||||
sql = @"CREATE TABLE IF NOT EXISTS `sa_servers` (
|
sql = @"CREATE TABLE IF NOT EXISTS `sa_servers` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`address` varchar(64) NOT NULL,
|
`address` varchar(64) NOT NULL,
|
||||||
`hostname` varchar(64) NOT NULL,
|
`hostname` varchar(64) NOT NULL,
|
||||||
@@ -145,22 +148,23 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||||
";
|
";
|
||||||
|
|
||||||
await connection.QueryAsync(sql, transaction: transaction);
|
await connection.QueryAsync(sql, transaction: transaction);
|
||||||
|
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await transaction.RollbackAsync();
|
await transaction.RollbackAsync();
|
||||||
throw;
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception)
|
||||||
catch (Exception)
|
{
|
||||||
{
|
Logger.LogError("Unable to connect to the database!");
|
||||||
Logger.LogError("Unable to connect to the database!");
|
throw new Exception("[CS2-SimpleAdmin] Unable to connect to the Database!");
|
||||||
throw new Exception("[CS2-SimpleAdmin] Unable to connect to the Database!");
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
_localizer = Localizer;
|
_localizer = Localizer;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin;
|
||||||
public class Database
|
public class Database
|
||||||
{
|
{
|
||||||
private readonly string _dbConnectionString;
|
private readonly string _dbConnectionString;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Admin;
|
|||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using static CounterStrikeSharp.API.Core.Listeners;
|
using static CounterStrikeSharp.API.Core.Listeners;
|
||||||
|
|||||||
Reference in New Issue
Block a user