mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 05:59:03 +03:00
<!-- 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 This adds the Time Transfer Panel that Goobstation uses. This panel enables Admins to do Time Transfers without commands and makes their lives easier. This immediately has access to all playtime trackers and allows an Admin to Add Time and/or Set Time (overwriting the previous time) for any job role. It also enables extra strings since I ported from Wizden upstream as well, which can be seen in the commit history. A thing of note when testing this and using it in a server: the times **DO NOT UPDATE** for Client until your **RELOG**. This is how it works on Goobstation as well. The time adding process is faster and will be easier tool. This is tied to the AdminFlags.Admin so it can be customized on a per-server basis if a custom flag is added. --- # TODO - [x] Port Upstream Role Define. - [x] Port string extras for playtime commands. - [x] Port Time Transfer Panel - [x] Remove Overall (it just doesn't work on Goob either). --- <details><summary><h1>Media</h1></summary> <p>          </p> </details> --- # Changelog 🆑 ADMIN: - add: Add Time Transfer Panel --------- Co-authored-by: BombasterDS <115770678+BombasterDS@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: flyingkarii <123355664+flyingkarii@users.noreply.github.com> (cherry picked from commit a05bbce7491677a27656fd67ee72fb8dbdb4c53c)
142 lines
4.7 KiB
C#
142 lines
4.7 KiB
C#
using Content.Server.Administration;
|
|
using Content.Server.Administration.Commands;
|
|
using Content.Server.Administration.Managers;
|
|
using Content.Server.Database;
|
|
using Content.Server.EUI;
|
|
using Content.Server.Players.PlayTimeTracking;
|
|
using Content.Shared._Goobstation.Administration;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Eui;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server._Goobstation.Administration;
|
|
|
|
public sealed class TimeTransferPanelEui : BaseEui
|
|
{
|
|
[Dependency] private readonly IAdminManager _adminMan = default!;
|
|
[Dependency] private readonly ILogManager _log = default!;
|
|
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
|
|
[Dependency] private readonly IPlayerManager _playerMan = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
|
[Dependency] private readonly IServerDbManager _databaseMan = default!;
|
|
[Dependency] private readonly PlayTimeTrackingManager _playTimeMan = default!;
|
|
|
|
private readonly ISawmill _sawmill;
|
|
|
|
public TimeTransferPanelEui()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_sawmill = _log.GetSawmill("admin.time_eui");
|
|
}
|
|
|
|
public override TimeTransferPanelEuiState GetNewState()
|
|
{
|
|
var hasFlag = _adminMan.HasAdminFlag(Player, AdminFlags.Admin);
|
|
|
|
return new TimeTransferPanelEuiState(hasFlag);
|
|
}
|
|
|
|
public override void HandleMessage(EuiMessageBase msg)
|
|
{
|
|
base.HandleMessage(msg);
|
|
|
|
if (msg is not TimeTransferEuiMessage message)
|
|
return;
|
|
|
|
TransferTime(message.PlayerId, message.TimeData, message.Overwrite);
|
|
}
|
|
|
|
public async void TransferTime(string playerId, List<TimeTransferData> timeData, bool overwrite)
|
|
{
|
|
if (!_adminMan.HasAdminFlag(Player, AdminFlags.Admin))
|
|
{
|
|
_sawmill.Warning($"{Player.Name} ({Player.UserId} tried to add roles time without moderator flag)");
|
|
return;
|
|
}
|
|
|
|
var playerData = await _playerLocator.LookupIdByNameAsync(playerId);
|
|
if (playerData == null)
|
|
{
|
|
_sawmill.Warning($"{Player.Name} ({Player.UserId} tried to add roles time to not existing player {playerId})");
|
|
SendMessage(new TimeTransferWarningEuiMessage(Loc.GetString("time-transfer-panel-no-player-database-message"), Color.Red));
|
|
return;
|
|
}
|
|
|
|
if (overwrite)
|
|
SetTime(playerData.UserId, timeData);
|
|
else
|
|
AddTime(playerData.UserId, timeData);
|
|
}
|
|
|
|
public async void SetTime(NetUserId userId, List<TimeTransferData> timeData)
|
|
{
|
|
var updateList = new List<PlayTimeUpdate>();
|
|
|
|
foreach (var data in timeData)
|
|
{
|
|
var time = TimeSpan.FromMinutes(PlayTimeCommandUtilities.CountMinutes(data.TimeString));
|
|
updateList.Add(new PlayTimeUpdate(userId, data.PlaytimeTracker, time));
|
|
}
|
|
|
|
await _databaseMan.UpdatePlayTimes(updateList);
|
|
|
|
_sawmill.Info($"{Player.Name} ({Player.UserId} saved {updateList.Count} trackers for {userId})");
|
|
|
|
SendMessage(new TimeTransferWarningEuiMessage(Loc.GetString("time-transfer-panel-warning-set-success"), Color.LightGreen));
|
|
}
|
|
|
|
public async void AddTime(NetUserId userId, List<TimeTransferData> timeData)
|
|
{
|
|
var playTimeList = await _databaseMan.GetPlayTimes(userId);
|
|
|
|
Dictionary<string, TimeSpan> playTimeDict = new();
|
|
|
|
foreach (var playTime in playTimeList)
|
|
{
|
|
playTimeDict.Add(playTime.Tracker, playTime.TimeSpent);
|
|
}
|
|
|
|
var updateList = new List<PlayTimeUpdate>();
|
|
|
|
foreach (var data in timeData)
|
|
{
|
|
var time = TimeSpan.FromMinutes(PlayTimeCommandUtilities.CountMinutes(data.TimeString));
|
|
if (playTimeDict.TryGetValue(data.PlaytimeTracker, out var addTime))
|
|
time += addTime;
|
|
|
|
updateList.Add(new PlayTimeUpdate(userId, data.PlaytimeTracker, time));
|
|
}
|
|
|
|
await _databaseMan.UpdatePlayTimes(updateList);
|
|
|
|
_sawmill.Info($"{Player.Name} ({Player.UserId} saved {updateList.Count} trackers for {userId})");
|
|
|
|
SendMessage(new TimeTransferWarningEuiMessage(Loc.GetString("time-transfer-panel-warning-add-success"), Color.LightGreen));
|
|
}
|
|
|
|
public override async void Opened()
|
|
{
|
|
base.Opened();
|
|
_adminMan.OnPermsChanged += OnPermsChanged;
|
|
}
|
|
|
|
public override void Closed()
|
|
{
|
|
base.Closed();
|
|
_adminMan.OnPermsChanged -= OnPermsChanged;
|
|
}
|
|
|
|
private void OnPermsChanged(AdminPermsChangedEventArgs args)
|
|
{
|
|
if (args.Player != Player)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StateDirty();
|
|
}
|
|
}
|