@@ -5,18 +5,18 @@ using System.Threading.Tasks;
|
||||
using Content.Server.Database;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Asynchronous;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Exceptions;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Players.PlayTimeTracking;
|
||||
|
||||
public delegate void CalcPlayTimeTrackersCallback(ICommonSession player, HashSet<string> trackers);
|
||||
public delegate void CalcPlayTimeTrackersCallback(IPlayerSession player, HashSet<string> trackers);
|
||||
|
||||
/// <summary>
|
||||
/// Tracks play time for players, across all roles.
|
||||
@@ -66,7 +66,7 @@ public sealed class PlayTimeTrackingManager
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
// List of players that need some kind of update (refresh timers or resend).
|
||||
private ValueList<ICommonSession> _playersDirty;
|
||||
private ValueList<IPlayerSession> _playersDirty;
|
||||
|
||||
// DB auto-saving logic.
|
||||
private TimeSpan _saveInterval;
|
||||
@@ -76,7 +76,7 @@ public sealed class PlayTimeTrackingManager
|
||||
// We must block server shutdown on these to avoid losing data.
|
||||
private readonly List<Task> _pendingSaveTasks = new();
|
||||
|
||||
private readonly Dictionary<ICommonSession, PlayTimeData> _playTimeData = new();
|
||||
private readonly Dictionary<IPlayerSession, PlayTimeData> _playTimeData = new();
|
||||
|
||||
public event CalcPlayTimeTrackersCallback? CalcTrackers;
|
||||
|
||||
@@ -139,7 +139,7 @@ public sealed class PlayTimeTrackingManager
|
||||
_playersDirty.Clear();
|
||||
}
|
||||
|
||||
private void RefreshSingleTracker(ICommonSession dirty, PlayTimeData data, TimeSpan time)
|
||||
private void RefreshSingleTracker(IPlayerSession dirty, PlayTimeData data, TimeSpan time)
|
||||
{
|
||||
DebugTools.Assert(data.Initialized);
|
||||
|
||||
@@ -181,7 +181,7 @@ public sealed class PlayTimeTrackingManager
|
||||
/// so APIs like <see cref="GetPlayTimeForTracker"/> return up-to-date info.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlushAllTrackers"/>
|
||||
public void FlushTracker(ICommonSession player)
|
||||
public void FlushTracker(IPlayerSession player)
|
||||
{
|
||||
var time = _timing.RealTime;
|
||||
var data = _playTimeData[player];
|
||||
@@ -201,7 +201,7 @@ public sealed class PlayTimeTrackingManager
|
||||
}
|
||||
}
|
||||
|
||||
private void SendPlayTimes(ICommonSession pSession)
|
||||
private void SendPlayTimes(IPlayerSession pSession)
|
||||
{
|
||||
var roles = GetTrackerTimes(pSession);
|
||||
|
||||
@@ -228,7 +228,7 @@ public sealed class PlayTimeTrackingManager
|
||||
/// <summary>
|
||||
/// Save all modified time trackers for a player to the database.
|
||||
/// </summary>
|
||||
public async void SaveSession(ICommonSession session)
|
||||
public async void SaveSession(IPlayerSession session)
|
||||
{
|
||||
// This causes all trackers to refresh, ah well.
|
||||
FlushAllTrackers();
|
||||
@@ -278,7 +278,7 @@ public sealed class PlayTimeTrackingManager
|
||||
_sawmill.Debug($"Saved {log.Count} trackers");
|
||||
}
|
||||
|
||||
private async Task DoSaveSessionAsync(ICommonSession session)
|
||||
private async Task DoSaveSessionAsync(IPlayerSession session)
|
||||
{
|
||||
var log = new List<PlayTimeUpdate>();
|
||||
|
||||
@@ -299,7 +299,7 @@ public sealed class PlayTimeTrackingManager
|
||||
_sawmill.Debug($"Saved {log.Count} trackers for {session.Name}");
|
||||
}
|
||||
|
||||
public async Task LoadData(ICommonSession session, CancellationToken cancel)
|
||||
public async Task LoadData(IPlayerSession session, CancellationToken cancel)
|
||||
{
|
||||
var data = new PlayTimeData();
|
||||
_playTimeData.Add(session, data);
|
||||
@@ -318,14 +318,14 @@ public sealed class PlayTimeTrackingManager
|
||||
QueueSendTimers(session);
|
||||
}
|
||||
|
||||
public void ClientDisconnected(ICommonSession session)
|
||||
public void ClientDisconnected(IPlayerSession session)
|
||||
{
|
||||
SaveSession(session);
|
||||
|
||||
_playTimeData.Remove(session);
|
||||
}
|
||||
|
||||
public void AddTimeToTracker(ICommonSession id, string tracker, TimeSpan time)
|
||||
public void AddTimeToTracker(IPlayerSession id, string tracker, TimeSpan time)
|
||||
{
|
||||
if (!_playTimeData.TryGetValue(id, out var data) || !data.Initialized)
|
||||
throw new InvalidOperationException("Play time info is not yet loaded for this player!");
|
||||
@@ -341,17 +341,17 @@ public sealed class PlayTimeTrackingManager
|
||||
data.DbTrackersDirty.Add(tracker);
|
||||
}
|
||||
|
||||
public void AddTimeToOverallPlaytime(ICommonSession id, TimeSpan time)
|
||||
public void AddTimeToOverallPlaytime(IPlayerSession id, TimeSpan time)
|
||||
{
|
||||
AddTimeToTracker(id, PlayTimeTrackingShared.TrackerOverall, time);
|
||||
}
|
||||
|
||||
public TimeSpan GetOverallPlaytime(ICommonSession id)
|
||||
public TimeSpan GetOverallPlaytime(IPlayerSession id)
|
||||
{
|
||||
return GetPlayTimeForTracker(id, PlayTimeTrackingShared.TrackerOverall);
|
||||
}
|
||||
|
||||
public bool TryGetTrackerTimes(ICommonSession id, [NotNullWhen(true)] out Dictionary<string, TimeSpan>? time)
|
||||
public bool TryGetTrackerTimes(IPlayerSession id, [NotNullWhen(true)] out Dictionary<string, TimeSpan>? time)
|
||||
{
|
||||
time = null;
|
||||
|
||||
@@ -364,7 +364,7 @@ public sealed class PlayTimeTrackingManager
|
||||
return true;
|
||||
}
|
||||
|
||||
public Dictionary<string, TimeSpan> GetTrackerTimes(ICommonSession id)
|
||||
public Dictionary<string, TimeSpan> GetTrackerTimes(IPlayerSession id)
|
||||
{
|
||||
if (!_playTimeData.TryGetValue(id, out var data) || !data.Initialized)
|
||||
throw new InvalidOperationException("Play time info is not yet loaded for this player!");
|
||||
@@ -372,7 +372,7 @@ public sealed class PlayTimeTrackingManager
|
||||
return data.TrackerTimes;
|
||||
}
|
||||
|
||||
public TimeSpan GetPlayTimeForTracker(ICommonSession id, string tracker)
|
||||
public TimeSpan GetPlayTimeForTracker(IPlayerSession id, string tracker)
|
||||
{
|
||||
if (!_playTimeData.TryGetValue(id, out var data) || !data.Initialized)
|
||||
throw new InvalidOperationException("Play time info is not yet loaded for this player!");
|
||||
@@ -383,7 +383,7 @@ public sealed class PlayTimeTrackingManager
|
||||
/// <summary>
|
||||
/// Queue for play time trackers to be refreshed on a player, in case the set of active trackers may have changed.
|
||||
/// </summary>
|
||||
public void QueueRefreshTrackers(ICommonSession player)
|
||||
public void QueueRefreshTrackers(IPlayerSession player)
|
||||
{
|
||||
if (DirtyPlayer(player) is { } data)
|
||||
data.NeedRefreshTackers = true;
|
||||
@@ -392,13 +392,13 @@ public sealed class PlayTimeTrackingManager
|
||||
/// <summary>
|
||||
/// Queue for play time information to be sent to a client, for showing in UIs etc.
|
||||
/// </summary>
|
||||
public void QueueSendTimers(ICommonSession player)
|
||||
public void QueueSendTimers(IPlayerSession player)
|
||||
{
|
||||
if (DirtyPlayer(player) is { } data)
|
||||
data.NeedSendTimers = true;
|
||||
}
|
||||
|
||||
private PlayTimeData? DirtyPlayer(ICommonSession player)
|
||||
private PlayTimeData? DirtyPlayer(IPlayerSession player)
|
||||
{
|
||||
if (!_playTimeData.TryGetValue(player, out var data) || !data.Initialized)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user