mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 10:43:23 +00:00
```diff
+ `Refactored Code`: Improved code structure for better maintainability.
+ `Player Penalties Command`: Introduced the `css_penalties` command to display player penalties.
+ `Admin Penalties Information`: Added functionality to provide information for admins regarding penalties of connecting players.
+ `Disconnected Players Command`: Added the `css_disconnected` command to show a list of disconnected players.
+ `Colorful Messages`: Implemented the `css_cssay` command to send colorful messages, e.g., `css_cssay {lightgreen}Test`.
+ `Respawn Functionality`: Updated the `css_respawn` command to respawn players at their death location.
+ `Menu Type Management`: Introduced the `css_menus` command to change the menu type via `MenuManagerCS2`.
+ `Dynamic Menu Control`: Enhanced menu interaction with dynamic controls using WASD + ER keys.
+ `Language File Updates`: Updated language files for better localization.
+ `API Integration`: Added a simple API for external interaction.
+ `Configurable Timezone`: Introduced timezone settings in the configuration.
+ `Admin Activity Display Options`: Added configurable settings for displaying admin activity:
+ `0`: Do not show
+ `1`: Hide admin name
+ `2`: Show admin name
+ `Discord Notification Customization`: Made Discord duration notifications customizable with `{relative}` and `{normal}` placeholders.
+ Improved command logging
+
`Configuration Options:`
+ `Timezone`
+ `Other Settings`
+ `Disconnected Players History Count`
+ `Show Activity Type`
```
62 lines
2.3 KiB
C#
62 lines
2.3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using MySqlConnector;
|
|
|
|
namespace CS2_SimpleAdmin.Database;
|
|
|
|
public class Migration(Database database)
|
|
{
|
|
public void ExecuteMigrations()
|
|
{
|
|
var migrationsDirectory = CS2_SimpleAdmin.Instance.ModuleDirectory + "/Database/Migrations";
|
|
|
|
var files = Directory.GetFiles(migrationsDirectory, "*.sql")
|
|
.OrderBy(f => f);
|
|
|
|
using var connection = database.GetConnection();
|
|
|
|
// Create sa_migrations table if not exists
|
|
using var cmd = new MySqlCommand("""
|
|
CREATE TABLE IF NOT EXISTS `sa_migrations` (
|
|
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
|
`version` VARCHAR(255) NOT NULL
|
|
);
|
|
""", connection);
|
|
|
|
cmd.ExecuteNonQuery();
|
|
|
|
// Get the last applied migration version
|
|
var lastAppliedVersion = GetLastAppliedVersion(connection);
|
|
|
|
foreach (var file in files)
|
|
{
|
|
var version = Path.GetFileNameWithoutExtension(file);
|
|
|
|
// Check if the migration has already been applied
|
|
if (string.Compare(version, lastAppliedVersion, StringComparison.OrdinalIgnoreCase) <= 0) continue;
|
|
var sqlScript = File.ReadAllText(file);
|
|
|
|
using var cmdMigration = new MySqlCommand(sqlScript, connection);
|
|
cmdMigration.ExecuteNonQuery();
|
|
|
|
// Update the last applied migration version
|
|
UpdateLastAppliedVersion(connection, version);
|
|
|
|
CS2_SimpleAdmin._logger?.LogInformation($"Migration \"{version}\" successfully applied.");
|
|
}
|
|
}
|
|
|
|
private static string GetLastAppliedVersion(MySqlConnection connection)
|
|
{
|
|
using var cmd = new MySqlCommand("SELECT `version` FROM `sa_migrations` ORDER BY `id` DESC LIMIT 1;", connection);
|
|
var result = cmd.ExecuteScalar();
|
|
return result?.ToString() ?? string.Empty;
|
|
}
|
|
|
|
private static void UpdateLastAppliedVersion(MySqlConnection connection, string version)
|
|
{
|
|
using var cmd = new MySqlCommand("INSERT INTO `sa_migrations` (`version`) VALUES (@Version);", connection);
|
|
cmd.Parameters.AddWithValue("@Version", version);
|
|
cmd.ExecuteNonQuery();
|
|
}
|
|
}
|