Un-revert IPlayerManager refactor (#21244)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Content.Server.Voting.Managers;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Voting
|
||||
{
|
||||
@@ -75,7 +75,7 @@ namespace Content.Server.Voting
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="optionId"/> is not a valid option ID.
|
||||
/// </exception>
|
||||
void CastVote(IPlayerSession session, int? optionId);
|
||||
void CastVote(ICommonSession session, int? optionId);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel this vote.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Voting;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Voting.Managers
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace Content.Server.Voting.Managers
|
||||
/// True if <paramref name="initiator"/> can start votes right now,
|
||||
/// and if provided if they can start votes of type <paramref name="voteType"/>.
|
||||
/// </returns>
|
||||
bool CanCallVote(IPlayerSession initiator, StandardVoteType? voteType = null);
|
||||
bool CanCallVote(ICommonSession initiator, StandardVoteType? voteType = null);
|
||||
|
||||
/// <summary>
|
||||
/// Initiate a standard vote such as restart round, that can be initiated by players.
|
||||
@@ -51,7 +51,7 @@ namespace Content.Server.Voting.Managers
|
||||
/// If null it is assumed to be an automatic vote by the server.
|
||||
/// </param>
|
||||
/// <param name="voteType">The type of standard vote to make.</param>
|
||||
void CreateStandardVote(IPlayerSession? initiator, StandardVoteType voteType);
|
||||
void CreateStandardVote(ICommonSession? initiator, StandardVoteType voteType);
|
||||
|
||||
/// <summary>
|
||||
/// Create a non-standard vote with special parameters.
|
||||
|
||||
@@ -6,8 +6,8 @@ using Content.Server.RoundEnd;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Voting;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Voting.Managers
|
||||
@@ -21,7 +21,7 @@ namespace Content.Server.Voting.Managers
|
||||
{StandardVoteType.Map, CCVars.VoteMapEnabled},
|
||||
};
|
||||
|
||||
public void CreateStandardVote(IPlayerSession? initiator, StandardVoteType voteType)
|
||||
public void CreateStandardVote(ICommonSession? initiator, StandardVoteType voteType)
|
||||
{
|
||||
if (initiator != null)
|
||||
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{initiator} initiated a {voteType.ToString()} vote");
|
||||
@@ -47,7 +47,7 @@ namespace Content.Server.Voting.Managers
|
||||
TimeoutStandardVote(voteType);
|
||||
}
|
||||
|
||||
private void CreateRestartVote(IPlayerSession? initiator)
|
||||
private void CreateRestartVote(ICommonSession? initiator)
|
||||
{
|
||||
var alone = _playerManager.PlayerCount == 1 && initiator != null;
|
||||
var options = new VoteOptions
|
||||
@@ -100,7 +100,7 @@ namespace Content.Server.Voting.Managers
|
||||
vote.CastVote(initiator, 0);
|
||||
}
|
||||
|
||||
foreach (var player in _playerManager.ServerSessions)
|
||||
foreach (var player in _playerManager.Sessions)
|
||||
{
|
||||
if (player != initiator)
|
||||
{
|
||||
@@ -110,7 +110,7 @@ namespace Content.Server.Voting.Managers
|
||||
}
|
||||
}
|
||||
|
||||
private void CreatePresetVote(IPlayerSession? initiator)
|
||||
private void CreatePresetVote(ICommonSession? initiator)
|
||||
{
|
||||
var presets = GetGamePresets();
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace Content.Server.Voting.Managers
|
||||
};
|
||||
}
|
||||
|
||||
private void CreateMapVote(IPlayerSession? initiator)
|
||||
private void CreateMapVote(ICommonSession? initiator)
|
||||
{
|
||||
var maps = _gameMapManager.CurrentlyEligibleMaps().ToDictionary(map => map, map => map.MapName);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -45,7 +46,7 @@ namespace Content.Server.Voting.Managers
|
||||
|
||||
private readonly Dictionary<StandardVoteType, TimeSpan> _standardVoteTimeout = new();
|
||||
private readonly Dictionary<NetUserId, TimeSpan> _voteTimeout = new();
|
||||
private readonly HashSet<IPlayerSession> _playerCanCallVoteDirty = new();
|
||||
private readonly HashSet<ICommonSession> _playerCanCallVoteDirty = new();
|
||||
private readonly StandardVoteType[] _standardVoteTypeValues = Enum.GetValues<StandardVoteType>();
|
||||
|
||||
public void Initialize()
|
||||
@@ -106,7 +107,7 @@ namespace Content.Server.Voting.Managers
|
||||
}
|
||||
}
|
||||
|
||||
private void CastVote(VoteReg v, IPlayerSession player, int? option)
|
||||
private void CastVote(VoteReg v, ICommonSession player, int? option)
|
||||
{
|
||||
if (!IsValidOption(v, option))
|
||||
throw new ArgumentOutOfRangeException(nameof(option), "Invalid vote option ID");
|
||||
@@ -228,7 +229,7 @@ namespace Content.Server.Voting.Managers
|
||||
|
||||
private void SendUpdates(VoteReg v)
|
||||
{
|
||||
foreach (var player in _playerManager.ServerSessions)
|
||||
foreach (var player in _playerManager.Sessions)
|
||||
{
|
||||
SendSingleUpdate(v, player);
|
||||
}
|
||||
@@ -237,7 +238,7 @@ namespace Content.Server.Voting.Managers
|
||||
v.Dirty = false;
|
||||
}
|
||||
|
||||
private void SendSingleUpdate(VoteReg v, IPlayerSession player)
|
||||
private void SendSingleUpdate(VoteReg v, ICommonSession player)
|
||||
{
|
||||
var msg = new MsgVoteData();
|
||||
|
||||
@@ -277,10 +278,10 @@ namespace Content.Server.Voting.Managers
|
||||
|
||||
private void DirtyCanCallVoteAll()
|
||||
{
|
||||
_playerCanCallVoteDirty.UnionWith(_playerManager.ServerSessions);
|
||||
_playerCanCallVoteDirty.UnionWith(_playerManager.Sessions);
|
||||
}
|
||||
|
||||
private void SendUpdateCanCallVote(IPlayerSession player)
|
||||
private void SendUpdateCanCallVote(ICommonSession player)
|
||||
{
|
||||
var msg = new MsgVoteCanCall();
|
||||
msg.CanCall = CanCallVote(player, null, out var isAdmin, out var timeSpan);
|
||||
@@ -306,7 +307,7 @@ namespace Content.Server.Voting.Managers
|
||||
}
|
||||
|
||||
private bool CanCallVote(
|
||||
IPlayerSession initiator,
|
||||
ICommonSession initiator,
|
||||
StandardVoteType? voteType,
|
||||
out bool isAdmin,
|
||||
out TimeSpan timeSpan)
|
||||
@@ -353,7 +354,7 @@ namespace Content.Server.Voting.Managers
|
||||
return !_voteTimeout.TryGetValue(initiator.UserId, out timeSpan);
|
||||
}
|
||||
|
||||
public bool CanCallVote(IPlayerSession initiator, StandardVoteType? voteType = null)
|
||||
public bool CanCallVote(ICommonSession initiator, StandardVoteType? voteType = null)
|
||||
{
|
||||
return CanCallVote(initiator, voteType, out _, out _);
|
||||
}
|
||||
@@ -406,14 +407,14 @@ namespace Content.Server.Voting.Managers
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DirtyCanCallVote(IPlayerSession player)
|
||||
private void DirtyCanCallVote(ICommonSession player)
|
||||
{
|
||||
_playerCanCallVoteDirty.Add(player);
|
||||
}
|
||||
|
||||
#region Preset Votes
|
||||
|
||||
private void WirePresetVoteInitiator(VoteOptions options, IPlayerSession? player)
|
||||
private void WirePresetVoteInitiator(VoteOptions options, ICommonSession? player)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
@@ -432,13 +433,13 @@ namespace Content.Server.Voting.Managers
|
||||
private sealed class VoteReg
|
||||
{
|
||||
public readonly int Id;
|
||||
public readonly Dictionary<IPlayerSession, int> CastVotes = new();
|
||||
public readonly Dictionary<ICommonSession, int> CastVotes = new();
|
||||
public readonly VoteEntry[] Entries;
|
||||
public readonly string Title;
|
||||
public readonly string InitiatorText;
|
||||
public readonly TimeSpan StartTime;
|
||||
public readonly TimeSpan EndTime;
|
||||
public readonly HashSet<IPlayerSession> VotesDirty = new();
|
||||
public readonly HashSet<ICommonSession> VotesDirty = new();
|
||||
|
||||
public bool Cancelled;
|
||||
public bool Finished;
|
||||
@@ -446,10 +447,10 @@ namespace Content.Server.Voting.Managers
|
||||
|
||||
public VoteFinishedEventHandler? OnFinished;
|
||||
public VoteCancelledEventHandler? OnCancelled;
|
||||
public IPlayerSession? Initiator { get; }
|
||||
public ICommonSession? Initiator { get; }
|
||||
|
||||
public VoteReg(int id, VoteEntry[] entries, string title, string initiatorText,
|
||||
IPlayerSession? initiator, TimeSpan start, TimeSpan end)
|
||||
ICommonSession? initiator, TimeSpan start, TimeSpan end)
|
||||
{
|
||||
Id = id;
|
||||
Entries = entries;
|
||||
@@ -517,7 +518,7 @@ namespace Content.Server.Voting.Managers
|
||||
return _mgr.IsValidOption(_reg, optionId);
|
||||
}
|
||||
|
||||
public void CastVote(IPlayerSession session, int? optionId)
|
||||
public void CastVote(ICommonSession session, int? optionId)
|
||||
{
|
||||
_mgr.CastVote(_reg, session, optionId);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using Content.Server.Voting.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Voting;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.Voting
|
||||
@@ -36,14 +35,14 @@ namespace Content.Server.Voting
|
||||
|
||||
var mgr = IoCManager.Resolve<IVoteManager>();
|
||||
|
||||
if (shell.Player != null && !mgr.CanCallVote((IPlayerSession) shell.Player, type))
|
||||
if (shell.Player != null && !mgr.CanCallVote(shell.Player, type))
|
||||
{
|
||||
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{shell.Player} failed to start {type.ToString()} vote");
|
||||
shell.WriteError(Loc.GetString("cmd-createvote-cannot-call-vote-now"));
|
||||
return;
|
||||
}
|
||||
|
||||
mgr.CreateStandardVote((IPlayerSession?) shell.Player, type);
|
||||
mgr.CreateStandardVote(shell.Player, type);
|
||||
}
|
||||
|
||||
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
||||
@@ -92,7 +91,7 @@ namespace Content.Server.Voting
|
||||
options.Options.Add((args[i], i));
|
||||
}
|
||||
|
||||
options.SetInitiatorOrServer((IPlayerSession?) shell.Player);
|
||||
options.SetInitiatorOrServer(shell.Player);
|
||||
|
||||
if (shell.Player != null)
|
||||
_adminLogger.Add(LogType.Vote, LogImpact.Medium, $"{shell.Player} initiated a custom vote: {options.Title} - {string.Join("; ", options.Options.Select(x => x.text))}");
|
||||
@@ -187,7 +186,7 @@ namespace Content.Server.Voting
|
||||
return;
|
||||
}
|
||||
|
||||
vote.CastVote((IPlayerSession) shell.Player!, optionN);
|
||||
vote.CastVote(shell.Player!, optionN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
|
||||
namespace Content.Server.Voting
|
||||
@@ -16,7 +16,7 @@ namespace Content.Server.Voting
|
||||
/// <summary>
|
||||
/// The player that started the vote. Used to keep track of player cooldowns to avoid vote spam.
|
||||
/// </summary>
|
||||
public IPlayerSession? InitiatorPlayer { get; set; }
|
||||
public ICommonSession? InitiatorPlayer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The shown title of the vote.
|
||||
@@ -43,13 +43,13 @@ namespace Content.Server.Voting
|
||||
/// Sets <see cref="InitiatorPlayer"/> and <see cref="InitiatorText"/>
|
||||
/// by setting the latter to the player's name.
|
||||
/// </summary>
|
||||
public void SetInitiator(IPlayerSession player)
|
||||
public void SetInitiator(ICommonSession player)
|
||||
{
|
||||
InitiatorPlayer = player;
|
||||
InitiatorText = player.Name;
|
||||
}
|
||||
|
||||
public void SetInitiatorOrServer(IPlayerSession? player)
|
||||
public void SetInitiatorOrServer(ICommonSession? player)
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user