Fix Cosmic Cult Server Crash (#5097)

* Fixed a bug where the server would crash if there were zero cultists and it would try to hold a vote with zero options.

* Added a check to prevent the vote if a steward already exists.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added clarity to logs in case a 2nd cult gets added or something.

* Update Content.Server/_DV/CosmicCult/CosmicCultRuleSystem.cs

Co-authored-by: Milon <milonpl.git@proton.me>
Signed-off-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>

---------

Signed-off-by: Vanessa <908648+ShepardToTheStars@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Milon <milonpl.git@proton.me>
This commit is contained in:
Vanessa
2026-01-02 17:47:27 -07:00
committed by GitHub
co-authored by Milon pre-commit-ci[bot]
parent 509ffa86c8
commit 3617bc3b53
@@ -284,9 +284,18 @@ public sealed class CosmicCultRuleSystem : GameRuleSystem<CosmicCultRuleComponen
private void StewardVote()
{
// If there's already an entity with steward, don't hold a vote. This allows admins to add the Cosmic Cult rule a 2nd time
// in the case that there is only one cultist and they've been chosen as the steward already.
if (EntityQuery<CosmicCultLeadComponent>().Any())
{
_adminLogger.Add(LogType.Vote, LogImpact.Medium,
$"Cosmic cult steward already exists. Cancelling steward vote.");
return;
}
var cultists = new List<(string, EntityUid)>();
var cultQuery = EntityQueryEnumerator<CosmicCultComponent, MetaDataComponent>();
while (cultQuery.MoveNext(out var cult, out _, out var metadata))
{
var playerInfo = metadata.EntityName;
@@ -304,11 +313,28 @@ public sealed class CosmicCultRuleSystem : GameRuleSystem<CosmicCultRuleComponen
VoterEligibility = VoteManager.VoterEligibility.CosmicCult
};
// If there are no cultists, don't hold a vote, or the server will crash.
if (cultists.Count == 0)
{
Log.Warning($"There are no cosmic cultists present for the steward vote. Voting is cancelled to prevent the server crashing.");
_adminLogger.Add(LogType.Vote, LogImpact.Extreme, $"There are no cosmic cultists for the steward vote. Steward vote is cancelled to prevent the server crashing.");
return;
}
foreach (var (name, ent) in cultists)
{
options.Options.Add((Loc.GetString(name), ent));
}
// If somehow there are cultists but no options, still don't hold a vote.
// Holding a vote with zero options crashes the server.
if (options.Options.Count == 0)
{
Log.Warning($"There are {cultists.Count} cosmic cultists but no options for the steward vote. Voting is cancelled to prevent the server crashing.");
_adminLogger.Add(LogType.Vote, LogImpact.Extreme, $"There are {cultists.Count} cosmic cultists but no options for the steward vote. Steward vote is cancelled to prevent the server crashing.");
return;
}
var vote = _votes.CreateVote(options);
vote.OnFinished += (_, args) =>