From 53f27643187a177be0bfc5a4cb7f627aab47addf Mon Sep 17 00:00:00 2001 From: sleepyyapril Date: Mon, 11 Nov 2024 22:00:54 -0400 Subject: [PATCH 1/7] Auto voting system for first-time player join as well as return to lobby. --- Content.Server/AutoVote/AutoVoteSystem.cs | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Content.Server/AutoVote/AutoVoteSystem.cs diff --git a/Content.Server/AutoVote/AutoVoteSystem.cs b/Content.Server/AutoVote/AutoVoteSystem.cs new file mode 100644 index 00000000000..77ba406a302 --- /dev/null +++ b/Content.Server/AutoVote/AutoVoteSystem.cs @@ -0,0 +1,57 @@ +using Robust.Shared.Configuration; +using Content.Server.Voting.Managers; +using Content.Shared.GameTicking; +using Content.Shared.Voting; +using Content.Shared.CCVar; +using Robust.Server.Player; +using Content.Server.GameTicking; + +namespace Content.Server.AutoVote; + +public sealed class AutoVoteSystem : EntitySystem +{ + [Dependency] private readonly IConfigurationManager _cfg = default!; + [Dependency] public readonly IVoteManager _voteManager = default!; + [Dependency] public readonly IPlayerManager _playerManager = default!; + + public bool _shouldVoteNextJoin = false; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnReturnedToLobby); + SubscribeLocalEvent(OnPlayerJoinedLobby); + } + + public void OnReturnedToLobby(RoundRestartCleanupEvent ev) + { + CallAutovote(); + } + + public void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev) + { + if (_shouldVoteNextJoin) + { + CallAutovote(); + _shouldVoteNextJoin = false; + } + } + + private void CallAutovote() + { + if (!_cfg.GetCVar(CCVars.AutoVoteEnabled)) + return; + + if (_playerManager.PlayerCount == 0) + { + _shouldVoteNextJoin = true; + return; + } + + if (_cfg.GetCVar(CCVars.MapAutoVoteEnabled)) + _voteManager.CreateStandardVote(null, StandardVoteType.Preset); + if (_cfg.GetCVar(CCVars.PresetAutoVoteEnabled)) + _voteManager.CreateStandardVote(null, StandardVoteType.Map); + } +} From eedcdfc3dcd2adbd58ec36f67f24ca3e9cf6a3e4 Mon Sep 17 00:00:00 2001 From: sleepyyapril Date: Mon, 11 Nov 2024 22:15:47 -0400 Subject: [PATCH 2/7] CVars --- Content.Shared/CCVar/CCVars.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index ccef09000f3..5cf21d661f2 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1502,7 +1502,6 @@ public static readonly CVarDef public static readonly CVarDef VoteTimerAlone = CVarDef.Create("vote.timeralone", 10, CVar.SERVERONLY); - /* * BAN */ @@ -2640,5 +2639,27 @@ public static readonly CVarDef /// public static readonly CVarDef DebugPow3rDisableParallel = CVarDef.Create("debug.pow3r_disable_parallel", true, CVar.SERVERONLY); + + /* + * AUTOVOTE SYSTEM + */ + + /// + /// Enables the automatic voting system. + /// + public static readonly CVarDef AutoVoteEnabled = + CVarDef.Create("vote.autovote_enabled", false, CVar.SERVERONLY); + + /// + /// Automatically make map votes on return to lobby? Requires auto voting to be enabled. + /// + public static readonly CVarDef MapAutoVoteEnabled = + CVarDef.Create("vote.map_autovote_enabled", true, CVar.SERVERONLY); + + /// + /// Automatically make preset votes on return to lobby? Requires auto voting to be enabled. + /// + public static readonly CVarDef PresetAutoVoteEnabled = + CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY); } } From 75371493712939468cf2e7da216049aef204d8a5 Mon Sep 17 00:00:00 2001 From: sleepyyapril Date: Mon, 11 Nov 2024 22:21:23 -0400 Subject: [PATCH 3/7] Don't change CCVars above autovote's, merge conflict hell avoidance. --- Content.Shared/CCVar/CCVars.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 5cf21d661f2..8b4bcceb109 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1502,6 +1502,7 @@ public static readonly CVarDef public static readonly CVarDef VoteTimerAlone = CVarDef.Create("vote.timeralone", 10, CVar.SERVERONLY); + /* * BAN */ From 2c1dcd2fc31fd1d5c19972d7e1992c8e9a946693 Mon Sep 17 00:00:00 2001 From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:46:45 -0400 Subject: [PATCH 4/7] Update Content.Shared/CCVar/CCVars.cs Co-authored-by: DEATHB4DEFEAT <77995199+DEATHB4DEFEAT@users.noreply.github.com> Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> --- Content.Shared/CCVar/CCVars.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 8b4bcceb109..60dceea897e 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -2645,21 +2645,17 @@ public static readonly CVarDef * AUTOVOTE SYSTEM */ - /// - /// Enables the automatic voting system. - /// + /// Enables the automatic voting system. public static readonly CVarDef AutoVoteEnabled = CVarDef.Create("vote.autovote_enabled", false, CVar.SERVERONLY); - /// - /// Automatically make map votes on return to lobby? Requires auto voting to be enabled. - /// + /// Automatically starts a map vote when returning to the lobby. + /// Requires auto voting to be enabled. public static readonly CVarDef MapAutoVoteEnabled = CVarDef.Create("vote.map_autovote_enabled", true, CVar.SERVERONLY); - /// - /// Automatically make preset votes on return to lobby? Requires auto voting to be enabled. - /// + /// Automatically starts a gamemode vote when returning to the lobby. + /// Requires auto voting to be enabled. public static readonly CVarDef PresetAutoVoteEnabled = CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY); } From 3a6fc079d57ce7b91b2b59f5159403052f35fd18 Mon Sep 17 00:00:00 2001 From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:38:24 -0400 Subject: [PATCH 5/7] Update Content.Server/AutoVote/AutoVoteSystem.cs Co-authored-by: FoxxoTrystan <45297731+FoxxoTrystan@users.noreply.github.com> Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> --- Content.Server/AutoVote/AutoVoteSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Server/AutoVote/AutoVoteSystem.cs b/Content.Server/AutoVote/AutoVoteSystem.cs index 77ba406a302..b19e63c9c24 100644 --- a/Content.Server/AutoVote/AutoVoteSystem.cs +++ b/Content.Server/AutoVote/AutoVoteSystem.cs @@ -50,8 +50,8 @@ private void CallAutovote() } if (_cfg.GetCVar(CCVars.MapAutoVoteEnabled)) - _voteManager.CreateStandardVote(null, StandardVoteType.Preset); - if (_cfg.GetCVar(CCVars.PresetAutoVoteEnabled)) _voteManager.CreateStandardVote(null, StandardVoteType.Map); + if (_cfg.GetCVar(CCVars.PresetAutoVoteEnabled)) + _voteManager.CreateStandardVote(null, StandardVoteType.Preset); } } From c3b1f1cd2066bb91d871c79ad86cce23b452802d Mon Sep 17 00:00:00 2001 From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:50:57 -0400 Subject: [PATCH 6/7] They ain't even real... Co-authored-by: VMSolidus Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> --- Content.Server/AutoVote/AutoVoteSystem.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Content.Server/AutoVote/AutoVoteSystem.cs b/Content.Server/AutoVote/AutoVoteSystem.cs index b19e63c9c24..42feb770345 100644 --- a/Content.Server/AutoVote/AutoVoteSystem.cs +++ b/Content.Server/AutoVote/AutoVoteSystem.cs @@ -31,11 +31,11 @@ public void OnReturnedToLobby(RoundRestartCleanupEvent ev) public void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev) { - if (_shouldVoteNextJoin) - { - CallAutovote(); - _shouldVoteNextJoin = false; - } + if (!_shouldVoteNextJoin) + return; + + CallAutovote(); + _shouldVoteNextJoin = false; } private void CallAutovote() From c44994baf3b58df9c19182827cf31869f772aff6 Mon Sep 17 00:00:00 2001 From: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Date: Wed, 13 Nov 2024 21:55:11 -0400 Subject: [PATCH 7/7] This guy just googled just to make my PR run more tests This is a joke Co-authored-by: VMSolidus Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> --- Content.Server/AutoVote/AutoVoteSystem.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Content.Server/AutoVote/AutoVoteSystem.cs b/Content.Server/AutoVote/AutoVoteSystem.cs index 42feb770345..7fb053b2f82 100644 --- a/Content.Server/AutoVote/AutoVoteSystem.cs +++ b/Content.Server/AutoVote/AutoVoteSystem.cs @@ -24,10 +24,7 @@ public override void Initialize() SubscribeLocalEvent(OnPlayerJoinedLobby); } - public void OnReturnedToLobby(RoundRestartCleanupEvent ev) - { - CallAutovote(); - } + public void OnReturnedToLobby(RoundRestartCleanupEvent ev) => CallAutovote(); public void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev) {