]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow votekicks to be initiated in the lobby (#32528)
authorSlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
Fri, 1 Nov 2024 01:52:55 +0000 (02:52 +0100)
committerGitHub <noreply@github.com>
Fri, 1 Nov 2024 01:52:55 +0000 (21:52 -0400)
Initial commit

Content.Client/Voting/UI/VoteCallMenu.xaml.cs
Content.Client/Voting/VotingSystem.cs
Content.Server/Voting/Managers/VoteManager.DefaultVotes.cs
Content.Server/Voting/VotingSystem.cs
Content.Shared/CCVar/CCVars.cs

index c682a937120dc712b5ecbdf1b90188d13ab49e34..b9dd11f7a78fc4504a5966acab5a86aa73a8a595 100644 (file)
@@ -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)
index d2049174605f9df8cde2aa0839b932a47e7636ea..dd74e1ccb1851115f23416306d1d1d70962a420d 100644 (file)
@@ -19,11 +19,6 @@ public sealed class VotingSystem : EntitySystem
 
     private void OnVotePlayerListResponseEvent(VotePlayerListResponseEvent msg)
     {
-        if (!_ghostSystem.IsGhost)
-        {
-            return;
-        }
-
         VotePlayerListResponse?.Invoke(msg);
     }
 
index 736ff48817eed8a08fab77915c27bcc96400c4e0..fb99b3cfad821ec6262f7770f6465137693d58f8 100644 (file)
@@ -32,6 +32,7 @@ namespace Content.Server.Voting.Managers
 
         private VotingSystem? _votingSystem;
         private RoleSystem? _roleSystem;
+        private GameTicker? _gameTicker;
 
         private static readonly Dictionary<StandardVoteType, CVarDef<bool>> _voteTypesToEnableCVars = new()
         {
@@ -70,8 +71,8 @@ namespace Content.Server.Voting.Managers
                 default:
                     throw new ArgumentOutOfRangeException(nameof(voteType), voteType, null);
             }
-            var ticker = _entityManager.EntitySysManager.GetEntitySystem<GameTicker>();
-            ticker.UpdateInfoText();
+            _gameTicker = _entityManager.EntitySysManager.GetEntitySystem<GameTicker>();
+            _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
             };
index 25475c2157a1cd8a2392b05cf3b46ffe2650100f..3d3aeb485989f854701e37c6176da6d161eb46cb 100644 (file)
@@ -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
index f333f6536d40a745f9ecdb641c9ab9be5f254859..d1dc9d9ade16dae5378486349832f7ef732b0056 100644 (file)
@@ -1537,6 +1537,12 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<int> VotekickBanDuration =
             CVarDef.Create("votekick.ban_duration", 180, CVar.SERVERONLY);
 
+        /// <summary>
+        ///     Whether the ghost requirement settings for votekicks should be ignored for the lobby. 
+        /// </summary>
+        public static readonly CVarDef<bool> VotekickIgnoreGhostReqInLobby =
+            CVarDef.Create("votekick.ignore_ghost_req_in_lobby", true, CVar.SERVERONLY);
+
         /*
          * BAN
          */