mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-03-06 15:26:34 +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:
@@ -12,16 +12,16 @@ using System.Collections.Concurrent;
|
|||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
[MinimumApiVersion(198)]
|
[MinimumApiVersion(201)]
|
||||||
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
||||||
{
|
{
|
||||||
public static CS2_SimpleAdmin Instance { get; private set; } = new();
|
public static CS2_SimpleAdmin Instance { get; private set; } = new();
|
||||||
|
|
||||||
public static IStringLocalizer? _localizer;
|
public static IStringLocalizer? _localizer;
|
||||||
public static Dictionary<string, int> voteAnswers = new Dictionary<string, int>();
|
public static Dictionary<string, int> voteAnswers = [];
|
||||||
public static ConcurrentBag<int> godPlayers = new ConcurrentBag<int>();
|
public static ConcurrentBag<int> godPlayers = [];
|
||||||
public static ConcurrentBag<int> silentPlayers = new ConcurrentBag<int>();
|
public static ConcurrentBag<int> silentPlayers = [];
|
||||||
public static ConcurrentBag<string> bannedPlayers = new ConcurrentBag<string>();
|
public static ConcurrentBag<string> bannedPlayers = [];
|
||||||
public static bool TagsDetected = false;
|
public static bool TagsDetected = false;
|
||||||
public static bool voteInProgress = false;
|
public static bool voteInProgress = false;
|
||||||
public static int? ServerId = null;
|
public static int? ServerId = null;
|
||||||
@@ -38,7 +38,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public override string ModuleName => "CS2-SimpleAdmin";
|
public override string ModuleName => "CS2-SimpleAdmin";
|
||||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||||
public override string ModuleVersion => "1.3.6d";
|
public override string ModuleVersion => "1.3.7a";
|
||||||
|
|
||||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Pooling = true,
|
Pooling = true,
|
||||||
MinimumPoolSize = 0,
|
MinimumPoolSize = 0,
|
||||||
MaximumPoolSize = 640,
|
MaximumPoolSize = 640,
|
||||||
ConnectionIdleTimeout = 30
|
ConnectionReset = false
|
||||||
};
|
};
|
||||||
|
|
||||||
dbConnectionString = builder.ConnectionString;
|
dbConnectionString = builder.ConnectionString;
|
||||||
@@ -93,8 +93,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
string sql = await File.ReadAllTextAsync(sqlFilePath);
|
string sql = await File.ReadAllTextAsync(sqlFilePath);
|
||||||
|
|
||||||
await connection.QueryAsync(sql, transaction: transaction);
|
await connection.QueryAsync(sql, transaction: transaction);
|
||||||
|
|
||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
|
|
||||||
|
Console.WriteLine("[CS2-SimpleAdmin] Connected to database!");
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<RootNamespace>CS2_SimpleAdmin</RootNamespace>
|
<RootNamespace>CS2_SimpleAdmin</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.198" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.202" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ namespace CS2_SimpleAdmin
|
|||||||
commandSql1.CommandText = commandText;
|
commandSql1.CommandText = commandText;
|
||||||
await commandSql1.ExecuteNonQueryAsync();
|
await commandSql1.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
|
commandText = "ALTER TABLE `sa_bans` MODIFY `ends` TIMESTAMP NULL DEFAULT NULL;";
|
||||||
|
using var commandSql2 = connection.CreateCommand();
|
||||||
|
commandSql2.CommandText = commandText;
|
||||||
|
await commandSql2.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
command.ReplyToCommand($"Successfully updated the database - {ModuleVersion}");
|
command.ReplyToCommand($"Successfully updated the database - {ModuleVersion}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||||
{
|
{
|
||||||
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 8;
|
[JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 9;
|
||||||
|
|
||||||
[JsonPropertyName("DatabaseHost")]
|
[JsonPropertyName("DatabaseHost")]
|
||||||
public string DatabaseHost { get; set; } = "";
|
public string DatabaseHost { get; set; } = "";
|
||||||
@@ -43,6 +43,9 @@ namespace CS2_SimpleAdmin
|
|||||||
[JsonPropertyName("DatabaseName")]
|
[JsonPropertyName("DatabaseName")]
|
||||||
public string DatabaseName { get; set; } = "";
|
public string DatabaseName { get; set; } = "";
|
||||||
|
|
||||||
|
[JsonPropertyName("EnableMetrics")]
|
||||||
|
public bool EnableMetrics { get; set; } = true;
|
||||||
|
|
||||||
[JsonPropertyName("UseChatMenu")]
|
[JsonPropertyName("UseChatMenu")]
|
||||||
public bool UseChatMenu { get; set; } = false;
|
public bool UseChatMenu { get; set; } = false;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `sa_bans` (
|
|||||||
`admin_name` VARCHAR(128) NOT NULL,
|
`admin_name` VARCHAR(128) NOT NULL,
|
||||||
`reason` VARCHAR(255) NOT NULL,
|
`reason` VARCHAR(255) NOT NULL,
|
||||||
`duration` INT NOT NULL,
|
`duration` INT NOT NULL,
|
||||||
`ends` TIMESTAMP NOT NULL,
|
`ends` TIMESTAMP NULL,
|
||||||
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`server_id` INT NULL,
|
`server_id` INT NULL,
|
||||||
`status` ENUM('ACTIVE', 'UNBANNED', 'EXPIRED', '') NOT NULL DEFAULT 'ACTIVE'
|
`status` ENUM('ACTIVE', 'UNBANNED', 'EXPIRED', '') NOT NULL DEFAULT 'ACTIVE'
|
||||||
@@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
|||||||
`admin_name` varchar(128) NOT NULL,
|
`admin_name` varchar(128) NOT NULL,
|
||||||
`reason` varchar(255) NOT NULL,
|
`reason` varchar(255) NOT NULL,
|
||||||
`duration` int(11) NOT NULL,
|
`duration` int(11) NOT NULL,
|
||||||
`ends` timestamp NOT NULL,
|
`ends` timestamp NULL,
|
||||||
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`type` enum('GAG','MUTE','SILENCE','') NOT NULL DEFAULT 'GAG',
|
`type` enum('GAG','MUTE','SILENCE','') NOT NULL DEFAULT 'GAG',
|
||||||
`server_id` INT NULL,
|
`server_id` INT NULL,
|
||||||
|
|||||||
128
Events.cs
128
Events.cs
@@ -121,76 +121,89 @@ public partial class CS2_SimpleAdmin
|
|||||||
IpAddress = ipAddress
|
IpAddress = ipAddress
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Perform asynchronous database operations within a single method
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
// Initialize BanManager, MuteManager, and PlayerPenaltyManager within the async delegate
|
// Initialize managers
|
||||||
BanManager _banManager = new(_database, Config);
|
BanManager _banManager = new(_database, Config);
|
||||||
MuteManager _muteManager = new(_database);
|
MuteManager _muteManager = new(_database);
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||||
|
|
||||||
if (await _banManager.IsPlayerBanned(playerInfo))
|
try
|
||||||
{
|
{
|
||||||
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
// Check if the player is banned
|
||||||
bannedPlayers.Add(playerInfo.IpAddress);
|
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||||
|
if (isBanned)
|
||||||
if (playerInfo.SteamId != null && !bannedPlayers.Contains(playerInfo.SteamId))
|
|
||||||
bannedPlayers.Add(playerInfo.SteamId);
|
|
||||||
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
{
|
||||||
var victim = Utilities.GetPlayerFromUserid(playerInfo.UserId);
|
// Add player's IP and SteamID to bannedPlayers list if not already present
|
||||||
if (victim != null && victim.UserId.HasValue)
|
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
||||||
|
bannedPlayers.Add(playerInfo.IpAddress);
|
||||||
|
|
||||||
|
if (playerInfo.SteamId != null && !bannedPlayers.Contains(playerInfo.SteamId))
|
||||||
|
bannedPlayers.Add(playerInfo.SteamId);
|
||||||
|
|
||||||
|
// Kick the player if banned
|
||||||
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
Helper.KickPlayer(victim.UserId.Value, "Banned");
|
var victim = Utilities.GetPlayerFromUserid(playerInfo.UserId);
|
||||||
}
|
if (victim != null && victim.UserId.HasValue)
|
||||||
});
|
{
|
||||||
|
Helper.KickPlayer(victim.UserId.Value, "Banned");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
// Check if the player is muted
|
||||||
|
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||||
if (activeMutes.Count > 0)
|
if (activeMutes.Count > 0)
|
||||||
{
|
|
||||||
foreach (dynamic mute in activeMutes)
|
|
||||||
{
|
{
|
||||||
string muteType = mute.type;
|
foreach (dynamic mute in activeMutes)
|
||||||
DateTime ends = mute.ends;
|
{
|
||||||
int duration = mute.duration;
|
string muteType = mute.type;
|
||||||
|
DateTime ends = mute.ends;
|
||||||
|
int duration = mute.duration;
|
||||||
|
|
||||||
if (muteType == "GAG")
|
// Apply mute penalty based on mute type
|
||||||
{
|
if (muteType == "GAG")
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Gag, ends, duration);
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
{
|
||||||
if (TagsDetected)
|
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Gag, ends, duration);
|
||||||
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
if (TagsDetected)
|
||||||
}
|
{
|
||||||
});
|
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
||||||
}
|
}
|
||||||
else if (muteType == "MUTE")
|
});
|
||||||
{
|
}
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Mute, ends, duration);
|
else if (muteType == "MUTE")
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
{
|
||||||
player.VoiceFlags = VoiceFlags.Muted;
|
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Mute, ends, duration);
|
||||||
});
|
Server.NextFrame(() =>
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Silence, ends, duration);
|
|
||||||
Server.NextFrame(() =>
|
|
||||||
{
|
|
||||||
player.VoiceFlags = VoiceFlags.Muted;
|
|
||||||
if (TagsDetected)
|
|
||||||
{
|
{
|
||||||
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
player.VoiceFlags = VoiceFlags.Muted;
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Silence, ends, duration);
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
player.VoiceFlags = VoiceFlags.Muted;
|
||||||
|
if (TagsDetected)
|
||||||
|
{
|
||||||
|
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.LogError($"Error processing player connection: {ex}");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add player to loadedPlayers
|
// Add player to loadedPlayers
|
||||||
@@ -377,6 +390,21 @@ public partial class CS2_SimpleAdmin
|
|||||||
_logger?.LogCritical("Unable to create or get server_id" + ex.Message);
|
_logger?.LogCritical("Unable to create or get server_id" + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Config.EnableMetrics)
|
||||||
|
{
|
||||||
|
string queryString = $"?address={address}&hostname={hostname}";
|
||||||
|
using HttpClient client = new();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HttpResponseMessage response = await client.GetAsync($"https://api.daffyy.love/index.php{queryString}");
|
||||||
|
}
|
||||||
|
catch (HttpRequestException ex)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Unable to make metrics call: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await _adminManager.GiveAllFlags();
|
await _adminManager.GiveAllFlags();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
@@ -24,7 +25,7 @@ public class AdminSQLManager
|
|||||||
{
|
{
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
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)";
|
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();
|
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
|
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)";
|
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();
|
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 _);
|
//_adminCache.TryRemove(playerSteamId, out _);
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
string sql = "";
|
string sql = "";
|
||||||
|
|
||||||
@@ -189,7 +190,7 @@ public class AdminSQLManager
|
|||||||
else
|
else
|
||||||
futureTime = null;
|
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`) " +
|
var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`, `server_id`) " +
|
||||||
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)";
|
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)";
|
||||||
@@ -212,7 +213,7 @@ public class AdminSQLManager
|
|||||||
{
|
{
|
||||||
try
|
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";
|
string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
||||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ internal class BanManager
|
|||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).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`) " +
|
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)";
|
"VALUES (@playerSteamid, @playerName, @playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||||
@@ -46,7 +47,7 @@ internal class BanManager
|
|||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).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`) " +
|
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)";
|
"VALUES (@playerSteamid, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||||
@@ -71,7 +72,7 @@ internal class BanManager
|
|||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).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`) " +
|
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)";
|
"VALUES (@playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||||
@@ -91,7 +92,7 @@ internal class BanManager
|
|||||||
|
|
||||||
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (player.SteamId == null && player.IpAddress == null)
|
if (player.SteamId == null || player.IpAddress == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -120,7 +121,7 @@ internal class BanManager
|
|||||||
AND status = 'ACTIVE'
|
AND status = 'ACTIVE'
|
||||||
AND (duration = 0 OR ends > @CurrentTime);";
|
AND (duration = 0 OR ends > @CurrentTime);";
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
var parameters = new
|
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)";
|
string sql = "SELECT COUNT(*) FROM sa_bans WHERE (player_steamid = @PlayerSteamID OR player_ip = @PlayerIP)";
|
||||||
int banCount;
|
int banCount;
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(player.IpAddress))
|
if (!string.IsNullOrEmpty(player.IpAddress))
|
||||||
{
|
{
|
||||||
@@ -166,7 +167,7 @@ internal class BanManager
|
|||||||
return;
|
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'";
|
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 });
|
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern });
|
||||||
@@ -178,11 +179,11 @@ internal class BanManager
|
|||||||
{
|
{
|
||||||
DateTime currentTime = DateTime.UtcNow.ToLocalTime();
|
DateTime currentTime = DateTime.UtcNow.ToLocalTime();
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
string sql = "";
|
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";
|
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() });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.UtcNow.ToLocalTime() });
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ internal class MuteManager
|
|||||||
{
|
{
|
||||||
if (player == null || player.SteamId == null) return;
|
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 now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||||
@@ -49,7 +50,7 @@ internal class MuteManager
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
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 now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||||
@@ -91,7 +92,7 @@ internal class MuteManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
DateTime currentTime = DateTime.Now.ToLocalTime();
|
DateTime currentTime = DateTime.Now.ToLocalTime();
|
||||||
string sql = "SELECT * FROM sa_mutes WHERE player_steamid = @PlayerSteamID AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
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)
|
public async Task<int> GetPlayerMutes(string steamId)
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
int muteCount;
|
int muteCount;
|
||||||
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
||||||
@@ -124,7 +125,7 @@ internal class MuteManager
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
if (type == 2)
|
if (type == 2)
|
||||||
{
|
{
|
||||||
@@ -150,7 +151,7 @@ internal class MuteManager
|
|||||||
{
|
{
|
||||||
try
|
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";
|
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() });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
||||||
|
|||||||
@@ -61,14 +61,18 @@ Manage your Counter-Strike 2 server by simple commands :)
|
|||||||
- team_chat @Message - Say message to all admins // @css/chat
|
- team_chat @Message - Say message to all admins // @css/chat
|
||||||
```
|
```
|
||||||
|
|
||||||
### Requirments
|
### Requirements
|
||||||
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) **tested on v168**
|
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) **tested on v201**
|
||||||
- MySQL **tested on MySQL (MariaDB) Server version: 10.11.4-MariaDB-1~deb12u1 Debian 12**
|
- MySQL **tested on MySQL (MariaDB) Server version: 10.11.4-MariaDB-1~deb12u1 Debian 12**
|
||||||
|
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
After first launch, u need to configure plugin in addons/counterstrikesharp/configs/plugins/CS2-SimpleAdmin/CS2-SimpleAdmin.json
|
After first launch, u need to configure plugin in addons/counterstrikesharp/configs/plugins/CS2-SimpleAdmin/CS2-SimpleAdmin.json
|
||||||
|
|
||||||
|
### Metrics
|
||||||
|
From version 1.3.7a, CS2-SimpleAdmin now initiates metrics data collection. This includes gathering essential information such as the `server name` and `server address`.
|
||||||
|
You can disable metrics by set `EnableMetrics` to false in plugin configuration.
|
||||||
|
|
||||||
### Colors
|
### Colors
|
||||||
```
|
```
|
||||||
public static char Default = '\x01';
|
public static char Default = '\x01';
|
||||||
|
|||||||
Reference in New Issue
Block a user