Files
wwdpublic/Content.Server/_Funkystation/Administration/ServerApi.Funkystation.cs
sleepyyapril 1d79c0b886 Port (Totally Tay's and Not Mine) Funky's Whitelist HTTP API Action (#2297)
i totally didn't write this, tay did, mhm
backend game portion for from-discord whitelisting
https://github.com/funky-station/funky-station/pull/679

<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Add a player to the whitelist via the admin HTTP API.
Meant to be used with a bot like
https://github.com/sleepyyapril/FunkyWhitelist

Co-authored-by: VMSolidus <evilexecutive@gmail.com>
2025-07-20 12:54:38 +10:00

62 lines
1.6 KiB
C#

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Content.Server.Database;
using Robust.Server.ServerStatus;
namespace Content.Server.Administration;
public sealed partial class ServerApi
{
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
public void InitializeFunky()
{
RegisterHandler(HttpMethod.Post, "/admin/actions/whitelist", ActionWhitelist);
}
/// <summary>
/// Whitelists a player.
/// </summary>
private async Task ActionWhitelist(IStatusHandlerContext context)
{
var body = await ReadJson<WhitelistActionBody>(context);
if (body == null)
return;
var data = await _playerLocator.LookupIdByNameOrIdAsync(body.Username);
if (data == null)
{
await RespondError(
context,
ErrorCode.PlayerNotFound,
HttpStatusCode.UnprocessableContent,
"Player not found");
return;
}
var isWhitelisted = await _dbManager.GetWhitelistStatusAsync(data.UserId);
if (isWhitelisted)
{
await RespondError(
context,
ErrorCode.BadRequest,
HttpStatusCode.Conflict,
"Already whitelisted");
return;
}
await _dbManager.AddToWhitelistAsync(data.UserId);
await RespondOk(context);
}
private sealed class WhitelistActionBody
{
public required string Username { get; init; }
}
}