Files
wwdpublic/Content.Server/Administration/Toolshed/SpawnPassportCommand.cs
Timfa 6bec449856 Allow Admins to Spawn a Passport for Players (#2150)
<!--
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]?
-->

Adds an admin command to spawn a passport

---

<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

![image](https://github.com/user-attachments/assets/2f81d318-45d7-445c-8857-88d53a7a786e)

</p>
</details>

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑
- add: Added admin command to spawn a passport for a player

---------

Signed-off-by: Timfa <timfalken@hotmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit e7497abdadc017ff2f4494f505c253059d688e83)
2025-04-04 15:02:05 +03:00

64 lines
2.2 KiB
C#

using Content.Server.GameTicking;
using Content.Shared._EE.Contractors.Systems;
using Content.Shared.Administration;
using Robust.Shared.Player;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Errors;
using Content.Shared.Roles.Jobs;
using Content.Server.Mind;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
public sealed class SpawnPassportCommand : ToolshedCommand
{
private SharedPassportSystem? _passportSystem;
private GameTicker? _ticker;
private MindSystem? _mindSystem;
private SharedJobSystem? _jobSystem;
[CommandImplementation]
public IEnumerable<EntityUid> SpawnPassport([PipedArgument] IEnumerable<EntityUid> input)
{
_passportSystem ??= GetSys<SharedPassportSystem>();
_ticker ??= GetSys<GameTicker>();
_mindSystem ??= GetSys<MindSystem>();
_jobSystem ??= GetSys<SharedJobSystem>();
foreach (var i in input)
{
if (!TryComp(i, out ActorComponent? targetActor) || !_mindSystem.TryGetMind(i, out var mindId, out _) || !_jobSystem.MindTryGetJob(mindId, out var job))
continue;
var profile = _ticker.GetPlayerProfile(targetActor.PlayerSession);
_passportSystem.SpawnPassportForPlayer(i, profile, job.ID);
yield return i;
}
}
[CommandImplementation]
public void SpawnPassport(IInvocationContext ctx)
{
_passportSystem ??= GetSys<SharedPassportSystem>();
_ticker ??= GetSys<GameTicker>();
_mindSystem ??= GetSys<MindSystem>();
_jobSystem ??= GetSys<SharedJobSystem>();
if (ExecutingEntity(ctx) is not { } ent)
{
if (ctx.Session is {} session)
ctx.ReportError(new SessionHasNoEntityError(session));
else
ctx.ReportError(new NotForServerConsoleError());
}
else
{
if (!TryComp(ent, out ActorComponent? targetActor)|| !_mindSystem.TryGetMind(ent, out var mindId, out _) || !_jobSystem.MindTryGetJob(mindId, out var job))
return;
var profile = _ticker.GetPlayerProfile(targetActor.PlayerSession);
_passportSystem.SpawnPassportForPlayer(ent, profile, job.ID);
}
}
}