Change cvar usages to use CVarDef and define them in CCVars (#2250)

* Change cvar usages to use CVarDef and define them in CCVars

* Merge fixes

* Remove duplicate cvar registration
This commit is contained in:
DrSmugleaf
2020-11-07 01:15:56 +01:00
committed by GitHub
parent a7e7f20417
commit bf5b9ad03b
19 changed files with 136 additions and 72 deletions

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared;
using Content.Shared.GameObjects.Components.Movement;
using JetBrains.Annotations;
using Robust.Server.AI;
@@ -42,7 +43,6 @@ namespace Content.Server.GameObjects.EntitySystems.AI
public override void Initialize()
{
base.Initialize();
_configurationManager.RegisterCVar("ai.maxupdates", 64);
SubscribeLocalEvent<SleepAiMessage>(HandleAiSleep);
var processors = _reflectionManager.GetAllChildren<AiLogicProcessor>();
@@ -58,7 +58,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
/// <inheritdoc />
public override void Update(float frameTime)
{
var cvarMaxUpdates = _configurationManager.GetCVar<int>("ai.maxupdates");
var cvarMaxUpdates = _configurationManager.GetCVar(CCVars.AIMaxUpdates);
if (cvarMaxUpdates <= 0)
return;
@@ -75,7 +75,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
break;
case false:
_awakeAi.Add(message.Processor);
if (_awakeAi.Count > cvarMaxUpdates)
{
Logger.Warning($"AI limit exceeded: {_awakeAi.Count} / {cvarMaxUpdates}");
@@ -101,7 +101,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
toRemove.Add(processor);
continue;
}
processor.Update(frameTime);
count++;
}

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.Atmos;
using Content.Shared;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos;
using JetBrains.Annotations;
@@ -47,7 +48,6 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
_atmosphereSystem = Get<AtmosphereSystem>();
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_configManager.RegisterCVar("net.atmosdbgoverlaytickrate", 3.0f);
}
public override void Shutdown()
@@ -89,7 +89,7 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
public override void Update(float frameTime)
{
AccumulatedFrameTime += frameTime;
_updateCooldown = 1 / _configManager.GetCVar<float>("net.atmosdbgoverlaytickrate");
_updateCooldown = 1 / _configManager.GetCVar(CCVars.NetAtmosDebugOverlayTickRate);
if (AccumulatedFrameTime < _updateCooldown)
{

View File

@@ -4,12 +4,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.GameObjects.Components.Atmos;
using Content.Shared;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.EntitySystems.Atmos;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared;
using Robust.Shared.Enums;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Interfaces.GameObjects;
@@ -65,7 +67,6 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
_atmosphereSystem = Get<AtmosphereSystem>();
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_mapManager.OnGridRemoved += OnGridRemoved;
_configManager.RegisterCVar("net.gasoverlaytickrate", 3.0f);
}
public override void Shutdown()
@@ -228,14 +229,14 @@ namespace Content.Server.GameObjects.EntitySystems.Atmos
public override void Update(float frameTime)
{
AccumulatedFrameTime += frameTime;
_updateCooldown = 1 / _configManager.GetCVar<float>("net.gasoverlaytickrate");
_updateCooldown = 1 / _configManager.GetCVar(CCVars.NetGasOverlayTickRate);
if (AccumulatedFrameTime < _updateCooldown)
{
return;
}
_updateRange = _configManager.GetCVar<float>("net.maxupdaterange") + RangeOffset;
_updateRange = _configManager.GetCVar(CVars.NetMaxUpdateRange) + RangeOffset;
// TODO: So in the worst case scenario we still have to send a LOT of tile data per tick if there's a fire.
// If we go with say 15 tile radius then we have up to 900 tiles to update per tick.

View File

@@ -9,6 +9,7 @@ using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Mobs.Roles.Suspicion;
using Content.Server.Players;
using Content.Shared;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.PDA;
using Content.Shared.Roles;
@@ -44,20 +45,12 @@ namespace Content.Server.GameTicking.GamePresets
private static string TraitorID = "SuspicionTraitor";
private static string InnocentID = "SuspicionInnocent";
public static void RegisterCVars(IConfigurationManager cfg)
{
cfg.RegisterCVar("game.suspicion_min_players", 5);
cfg.RegisterCVar("game.suspicion_min_traitors", 2);
cfg.RegisterCVar("game.suspicion_players_per_traitor", 5);
cfg.RegisterCVar("game.suspicion_starting_balance", 20);
}
public override bool Start(IReadOnlyList<IPlayerSession> readyPlayers, bool force = false)
{
MinPlayers = _cfg.GetCVar<int>("game.suspicion_min_players");
MinTraitors = _cfg.GetCVar<int>("game.suspicion_min_traitors");
PlayersPerTraitor = _cfg.GetCVar<int>("game.suspicion_players_per_traitor");
TraitorStartingBalance = _cfg.GetCVar<int>("game.suspicion_starting_balance");
MinPlayers = _cfg.GetCVar(CCVars.GameSuspicionMinPlayers);
MinTraitors = _cfg.GetCVar(CCVars.GameSuspicionMinTraitors);
PlayersPerTraitor = _cfg.GetCVar(CCVars.GameSuspicionPlayersPerTraitor);
TraitorStartingBalance = _cfg.GetCVar(CCVars.GameSuspicionStartingBalance);
if (!force && readyPlayers.Count < MinPlayers)
{

View File

@@ -2,6 +2,7 @@
using System.Threading;
using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameTicking;
using Content.Shared;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
@@ -56,7 +57,7 @@ namespace Content.Server.GameTicking.GameRules
{
_checkTimerCancel = null;
if (!_cfg.GetCVar<bool>("game.enablewin"))
if (!_cfg.GetCVar(CCVars.GameLobbyEnableWin))
return;
IPlayerSession winner = null;

View File

@@ -6,6 +6,7 @@ using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Mobs.Roles.Suspicion;
using Content.Server.Players;
using Content.Shared;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
@@ -58,7 +59,7 @@ namespace Content.Server.GameTicking.GameRules
private void _checkWinConditions()
{
if (!_cfg.GetCVar<bool>("game.enablewin"))
if (!_cfg.GetCVar(CCVars.GameLobbyEnableWin))
return;
var traitorsAlive = 0;

View File

@@ -88,7 +88,7 @@ namespace Content.Server.GameTicking
[ViewVariables] private bool DisallowLateJoin { get; set; } = false;
[ViewVariables] private bool LobbyEnabled => _configurationManager.GetCVar<bool>("game.lobbyenabled");
[ViewVariables] private bool LobbyEnabled => _configurationManager.GetCVar(CCVars.GameLobbyEnabled);
[ViewVariables] private bool _updateOnRoundEnd;
private CancellationTokenSource _updateShutdownCts;
@@ -119,7 +119,7 @@ namespace Content.Server.GameTicking
public event Action<GameRuleAddedEventArgs> OnRuleAdded;
private TimeSpan LobbyDuration =>
TimeSpan.FromSeconds(_configurationManager.GetCVar<int>("game.lobbyduration"));
TimeSpan.FromSeconds(_configurationManager.GetCVar(CCVars.GameLobbyDuration));
public override void Initialize()
{
@@ -127,8 +127,6 @@ namespace Content.Server.GameTicking
DebugTools.Assert(!_initialized);
PresetSuspicion.RegisterCVars(_configurationManager);
_netManager.RegisterNetMessage<MsgTickerJoinLobby>(nameof(MsgTickerJoinLobby));
_netManager.RegisterNetMessage<MsgTickerJoinGame>(nameof(MsgTickerJoinGame));
_netManager.RegisterNetMessage<MsgTickerLobbyStatus>(nameof(MsgTickerLobbyStatus));
@@ -286,9 +284,9 @@ namespace Content.Server.GameTicking
if (!preset.Start(assignedJobs.Keys.ToList(), force))
{
if (_configurationManager.GetCVar<bool>("game.fallbackenabled"))
if (_configurationManager.GetCVar(CCVars.GameLobbyFallbackEnabled))
{
SetStartPreset(_configurationManager.GetCVar<string>("game.fallbackpreset"));
SetStartPreset(_configurationManager.GetCVar(CCVars.GameLobbyFallbackPreset));
var newPreset = MakeGamePreset(profiles);
_chatManager.DispatchServerAnnouncement(
$"Failed to start {preset.ModeTitle} mode! Defaulting to {newPreset.ModeTitle}...");

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Shared;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Robust.Server.Interfaces.ServerStatus;
@@ -27,9 +28,6 @@ namespace Content.Server
void IPostInjectInit.PostInject()
{
_configurationManager.RegisterCVar<string>("status.mommiurl", null);
_configurationManager.RegisterCVar<string>("status.mommipassword", null);
_statusHost.AddHandler(_handleChatPost);
}
@@ -46,8 +44,8 @@ namespace Content.Server
private async Task _sendMessageInternal(string type, object messageObject)
{
var url = _configurationManager.GetCVar<string>("status.mommiurl");
var password = _configurationManager.GetCVar<string>("status.mommipassword");
var url = _configurationManager.GetCVar(CCVars.StatusMoMMIUrl);
var password = _configurationManager.GetCVar(CCVars.StatusMoMMIPassword);
if (string.IsNullOrWhiteSpace(url))
{
return;
@@ -83,7 +81,7 @@ namespace Content.Server
return false;
}
var password = _configurationManager.GetCVar<string>("status.mommipassword");
var password = _configurationManager.GetCVar(CCVars.StatusMoMMIPassword);
OOCPostMessage message = null;
try