mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-09-27 20:17:04 +02:00
Clean up orphaned non-global admins on the expire timer
This commit is contained in:
parent
e028441b56
commit
fd94ac8d2b
5 changed files with 29 additions and 1 deletions
|
|
@ -30,6 +30,7 @@ public interface IDatabaseProvider
|
|||
string GetAddGroupServerQuery();
|
||||
string GetDeleteGroupQuery();
|
||||
string GetDeleteOldAdminsQuery();
|
||||
string GetDeleteOrphanedAdminsQuery();
|
||||
|
||||
// BanManager
|
||||
string GetAddBanQuery();
|
||||
|
|
|
|||
|
|
@ -188,6 +188,9 @@ public class MySqlDatabaseProvider(string connectionString) : IDatabaseProvider
|
|||
public string GetDeleteOldAdminsQuery() =>
|
||||
"DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime;";
|
||||
|
||||
public string GetDeleteOrphanedAdminsQuery() =>
|
||||
"DELETE FROM sa_admins WHERE `global` = 0 AND id NOT IN (SELECT admin_id FROM sa_admins_servers);";
|
||||
|
||||
public string GetAddBanQuery()
|
||||
{
|
||||
return """
|
||||
|
|
|
|||
|
|
@ -241,6 +241,9 @@ public class SqliteDatabaseProvider(string filePath) : IDatabaseProvider
|
|||
public string GetDeleteOldAdminsQuery() =>
|
||||
"DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime;";
|
||||
|
||||
public string GetDeleteOrphanedAdminsQuery() =>
|
||||
"DELETE FROM sa_admins WHERE `global` = 0 AND id NOT IN (SELECT admin_id FROM sa_admins_servers);";
|
||||
|
||||
public string GetAddMuteQuery(bool includePlayerName) =>
|
||||
includePlayerName
|
||||
? """
|
||||
|
|
|
|||
|
|
@ -677,4 +677,24 @@ public class PermissionManager(IDatabaseProvider? databaseProvider)
|
|||
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired admins");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes orphaned admins that are not global and have no server assignments left.
|
||||
/// </summary>
|
||||
public async Task DeleteOrphanedAdmins()
|
||||
{
|
||||
if (databaseProvider == null) return;
|
||||
|
||||
try
|
||||
{
|
||||
await using var connection = await databaseProvider.CreateConnectionAsync();
|
||||
|
||||
var sql = databaseProvider.GetDeleteOrphanedAdminsQuery();
|
||||
await connection.ExecuteAsync(sql);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove orphaned admins");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -306,7 +306,8 @@ internal class PlayerManager
|
|||
pluginInstance.MuteManager.ExpireOldMutes(),
|
||||
pluginInstance.WarnManager.ExpireOldWarns(),
|
||||
pluginInstance.CacheManager?.RefreshCacheAsync() ?? Task.CompletedTask,
|
||||
pluginInstance.PermissionManager.DeleteOldAdmins()
|
||||
pluginInstance.PermissionManager.DeleteOldAdmins(),
|
||||
pluginInstance.PermissionManager.DeleteOrphanedAdmins()
|
||||
};
|
||||
|
||||
await Task.WhenAll(expireTasks);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue