From f69ba3b51ce635f01ce3c7f28065a4a7beffd878 Mon Sep 17 00:00:00 2001 From: Dollan Date: Fri, 12 Apr 2024 00:02:44 +0200 Subject: [PATCH] feat: Full reload and individual reload working --- Events.cs | 5 +++++ Managers/AdminSQLManager.cs | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Events.cs b/Events.cs index f4a7fd5..6379c13 100644 --- a/Events.cs +++ b/Events.cs @@ -396,6 +396,11 @@ public partial class CS2_SimpleAdmin { GroupIds = groupIds?.Split(',').Select(int.Parse).ToArray(); } + else + { + // We must set it to null if it's empty to ensure reloads work properly + GroupIds = null; + } // For testing only diff --git a/Managers/AdminSQLManager.cs b/Managers/AdminSQLManager.cs index 80df143..7000c05 100644 --- a/Managers/AdminSQLManager.cs +++ b/Managers/AdminSQLManager.cs @@ -1,4 +1,5 @@ using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Utils; using Dapper; using Microsoft.Extensions.Logging; using MySqlConnector; @@ -27,8 +28,10 @@ public class AdminSQLManager await using MySqlConnection connection = await _database.GetConnectionAsync(); - string sql = "SELECT flags, immunity, ends FROM sa_admins WHERE player_steamid = @PlayerSteamID AND (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid)"; - List? activeFlags = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList(); + string groupId = CS2_SimpleAdmin.GroupIds != null ? string.Join("", CS2_SimpleAdmin.GroupIds) : string.Empty; + + string sql = "SELECT flags, immunity, ends FROM sa_admins WHERE player_steamid = @PlayerSteamID AND (ends IS NULL OR ends > @CurrentTime) AND ((server_id IS NULL OR server_id = @serverid) OR ((@groupid IS NOT NULL AND @groupid <> 0) AND group_id LIKE CONCAT('%', @groupid, '%')));"; + List? activeFlags = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId, groupid = groupId }))?.ToList(); if (activeFlags == null) { @@ -70,8 +73,10 @@ public class AdminSQLManager { await using MySqlConnection connection = await _database.GetConnectionAsync(); - string sql = "SELECT player_steamid, flags, immunity, ends FROM sa_admins WHERE (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid) AND (group_id LIKE CONCAT('%', @groupid, '%'));"; - List? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId, groupid = CS2_SimpleAdmin.GroupIds }))?.ToList(); + string groupId = CS2_SimpleAdmin.GroupIds != null ? string.Join("", CS2_SimpleAdmin.GroupIds) : string.Empty; + + string sql = "SELECT player_steamid, flags, immunity, ends FROM sa_admins WHERE (ends IS NULL OR ends > @CurrentTime) AND ((server_id IS NULL OR server_id = @serverid) OR ((@groupid IS NOT NULL AND @groupid <> 0) AND group_id LIKE CONCAT('%', @groupid, '%')));"; + List? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId, groupid = groupId }))?.ToList(); if (activeFlags == null) { @@ -116,7 +121,6 @@ public class AdminSQLManager //Console.WriteLine("Failed to parse one or more values."); continue; } - filteredFlagsWithImmunity.Add((steamId, flagsValue.Split(',').ToList(), immunityValue, ends)); }