* Basic structure for the player panel ui * Ensure basic functionality Player panel now receives and displays basic info * Make whitelistcommands accept user ids * Make PlayerPanel use GUIDs where possible * Add functionality to most playerpanel buttons * Implement remaining playerpanel features * Localize everything * Finish up * Put command arguments in quotes I am not sure if it's even possible to have something like a space in them considering they are guids and usernames but sure why not * Make playerpanel a verb * Add Logs button to player panel * Change Notesbutton text and make whitelistbutton a confirmtion button * Add freeze button that does not mute the player * Add sharedconnections counter to playerpanel * Make the playetime format clearer * Allow for copying of the a player's username * Do minor cleanup * Rearrange buttons * Fix unfreeze button not updating * Fix wrong localisation text * "Fix" the same role ban counting multiple times The way rolebans are stored is horrible. As such if you ban someone from a departmenrt or something role bans are individually placed for every role. The only way I found to distinguish them is the bantime. This is horrible but I do not want to rewrite how all the bans are stored right now. * Add Delete and Rejuvenate buttons to player panel By popular demand * Marginally improve ui * Add logs * review update * Fix verb * Fix double notes --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
145 lines
4.5 KiB
C#
145 lines
4.5 KiB
C#
using Content.Server.Administration;
|
|
using Content.Server.Database;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Content.Server.Whitelist;
|
|
|
|
[AdminCommand(AdminFlags.Ban)]
|
|
public sealed class AddWhitelistCommand : LocalizedCommands
|
|
{
|
|
public override string Command => "whitelistadd";
|
|
|
|
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length == 0)
|
|
{
|
|
shell.WriteError(Loc.GetString("shell-need-minimum-one-argument"));
|
|
shell.WriteLine(Help);
|
|
return;
|
|
}
|
|
|
|
var db = IoCManager.Resolve<IServerDbManager>();
|
|
var loc = IoCManager.Resolve<IPlayerLocator>();
|
|
|
|
var name = string.Join(' ', args).Trim();
|
|
var data = await loc.LookupIdByNameOrIdAsync(name);
|
|
|
|
if (data != null)
|
|
{
|
|
var guid = data.UserId;
|
|
var isWhitelisted = await db.GetWhitelistStatusAsync(guid);
|
|
if (isWhitelisted)
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-whitelistadd-existing", ("username", data.Username)));
|
|
return;
|
|
}
|
|
|
|
await db.AddToWhitelistAsync(guid);
|
|
shell.WriteLine(Loc.GetString("cmd-whitelistadd-added", ("username", data.Username)));
|
|
return;
|
|
}
|
|
|
|
shell.WriteError(Loc.GetString("cmd-whitelistadd-not-found", ("username", args[0])));
|
|
}
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-whitelistadd-arg-player"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Ban)]
|
|
public sealed class RemoveWhitelistCommand : LocalizedCommands
|
|
{
|
|
public override string Command => "whitelistremove";
|
|
|
|
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length == 0)
|
|
{
|
|
shell.WriteError(Loc.GetString("shell-need-minimum-one-argument"));
|
|
shell.WriteLine(Help);
|
|
return;
|
|
}
|
|
|
|
var db = IoCManager.Resolve<IServerDbManager>();
|
|
var loc = IoCManager.Resolve<IPlayerLocator>();
|
|
|
|
var name = string.Join(' ', args).Trim();
|
|
var data = await loc.LookupIdByNameOrIdAsync(name);
|
|
|
|
if (data != null)
|
|
{
|
|
var guid = data.UserId;
|
|
var isWhitelisted = await db.GetWhitelistStatusAsync(guid);
|
|
if (!isWhitelisted)
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-whitelistremove-existing", ("username", data.Username)));
|
|
return;
|
|
}
|
|
|
|
await db.RemoveFromWhitelistAsync(guid);
|
|
shell.WriteLine(Loc.GetString("cmd-whitelistremove-removed", ("username", data.Username)));
|
|
return;
|
|
}
|
|
|
|
shell.WriteError(Loc.GetString("cmd-whitelistremove-not-found", ("username", args[0])));
|
|
}
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-whitelistremove-arg-player"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Ban)]
|
|
public sealed class KickNonWhitelistedCommand : LocalizedCommands
|
|
{
|
|
public override string Command => "kicknonwhitelisted";
|
|
|
|
public override async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 0)
|
|
{
|
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number-need-specific", ("properAmount", 0), ("currentAmount", args.Length)));
|
|
shell.WriteLine(Help);
|
|
return;
|
|
}
|
|
|
|
var cfg = IoCManager.Resolve<IConfigurationManager>();
|
|
|
|
if (!cfg.GetCVar(CCVars.WhitelistEnabled))
|
|
return;
|
|
|
|
var player = IoCManager.Resolve<IPlayerManager>();
|
|
var db = IoCManager.Resolve<IServerDbManager>();
|
|
var net = IoCManager.Resolve<IServerNetManager>();
|
|
|
|
foreach (var session in player.NetworkedSessions)
|
|
{
|
|
if (await db.GetAdminDataForAsync(session.UserId) is not null)
|
|
continue;
|
|
|
|
if (!await db.GetWhitelistStatusAsync(session.UserId))
|
|
{
|
|
net.DisconnectChannel(session.Channel, Loc.GetString("whitelist-not-whitelisted"));
|
|
}
|
|
}
|
|
}
|
|
}
|