mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-24 00:58:01 +03:00
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>
62 lines
1.6 KiB
C#
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; }
|
|
}
|
|
}
|