Fix css_unban/css_unmute silently failing on SQLite

On SQLite, INTEGER PRIMARY KEY AUTOINCREMENT values flow through
Dapper as boxed long. `int banId = ban.id;` / `int muteId = mute.id;`
against a dynamic row triggers RuntimeBinderException
("Cannot implicitly convert type 'long' to 'int'") before any
INSERT/UPDATE runs, and the surrounding bare `catch { }` in
BanManager.UnbanPlayer swallows it — leaving sa_bans.status='ACTIVE',
sa_unbans empty, and the admin staring at a cosmetic
"Unbanned with pattern X." reply. MySQL is unaffected because
MySqlConnector materialises INT as int.

Normalise the conversion path via Convert.ToInt32((object)x.id),
which handles both boxed int (MySQL) and boxed long (SQLite)
without invoking the C# dynamic binder. Same pattern fixed in
both UnbanPlayer and UnmutePlayer.

Also tighten BanManager.UnbanPlayer's bare `catch { }` to log via
the existing CS2_SimpleAdmin.Instance.Logger, matching the style
of BanPlayer/AddBanBySteamid/AddBanByIp in the same file. This is
what surfaced the bug during root-cause analysis.
This commit is contained in:
playaopindo-dev 2026-05-29 00:19:36 +02:00
parent eea700bfb4
commit 1f56b5b251
2 changed files with 6 additions and 3 deletions

View file

@ -331,7 +331,7 @@ public async Task UnbanPlayer(string playerPattern, string adminSteamId, string
foreach (var ban in bansList)
{
int banId = ban.id;
int banId = Convert.ToInt32((object)ban.id);
var sqlInsertUnban = databaseProvider.GetInsertUnbanQuery(reason != null);
var unbanId = await connection.ExecuteScalarAsync<int>(sqlInsertUnban, new { banId, adminId, reason });
@ -340,7 +340,10 @@ public async Task UnbanPlayer(string playerPattern, string adminSteamId, string
await connection.ExecuteAsync(sqlUpdateBan, new { unbanId, banId });
}
}
catch { }
catch (Exception ex)
{
CS2_SimpleAdmin.Instance?.Logger?.LogError(ex, "UnbanPlayer failed for pattern {Pattern}", playerPattern);
}
}
// public async Task CheckOnlinePlayers(List<(string? IpAddress, ulong SteamID, int? UserId, int Slot)> players)

View file

@ -263,7 +263,7 @@ internal class MuteManager(IDatabaseProvider? databaseProvider)
foreach (var mute in mutesList)
{
int muteId = mute.id;
int muteId = Convert.ToInt32((object)mute.id);
int? unmuteId =
await connection.ExecuteScalarAsync<int>(sqlInsertUnmute, new { muteId, adminId, reason });