From 1f56b5b251fe8ea5e7fe231743dd57dc1ec3fffd Mon Sep 17 00:00:00 2001 From: playaopindo-dev Date: Fri, 29 May 2026 00:19:36 +0200 Subject: [PATCH] Fix css_unban/css_unmute silently failing on SQLite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- CS2-SimpleAdmin/Managers/BanManager.cs | 7 +++++-- CS2-SimpleAdmin/Managers/MuteManager.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CS2-SimpleAdmin/Managers/BanManager.cs b/CS2-SimpleAdmin/Managers/BanManager.cs index 5863b593..b3ae76de 100644 --- a/CS2-SimpleAdmin/Managers/BanManager.cs +++ b/CS2-SimpleAdmin/Managers/BanManager.cs @@ -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(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) diff --git a/CS2-SimpleAdmin/Managers/MuteManager.cs b/CS2-SimpleAdmin/Managers/MuteManager.cs index 01d83df9..cee82fdf 100644 --- a/CS2-SimpleAdmin/Managers/MuteManager.cs +++ b/CS2-SimpleAdmin/Managers/MuteManager.cs @@ -263,7 +263,7 @@ public async Task UnmutePlayer(string playerPattern, string adminSteamId, string foreach (var mute in mutesList) { - int muteId = mute.id; + int muteId = Convert.ToInt32((object)mute.id); int? unmuteId = await connection.ExecuteScalarAsync(sqlInsertUnmute, new { muteId, adminId, reason });