mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 18:49:23 +00:00
1.3.7a
- Throwing more informations - Updated CounterStrikeSharp - Fixed problem with expiring bans via `css_addban` - Added metrics - Minor changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySqlConnector;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
@@ -24,7 +25,7 @@ public class AdminSQLManager
|
||||
{
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "SELECT flags, immunity, ends FROM sa_admins WHERE player_steamid = @PlayerSteamID AND (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid)";
|
||||
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
||||
@@ -67,7 +68,7 @@ public class AdminSQLManager
|
||||
|
||||
try
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "SELECT player_steamid, flags, immunity, ends FROM sa_admins WHERE (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid)";
|
||||
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
||||
@@ -160,7 +161,7 @@ public class AdminSQLManager
|
||||
|
||||
//_adminCache.TryRemove(playerSteamId, out _);
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "";
|
||||
|
||||
@@ -189,7 +190,7 @@ public class AdminSQLManager
|
||||
else
|
||||
futureTime = null;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)";
|
||||
@@ -212,7 +213,7 @@ public class AdminSQLManager
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
||||
@@ -19,7 +20,7 @@ internal class BanManager
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_steamid`, `player_name`, `player_ip`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @playerName, @playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -46,7 +47,7 @@ internal class BanManager
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_steamid`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -71,7 +72,7 @@ internal class BanManager
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_ip`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -91,7 +92,7 @@ internal class BanManager
|
||||
|
||||
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
||||
{
|
||||
if (player.SteamId == null && player.IpAddress == null)
|
||||
if (player.SteamId == null || player.IpAddress == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -120,7 +121,7 @@ internal class BanManager
|
||||
AND status = 'ACTIVE'
|
||||
AND (duration = 0 OR ends > @CurrentTime);";
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
var parameters = new
|
||||
{
|
||||
@@ -145,7 +146,7 @@ internal class BanManager
|
||||
string sql = "SELECT COUNT(*) FROM sa_bans WHERE (player_steamid = @PlayerSteamID OR player_ip = @PlayerIP)";
|
||||
int banCount;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(player.IpAddress))
|
||||
{
|
||||
@@ -166,7 +167,7 @@ internal class BanManager
|
||||
return;
|
||||
}
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sqlUnban = "UPDATE sa_bans SET status = 'UNBANNED' WHERE player_steamid = @pattern OR player_name = @pattern OR player_ip = @pattern AND status = 'ACTIVE'";
|
||||
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern });
|
||||
@@ -178,11 +179,11 @@ internal class BanManager
|
||||
{
|
||||
DateTime currentTime = DateTime.UtcNow.ToLocalTime();
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
/*
|
||||
string sql = "";
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
sql = "UPDATE sa_bans SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.UtcNow.ToLocalTime() });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
||||
@@ -16,7 +17,7 @@ internal class MuteManager
|
||||
{
|
||||
if (player == null || player.SteamId == null) return;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||
@@ -49,7 +50,7 @@ internal class MuteManager
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||
@@ -91,7 +92,7 @@ internal class MuteManager
|
||||
|
||||
try
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
DateTime currentTime = DateTime.Now.ToLocalTime();
|
||||
string sql = "SELECT * FROM sa_mutes WHERE player_steamid = @PlayerSteamID AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
||||
|
||||
@@ -107,7 +108,7 @@ internal class MuteManager
|
||||
|
||||
public async Task<int> GetPlayerMutes(string steamId)
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
int muteCount;
|
||||
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
||||
@@ -124,7 +125,7 @@ internal class MuteManager
|
||||
return;
|
||||
}
|
||||
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
if (type == 2)
|
||||
{
|
||||
@@ -150,7 +151,7 @@ internal class MuteManager
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
||||
|
||||
Reference in New Issue
Block a user