Un-revert IPlayerManager refactor (#21244)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user