Skip to content

Commit

Permalink
Add admin log messages for gamerule addition and end (space-wizards#2…
Browse files Browse the repository at this point in the history
…4092)

* Add admin log messages for gamerule addition and end

* Use EventRan end EventStopped LogTypes instead of new GameRule logtype

* Apply suggestions from code review

---------

Co-authored-by: Chief-Engineer <[email protected]>
  • Loading branch information
tday93 and Chief-Engineer committed Jan 20, 2024
1 parent bd4a0b9 commit 25cde97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Content.Server/GameTicking/GameTicker.GameRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Administration;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.Administration;
using Content.Shared.Database;
using Content.Shared.Prototypes;
using JetBrains.Annotations;
using Robust.Shared.Console;
Expand Down Expand Up @@ -59,6 +60,7 @@ public EntityUid AddGameRule(string ruleId)
{
var ruleEntity = Spawn(ruleId, MapCoordinates.Nullspace);
_sawmill.Info($"Added game rule {ToPrettyString(ruleEntity)}");
_adminLogger.Add(LogType.EventStarted, $"Added game rule {ToPrettyString(ruleEntity)}");

var ev = new GameRuleAddedEvent(ruleEntity, ruleId);
RaiseLocalEvent(ruleEntity, ref ev, true);
Expand Down Expand Up @@ -102,6 +104,7 @@ public bool StartGameRule(EntityUid ruleEntity, GameRuleComponent? ruleData = nu

_allPreviousGameRules.Add((RoundDuration(), id));
_sawmill.Info($"Started game rule {ToPrettyString(ruleEntity)}");
_adminLogger.Add(LogType.EventStarted, $"Started game rule {ToPrettyString(ruleEntity)}");

EnsureComp<ActiveGameRuleComponent>(ruleEntity);
ruleData.ActivatedAt = _gameTiming.CurTime;
Expand Down Expand Up @@ -131,6 +134,7 @@ public bool EndGameRule(EntityUid ruleEntity, GameRuleComponent? ruleData = null
EnsureComp<EndedGameRuleComponent>(ruleEntity);

_sawmill.Info($"Ended game rule {ToPrettyString(ruleEntity)}");
_adminLogger.Add(LogType.EventStopped, $"Ended game rule {ToPrettyString(ruleEntity)}");

var ev = new GameRuleEndedEvent(ruleEntity, id);
RaiseLocalEvent(ruleEntity, ref ev, true);
Expand Down Expand Up @@ -227,6 +231,14 @@ private void AddGameRuleCommand(IConsoleShell shell, string argstr, string[] arg

foreach (var rule in args)
{
if (shell.Player != null)
{
_adminLogger.Add(LogType.EventStarted, $"{shell.Player} tried to add game rule [{rule}] via command");
}
else
{
_adminLogger.Add(LogType.EventStarted, $"Unknown tried to add game rule [{rule}] via command");
}
var ent = AddGameRule(rule);

// Start rule if we're already in the middle of a round
Expand All @@ -250,6 +262,14 @@ private void EndGameRuleCommand(IConsoleShell shell, string argstr, string[] arg
{
if (!NetEntity.TryParse(rule, out var ruleEntNet) || !TryGetEntity(ruleEntNet, out var ruleEnt))
continue;
if (shell.Player != null)
{
_adminLogger.Add(LogType.EventStopped, $"{shell.Player} tried to end game rule [{rule}] via command");
}
else
{
_adminLogger.Add(LogType.EventStopped, $"Unknown tried to end game rule [{rule}] via command");
}

EndGameRule(ruleEnt.Value);
}
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/GameTicking/Rules/SecretRuleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Content.Server.Administration.Logs;
using Content.Server.GameTicking.Presets;
using Content.Server.GameTicking.Rules.Components;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Configuration;
Expand All @@ -14,6 +16,7 @@ public sealed class SecretRuleSystem : GameRuleSystem<SecretRuleComponent>
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;

protected override void Started(EntityUid uid, SecretRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
Expand All @@ -38,6 +41,7 @@ private void PickRule(SecretRuleComponent component)
var presetString = _configurationManager.GetCVar(CCVars.SecretWeightPrototype);
var preset = _prototypeManager.Index<WeightedRandomPrototype>(presetString).Pick(_random);
Logger.InfoS("gamepreset", $"Selected {preset} for secret.");
_adminLogger.Add(LogType.EventStarted, $"Selected {preset} for secret.");

var rules = _prototypeManager.Index<GamePresetPrototype>(preset).Rules;
foreach (var rule in rules)
Expand Down

0 comments on commit 25cde97

Please sign in to comment.