diff --git a/Robust.Client/BaseClient.cs b/Robust.Client/BaseClient.cs index af131826f..be9707e4b 100644 --- a/Robust.Client/BaseClient.cs +++ b/Robust.Client/BaseClient.cs @@ -6,6 +6,7 @@ using Robust.Client.Interfaces.GameObjects; using Robust.Client.Interfaces.GameStates; using Robust.Client.Interfaces.Utility; using Robust.Client.Player; +using Robust.Shared; using Robust.Shared.Enums; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Map; @@ -75,7 +76,7 @@ namespace Robust.Client OnRunLevelChanged(ClientRunLevel.Connecting); _net.ClientConnect(endPoint.Host, endPoint.Port, - PlayerNameOverride ?? _configManager.GetCVar("player.name")); + PlayerNameOverride ?? _configManager.GetCVar(CVars.PlayerName)); } /// diff --git a/Robust.Client/GameStates/ClientGameStateManager.cs b/Robust.Client/GameStates/ClientGameStateManager.cs index 2ae155a00..a9cd7de70 100644 --- a/Robust.Client/GameStates/ClientGameStateManager.cs +++ b/Robust.Client/GameStates/ClientGameStateManager.cs @@ -10,9 +10,8 @@ using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; using Robust.Shared.Network.Messages; using Robust.Client.Player; -using Robust.Shared.Configuration; +using Robust.Shared; using Robust.Shared.GameObjects; -using Robust.Shared.GameObjects.Systems; using Robust.Shared.Input; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.GameObjects; @@ -79,18 +78,18 @@ namespace Robust.Client.GameStates _network.RegisterNetMessage(MsgStateAck.NAME); _client.RunLevelChanged += RunLevelChanged; - _config.RegisterCVar("net.interp", true, CVar.ARCHIVE, b => _processor.Interpolation = b); - _config.RegisterCVar("net.interp_ratio", 0, CVar.ARCHIVE, i => _processor.InterpRatio = i); - _config.RegisterCVar("net.logging", false, CVar.ARCHIVE, b => _processor.Logging = b); - _config.RegisterCVar("net.predict", true, CVar.ARCHIVE, b => Predicting = b); - _config.RegisterCVar("net.predict_size", 1, CVar.ARCHIVE, i => PredictSize = i); - _config.RegisterCVar("net.state_buf_merge_threshold", 5, CVar.ARCHIVE, i => StateBufferMergeThreshold = i); + _config.OnValueChanged(CVars.NetInterp, b => _processor.Interpolation = b, true); + _config.OnValueChanged(CVars.NetInterpRatio, i => _processor.InterpRatio = i, true); + _config.OnValueChanged(CVars.NetLogging, b => _processor.Logging = b, true); + _config.OnValueChanged(CVars.NetPredict, b => Predicting = b, true); + _config.OnValueChanged(CVars.NetPredictSize, i => PredictSize = i, true); + _config.OnValueChanged(CVars.NetStateBufMergeThreshold, i => StateBufferMergeThreshold = i, true); - _processor.Interpolation = _config.GetCVar("net.interp"); - _processor.InterpRatio = _config.GetCVar("net.interp_ratio"); - _processor.Logging = _config.GetCVar("net.logging"); - Predicting = _config.GetCVar("net.predict"); - PredictSize = _config.GetCVar("net.predict_size"); + _processor.Interpolation = _config.GetCVar(CVars.NetInterp); + _processor.InterpRatio = _config.GetCVar(CVars.NetInterpRatio); + _processor.Logging = _config.GetCVar(CVars.NetLogging); + Predicting = _config.GetCVar(CVars.NetPredict); + PredictSize = _config.GetCVar(CVars.NetPredictSize); } /// @@ -123,7 +122,7 @@ namespace Robust.Client.GameStates var inputMan = IoCManager.Resolve(); inputMan.NetworkBindMap.TryGetKeyFunction(message.InputFunctionId, out var boundFunc); - Logger.DebugS("net.predict", + Logger.DebugS(CVars.NetPredict.Name, $"CL> SENT tick={_timing.CurTick}, sub={_timing.TickFraction}, seq={_nextInputCmdSeq}, func={boundFunc.FunctionName}, state={message.State}"); _nextInputCmdSeq++; } @@ -212,7 +211,7 @@ namespace Robust.Client.GameStates if (_lastProcessedSeq < curState.LastProcessedInput) { - Logger.DebugS("net.predict", $"SV> RCV tick={_timing.CurTick}, seq={_lastProcessedSeq}"); + Logger.DebugS(CVars.NetPredict.Name, $"SV> RCV tick={_timing.CurTick}, seq={_lastProcessedSeq}"); _lastProcessedSeq = curState.LastProcessedInput; } } @@ -231,7 +230,7 @@ namespace Robust.Client.GameStates var inCmd = _pendingInputs.Dequeue(); _inputManager.NetworkBindMap.TryGetKeyFunction(inCmd.InputFunctionId, out var boundFunc); - Logger.DebugS("net.predict", + Logger.DebugS(CVars.NetPredict.Name, $"SV> seq={inCmd.InputSequence}, func={boundFunc.FunctionName}, state={inCmd.State}"); } @@ -249,7 +248,7 @@ namespace Robust.Client.GameStates if (_pendingInputs.Count > 0) { - Logger.DebugS("net.predict", "CL> Predicted:"); + Logger.DebugS(CVars.NetPredict.Name, "CL> Predicted:"); } var pendingInputEnumerator = _pendingInputs.GetEnumerator(); @@ -274,7 +273,7 @@ namespace Robust.Client.GameStates _inputManager.NetworkBindMap.TryGetKeyFunction(inputCmd.InputFunctionId, out var boundFunc); - Logger.DebugS("net.predict", + Logger.DebugS(CVars.NetPredict.Name, $" seq={inputCmd.InputSequence}, sub={inputCmd.SubTick}, dTick={tick}, func={boundFunc.FunctionName}, " + $"state={inputCmd.State}"); @@ -315,7 +314,7 @@ namespace Robust.Client.GameStates continue; } - Logger.DebugS("net.predict", $"Entity {entity.Uid} was made dirty."); + Logger.DebugS(CVars.NetPredict.Name, $"Entity {entity.Uid} was made dirty."); if (!_processor.TryGetLastServerStates(entity.Uid, out var last)) { @@ -333,7 +332,7 @@ namespace Robust.Client.GameStates continue; } - Logger.DebugS("net.predict", $" And also its component {comp.Name}"); + Logger.DebugS(CVars.NetPredict.Name, $" And also its component {comp.Name}"); // TODO: Handle interpolation. comp.HandleComponentState(compState, null); } diff --git a/Robust.Client/Graphics/Clyde/Audio/Clyde.Audio.cs b/Robust.Client/Graphics/Clyde/Audio/Clyde.Audio.cs index b67c574bd..950bed56b 100644 --- a/Robust.Client/Graphics/Clyde/Audio/Clyde.Audio.cs +++ b/Robust.Client/Graphics/Clyde/Audio/Clyde.Audio.cs @@ -9,6 +9,7 @@ using OpenToolkit.Audio.OpenAL; using OpenToolkit.Audio.OpenAL.Extensions.Creative.EFX; using Robust.Client.Audio; using Robust.Client.Interfaces.Graphics; +using Robust.Shared; using Robust.Shared.Log; using Vector2 = Robust.Shared.Maths.Vector2; @@ -76,8 +77,7 @@ namespace Robust.Client.Graphics.Clyde private void _audioOpenDevice() { - - var preferredDevice = _configurationManager.GetCVar("audio.device"); + var preferredDevice = _configurationManager.GetCVar(CVars.AudioDevice); // Open device. if (!string.IsNullOrEmpty(preferredDevice)) diff --git a/Robust.Client/Graphics/Clyde/Clyde.Windowing.cs b/Robust.Client/Graphics/Clyde/Clyde.Windowing.cs index 00a91ca3c..2ef83faec 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.Windowing.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.Windowing.cs @@ -11,6 +11,7 @@ using Robust.Client.Input; using Robust.Client.Interfaces.Graphics; using Robust.Client.Interfaces.UserInterface; using Robust.Client.Utility; +using Robust.Shared; using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Maths; @@ -140,8 +141,8 @@ namespace Robust.Client.Graphics.Clyde private bool InitWindow() { - var width = _configurationManager.GetCVar("display.width"); - var height = _configurationManager.GetCVar("display.height"); + var width = _configurationManager.GetCVar(CVars.DisplayWidth); + var height = _configurationManager.GetCVar(CVars.DisplayHeight); Monitor* monitor = null; @@ -159,7 +160,7 @@ namespace Robust.Client.Graphics.Clyde GLFW.WindowHint(WindowHintString.X11ClassName, "SS14"); GLFW.WindowHint(WindowHintString.X11InstanceName, "SS14"); - var renderer = (Renderer) _configurationManager.GetCVar("display.renderer"); + var renderer = (Renderer) _configurationManager.GetCVar(CVars.DisplayRenderer); Span renderers = (renderer == Renderer.Default) ? stackalloc Renderer[] { Renderer.OpenGL33, diff --git a/Robust.Client/Graphics/Clyde/Clyde.cs b/Robust.Client/Graphics/Clyde/Clyde.cs index d8817627d..d13f62cea 100644 --- a/Robust.Client/Graphics/Clyde/Clyde.cs +++ b/Robust.Client/Graphics/Clyde/Clyde.cs @@ -12,10 +12,12 @@ using Robust.Client.Interfaces.Graphics.Overlays; using Robust.Client.Interfaces.Map; using Robust.Client.Interfaces.ResourceManagement; using Robust.Client.Interfaces.UserInterface; +using Robust.Shared; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Log; using Robust.Shared.Interfaces.Map; using Robust.Shared.Interfaces.Timing; +using Robust.Shared.IoC; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Timing; @@ -28,7 +30,7 @@ namespace Robust.Client.Graphics.Clyde /// /// Responsible for most things rendering on OpenGL mode. /// - internal sealed partial class Clyde : ClydeBase, IClydeInternal, IClydeAudio + internal sealed partial class Clyde : ClydeBase, IClydeInternal, IClydeAudio, IPostInjectInit { [Dependency] private readonly IClydeTileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly IEyeManager _eyeManager = default!; @@ -91,6 +93,10 @@ namespace Robust.Client.Graphics.Clyde public override bool Initialize() { + base.Initialize(); + + _configurationManager.OnValueChanged(CVars.DisplayOGLCheckErrors, b => _checkGLErrors = b, true); + if (!InitWindowing()) { return false; @@ -126,8 +132,8 @@ namespace Robust.Client.Graphics.Clyde protected override void ReadConfig() { base.ReadConfig(); - _lightmapDivider = _configurationManager.GetCVar("display.lightmapdivider"); - _enableSoftShadows = _configurationManager.GetCVar("display.softshadows"); + _lightmapDivider = _configurationManager.GetCVar(CVars.DisplayLightMapDivider); + _enableSoftShadows = _configurationManager.GetCVar(CVars.DisplaySoftShadows); } protected override void ReloadConfig() @@ -137,20 +143,15 @@ namespace Robust.Client.Graphics.Clyde RegenAllLightRts(); } - public override void PostInject() + public void PostInject() { - base.PostInject(); - _mapManager.TileChanged += _updateTileMapOnUpdate; _mapManager.OnGridCreated += _updateOnGridCreated; _mapManager.OnGridRemoved += _updateOnGridRemoved; _mapManager.GridChanged += _updateOnGridModified; - _configurationManager.RegisterCVar("display.renderer", (int) Renderer.Default); - _configurationManager.RegisterCVar("display.ogl_check_errors", false, onValueChanged: b => _checkGLErrors = b); // This cvar does not modify the actual GL version requested or anything, // it overrides the version we detect to detect GL features. - _configurationManager.RegisterCVar("display.ogl_override_version", ""); RegisterBlockCVars(); } @@ -242,7 +243,7 @@ namespace Robust.Client.Graphics.Clyde private (int major, int minor)? ParseGLOverrideVersion() { - var overrideGLVersion = _configurationManager.GetCVar("display.ogl_override_version"); + var overrideGLVersion = _configurationManager.GetCVar(CVars.DisplayOGLOverrideVersion); if (string.IsNullOrEmpty(overrideGLVersion)) { return null; diff --git a/Robust.Client/Graphics/Clyde/ClydeHeadless.cs b/Robust.Client/Graphics/Clyde/ClydeHeadless.cs index da37646af..8ee912434 100644 --- a/Robust.Client/Graphics/Clyde/ClydeHeadless.cs +++ b/Robust.Client/Graphics/Clyde/ClydeHeadless.cs @@ -66,6 +66,7 @@ namespace Robust.Client.Graphics.Clyde public override bool Initialize() { + base.Initialize(); return true; } diff --git a/Robust.Client/Graphics/ClydeBase.cs b/Robust.Client/Graphics/ClydeBase.cs index 8896042d9..e02087a1b 100644 --- a/Robust.Client/Graphics/ClydeBase.cs +++ b/Robust.Client/Graphics/ClydeBase.cs @@ -1,7 +1,7 @@ using System; using Robust.Client.Interfaces; using Robust.Client.Interfaces.Graphics; -using Robust.Shared.Configuration; +using Robust.Shared; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.IoC; using Robust.Shared.Maths; @@ -18,31 +18,26 @@ namespace Robust.Client.Graphics /// /// Manages the game window, resolutions, fullscreen mode, VSync, etc... /// - internal abstract class ClydeBase : IPostInjectInit + internal abstract class ClydeBase { - private const string CVarVSync = "display.vsync"; - private const string CVarWindowMode = "display.windowmode"; - [Dependency] protected readonly IConfigurationManager _configurationManager = default!; [Dependency] protected readonly IGameControllerInternal _gameController = default!; protected WindowMode WindowMode { get; private set; } = WindowMode.Windowed; protected bool VSync { get; private set; } = true; - public virtual void PostInject() - { - _configurationManager.RegisterCVar(CVarVSync, VSync, CVar.ARCHIVE, _vSyncChanged); - _configurationManager.RegisterCVar(CVarWindowMode, (int) WindowMode, CVar.ARCHIVE, _windowModeChanged); - _configurationManager.RegisterCVar("display.width", 1280); - _configurationManager.RegisterCVar("display.height", 720); - _configurationManager.RegisterCVar("display.lightmapdivider", 2, onValueChanged: LightmapDividerChanged); - _configurationManager.RegisterCVar("display.softshadows", true, onValueChanged: SoftShadowsChanged); - _configurationManager.RegisterCVar("audio.device", ""); - } - public abstract Vector2i ScreenSize { get; } public abstract void SetWindowTitle(string title); - public abstract bool Initialize(); + + public virtual bool Initialize() + { + _configurationManager.OnValueChanged(CVars.DisplayVSync, _vSyncChanged, true); + _configurationManager.OnValueChanged(CVars.DisplayWindowMode, _windowModeChanged, true); + _configurationManager.OnValueChanged(CVars.DisplayLightMapDivider, LightmapDividerChanged, true); + _configurationManager.OnValueChanged(CVars.DisplaySoftShadows, SoftShadowsChanged, true); + + return true; + } protected virtual void ReloadConfig() { @@ -53,8 +48,8 @@ namespace Robust.Client.Graphics protected virtual void ReadConfig() { - WindowMode = (WindowMode) _configurationManager.GetCVar(CVarWindowMode); - VSync = _configurationManager.GetCVar(CVarVSync); + WindowMode = (WindowMode) _configurationManager.GetCVar(CVars.DisplayWindowMode); + VSync = _configurationManager.GetCVar(CVars.DisplayVSync); } private void _vSyncChanged(bool newValue) @@ -69,7 +64,7 @@ namespace Robust.Client.Graphics private void _windowModeChanged(int newValue) { - WindowMode = (Graphics.WindowMode)newValue; + WindowMode = (WindowMode) newValue; WindowModeChanged(); } diff --git a/Robust.Client/Graphics/FontManager.cs b/Robust.Client/Graphics/FontManager.cs index 7876d28d4..a5392bd2a 100644 --- a/Robust.Client/Graphics/FontManager.cs +++ b/Robust.Client/Graphics/FontManager.cs @@ -12,11 +12,10 @@ using Robust.Shared.Utility; using SharpFont; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; namespace Robust.Client.Graphics { - internal sealed class FontManager : IFontManagerInternal, IPostInjectInit + internal sealed class FontManager : IFontManagerInternal { [Dependency] private readonly IConfigurationManager _configuration = default!; @@ -41,7 +40,7 @@ namespace Robust.Client.Graphics void IFontManagerInternal.Initialize() { - BaseFontDPI = (uint) _configuration.GetCVar("display.fontdpi"); + BaseFontDPI = (uint) _configuration.GetCVar(CVars.DisplayFontDpi); } public IFontInstanceHandle MakeInstance(IFontFaceHandle handle, int size) @@ -401,10 +400,5 @@ namespace Robust.Client.Graphics // Maps glyph index to atlas. public Dictionary AtlasData { get; } } - - void IPostInjectInit.PostInject() - { - _configuration.RegisterCVar("display.fontdpi", 96); - } } } diff --git a/Robust.Client/Interfaces/UserInterface/IUserInterfaceManager.cs b/Robust.Client/Interfaces/UserInterface/IUserInterfaceManager.cs index 4d4b74ded..145d6b5c3 100644 --- a/Robust.Client/Interfaces/UserInterface/IUserInterfaceManager.cs +++ b/Robust.Client/Interfaces/UserInterface/IUserInterfaceManager.cs @@ -3,6 +3,7 @@ using Robust.Client.Input; using Robust.Client.Interfaces.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; +using Robust.Shared; using Robust.Shared.Input; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -33,8 +34,9 @@ namespace Robust.Client.Interfaces.UserInterface Control? CurrentlyHovered { get; } float UIScale { get; } + /// - /// Gets the default UIScale that we will use if display.uiScale gets set to 0. + /// Gets the default UIScale that we will use if gets set to 0. /// Based on the OS-assigned window scale factor. /// float DefaultUIScale { get; } diff --git a/Robust.Client/Player/PlayerManager.cs b/Robust.Client/Player/PlayerManager.cs index 8385d7543..4dad969f2 100644 --- a/Robust.Client/Player/PlayerManager.cs +++ b/Robust.Client/Player/PlayerManager.cs @@ -55,8 +55,6 @@ namespace Robust.Client.Player /// public void Initialize() { - _config.RegisterCVar("player.name", "JoeGenero", CVar.ARCHIVE); - _network.RegisterNetMessage(MsgPlayerListReq.NAME); _network.RegisterNetMessage(MsgPlayerList.NAME, HandlePlayerList); } diff --git a/Robust.Client/UserInterface/UserInterfaceManager.cs b/Robust.Client/UserInterface/UserInterfaceManager.cs index ecdbd9a4e..920db913b 100644 --- a/Robust.Client/UserInterface/UserInterfaceManager.cs +++ b/Robust.Client/UserInterface/UserInterfaceManager.cs @@ -10,7 +10,7 @@ using Robust.Client.Interfaces.UserInterface; using Robust.Client.Player; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.Configuration; +using Robust.Shared; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.Interfaces.Configuration; @@ -25,7 +25,7 @@ using Robust.Shared.Timing; namespace Robust.Client.UserInterface { - internal sealed class UserInterfaceManager : IDisposable, IUserInterfaceManagerInternal, IPostInjectInit + internal sealed class UserInterfaceManager : IDisposable, IUserInterfaceManagerInternal { [Dependency] private readonly IInputManager _inputManager = default!; [Dependency] private readonly IClyde _displayManager = default!; @@ -88,7 +88,9 @@ namespace Robust.Client.UserInterface public void Initialize() { - _uiScaleChanged(_configurationManager.GetCVar("display.uiScale")); + _configurationManager.OnValueChanged(CVars.DisplayUIScale, _uiScaleChanged, true); + + _uiScaleChanged(_configurationManager.GetCVar(CVars.DisplayUIScale)); ThemeDefaults = new UIThemeDummy(); _initializeCommon(); @@ -724,11 +726,6 @@ namespace Robust.Client.UserInterface } } - void IPostInjectInit.PostInject() - { - _configurationManager.RegisterCVar("display.uiScale", 0f, CVar.ARCHIVE, _uiScaleChanged); - } - private void _uiScaleChanged(float newValue) { UIScale = newValue == 0f ? DefaultUIScale : newValue; diff --git a/Robust.Client/Utility/DiscordRichPresence.cs b/Robust.Client/Utility/DiscordRichPresence.cs index 7318e552d..e63dedbf7 100644 --- a/Robust.Client/Utility/DiscordRichPresence.cs +++ b/Robust.Client/Utility/DiscordRichPresence.cs @@ -1,13 +1,14 @@ using DiscordRPC; using DiscordRPC.Logging; using Robust.Client.Interfaces.Utility; +using Robust.Shared; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Log; using Robust.Shared.IoC; namespace Robust.Client.Utility { - internal sealed class DiscordRichPresence : IDiscordRichPresence, IPostInjectInit + internal sealed class DiscordRichPresence : IDiscordRichPresence { private static readonly RichPresence _defaultPresence = new RichPresence { @@ -32,7 +33,27 @@ namespace Robust.Client.Utility public void Initialize() { - if (_configurationManager.GetCVar("discord.enabled")) + _configurationManager.OnValueChanged(CVars.DiscordEnabled, newValue => + { + if (!_initialized) + { + return; + } + + if (newValue) + { + if (_client == null || _client.IsDisposed) + { + _start(); + } + } + else + { + _stop(); + } + }); + + if (_configurationManager.GetCVar(CVars.DiscordEnabled)) { _start(); } @@ -98,29 +119,6 @@ namespace Robust.Client.Utility _stop(); } - public void PostInject() - { - _configurationManager.RegisterCVar("discord.enabled", true, onValueChanged: newValue => - { - if (!_initialized) - { - return; - } - - if (newValue) - { - if (_client == null || _client.IsDisposed) - { - _start(); - } - } - else - { - _stop(); - } - }); - } - private sealed class NativeLogger : ILogger { private readonly ISawmill _sawmill; diff --git a/Robust.Server/BaseServer.cs b/Robust.Server/BaseServer.cs index f4ddb3181..9d67c687e 100644 --- a/Robust.Server/BaseServer.cs +++ b/Robust.Server/BaseServer.cs @@ -109,7 +109,7 @@ namespace Robust.Server public int MaxPlayers => _config.GetCVar(CVars.GameMaxPlayers); /// - public string ServerName => _config.GetCVar("game.hostname"); + public string ServerName => _config.GetCVar(CVars.GameHostName); /// public void Restart() @@ -185,22 +185,16 @@ namespace Robust.Server //Sets up Logging - _config.RegisterCVar("log.enabled", true, CVar.ARCHIVE); - _config.RegisterCVar("log.path", "logs", CVar.ARCHIVE); - _config.RegisterCVar("log.format", "log_%(date)s-T%(time)s.txt", CVar.ARCHIVE); - _config.RegisterCVar("log.level", LogLevel.Info, CVar.ARCHIVE); - _config.RegisterCVar("log.runtimelog", true, CVar.ARCHIVE); - _logHandlerFactory = logHandlerFactory; var logHandler = logHandlerFactory?.Invoke() ?? null; - var logEnabled = _config.GetCVar("log.enabled"); + var logEnabled = _config.GetCVar(CVars.LogEnabled); if (logEnabled && logHandler == null) { - var logPath = _config.GetCVar("log.path"); - var logFormat = _config.GetCVar("log.format"); + var logPath = _config.GetCVar(CVars.LogPath); + var logFormat = _config.GetCVar(CVars.LogFormat); var logFilename = logFormat.Replace("%(date)s", DateTime.Now.ToString("yyyy-MM-dd")) .Replace("%(time)s", DateTime.Now.ToString("hh-mm-ss")); var fullPath = Path.Combine(logPath, logFilename); @@ -213,7 +207,7 @@ namespace Robust.Server logHandler = new FileLogHandler(logPath); } - _log.RootSawmill.Level = _config.GetCVar("log.level"); + _log.RootSawmill.Level = _config.GetCVar(CVars.LogLevel); if (logEnabled && logHandler != null) { @@ -342,22 +336,16 @@ namespace Robust.Server private bool SetupLoki() { - _config.RegisterCVar("loki.enabled", false); - _config.RegisterCVar("loki.name", ""); - _config.RegisterCVar("loki.address", ""); - _config.RegisterCVar("loki.username", ""); - _config.RegisterCVar("loki.password", ""); - - var enabled = _config.GetCVar("loki.enabled"); + var enabled = _config.GetCVar(CVars.LokiEnabled); if (!enabled) { return true; } - var serverName = _config.GetCVar("loki.name"); - var address = _config.GetCVar("loki.address"); - var username = _config.GetCVar("loki.username"); - var password = _config.GetCVar("loki.password"); + var serverName = _config.GetCVar(CVars.LokiName); + var address = _config.GetCVar(CVars.LokiAddress); + var username = _config.GetCVar(CVars.LokiUsername); + var password = _config.GetCVar(CVars.LokiPassword); if (string.IsNullOrWhiteSpace(serverName)) { @@ -476,7 +464,7 @@ namespace Robust.Server { var cfgMgr = IoCManager.Resolve(); - cfgMgr.RegisterCVar("net.tickrate", 60, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER, i => + cfgMgr.OnValueChanged(CVars.NetTickrate, i => { var b = (byte) i; _time.TickRate = b; @@ -484,11 +472,10 @@ namespace Robust.Server Logger.InfoS("game", $"Tickrate changed to: {b} on tick {_time.CurTick}"); SendTickRateUpdateToClients(b); }); + + cfgMgr.SetCVar(CVars.GameType, (int) GameType.Game); - cfgMgr.RegisterCVar("game.hostname", "MyServer", CVar.ARCHIVE); - cfgMgr.RegisterCVar("game.type", GameType.Game); - - _time.TickRate = (byte) _config.GetCVar("net.tickrate"); + _time.TickRate = (byte) _config.GetCVar(CVars.NetTickrate); Logger.InfoS("srv", $"Name: {ServerName}"); Logger.InfoS("srv", $"TickRate: {_time.TickRate}({_time.TickPeriod.TotalMilliseconds:0.00}ms)"); @@ -512,10 +499,10 @@ namespace Robust.Server // shutdown entities _entities.Shutdown(); - if (_config.GetCVar("log.runtimelog")) + if (_config.GetCVar(CVars.LogRuntimeLog)) { // Wrtie down exception log - var logPath = _config.GetCVar("log.path"); + var logPath = _config.GetCVar(CVars.LogPath); var relPath = PathHelpers.ExecutableRelativeFile(logPath); Directory.CreateDirectory(relPath); var pathToWrite = Path.Combine(relPath, diff --git a/Robust.Server/Console/ConGroupController.cs b/Robust.Server/Console/ConGroupController.cs index ef99a8c79..c4f283c7e 100644 --- a/Robust.Server/Console/ConGroupController.cs +++ b/Robust.Server/Console/ConGroupController.cs @@ -2,6 +2,7 @@ using System.Net; using Robust.Server.Interfaces.Player; using Robust.Server.Player; +using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.Console; using Robust.Shared.Enums; @@ -31,8 +32,6 @@ namespace Robust.Server.Console { var logger = _logManager.GetSawmill("con.groups"); - _configurationManager.RegisterCVar("console.loginlocal", true, CVar.ARCHIVE); - _netManager.RegisterNetMessage(MsgConGroupUpdate.Name); _playerManager.PlayerStatusChanged += _onClientStatusChanged; @@ -51,13 +50,14 @@ namespace Robust.Server.Console { _sessions.OnClientStatusChanged(sender, e); - if (e.NewStatus == SessionStatus.Connected && _configurationManager.GetCVar("console.loginlocal")) + if (e.NewStatus == SessionStatus.Connected && + _configurationManager.GetCVar(CVars.ConsoleLoginLocal)) { var session = e.Session; var address = session.ConnectedClient.RemoteEndPoint.Address; if (Equals(address, IPAddress.Loopback) || Equals(address, IPAddress.IPv6Loopback)) { - SetGroup(session, new ConGroupIndex(_configurationManager.GetCVar("console.hostGroup"))); + SetGroup(session, new ConGroupIndex(_configurationManager.GetCVar(CVars.ConsoleHostGroup))); UpdateClientData(session); } } diff --git a/Robust.Server/Console/ConsoleShell.cs b/Robust.Server/Console/ConsoleShell.cs index 497b0e01b..50e5952cc 100644 --- a/Robust.Server/Console/ConsoleShell.cs +++ b/Robust.Server/Console/ConsoleShell.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Robust.Server.Interfaces.Console; using Robust.Server.Interfaces.Player; +using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.Console; using Robust.Shared.Interfaces.Configuration; @@ -59,21 +60,6 @@ namespace Robust.Server.Console /// public void Initialize() { - // register console admin global password. DO NOT ADD THE REPLICATED FLAG - if (!_configMan.IsCVarRegistered("console.password")) - _configMan.RegisterCVar("console.password", string.Empty, - CVar.ARCHIVE | CVar.SERVER | CVar.NOT_CONNECTED); - - if (!_configMan.IsCVarRegistered("console.hostpassword")) - _configMan.RegisterCVar("console.hostpassword", string.Empty, - CVar.ARCHIVE | CVar.SERVER | CVar.NOT_CONNECTED); - - if (!_configMan.IsCVarRegistered("console.adminGroup")) - _configMan.RegisterCVar("console.adminGroup", 100, CVar.ARCHIVE | CVar.SERVER); - - if (!_configMan.IsCVarRegistered("console.hostGroup")) - _configMan.RegisterCVar("console.hostGroup", 200, CVar.ARCHIVE | CVar.SERVER); - ReloadCommands(); // setup networking with clients @@ -185,8 +171,8 @@ namespace Robust.Server.Console if (session == null) throw new ArgumentNullException(nameof(session)); - var realPass = _configMan.GetCVar("console.password"); - var hostPass = _configMan.GetCVar("console.hostpassword"); + var realPass = _configMan.GetCVar(CVars.ConsolePassword); + var hostPass = _configMan.GetCVar(CVars.ConsoleHostPassword); // password disabled if (string.IsNullOrWhiteSpace(realPass)) @@ -197,7 +183,7 @@ namespace Robust.Server.Console return false; // success! - _groupController.SetGroup(session, new ConGroupIndex(_configMan.GetCVar("console.adminGroup"))); + _groupController.SetGroup(session, new ConGroupIndex(_configMan.GetCVar(CVars.ConsoleAdminGroup))); return true; } @@ -238,7 +224,7 @@ namespace Robust.Server.Console if (session == null) throw new ArgumentNullException(nameof(session)); - var realPass = _configMan.GetCVar("console.hostpassword"); + var realPass = _configMan.GetCVar(CVars.ConsoleHostPassword); // password disabled if (string.IsNullOrWhiteSpace(realPass)) @@ -249,7 +235,7 @@ namespace Robust.Server.Console return false; // success! - _groupController.SetGroup(session, new ConGroupIndex(_configMan.GetCVar("console.hostGroup"))); + _groupController.SetGroup(session, new ConGroupIndex(_configMan.GetCVar(CVars.ConsoleHostGroup))); return true; } diff --git a/Robust.Server/Console/SessionGroupContainer.cs b/Robust.Server/Console/SessionGroupContainer.cs index d9ecc47a0..a414ecac6 100644 --- a/Robust.Server/Console/SessionGroupContainer.cs +++ b/Robust.Server/Console/SessionGroupContainer.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using Robust.Server.Interfaces.Player; using Robust.Server.Player; -using Robust.Shared.Configuration; +using Robust.Shared; using Robust.Shared.Console; using Robust.Shared.Enums; using Robust.Shared.Interfaces.Configuration; @@ -24,8 +24,8 @@ namespace Robust.Server.Console /// public ConGroupIndex DefaultGroup { - get => new ConGroupIndex(_configMan.GetCVar("console.defaultGroup")); - set => _configMan.SetCVar("console.defaultGroup", value.Index); + get => new ConGroupIndex(_configMan.GetCVar(CVars.ConsoleDefaultGroup)); + set => _configMan.SetCVar(CVars.ConsoleDefaultGroup, value.Index); } /// @@ -37,9 +37,6 @@ namespace Robust.Server.Console { _configMan = configMan; _logger = logger; - - if(!_configMan.IsCVarRegistered("console.defaultGroup")) - _configMan.RegisterCVar("console.defaultGroup", 1, CVar.ARCHIVE); } /// diff --git a/Robust.Server/DataMetrics/MetricsManager.cs b/Robust.Server/DataMetrics/MetricsManager.cs index 1d0a18ad9..e90836b2d 100644 --- a/Robust.Server/DataMetrics/MetricsManager.cs +++ b/Robust.Server/DataMetrics/MetricsManager.cs @@ -1,5 +1,6 @@ using System; using Prometheus; +using Robust.Shared; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.IoC; using Robust.Shared.Log; @@ -8,7 +9,7 @@ using Robust.Shared.Log; namespace Robust.Server.DataMetrics { - internal sealed class MetricsManager : IMetricsManager, IPostInjectInit, IDisposable + internal sealed class MetricsManager : IMetricsManager, IDisposable { [Dependency] private readonly IConfigurationManager _configurationManager = default!; @@ -19,17 +20,14 @@ namespace Robust.Server.DataMetrics public void Initialize() { _initialized = true; + + _configurationManager.OnValueChanged(CVars.MetricsEnabled, _ => Reload()); + _configurationManager.OnValueChanged(CVars.MetricsHost, _ => Reload()); + _configurationManager.OnValueChanged(CVars.MetricsPort, _ => Reload()); Reload(); } - void IPostInjectInit.PostInject() - { - _configurationManager.RegisterCVar("metrics.enabled", false, onValueChanged: _ => Reload()); - _configurationManager.RegisterCVar("metrics.host", "localhost", onValueChanged: _ => Reload()); - _configurationManager.RegisterCVar("metrics.port", 44880, onValueChanged: _ => Reload()); - } - private async void Stop() { if (_metricServer == null) @@ -58,14 +56,14 @@ namespace Robust.Server.DataMetrics Stop(); - var enabled = _configurationManager.GetCVar("metrics.enabled"); + var enabled = _configurationManager.GetCVar(CVars.MetricsEnabled); if (!enabled) { return; } - var host = _configurationManager.GetCVar("metrics.host"); - var port = _configurationManager.GetCVar("metrics.port"); + var host = _configurationManager.GetCVar(CVars.MetricsHost); + var port = _configurationManager.GetCVar(CVars.MetricsPort); Logger.InfoS("metrics", "Prometheus metrics enabled, host: {1} port: {0}", port, host); _metricServer = new MetricServer(host, port); diff --git a/Robust.Server/GameObjects/ServerEntityManager.cs b/Robust.Server/GameObjects/ServerEntityManager.cs index c2b94edc4..af6d73312 100644 --- a/Robust.Server/GameObjects/ServerEntityManager.cs +++ b/Robust.Server/GameObjects/ServerEntityManager.cs @@ -9,6 +9,7 @@ using Robust.Server.GameObjects.EntitySystemMessages; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Server.Interfaces.Timing; +using Robust.Shared; using Robust.Shared.GameObjects; using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components.Transform; @@ -42,7 +43,7 @@ namespace Robust.Server.GameObjects private float? _maxUpdateRangeCache; public float MaxUpdateRange => _maxUpdateRangeCache - ??= _configurationManager.GetCVar("net.maxupdaterange"); + ??= _configurationManager.GetCVar(CVars.NetMaxUpdateRange); private int _nextServerEntityUid = (int) EntityUid.FirstUid; diff --git a/Robust.Server/GameObjects/ServerEntityNetworkManager.cs b/Robust.Server/GameObjects/ServerEntityNetworkManager.cs index 2e3fdcbe3..a44dac7ff 100644 --- a/Robust.Server/GameObjects/ServerEntityNetworkManager.cs +++ b/Robust.Server/GameObjects/ServerEntityNetworkManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Server.Player; +using Robust.Shared; using Robust.Shared.Enums; using Robust.Shared.GameObjects; using Robust.Shared.Interfaces.Configuration; @@ -19,7 +20,7 @@ namespace Robust.Server.GameObjects /// /// The server implementation of the Entity Network Manager. /// - public class ServerEntityNetworkManager : IServerEntityNetworkManager, IPostInjectInit + public class ServerEntityNetworkManager : IServerEntityNetworkManager { [Dependency] private readonly IServerNetManager _networkManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; @@ -46,7 +47,7 @@ namespace Robust.Server.GameObjects _playerManager.PlayerStatusChanged += OnPlayerStatusChanged; - _logLateMsgs = _configurationManager.GetCVar("net.log_late_msg"); + _configurationManager.OnValueChanged(CVars.NetLogLateMsg, b => _logLateMsgs = b, true); } public void Update() @@ -193,10 +194,5 @@ namespace Robust.Server.GameObjects return y.Sequence.CompareTo(x.Sequence); } } - - void IPostInjectInit.PostInject() - { - _configurationManager.RegisterCVar("net.log_late_msg", true, onValueChanged: b => _logLateMsgs = b); - } } } diff --git a/Robust.Server/GameStates/ServerGameStateManager.cs b/Robust.Server/GameStates/ServerGameStateManager.cs index 4cfa557f7..2599354ae 100644 --- a/Robust.Server/GameStates/ServerGameStateManager.cs +++ b/Robust.Server/GameStates/ServerGameStateManager.cs @@ -7,6 +7,7 @@ using Robust.Server.GameObjects.EntitySystems; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameState; using Robust.Server.Interfaces.Player; +using Robust.Shared; using Robust.Shared.Configuration; using Robust.Shared.Enums; using Robust.Shared.GameStates; @@ -41,7 +42,7 @@ namespace Robust.Server.GameStates [Dependency] private readonly IServerEntityNetworkManager _entityNetworkManager = default!; [Dependency] private readonly IConfigurationManager _configurationManager = default!; - public bool PvsEnabled => _configurationManager.GetCVar("net.pvs"); + public bool PvsEnabled => _configurationManager.GetCVar(CVars.NetPVS); /// public void Initialize() @@ -51,9 +52,6 @@ namespace Robust.Server.GameStates _networkManager.Connected += HandleClientConnected; _networkManager.Disconnect += HandleClientDisconnect; - - _configurationManager.RegisterCVar("net.pvs", true, CVar.ARCHIVE); - _configurationManager.RegisterCVar("net.maxupdaterange", 12.5f, CVar.ARCHIVE); } private void HandleClientConnected(object? sender, NetChannelArgs e) diff --git a/Robust.Server/ServerStatus/StatusHost.Handlers.cs b/Robust.Server/ServerStatus/StatusHost.Handlers.cs index 58e882c46..c868550b6 100644 --- a/Robust.Server/ServerStatus/StatusHost.Handlers.cs +++ b/Robust.Server/ServerStatus/StatusHost.Handlers.cs @@ -5,6 +5,7 @@ using System.Net.Http; using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Robust.Shared; using Robust.Shared.Log; using Robust.Shared.Utility; @@ -85,7 +86,7 @@ namespace Robust.Server.ServerStatus return true; } - var downloadUrlWindows = _configurationManager.GetCVar("build.download_url_windows"); + var downloadUrlWindows = _configurationManager.GetCVar(CVars.BuildDownloadUrlWindows); JObject? buildInfo; @@ -100,16 +101,16 @@ namespace Robust.Server.ServerStatus ["download_urls"] = new JObject { ["Windows"] = downloadUrlWindows, - ["MacOS"] = _configurationManager.GetCVar("build.download_url_macos"), - ["Linux"] = _configurationManager.GetCVar("build.download_url_linux") + ["MacOS"] = _configurationManager.GetCVar(CVars.BuildDownloadUrlMacOS), + ["Linux"] = _configurationManager.GetCVar(CVars.BuildDownloadUrlLinux) }, - ["fork_id"] = _configurationManager.GetCVar("build.fork_id"), - ["version"] = _configurationManager.GetCVar("build.version"), + ["fork_id"] = _configurationManager.GetCVar(CVars.BuildForkId), + ["version"] = _configurationManager.GetCVar(CVars.BuildVersion), ["hashes"] = new JObject { - ["Windows"] = _configurationManager.GetCVar("build.hash_windows"), - ["MacOS"] = _configurationManager.GetCVar("build.hash_macos"), - ["Linux"] = _configurationManager.GetCVar("build.hash_linux"), + ["Windows"] = _configurationManager.GetCVar(CVars.BuildHashWindows), + ["MacOS"] = _configurationManager.GetCVar(CVars.BuildHashMacOS), + ["Linux"] = _configurationManager.GetCVar(CVars.BuildHashLinux), }, }; } @@ -124,7 +125,7 @@ namespace Robust.Server.ServerStatus var jObject = new JObject { - ["connect_address"] = _configurationManager.GetCVar("status.connectaddress"), + ["connect_address"] = _configurationManager.GetCVar(CVars.StatusConnectAddress), ["auth"] = authInfo, ["build"] = buildInfo }; diff --git a/Robust.Server/ServerStatus/StatusHost.cs b/Robust.Server/ServerStatus/StatusHost.cs index 39cb0f5bf..e0fc3696d 100644 --- a/Robust.Server/ServerStatus/StatusHost.cs +++ b/Robust.Server/ServerStatus/StatusHost.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Robust.Server.Interfaces.ServerStatus; -using Robust.Shared.Configuration; +using Robust.Shared; using Robust.Shared.ContentPack; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Network; @@ -94,7 +94,7 @@ namespace Robust.Server.ServerStatus { RegisterCVars(); - if (!_configurationManager.GetCVar("status.enabled")) + if (!_configurationManager.GetCVar(CVars.StatusEnabled)) { return; } @@ -133,7 +133,7 @@ namespace Robust.Server.ServerStatus private IPEndPoint GetBinding() { - var binding = _configurationManager.GetCVar("status.bind").Split(':'); + var binding = _configurationManager.GetCVar(CVars.StatusBind).Split(':'); var ipAddrStr = binding[0]; if (ipAddrStr == "+" || ipAddrStr == "*") { @@ -171,18 +171,14 @@ namespace Robust.Server.ServerStatus { } - _configurationManager.RegisterCVar("status.enabled", true, CVar.ARCHIVE); - _configurationManager.RegisterCVar("status.bind", "*:1212", CVar.ARCHIVE); - _configurationManager.RegisterCVar("status.connectaddress", "", CVar.ARCHIVE); - - _configurationManager.RegisterCVar("build.fork_id", info?.ForkId ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.version", info?.Version ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.download_url_windows", info?.Downloads.Windows ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.download_url_macos", info?.Downloads.MacOS ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.download_url_linux", info?.Downloads.Linux ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.hash_windows", info?.Hashes.Windows ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.hash_macos", info?.Hashes.MacOS ?? "", CVar.ARCHIVE); - _configurationManager.RegisterCVar("build.hash_linux", info?.Hashes.Linux ?? "", CVar.ARCHIVE); + _configurationManager.SetCVar(CVars.BuildForkId, info?.ForkId ?? ""); + _configurationManager.SetCVar(CVars.BuildVersion, info?.Version ?? ""); + _configurationManager.SetCVar(CVars.BuildDownloadUrlWindows, info?.Downloads.Windows ?? ""); + _configurationManager.SetCVar(CVars.BuildDownloadUrlMacOS, info?.Downloads.MacOS ?? ""); + _configurationManager.SetCVar(CVars.BuildDownloadUrlLinux, info?.Downloads.Linux ?? ""); + _configurationManager.SetCVar(CVars.BuildHashWindows, info?.Hashes.Windows ?? ""); + _configurationManager.SetCVar(CVars.BuildHashMacOS, info?.Hashes.MacOS ?? ""); + _configurationManager.SetCVar(CVars.BuildHashLinux, info?.Hashes.Linux ?? ""); } [JsonObject(ItemRequired = Required.DisallowNull)] diff --git a/Robust.Server/ServerStatus/WatchdogApi.cs b/Robust.Server/ServerStatus/WatchdogApi.cs index e19fbb87b..487b8ce31 100644 --- a/Robust.Server/ServerStatus/WatchdogApi.cs +++ b/Robust.Server/ServerStatus/WatchdogApi.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using Robust.Server.Interfaces; using Robust.Server.Interfaces.ServerStatus; +using Robust.Shared; using Robust.Shared.Asynchronous; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Timing; @@ -39,10 +40,6 @@ namespace Robust.Server.ServerStatus { _statusHost.AddHandler(UpdateHandler); _statusHost.AddHandler(ShutdownHandler); - - _configurationManager.RegisterCVar("watchdog.token", "", onValueChanged: _ => UpdateToken()); - _configurationManager.RegisterCVar("watchdog.key", "", onValueChanged: _ => UpdateToken()); - _configurationManager.RegisterCVar("watchdog.baseUrl", "http://localhost:5000"); } private bool UpdateHandler(HttpMethod method, HttpRequest request, HttpResponse response) @@ -169,14 +166,17 @@ namespace Robust.Server.ServerStatus public void Initialize() { + _configurationManager.OnValueChanged(CVars.WatchdogToken, _ => UpdateToken()); + _configurationManager.OnValueChanged(CVars.WatchdogKey, _ => UpdateToken()); + UpdateToken(); } private void UpdateToken() { - var tok = _configurationManager.GetCVar("watchdog.token"); - var key = _configurationManager.GetCVar("watchdog.key"); - var baseUrl = _configurationManager.GetCVar("watchdog.baseUrl"); + var tok = _configurationManager.GetCVar(CVars.WatchdogToken); + var key = _configurationManager.GetCVar(CVars.WatchdogKey); + var baseUrl = _configurationManager.GetCVar(CVars.WatchdogBaseUrl); _watchdogToken = string.IsNullOrEmpty(tok) ? null : tok; _watchdogKey = string.IsNullOrEmpty(key) ? null : key; _baseUri = string.IsNullOrEmpty(baseUrl) ? null : new Uri(baseUrl); diff --git a/Robust.Shared/CVars.cs b/Robust.Shared/CVars.cs index 281740777..3ec203fef 100644 --- a/Robust.Shared/CVars.cs +++ b/Robust.Shared/CVars.cs @@ -1,5 +1,6 @@ using System; using Robust.Shared.Configuration; +using Robust.Shared.Log; namespace Robust.Shared { @@ -42,9 +43,126 @@ namespace Robust.Shared public static readonly CVarDef NetDualStack = CVarDef.Create("net.dualstack", false, CVar.ARCHIVE | CVar.SERVERONLY); + public static readonly CVarDef NetInterp = + CVarDef.Create("net.interp", true, CVar.ARCHIVE); + + public static readonly CVarDef NetInterpRatio = + CVarDef.Create("net.interp_ratio", 0, CVar.ARCHIVE); + + public static readonly CVarDef NetLogging = + CVarDef.Create("net.logging", false, CVar.ARCHIVE); + + public static readonly CVarDef NetPredict = + CVarDef.Create("net.predict", true, CVar.ARCHIVE); + + public static readonly CVarDef NetPredictSize = + CVarDef.Create("net.predict_size", 1, CVar.ARCHIVE); + + public static readonly CVarDef NetStateBufMergeThreshold = + CVarDef.Create("net.state_buf_merge_threshold", 5, CVar.ARCHIVE); + + public static readonly CVarDef NetPVS = + CVarDef.Create("net.pvs", true, CVar.ARCHIVE); + + public static readonly CVarDef NetMaxUpdateRange = + CVarDef.Create("net.maxupdaterange", 12.5f, CVar.ARCHIVE); + + public static readonly CVarDef NetLogLateMsg = + CVarDef.Create("net.log_late_msg", true); + + public static readonly CVarDef NetTickrate = + CVarDef.Create("net.tickrate", 60, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER); + + public static readonly CVarDef MetricsEnabled = + CVarDef.Create("metrics.enabled", false); + + public static readonly CVarDef MetricsHost = + CVarDef.Create("metrics.host", "localhost"); + + public static readonly CVarDef MetricsPort = + CVarDef.Create("metrics.port", 44880); + + public static readonly CVarDef StatusEnabled = + CVarDef.Create("status.enabled", true, CVar.ARCHIVE); + + public static readonly CVarDef StatusBind = + CVarDef.Create("status.bind", "*:1212", CVar.ARCHIVE); + + public static readonly CVarDef StatusConnectAddress = + CVarDef.Create("status.connectaddress", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildForkId = + CVarDef.Create("build.fork_id", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildVersion = + CVarDef.Create("build.version", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildDownloadUrlWindows = + CVarDef.Create("build.download_url_windows", string.Empty, CVar.ARCHIVE); + + public static readonly CVarDef BuildDownloadUrlMacOS = + CVarDef.Create("build.download_url_macos", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildDownloadUrlLinux = + CVarDef.Create("build.download_url_linux", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildHashWindows = + CVarDef.Create("build.hash_windows", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildHashMacOS = + CVarDef.Create("build.hash_macos", "", CVar.ARCHIVE); + + public static readonly CVarDef BuildHashLinux = + CVarDef.Create("build.hash_linux", "", CVar.ARCHIVE); + + public static readonly CVarDef WatchdogToken = + CVarDef.Create("watchdog.token", ""); + + public static readonly CVarDef WatchdogKey = + CVarDef.Create("watchdog.key", ""); + + public static readonly CVarDef WatchdogBaseUrl = + CVarDef.Create("watchdog.baseUrl", "http://localhost:5000"); + public static readonly CVarDef GameMaxPlayers = CVarDef.Create("game.maxplayers", 32, CVar.ARCHIVE | CVar.SERVERONLY); + public static readonly CVarDef GameHostName = + CVarDef.Create("game.hostname", "MyServer", CVar.ARCHIVE); + + public static readonly CVarDef GameType = + CVarDef.Create("game.type", 0); + + public static readonly CVarDef LogEnabled = + CVarDef.Create("log.enabled", true, CVar.ARCHIVE); + + public static readonly CVarDef LogPath = + CVarDef.Create("log.path", "logs", CVar.ARCHIVE); + + public static readonly CVarDef LogFormat = + CVarDef.Create("log.format", "log_%(date)s-T%(time)s.txt", CVar.ARCHIVE); + + public static readonly CVarDef LogLevel = + CVarDef.Create("log.level", Log.LogLevel.Info, CVar.ARCHIVE); + + public static readonly CVarDef LogRuntimeLog = + CVarDef.Create("log.runtimelog", true, CVar.ARCHIVE); + + public static readonly CVarDef LokiEnabled = + CVarDef.Create("loki.enabled", false); + + public static readonly CVarDef LokiName = + CVarDef.Create("loki.name", ""); + + public static readonly CVarDef LokiAddress = + CVarDef.Create("loki.address", ""); + + public static readonly CVarDef LokiUsername = + CVarDef.Create("loki.username", ""); + + public static readonly CVarDef LokiPassword = + CVarDef.Create("loki.password", ""); + public static readonly CVarDef AuthMode = CVarDef.Create("auth.mode", (int) Network.AuthMode.Optional, CVar.SERVERONLY); @@ -63,6 +181,70 @@ namespace Robust.Shared public static readonly CVarDef AuthServer = CVarDef.Create("auth.server", "http://localhost:5000/", CVar.SECURE); + public static readonly CVarDef ConsoleDefaultGroup = + CVarDef.Create("console.defaultGroup", 1, CVar.ARCHIVE); + + public static readonly CVarDef DisplayVSync = + CVarDef.Create("display.vsync", true, CVar.ARCHIVE); + + public static readonly CVarDef DisplayWindowMode = + CVarDef.Create("display.windowmode", 0, CVar.ARCHIVE); + + public static readonly CVarDef DisplayWidth = + CVarDef.Create("display.width", 1280); + + public static readonly CVarDef DisplayHeight = + CVarDef.Create("display.height", 720); + + public static readonly CVarDef DisplayLightMapDivider = + CVarDef.Create("display.lightmapdivider", 2); + + public static readonly CVarDef DisplaySoftShadows = + CVarDef.Create("display.softshadows", true); + + public static readonly CVarDef DisplayUIScale = + CVarDef.Create("display.uiScale", 0f, CVar.ARCHIVE); + + public static readonly CVarDef DisplayRenderer = + CVarDef.Create("display.renderer", 0); + + public static readonly CVarDef DisplayFontDpi = + CVarDef.Create("display.fontdpi", 96); + + public static readonly CVarDef DisplayOGLOverrideVersion = + CVarDef.Create("display.ogl_override_version", string.Empty); + + public static readonly CVarDef DisplayOGLCheckErrors = + CVarDef.Create("display.ogl_check_errors", false); + + public static readonly CVarDef AudioDevice = + CVarDef.Create("audio.device", string.Empty); + + public static readonly CVarDef PlayerName = + CVarDef.Create("player.name", "JoeGenero", CVar.ARCHIVE); + + public static readonly CVarDef DiscordEnabled = + CVarDef.Create("discord.enabled", true); + + public static readonly CVarDef ConsoleLoginLocal = + CVarDef.Create("console.loginlocal", true, CVar.ARCHIVE); + + // register console admin global password. DO NOT ADD THE REPLICATED FLAG + public static readonly CVarDef ConsolePassword = + CVarDef.Create("console.password", string.Empty, CVar.ARCHIVE | CVar.SERVER | CVar.NOT_CONNECTED); + + public static readonly CVarDef ConsoleHostPassword = + CVarDef.Create("console.hostpassword", string.Empty, CVar.ARCHIVE | CVar.SERVER | CVar.NOT_CONNECTED); + + public static readonly CVarDef ConsoleAdminGroup = + CVarDef.Create("console.adminGroup", 100, CVar.ARCHIVE | CVar.SERVER); + + public static readonly CVarDef ConsoleHostGroup = + CVarDef.Create("console.hostGroup", 200, CVar.ARCHIVE | CVar.SERVER); + + public static readonly CVarDef SignalsHandle = + CVarDef.Create("signals.handle", true); + #if DEBUG public static readonly CVarDef NetFakeLoss = CVarDef.Create("net.fakeloss", 0f, CVar.CHEAT); public static readonly CVarDef NetFakeLagMin = CVarDef.Create("net.fakelagmin", 0f, CVar.CHEAT); diff --git a/Robust.Shared/Configuration/ConfigurationManager.cs b/Robust.Shared/Configuration/ConfigurationManager.cs index 89a6d177d..1b39db3d2 100644 --- a/Robust.Shared/Configuration/ConfigurationManager.cs +++ b/Robust.Shared/Configuration/ConfigurationManager.cs @@ -238,7 +238,7 @@ namespace Robust.Shared.Configuration if (invokeImmediately) { - onValueChanged((T) reg.Value!); + onValueChanged((T) (reg.Value ?? reg.DefaultValue)!); } } diff --git a/Robust.Shared/Network/NetManager.ServerAuth.cs b/Robust.Shared/Network/NetManager.ServerAuth.cs index abf9cb580..61f5f3961 100644 --- a/Robust.Shared/Network/NetManager.ServerAuth.cs +++ b/Robust.Shared/Network/NetManager.ServerAuth.cs @@ -49,7 +49,7 @@ namespace Robust.Shared.Network msgLogin.ReadFromBuffer(incPacket); var ip = connection.RemoteEndPoint.Address; - var isLocal = IPAddress.IsLoopback(ip) && _config.GetCVar("auth.allowlocal"); + var isLocal = IPAddress.IsLoopback(ip) && _config.GetCVar(CVars.AuthAllowLocal); var canAuth = msgLogin.CanAuth; var needPk = msgLogin.NeedPubKey; var authServer = _config.GetSecureCVar("auth.server"); diff --git a/Robust.Shared/Network/NetManager.cs b/Robust.Shared/Network/NetManager.cs index b01cf110e..c5d5b794d 100644 --- a/Robust.Shared/Network/NetManager.cs +++ b/Robust.Shared/Network/NetManager.cs @@ -134,7 +134,7 @@ namespace Robust.Shared.Network = new Dictionary>(); /// - public int Port => _config.GetCVar("net.port"); + public int Port => _config.GetCVar(CVars.NetPort); public bool IsAuthEnabled => _config.GetCVar("auth.enabled"); @@ -516,10 +516,10 @@ namespace Robust.Shared.Network #if DEBUG //Simulate Latency - netConfig.SimulatedLoss = _config.GetCVar("net.fakeloss"); - netConfig.SimulatedMinimumLatency = _config.GetCVar("net.fakelagmin"); - netConfig.SimulatedRandomLatency = _config.GetCVar("net.fakelagrand"); - netConfig.SimulatedDuplicatesChance = _config.GetCVar("net.fakeduplicates"); + netConfig.SimulatedLoss = _config.GetCVar(CVars.NetFakeLoss); + netConfig.SimulatedMinimumLatency = _config.GetCVar(CVars.NetFakeLagMin); + netConfig.SimulatedRandomLatency = _config.GetCVar(CVars.NetFakeLagRand); + netConfig.SimulatedDuplicatesChance = _config.GetCVar(CVars.NetFakeDuplicates); netConfig.ConnectionTimeout = 30000f; #endif diff --git a/Robust.Shared/SignalHandler.cs b/Robust.Shared/SignalHandler.cs index 391c859ad..e34bb9514 100644 --- a/Robust.Shared/SignalHandler.cs +++ b/Robust.Shared/SignalHandler.cs @@ -9,24 +9,21 @@ using Robust.Shared.Log; namespace Robust.Shared { - internal abstract class SignalHandler : ISignalHandler, IDisposable, IPostInjectInit + internal abstract class SignalHandler : ISignalHandler, IDisposable { [Dependency] private readonly ITaskManager _taskManager = default!; +#pragma warning disable 414 [Dependency] private readonly IConfigurationManager _configurationManager = default!; +#pragma warning restore 414 private Thread? _signalThread; - public void PostInject() - { - _configurationManager.RegisterCVar("signals.handle", true); - } - public void MaybeStart() { // I actually did try to implement a onValueChanged handler but couldn't make it work well. // The problem is that shutting down the thread does not restore the default exit behavior. #if UNIX - if (_configurationManager.GetCVar("signals.handle")) + if (_configurationManager.GetCVar(CVars.SignalsHandle)) { Start(); } diff --git a/Robust.UnitTesting/RobustUnitTest.cs b/Robust.UnitTesting/RobustUnitTest.cs index a74100e95..2c87803dd 100644 --- a/Robust.UnitTesting/RobustUnitTest.cs +++ b/Robust.UnitTesting/RobustUnitTest.cs @@ -5,6 +5,7 @@ using System.Reflection; using NUnit.Framework; using Robust.Shared.ContentPack; using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.Reflection; using Robust.Shared.IoC; @@ -28,6 +29,7 @@ namespace Robust.UnitTesting // Clear state across tests. IoCManager.InitThread(); IoCManager.Clear(); + RegisterIoC(); var assemblies = new List(4); @@ -46,6 +48,11 @@ namespace Robust.UnitTesting assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared")); assemblies.Add(Assembly.GetExecutingAssembly()); + foreach (var assembly in assemblies) + { + IoCManager.Resolve().LoadCVarsFromAssembly(assembly); + } + IoCManager.Resolve().LoadAssemblies(assemblies); // Required components for the engine to work diff --git a/RobustToolbox.sln.DotSettings b/RobustToolbox.sln.DotSettings index fdb0fccfb..836a1c69a 100644 --- a/RobustToolbox.sln.DotSettings +++ b/RobustToolbox.sln.DotSettings @@ -1,4 +1,6 @@  True True - True \ No newline at end of file + True + True + True \ No newline at end of file