mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
Added Admins management menu
This commit is contained in:
@@ -111,10 +111,21 @@ namespace CS2_SimpleAdmin
|
||||
int time = 0;
|
||||
int.TryParse(command.GetArg(5), out time);
|
||||
|
||||
AddAdmin(caller, steamid, name, flags, immunity, time, globalAdmin);
|
||||
}
|
||||
|
||||
public void AddAdmin(CCSPlayerController? caller, string steamid, string name, string flags, int immunity, int time = 0, bool globalAdmin = false, CommandInfo? command = null)
|
||||
{
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin);
|
||||
|
||||
command.ReplyToCommand($"Added '{flags}' flags to '{name}' ({steamid})");
|
||||
string msg = $"Added '{flags}' flags to '{name}' ({steamid})";
|
||||
if (command != null)
|
||||
command.ReplyToCommand(msg);
|
||||
else if (caller != null && caller.IsValid)
|
||||
caller.PrintToChat(msg);
|
||||
else
|
||||
Server.PrintToConsole(msg);
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_deladmin")]
|
||||
@@ -140,6 +151,11 @@ namespace CS2_SimpleAdmin
|
||||
string steamid = command.GetArg(1);
|
||||
bool globalDelete = command.GetArg(2).ToLower().Equals("-g");
|
||||
|
||||
RemoveAdmin(caller, steamid, globalDelete);
|
||||
}
|
||||
|
||||
public void RemoveAdmin(CCSPlayerController? caller, string steamid, bool globalDelete = false, CommandInfo? command = null)
|
||||
{
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
_ = _adminManager.DeleteAdminBySteamId(steamid, globalDelete);
|
||||
|
||||
@@ -156,8 +172,14 @@ namespace CS2_SimpleAdmin
|
||||
AdminManager.RemovePlayerAdminData(steamId);
|
||||
}
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
command.ReplyToCommand($"Removed flags from '{steamid}'");
|
||||
|
||||
string msg = $"Removed flags from '{steamid}'";
|
||||
if (command != null)
|
||||
command.ReplyToCommand(msg);
|
||||
else if (caller != null && caller.IsValid)
|
||||
caller.PrintToChat(msg);
|
||||
else
|
||||
Server.PrintToConsole(msg);
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_reladmin")]
|
||||
@@ -167,6 +189,13 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
if (_database == null) return;
|
||||
|
||||
ReloadAdmins();
|
||||
|
||||
command.ReplyToCommand("Reloaded sql admins");
|
||||
}
|
||||
|
||||
public void ReloadAdmins()
|
||||
{
|
||||
foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList())
|
||||
{
|
||||
if (AdminSQLManager._adminCache.TryRemove(steamId, out _))
|
||||
@@ -178,8 +207,6 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
_ = _adminManager.GiveAllFlags();
|
||||
|
||||
command.ReplyToCommand("Reloaded sql admins");
|
||||
}
|
||||
|
||||
[ConsoleCommand("css_stealth")]
|
||||
|
||||
85
Menus/ManageAdminsMenu.cs
Normal file
85
Menus/ManageAdminsMenu.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Menu;
|
||||
|
||||
namespace CS2_SimpleAdmin.Menus
|
||||
{
|
||||
public static class ManageAdminsMenu
|
||||
{
|
||||
public static void OpenMenu(CCSPlayerController admin)
|
||||
{
|
||||
if (admin == null || admin.IsValid == false)
|
||||
return;
|
||||
|
||||
if (AdminManager.PlayerHasPermissions(admin, "@css/generic") == false)
|
||||
{
|
||||
// TODO: Localize
|
||||
admin.PrintToChat("[Simple Admin] You do not have permissions to use this command.");
|
||||
return;
|
||||
}
|
||||
|
||||
BaseMenu menu = AdminMenu.CreateMenu("Manage Admins");
|
||||
List<ChatMenuOptionData> options = new();
|
||||
|
||||
// TODO: Localize options
|
||||
// options added in order
|
||||
|
||||
options.Add(new ChatMenuOptionData("Add Admin", () => PlayersMenu.OpenAliveMenu(admin, "Add Admin", AddAdminMenu)));
|
||||
options.Add(new ChatMenuOptionData("Remove Admin", () => PlayersMenu.OpenAliveMenu(admin, "Remove Admin", RemoveAdmin, player => player != admin && admin.CanTarget(player))));
|
||||
options.Add(new ChatMenuOptionData("Reload Admins", ReloadAdmins));
|
||||
|
||||
foreach (ChatMenuOptionData menuOptionData in options)
|
||||
{
|
||||
string menuName = menuOptionData.name;
|
||||
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled);
|
||||
}
|
||||
|
||||
AdminMenu.OpenMenu(admin, menu);
|
||||
}
|
||||
|
||||
private static void AddAdminMenu(CCSPlayerController admin, CCSPlayerController player)
|
||||
{
|
||||
Tuple<string, string>[] flags = new[]
|
||||
{
|
||||
new Tuple<string, string>("Generic", "@css/generic"),
|
||||
new Tuple<string, string>("Chat", "@css/chat"),
|
||||
new Tuple<string, string>("Change Map", "@css/changemap"),
|
||||
new Tuple<string, string>("Slay", "@css/slay"),
|
||||
new Tuple<string, string>("Kick", "@css/kick"),
|
||||
new Tuple<string, string>("Ban", "@css/ban"),
|
||||
new Tuple<string, string>("Unban", "@css/unban"),
|
||||
new Tuple<string, string>("Cheats", "@css/cheats"),
|
||||
new Tuple<string, string>("CVAR", "@css/cvar"),
|
||||
new Tuple<string, string>("RCON", "@css/rcon"),
|
||||
new Tuple<string, string>("Root", "@css/root"),
|
||||
};
|
||||
|
||||
BaseMenu menu = AdminMenu.CreateMenu($"Add Admin: {player.PlayerName}");
|
||||
|
||||
foreach (Tuple<string, string> flagsTuple in flags)
|
||||
{
|
||||
string optionName = flagsTuple.Item1;
|
||||
bool disabled = AdminManager.PlayerHasPermissions(player, flagsTuple.Item2);
|
||||
menu.AddMenuOption(optionName, (_, _) => { AddAdmin(admin, player, flagsTuple.Item2); }, disabled);
|
||||
}
|
||||
|
||||
AdminMenu.OpenMenu(admin, menu);
|
||||
}
|
||||
|
||||
private static void AddAdmin(CCSPlayerController admin, CCSPlayerController player, string flag)
|
||||
{
|
||||
// TODO: Change default immunity?
|
||||
CS2_SimpleAdmin.Instance.AddAdmin(admin, player.SteamID.ToString(), player.PlayerName, flag, 10);
|
||||
}
|
||||
|
||||
private static void RemoveAdmin(CCSPlayerController admin, CCSPlayerController player)
|
||||
{
|
||||
CS2_SimpleAdmin.Instance.RemoveAdmin(admin, player.SteamID.ToString());
|
||||
}
|
||||
|
||||
private static void ReloadAdmins()
|
||||
{
|
||||
CS2_SimpleAdmin.Instance.ReloadAdmins();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user