From 8f1702bb755af253d7357cf002109401253ae0a3 Mon Sep 17 00:00:00 2001 From: Dollan Date: Thu, 11 Apr 2024 22:34:23 +0200 Subject: [PATCH] fix: major simplication of the server query and use correct dapper query --- Events.cs | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/Events.cs b/Events.cs index e0906e0..24272d2 100644 --- a/Events.cs +++ b/Events.cs @@ -17,27 +17,6 @@ public partial class CS2_SimpleAdmin { public static HashSet loadedPlayers = new HashSet(); - 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() { RegisterListener(OnMapStart); @@ -406,16 +385,18 @@ public partial class CS2_SimpleAdmin - ServerData serverData = await connection.ExecuteScalarAsync( - "SELECT `id`, `group_ids` FROM `sa_servers` WHERE `address` = @address", - new { address }); - ServerId = serverData.Id; - GroupIds = serverData.GroupIds; + + (int? serverId, string? groupIds) = await connection.QueryFirstAsync<(int?, string?)>( + "SELECT `id`, `group_ids` FROM `sa_servers` WHERE `address` = @address", + new { address }); + + ServerId = serverId; + GroupIds = groupIds?.Split(',').Select(int.Parse).ToArray(); // For testing only _logger?.LogInformation($"Server ID: {ServerId}"); - _logger?.LogInformation($"Group IDs: {GroupIds}"); + _logger?.LogInformation($"Group IDs: {string.Join(", ", GroupIds ?? Array.Empty())}"); } catch (Exception ex)