mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
# Conflicts: # .github/CODEOWNERS # Content.Client/Administration/UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs # Content.Client/Lobby/LobbyUIController.cs # Content.Server/Administration/Systems/AdminSystem.cs # Content.Server/Connection/ConnectionManager.cs # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Content.Shared/Administration/Events/PanicBunkerChangedEvent.cs # Content.Shared/Preferences/HumanoidCharacterProfile.cs # Resources/Prototypes/Accents/word_replacements.yml # Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/backpack.yml # Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/duffelbag.yml # Resources/Prototypes/Catalog/Fills/Backpacks/StarterGear/satchel.yml # Resources/Prototypes/Entities/Mobs/base.yml # Resources/Prototypes/Roles/Antags/nukeops.yml # Resources/Prototypes/Roles/Antags/revolutionary.yml # Resources/Prototypes/Roles/Antags/traitor.yml # Resources/Prototypes/Roles/Antags/zombie.yml # Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml # Resources/ServerInfo/Guidebook/Antagonist/Traitors.xml # Resources/ServerInfo/Guidebook/Cargo/Cargo.xml # Resources/ServerInfo/Guidebook/Cargo/CargoBounties.xml # Resources/ServerInfo/Guidebook/Cargo/Salvage.xml # Resources/ServerInfo/Guidebook/Controls/Controls.xml # Resources/ServerInfo/Guidebook/Controls/Radio.xml # Resources/ServerInfo/Guidebook/Engineering/Engineering.xml # Resources/ServerInfo/Guidebook/Engineering/Fires.xml # Resources/ServerInfo/Guidebook/Engineering/Singularity.xml # Resources/ServerInfo/Guidebook/Jobs.xml # Resources/ServerInfo/Guidebook/Medical/Chemist.xml # Resources/ServerInfo/Guidebook/Medical/Medical.xml # Resources/ServerInfo/Guidebook/Medical/MedicalDoctor.xml # Resources/ServerInfo/Guidebook/Science/Science.xml # Resources/ServerInfo/Guidebook/Security/Security.xml # Resources/ServerInfo/Guidebook/Service/Bartender.xml # Resources/ServerInfo/Guidebook/Service/Chef.xml # Resources/ServerInfo/Guidebook/SpaceStation14.xml # Resources/ServerInfo/Guidebook/Survival.xml # Resources/Textures/Objects/Storage/boxes.rsi/meta.json
337 lines
11 KiB
C#
337 lines
11 KiB
C#
using Content.Server.Players.PlayTimeTracking;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Players.PlayTimeTracking;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Console;
|
|
|
|
namespace Content.Server.Administration.Commands;
|
|
|
|
[AdminCommand(AdminFlags.Permissions)] // Corvax-DiscordRoles
|
|
public sealed class PlayTimeAddOverallCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_addoverall";
|
|
public string Description => Loc.GetString("cmd-playtime_addoverall-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_addoverall-help", ("command", Command));
|
|
|
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 2)
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-playtime_addoverall-error-args"));
|
|
return;
|
|
}
|
|
|
|
if (!int.TryParse(args[1], out var minutes))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-minutes-fail", ("minutes", args[1])));
|
|
return;
|
|
}
|
|
|
|
if (!_playerManager.TryGetSessionByUsername(args[0], out var player))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", args[0])));
|
|
return;
|
|
}
|
|
|
|
_playTimeTracking.AddTimeToOverallPlaytime(player, TimeSpan.FromMinutes(minutes));
|
|
var overall = _playTimeTracking.GetOverallPlaytime(player);
|
|
|
|
shell.WriteLine(Loc.GetString(
|
|
"cmd-playtime_addoverall-succeed",
|
|
("username", args[0]),
|
|
("time", overall)));
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
return CompletionResult.FromHintOptions(CompletionHelper.SessionNames(),
|
|
Loc.GetString("cmd-playtime_addoverall-arg-user"));
|
|
|
|
if (args.Length == 2)
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-playtime_addoverall-arg-minutes"));
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Permissions)] // Corvax-DiscordRoles
|
|
public sealed class PlayTimeAddRoleCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_addrole";
|
|
public string Description => Loc.GetString("cmd-playtime_addrole-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_addrole-help", ("command", Command));
|
|
|
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 3)
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-playtime_addrole-error-args"));
|
|
return;
|
|
}
|
|
|
|
var userName = args[0];
|
|
if (!_playerManager.TryGetSessionByUsername(userName, out var player))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", userName)));
|
|
return;
|
|
}
|
|
|
|
var role = args[1];
|
|
|
|
var m = args[2];
|
|
if (!int.TryParse(m, out var minutes))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-minutes-fail", ("minutes", minutes)));
|
|
return;
|
|
}
|
|
|
|
_playTimeTracking.AddTimeToTracker(player, role, TimeSpan.FromMinutes(minutes));
|
|
var time = _playTimeTracking.GetPlayTimeForTracker(player, role);
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_addrole-succeed",
|
|
("username", userName),
|
|
("role", role),
|
|
("time", time)));
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.SessionNames(players: _playerManager),
|
|
Loc.GetString("cmd-playtime_addrole-arg-user"));
|
|
}
|
|
|
|
if (args.Length == 2)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.PrototypeIDs<PlayTimeTrackerPrototype>(),
|
|
Loc.GetString("cmd-playtime_addrole-arg-role"));
|
|
}
|
|
|
|
if (args.Length == 3)
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-playtime_addrole-arg-minutes"));
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Moderator)]
|
|
public sealed class PlayTimeGetOverallCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_getoverall";
|
|
public string Description => Loc.GetString("cmd-playtime_getoverall-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_getoverall-help", ("command", Command));
|
|
|
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 1)
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-playtime_getoverall-error-args"));
|
|
return;
|
|
}
|
|
|
|
var userName = args[0];
|
|
if (!_playerManager.TryGetSessionByUsername(userName, out var player))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", userName)));
|
|
return;
|
|
}
|
|
|
|
var value = _playTimeTracking.GetOverallPlaytime(player);
|
|
shell.WriteLine(Loc.GetString(
|
|
"cmd-playtime_getoverall-success",
|
|
("username", userName),
|
|
("time", value)));
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.SessionNames(players: _playerManager),
|
|
Loc.GetString("cmd-playtime_getoverall-arg-user"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Moderator)]
|
|
public sealed class PlayTimeGetRoleCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_getrole";
|
|
public string Description => Loc.GetString("cmd-playtime_getrole-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_getrole-help", ("command", Command));
|
|
|
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length is not (1 or 2))
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_getrole-error-args"));
|
|
return;
|
|
}
|
|
|
|
var userName = args[0];
|
|
if (!_playerManager.TryGetSessionByUsername(userName, out var session))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", userName)));
|
|
return;
|
|
}
|
|
|
|
if (args.Length == 1)
|
|
{
|
|
var timers = _playTimeTracking.GetTrackerTimes(session);
|
|
|
|
if (timers.Count == 0)
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_getrole-no"));
|
|
return;
|
|
}
|
|
|
|
foreach (var (role, time) in timers)
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_getrole-role", ("role", role), ("time", time)));
|
|
}
|
|
}
|
|
|
|
if (args.Length >= 2)
|
|
{
|
|
if (args[1] == "Overall")
|
|
{
|
|
var timer = _playTimeTracking.GetOverallPlaytime(session);
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_getrole-overall", ("time", timer)));
|
|
return;
|
|
}
|
|
|
|
var time = _playTimeTracking.GetPlayTimeForTracker(session, args[1]);
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_getrole-succeed", ("username", session.Name),
|
|
("time", time)));
|
|
}
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.SessionNames(players: _playerManager),
|
|
Loc.GetString("cmd-playtime_getrole-arg-user"));
|
|
}
|
|
|
|
if (args.Length == 2)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.PrototypeIDs<PlayTimeTrackerPrototype>(),
|
|
Loc.GetString("cmd-playtime_getrole-arg-role"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Saves the timers for a particular player immediately
|
|
/// </summary>
|
|
[AdminCommand(AdminFlags.Moderator)]
|
|
public sealed class PlayTimeSaveCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_save";
|
|
public string Description => Loc.GetString("cmd-playtime_save-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_save-help", ("command", Command));
|
|
|
|
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length != 1)
|
|
{
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_save-error-args"));
|
|
return;
|
|
}
|
|
|
|
var name = args[0];
|
|
if (!_playerManager.TryGetSessionByUsername(name, out var pSession))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", name)));
|
|
return;
|
|
}
|
|
|
|
_playTimeTracking.SaveSession(pSession);
|
|
shell.WriteLine(Loc.GetString("cmd-playtime_save-succeed", ("username", name)));
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.SessionNames(players: _playerManager),
|
|
Loc.GetString("cmd-playtime_save-arg-user"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|
|
|
|
[AdminCommand(AdminFlags.Debug)]
|
|
public sealed class PlayTimeFlushCommand : IConsoleCommand
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeTracking = default!;
|
|
|
|
public string Command => "playtime_flush";
|
|
public string Description => Loc.GetString("cmd-playtime_flush-desc");
|
|
public string Help => Loc.GetString("cmd-playtime_flush-help", ("command", Command));
|
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length is not (0 or 1))
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-playtime_flush-error-args"));
|
|
return;
|
|
}
|
|
|
|
if (args.Length == 0)
|
|
{
|
|
_playTimeTracking.FlushAllTrackers();
|
|
return;
|
|
}
|
|
|
|
var name = args[0];
|
|
if (!_playerManager.TryGetSessionByUsername(name, out var pSession))
|
|
{
|
|
shell.WriteError(Loc.GetString("parse-session-fail", ("username", name)));
|
|
return;
|
|
}
|
|
|
|
_playTimeTracking.FlushTracker(pSession);
|
|
}
|
|
|
|
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
return CompletionResult.FromHintOptions(
|
|
CompletionHelper.SessionNames(players: _playerManager),
|
|
Loc.GetString("cmd-playtime_flush-arg-user"));
|
|
}
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|