Fix mutes lost on map change; fix SQLite penalty reads

OnMapStart clears all in-memory penalties and CounterStrikeSharp resets
voice flags, so mutes, gags and silences must be reloaded on reconnect.

- LoadPlayerData only reloaded them when the player was not already in
  PlayersInfo (since eea700b, 1.7.9a). An entry that outlives the map
  change skips the reload. Gate on fullConnect again.
- On SQLite the reload always threw: INTEGER columns come back as long
  and dynamic cannot convert that to int implicitly. Same cast fixed in
  UnmutePlayer and UnbanPlayer, which failed silently (#284).
- SQLite dates are stored as UTC but were read back shifted by the
  machine's UTC offset, so restored mutes ended early or late. The
  connection now uses DateTimeKind=Utc.
This commit is contained in:
Ravid-A 2026-11-25 14:21:55 +02:00
parent 03a454b1b5
commit 31172f38f7
4 changed files with 8 additions and 5 deletions

View file

@ -5,7 +5,8 @@ namespace CS2_SimpleAdmin.Database;
public class SqliteDatabaseProvider(string filePath) : IDatabaseProvider
{
private readonly string _connectionString = $"Data Source={filePath}";
// Dates are stored as UTC; without DateTimeKind=Utc they are read back shifted by the machine's UTC offset
private readonly string _connectionString = $"Data Source={filePath};DateTimeKind=Utc";
public async Task<DbConnection> CreateConnectionAsync()
{

View file

@ -332,7 +332,7 @@ public async Task UnbanPlayer(string playerPattern, string adminSteamId, string
foreach (var ban in bansList)
{
int banId = ban.id;
int banId = (int)ban.id; // SQLite returns long
var sqlInsertUnban = databaseProvider.GetInsertUnbanQuery(reason != null);
var unbanId = await connection.ExecuteScalarAsync<int>(sqlInsertUnban, new { banId, adminId, reason });

View file

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

View file

@ -85,7 +85,9 @@ internal class PlayerManager
return;
}
if (!CS2_SimpleAdmin.PlayersInfo.ContainsKey(steamId))
// Must run on every full connect: OnMapStart wipes all penalties (and CSS resets voice flags), while
// PlayersInfo can survive a map change, so gating on it would silently drop active mutes.
if (fullConnect)
{
var playerInfo = new PlayerInfo(userId, slot, new SteamID(steamId), playerName, ipAddress);
CS2_SimpleAdmin.PlayersInfo[steamId] = playerInfo;
@ -130,7 +132,7 @@ internal class PlayerManager
{
string muteType = mute.type;
DateTime ends = mute.ends;
int duration = mute.duration;
int duration = (int)mute.duration; // SQLite returns long
switch (muteType)
{
// Apply mute penalty based on mute type