Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autovote System #351

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Content.Server/AutoVote/AutoVoteSystem.cs
Original file line number Diff line number Diff line change
@@ -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<RoundRestartCleanupEvent>(OnReturnedToLobby);
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(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);
}
}
26 changes: 24 additions & 2 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,13 +2062,13 @@ public static readonly CVarDef<string>
*/

/// <summary>
/// Time that players have to wait before rules can be accepted.
/// Time that players have to wait before rules can be accepted.
/// </summary>
public static readonly CVarDef<float> RulesWaitTime =
CVarDef.Create("rules.time", 60f, CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Don't show rules to localhost/loopback interface.
/// Don't show rules to localhost/loopback interface.
/// </summary>
public static readonly CVarDef<bool> RulesExemptLocal =
CVarDef.Create("rules.exempt_local", true, CVar.SERVERONLY);
Expand Down Expand Up @@ -2640,5 +2640,27 @@ public static readonly CVarDef<float>
CVarDef.Create("ghost.allow_same_character", false, CVar.SERVERONLY);

#endregion

/*
* AUTOVOTE SYSTEM
*/

/// <summary>
/// Enables the automatic voting system.
/// </summary>
public static readonly CVarDef<bool> AutoVoteEnabled =
CVarDef.Create("vote.autovote_enabled", true, CVar.SERVERONLY); // Floof enabled by default

/// <summary>
/// Automatically make map votes on return to lobby? Requires auto voting to be enabled.
/// </summary>
public static readonly CVarDef<bool> MapAutoVoteEnabled =
CVarDef.Create("vote.map_autovote_enabled", true, CVar.SERVERONLY);

/// <summary>
/// Automatically make preset votes on return to lobby? Requires auto voting to be enabled.
/// </summary>
public static readonly CVarDef<bool> PresetAutoVoteEnabled =
CVarDef.Create("vote.preset_autovote_enabled", true, CVar.SERVERONLY);
}
}
Loading