From: SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com> Date: Fri, 1 Nov 2024 01:52:55 +0000 (+0100) Subject: Allow votekicks to be initiated in the lobby (#32528) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=06da4fcc6020c41d8dcac6612724bf5309518501;p=space-station-14.git Allow votekicks to be initiated in the lobby (#32528) Initial commit --- diff --git a/Content.Client/Voting/UI/VoteCallMenu.xaml.cs b/Content.Client/Voting/UI/VoteCallMenu.xaml.cs index c682a93712..b9dd11f7a7 100644 --- a/Content.Client/Voting/UI/VoteCallMenu.xaml.cs +++ b/Content.Client/Voting/UI/VoteCallMenu.xaml.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Numerics; +using Content.Client.Gameplay; using Content.Client.Stylesheets; using Content.Shared.Administration; using Content.Shared.CCVar; @@ -8,6 +9,7 @@ using Content.Shared.Voting; using JetBrains.Annotations; using Robust.Client.AutoGenerated; using Robust.Client.Console; +using Robust.Client.State; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; @@ -28,6 +30,7 @@ namespace Content.Client.Voting.UI [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityNetworkManager _entNetManager = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; + [Dependency] private readonly IStateManager _state = default!; private VotingSystem _votingSystem; @@ -70,6 +73,7 @@ namespace Content.Client.Voting.UI VoteTypeButton.AddItem(Loc.GetString(option.Name), (int)voteType); } + _state.OnStateChanged += OnStateChanged; VoteTypeButton.OnItemSelected += VoteTypeSelected; CreateButton.OnPressed += CreatePressed; FollowButton.OnPressed += FollowSelected; @@ -101,6 +105,14 @@ namespace Content.Client.Voting.UI UpdateVoteTimeout(); } + private void OnStateChanged(StateChangedEventArgs obj) + { + if (obj.NewState is not GameplayState) + return; + + Close(); + } + private void CanCallVoteChanged(bool obj) { if (!obj) diff --git a/Content.Client/Voting/VotingSystem.cs b/Content.Client/Voting/VotingSystem.cs index d204917460..dd74e1ccb1 100644 --- a/Content.Client/Voting/VotingSystem.cs +++ b/Content.Client/Voting/VotingSystem.cs @@ -19,11 +19,6 @@ public sealed class VotingSystem : EntitySystem private void OnVotePlayerListResponseEvent(VotePlayerListResponseEvent msg) { - if (!_ghostSystem.IsGhost) - { - return; - } - VotePlayerListResponse?.Invoke(msg); } diff --git a/Content.Server/Voting/Managers/VoteManager.DefaultVotes.cs b/Content.Server/Voting/Managers/VoteManager.DefaultVotes.cs index 736ff48817..fb99b3cfad 100644 --- a/Content.Server/Voting/Managers/VoteManager.DefaultVotes.cs +++ b/Content.Server/Voting/Managers/VoteManager.DefaultVotes.cs @@ -32,6 +32,7 @@ namespace Content.Server.Voting.Managers private VotingSystem? _votingSystem; private RoleSystem? _roleSystem; + private GameTicker? _gameTicker; private static readonly Dictionary> _voteTypesToEnableCVars = new() { @@ -70,8 +71,8 @@ namespace Content.Server.Voting.Managers default: throw new ArgumentOutOfRangeException(nameof(voteType), voteType, null); } - var ticker = _entityManager.EntitySysManager.GetEntitySystem(); - ticker.UpdateInfoText(); + _gameTicker = _entityManager.EntitySysManager.GetEntitySystem(); + _gameTicker.UpdateInfoText(); if (timeoutVote) TimeoutStandardVote(voteType); } @@ -346,8 +347,14 @@ namespace Content.Server.Voting.Managers return; } + + + var voterEligibility = _cfg.GetCVar(CCVars.VotekickVoterGhostRequirement) ? VoterEligibility.GhostMinimumPlaytime : VoterEligibility.MinimumPlaytime; + if (_cfg.GetCVar(CCVars.VotekickIgnoreGhostReqInLobby) && _gameTicker!.RunLevel == GameRunLevel.PreRoundLobby) + voterEligibility = VoterEligibility.MinimumPlaytime; + var eligibleVoterNumberRequirement = _cfg.GetCVar(CCVars.VotekickEligibleNumberRequirement); - var eligibleVoterNumber = _cfg.GetCVar(CCVars.VotekickVoterGhostRequirement) ? CalculateEligibleVoterNumber(VoterEligibility.GhostMinimumPlaytime) : CalculateEligibleVoterNumber(VoterEligibility.MinimumPlaytime); + var eligibleVoterNumber = CalculateEligibleVoterNumber(voterEligibility); string target = args[0]; string reason = args[1]; @@ -441,7 +448,7 @@ namespace Content.Server.Voting.Managers }, Duration = TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.VotekickTimer)), InitiatorTimeout = TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.VotekickTimeout)), - VoterEligibility = _cfg.GetCVar(CCVars.VotekickVoterGhostRequirement) ? VoterEligibility.GhostMinimumPlaytime : VoterEligibility.MinimumPlaytime, + VoterEligibility = voterEligibility, DisplayVotes = false, TargetEntity = targetNetEntity }; diff --git a/Content.Server/Voting/VotingSystem.cs b/Content.Server/Voting/VotingSystem.cs index 25475c2157..3d3aeb4859 100644 --- a/Content.Server/Voting/VotingSystem.cs +++ b/Content.Server/Voting/VotingSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Administration.Managers; using Content.Server.Database; +using Content.Server.GameTicking; using Content.Server.Ghost; using Content.Server.Roles.Jobs; using Content.Shared.CCVar; @@ -24,6 +25,7 @@ public sealed class VotingSystem : EntitySystem [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly JobSystem _jobs = default!; + [Dependency] private readonly GameTicker _gameTicker = default!; public override void Initialize() { @@ -34,8 +36,7 @@ public sealed class VotingSystem : EntitySystem private async void OnVotePlayerListRequestEvent(VotePlayerListRequestEvent msg, EntitySessionEventArgs args) { - if (args.SenderSession.AttachedEntity is not { Valid: true } entity - || !await CheckVotekickInitEligibility(args.SenderSession)) + if (!await CheckVotekickInitEligibility(args.SenderSession)) { var deniedResponse = new VotePlayerListResponseEvent(new (NetUserId, NetEntity, string)[0], true); RaiseNetworkEvent(deniedResponse, args.SenderSession.Channel); @@ -46,17 +47,23 @@ public sealed class VotingSystem : EntitySystem foreach (var player in _playerManager.Sessions) { - if (player.AttachedEntity is not { Valid: true } attached) - continue; - - if (attached == entity) continue; + if (args.SenderSession == player) continue; if (_adminManager.IsAdmin(player, false)) continue; - var playerName = GetPlayerVoteListName(attached); - var netEntity = GetNetEntity(attached); - - players.Add((player.UserId, netEntity, playerName)); + if (player.AttachedEntity is not { Valid: true } attached) + { + var playerName = player.Name; + var netEntity = NetEntity.Invalid; + players.Add((player.UserId, netEntity, playerName)); + } + else + { + var playerName = GetPlayerVoteListName(attached); + var netEntity = GetNetEntity(attached); + + players.Add((player.UserId, netEntity, playerName)); + } } var response = new VotePlayerListResponseEvent(players.ToArray(), false); @@ -86,15 +93,19 @@ public sealed class VotingSystem : EntitySystem if (initiator.AttachedEntity != null && _adminManager.IsAdmin(initiator.AttachedEntity.Value, false)) return true; - if (_cfg.GetCVar(CCVars.VotekickInitiatorGhostRequirement)) + // If cvar enabled, skip the ghost requirement in the preround lobby + if (!_cfg.GetCVar(CCVars.VotekickIgnoreGhostReqInLobby) || (_cfg.GetCVar(CCVars.VotekickIgnoreGhostReqInLobby) && _gameTicker.RunLevel != GameRunLevel.PreRoundLobby)) { - // Must be ghost - if (!TryComp(initiator.AttachedEntity, out GhostComponent? ghostComp)) - return false; - - // Must have been dead for x seconds - if ((int)_gameTiming.RealTime.Subtract(ghostComp.TimeOfDeath).TotalSeconds < _cfg.GetCVar(CCVars.VotekickEligibleVoterDeathtime)) - return false; + if (_cfg.GetCVar(CCVars.VotekickInitiatorGhostRequirement)) + { + // Must be ghost + if (!TryComp(initiator.AttachedEntity, out GhostComponent? ghostComp)) + return false; + + // Must have been dead for x seconds + if ((int)_gameTiming.RealTime.Subtract(ghostComp.TimeOfDeath).TotalSeconds < _cfg.GetCVar(CCVars.VotekickEligibleVoterDeathtime)) + return false; + } } // Must be whitelisted diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index f333f6536d..d1dc9d9ade 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1537,6 +1537,12 @@ namespace Content.Shared.CCVar public static readonly CVarDef VotekickBanDuration = CVarDef.Create("votekick.ban_duration", 180, CVar.SERVERONLY); + /// + /// Whether the ghost requirement settings for votekicks should be ignored for the lobby. + /// + public static readonly CVarDef VotekickIgnoreGhostReqInLobby = + CVarDef.Create("votekick.ignore_ghost_req_in_lobby", true, CVar.SERVERONLY); + /* * BAN */