mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
1.2.4a
- mysql admins - minor changes
This commit is contained in:
79
AdminSQLManager.cs
Normal file
79
AdminSQLManager.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Dapper;
|
||||
using MySqlConnector;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CS2_SimpleAdmin
|
||||
{
|
||||
internal class AdminSQLManager
|
||||
{
|
||||
private readonly MySqlConnection _dbConnection;
|
||||
|
||||
public AdminSQLManager(string connectionString)
|
||||
{
|
||||
_dbConnection = new MySqlConnection(connectionString);
|
||||
}
|
||||
|
||||
public async Task<List<dynamic>> GetAdminFlags(string steamId)
|
||||
{
|
||||
await using var connection = _dbConnection;
|
||||
await connection.OpenAsync();
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
string sql = "SELECT flags FROM sa_admins WHERE player_steamid = @PlayerSteamID AND (ends IS NULL OR ends > @CurrentTime)";
|
||||
List<dynamic> activeFlags = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now })).ToList();
|
||||
|
||||
return activeFlags;
|
||||
}
|
||||
|
||||
public async Task DeleteAdminBySteamId(string playerSteamId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||
|
||||
await using var connection = _dbConnection;
|
||||
await connection.OpenAsync();
|
||||
|
||||
string sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID";
|
||||
await connection.ExecuteAsync(sql, new { PlayerSteamID = playerSteamId });
|
||||
}
|
||||
|
||||
public async Task AddAdminBySteamId(string playerSteamId, string playerName, string flags, int immunity = 0, int time = 0)
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||
|
||||
flags = flags.Replace(" ", "");
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime? futureTime;
|
||||
if (time != 0)
|
||||
futureTime = now.AddMinutes(time);
|
||||
else
|
||||
futureTime = null;
|
||||
|
||||
await using var connection = _dbConnection;
|
||||
await connection.OpenAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`) " +
|
||||
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created)";
|
||||
|
||||
await connection.ExecuteAsync(sql, new
|
||||
{
|
||||
playerSteamId,
|
||||
playerName,
|
||||
flags,
|
||||
immunity,
|
||||
ends = futureTime,
|
||||
created = now
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteOldAdmins()
|
||||
{
|
||||
await using var connection = _dbConnection;
|
||||
await connection.OpenAsync();
|
||||
|
||||
string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
[MinimumApiVersion(126)]
|
||||
[MinimumApiVersion(124)]
|
||||
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
||||
{
|
||||
public static IStringLocalizer? _localizer;
|
||||
@@ -29,9 +29,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
|
||||
internal string dbConnectionString = string.Empty;
|
||||
public override string ModuleName => "CS2-SimpleAdmin";
|
||||
public override string ModuleDescription => "";
|
||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||
public override string ModuleAuthor => "daffyy";
|
||||
public override string ModuleVersion => "1.2.3a";
|
||||
public override string ModuleVersion => "1.2.4a";
|
||||
|
||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||
|
||||
@@ -104,6 +104,20 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
command = new MySqlCommand(sql, connection);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
sql = @"CREATE TABLE IF NOT EXISTS `sa_admins` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`player_steamid` varchar(64) NOT NULL,
|
||||
`player_name` varchar(128) NOT NULL,
|
||||
`flags` TEXT,
|
||||
`immunity` varchar(64) NOT NULL DEFAULT '0',
|
||||
`ends` timestamp,
|
||||
`created` timestamp NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci";
|
||||
|
||||
command = new MySqlCommand(sql, connection);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
@@ -132,6 +146,60 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_addadmin")]
|
||||
[CommandHelper(minArgs: 4, usage: "<steamid> <name> <flags/groups> <immunity> <duration>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||
[RequiresPermissions("@css/root")]
|
||||
public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command)
|
||||
{
|
||||
if (!Helper.IsValidSteamID64(command.GetArg(1)))
|
||||
{
|
||||
command.ReplyToCommand($"Invalid SteamID64.");
|
||||
return;
|
||||
}
|
||||
if (command.GetArg(2).Length <= 0)
|
||||
{
|
||||
command.ReplyToCommand($"Invalid player name.");
|
||||
return;
|
||||
}
|
||||
if (!command.GetArg(3).Contains("@") && !command.GetArg(3).Contains("#"))
|
||||
{
|
||||
command.ReplyToCommand($"Invalid player name.");
|
||||
return;
|
||||
}
|
||||
|
||||
string steamid = command.GetArg(1);
|
||||
string name = command.GetArg(2);
|
||||
string flags = command.GetArg(3);
|
||||
int immunity = 0;
|
||||
int.TryParse(command.GetArg(4), out immunity);
|
||||
int time = 0;
|
||||
int.TryParse(command.GetArg(5), out time);
|
||||
|
||||
AdminSQLManager _adminManager = new(dbConnectionString);
|
||||
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time);
|
||||
|
||||
command.ReplyToCommand($"Added '{flags}' flags to '{name}' ({steamid})");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_deladmin")]
|
||||
[CommandHelper(minArgs: 1, usage: "<steamid>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||
[RequiresPermissions("@css/root")]
|
||||
public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command)
|
||||
{
|
||||
if (!Helper.IsValidSteamID64(command.GetArg(1)))
|
||||
{
|
||||
command.ReplyToCommand($"Invalid SteamID64.");
|
||||
return;
|
||||
}
|
||||
|
||||
string steamid = command.GetArg(1);
|
||||
|
||||
AdminSQLManager _adminManager = new(dbConnectionString);
|
||||
_ = _adminManager.DeleteAdminBySteamId(steamid);
|
||||
|
||||
command.ReplyToCommand($"Removed flags from '{steamid}'");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_who")]
|
||||
[CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||
[RequiresPermissions("@css/generic")]
|
||||
@@ -163,30 +231,56 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
totalBans = await _banManager.GetPlayerBans(playerInfo);
|
||||
totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!);
|
||||
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
|
||||
|
||||
caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
|
||||
caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
|
||||
if (playerInfo.SteamId != null)
|
||||
caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
if (caller != null)
|
||||
{
|
||||
caller!.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
|
||||
caller!.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
|
||||
}
|
||||
if (playerInfo.IpAddress != null)
|
||||
caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
|
||||
caller!.PrintToConsole($"• Ping: \"{player.Ping}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
{
|
||||
caller!.PrintToConsole($"• Total Bans: \"{totalBans}\"");
|
||||
caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
|
||||
}
|
||||
caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
|
||||
|
||||
caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
|
||||
caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
|
||||
caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
|
||||
if (playerInfo.SteamId != null)
|
||||
caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
{
|
||||
caller!.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
|
||||
caller!.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
|
||||
}
|
||||
if (playerInfo.IpAddress != null)
|
||||
caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
|
||||
caller!.PrintToConsole($"• Ping: \"{player.Ping}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
{
|
||||
caller!.PrintToConsole($"• Total Bans: \"{totalBans}\"");
|
||||
caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
|
||||
}
|
||||
|
||||
caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
|
||||
}
|
||||
else
|
||||
{
|
||||
Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
|
||||
|
||||
Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
|
||||
Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
|
||||
if (playerInfo.SteamId != null)
|
||||
Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
{
|
||||
Server.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
|
||||
Server.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
|
||||
}
|
||||
if (playerInfo.IpAddress != null)
|
||||
Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
|
||||
Server.PrintToConsole($"• Ping: \"{player.Ping}\"");
|
||||
if (player.AuthorizedSteamID != null)
|
||||
{
|
||||
Server.PrintToConsole($"• Total Bans: \"{totalBans}\"");
|
||||
Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
|
||||
}
|
||||
|
||||
Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,13 +296,26 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
if (targets == null) return;
|
||||
List<CCSPlayerController> playersToTarget = targets!.Players.Where(player => caller!.CanTarget(player) && player != null && player.IsValid && !player.IsBot && !player.IsHLTV).ToList();
|
||||
|
||||
caller!.PrintToConsole($"--------- PLAYER LIST ---------");
|
||||
playersToTarget.ForEach(player =>
|
||||
if (caller != null)
|
||||
{
|
||||
caller!.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.AuthorizedSteamID?.SteamId64}\")");
|
||||
caller!.PrintToConsole($"--------- PLAYER LIST ---------");
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
caller!.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.AuthorizedSteamID?.SteamId64}\")");
|
||||
|
||||
});
|
||||
caller!.PrintToConsole($"--------- END PLAYER LIST ---------");
|
||||
});
|
||||
caller!.PrintToConsole($"--------- END PLAYER LIST ---------");
|
||||
}
|
||||
else
|
||||
{
|
||||
Server.PrintToConsole($"--------- PLAYER LIST ---------");
|
||||
playersToTarget.ForEach(player =>
|
||||
{
|
||||
Server.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.AuthorizedSteamID?.SteamId64}\")");
|
||||
|
||||
});
|
||||
Server.PrintToConsole($"--------- END PLAYER LIST ---------");
|
||||
}
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_kick")]
|
||||
@@ -1130,6 +1237,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[ConsoleCommand("css_hp")]
|
||||
[RequiresPermissions("@css/slay")]
|
||||
[CommandHelper(minArgs: 1, usage: "<#userid or name> <health>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||
@@ -1288,6 +1396,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[ConsoleCommand("css_vote")]
|
||||
[RequiresPermissions("@css/generic")]
|
||||
[CommandHelper(minArgs: 2, usage: "<question> [... options ...]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||
|
||||
35
Events.cs
35
Events.cs
@@ -127,6 +127,9 @@ public partial class CS2_SimpleAdmin
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId!);
|
||||
|
||||
AdminSQLManager _adminManager = new(dbConnectionString);
|
||||
List<dynamic> activeFlags = await _adminManager.GetAdminFlags(playerInfo.SteamId!);
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
@@ -218,6 +221,36 @@ public partial class CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (activeFlags != null && activeFlags.Count > 0)
|
||||
{
|
||||
foreach (var flags in activeFlags)
|
||||
{
|
||||
if (flags == null) continue;
|
||||
string flagsValue = flags.flags.ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(flagsValue))
|
||||
{
|
||||
string[] _flags = flagsValue.Split(",");
|
||||
|
||||
AddTimer(10, () =>
|
||||
{
|
||||
if (player == null) return;
|
||||
foreach (var _flag in _flags)
|
||||
{
|
||||
if (_flag.StartsWith("@"))
|
||||
{
|
||||
AdminManager.AddPlayerPermissions(player, _flag);
|
||||
}
|
||||
if (_flag.StartsWith("3"))
|
||||
{
|
||||
AdminManager.AddPlayerToGroup(player, _flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -261,6 +294,8 @@ public partial class CS2_SimpleAdmin
|
||||
_ = _banManager.ExpireOldBans();
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
_ = _muteManager.ExpireOldMutes();
|
||||
AdminSQLManager _adminManager = new(dbConnectionString);
|
||||
_ = _adminManager.DeleteOldAdmins();
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
string? path = Path.GetDirectoryName(ModuleDirectory);
|
||||
|
||||
@@ -9,6 +9,8 @@ Manage your Counter-Strike 2 server by simple commands :)
|
||||
|
||||
### Commands
|
||||
```js
|
||||
- css_addadmin <steamid> <name> <flags/groups> <immunity> [time in minutes] - Add admin by steamid // @css/root
|
||||
- css_deladmin <steamid> - Delete admin by steamid // @css/root
|
||||
- css_admin - Display all admin commands // @css/generic
|
||||
- css_who <#userid or name> - Display informations about player // @css/generic
|
||||
- css_players - Display player list // @css/generic
|
||||
|
||||
Reference in New Issue
Block a user