IPlayerManager refactor (#21215)
This commit is contained in:
@@ -5,6 +5,7 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Afk
|
||||
@@ -20,13 +21,13 @@ namespace Content.Server.Afk
|
||||
/// </summary>
|
||||
/// <param name="player">The player to check.</param>
|
||||
/// <returns>True if the player is AFK, false otherwise.</returns>
|
||||
bool IsAfk(IPlayerSession player);
|
||||
bool IsAfk(ICommonSession player);
|
||||
|
||||
/// <summary>
|
||||
/// Resets AFK status for the player as if they just did an action and are definitely not AFK.
|
||||
/// </summary>
|
||||
/// <param name="player">The player to set AFK status for.</param>
|
||||
void PlayerDidAction(IPlayerSession player);
|
||||
void PlayerDidAction(ICommonSession player);
|
||||
|
||||
void Initialize();
|
||||
}
|
||||
@@ -40,7 +41,7 @@ namespace Content.Server.Afk
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IConsoleHost _consoleHost = default!;
|
||||
|
||||
private readonly Dictionary<IPlayerSession, TimeSpan> _lastActionTimes = new();
|
||||
private readonly Dictionary<ICommonSession, TimeSpan> _lastActionTimes = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace Content.Server.Afk
|
||||
HandleInputCmd);
|
||||
}
|
||||
|
||||
public void PlayerDidAction(IPlayerSession player)
|
||||
public void PlayerDidAction(ICommonSession player)
|
||||
{
|
||||
if (player.Status == SessionStatus.Disconnected)
|
||||
// Make sure we don't re-add to the dictionary if the player is disconnected now.
|
||||
@@ -64,7 +65,7 @@ namespace Content.Server.Afk
|
||||
_lastActionTimes[player] = _gameTiming.RealTime;
|
||||
}
|
||||
|
||||
public bool IsAfk(IPlayerSession player)
|
||||
public bool IsAfk(ICommonSession player)
|
||||
{
|
||||
if (!_lastActionTimes.TryGetValue(player, out var time))
|
||||
// Some weird edge case like disconnected clients. Just say true I guess.
|
||||
@@ -87,13 +88,13 @@ namespace Content.Server.Afk
|
||||
|
||||
private void ConsoleHostOnAnyCommandExecuted(IConsoleShell shell, string commandname, string argstr, string[] args)
|
||||
{
|
||||
if (shell.Player is IPlayerSession player)
|
||||
if (shell.Player is { } player)
|
||||
PlayerDidAction(player);
|
||||
}
|
||||
|
||||
private void HandleInputCmd(FullInputCmdMessage msg, EntitySessionEventArgs args)
|
||||
{
|
||||
PlayerDidAction((IPlayerSession) args.SenderSession);
|
||||
PlayerDidAction(args.SenderSession);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user