mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-09-27 20:17:04 +02:00
fix: major simplication of the server query and use correct dapper query
This commit is contained in:
parent
cab74dcb0c
commit
8f1702bb75
1 changed files with 8 additions and 27 deletions
31
Events.cs
31
Events.cs
|
|
@ -17,27 +17,6 @@ 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);
|
||||||
|
|
@ -406,16 +385,18 @@ public partial class CS2_SimpleAdmin
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ServerData serverData = await connection.ExecuteScalarAsync<ServerData>(
|
|
||||||
|
|
||||||
|
(int? serverId, string? groupIds) = await connection.QueryFirstAsync<(int?, string?)>(
|
||||||
"SELECT `id`, `group_ids` FROM `sa_servers` WHERE `address` = @address",
|
"SELECT `id`, `group_ids` FROM `sa_servers` WHERE `address` = @address",
|
||||||
new { address });
|
new { address });
|
||||||
|
|
||||||
ServerId = serverData.Id;
|
ServerId = serverId;
|
||||||
GroupIds = serverData.GroupIds;
|
GroupIds = groupIds?.Split(',').Select(int.Parse).ToArray();
|
||||||
|
|
||||||
// For testing only
|
// For testing only
|
||||||
_logger?.LogInformation($"Server ID: {ServerId}");
|
_logger?.LogInformation($"Server ID: {ServerId}");
|
||||||
_logger?.LogInformation($"Group IDs: {GroupIds}");
|
_logger?.LogInformation($"Group IDs: {string.Join(", ", GroupIds ?? Array.Empty<int>())}");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue