mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-09-27 20:17:04 +02:00
feat: setting group id internally and migration
This commit is contained in:
parent
0ade5a1371
commit
d4340d69cf
3 changed files with 49 additions and 14 deletions
|
|
@ -26,6 +26,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||||
public static bool voteInProgress = false;
|
public static bool voteInProgress = false;
|
||||||
public static int? ServerId = null;
|
public static int? ServerId = null;
|
||||||
|
|
||||||
|
public static int[]? GroupIds = [];
|
||||||
|
|
||||||
public static DiscordWebhookClient? _discordWebhookClientLog;
|
public static DiscordWebhookClient? _discordWebhookClientLog;
|
||||||
public static DiscordWebhookClient? _discordWebhookClientPenalty;
|
public static DiscordWebhookClient? _discordWebhookClientPenalty;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||||
using CounterStrikeSharp.API.Core.Translations;
|
using CounterStrikeSharp.API.Core.Translations;
|
||||||
|
|
@ -27,22 +27,26 @@ namespace CS2_SimpleAdmin
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var connection = await _database.GetConnectionAsync();
|
using var connection = await _database.GetConnectionAsync();
|
||||||
var commandText = "ALTER TABLE `sa_mutes` CHANGE `type` `type` ENUM('GAG','MUTE', 'SILENCE', '') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'GAG';";
|
var commandText = "ALTER TABLE `sa_servers` ADD COLUMN `group_ids` VARCHAR(255) NULL AFTER `hostname`";
|
||||||
|
|
||||||
using var commandSql = connection.CreateCommand();
|
using var commandSql = connection.CreateCommand();
|
||||||
commandSql.CommandText = commandText;
|
commandSql.CommandText = commandText;
|
||||||
await commandSql.ExecuteNonQueryAsync();
|
await commandSql.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
commandText = "ALTER TABLE `sa_servers` MODIFY COLUMN `hostname` varchar(128);";
|
var commandText2 = "ALTER TABLE `sa_admins` ADD COLUMN `group_id` INT NULL AFTER `server_id`";
|
||||||
using var commandSql1 = connection.CreateCommand();
|
|
||||||
commandSql1.CommandText = commandText;
|
|
||||||
await commandSql1.ExecuteNonQueryAsync();
|
|
||||||
|
|
||||||
commandText = "ALTER TABLE `sa_bans` MODIFY `ends` TIMESTAMP NULL DEFAULT NULL;";
|
|
||||||
using var commandSql2 = connection.CreateCommand();
|
using var commandSql2 = connection.CreateCommand();
|
||||||
commandSql2.CommandText = commandText;
|
commandSql2.CommandText = commandText2;
|
||||||
await commandSql2.ExecuteNonQueryAsync();
|
await commandSql2.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
|
var commandText3 = "CREATE TABLE IF NOT EXISTS `sa_server_groups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `group_name` varchar(128) NOT NULL, PRIMARY KEY(`id`) ) ENGINE = InnoDB AUTO_INCREMENT = 2 DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci;`";
|
||||||
|
|
||||||
|
using var commandSql3 = connection.CreateCommand();
|
||||||
|
commandSql3.CommandText = commandText3;
|
||||||
|
await commandSql3.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
command.ReplyToCommand($"Successfully updated the database - {ModuleVersion}");
|
command.ReplyToCommand($"Successfully updated the database - {ModuleVersion}");
|
||||||
|
|
|
||||||
35
Events.cs
35
Events.cs
|
|
@ -17,6 +17,27 @@ public partial class CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
public static HashSet<int> loadedPlayers = new HashSet<int>();
|
public static HashSet<int> loadedPlayers = new HashSet<int>();
|
||||||
|
|
||||||
|
struct ServerData
|
||||||
|
{
|
||||||
|
public int? Id { get; }
|
||||||
|
public int[]? GroupIds { get; }
|
||||||
|
|
||||||
|
public ServerData(int? id, string? groupIds)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
GroupIds = ParseGroupIds(groupIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[]? ParseGroupIds(string? groupIds)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(groupIds))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return groupIds.Split(',')
|
||||||
|
.Select(id => int.TryParse(id, out int result) ? result : 0)
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
private void RegisterEvents()
|
private void RegisterEvents()
|
||||||
{
|
{
|
||||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||||
|
|
@ -383,11 +404,19 @@ public partial class CS2_SimpleAdmin
|
||||||
new { address, hostname });
|
new { address, hostname });
|
||||||
}
|
}
|
||||||
|
|
||||||
int? serverId = await connection.ExecuteScalarAsync<int>(
|
|
||||||
"SELECT `id` FROM `sa_servers` WHERE `address` = @address",
|
|
||||||
|
ServerData serverData = await connection.ExecuteScalarAsync<ServerData>(
|
||||||
|
"SELECT `id`, `group_ids` FROM `sa_servers` WHERE `address` = @address",
|
||||||
new { address });
|
new { address });
|
||||||
|
|
||||||
ServerId = serverId;
|
ServerId = serverData.Id;
|
||||||
|
GroupIds = serverData.GroupIds;
|
||||||
|
|
||||||
|
// For testing only
|
||||||
|
_logger?.LogInformation($"Server ID: {ServerId}");
|
||||||
|
_logger?.LogInformation($"Group IDs: {GroupIds}");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue