Extract CVars class (#653)

This commit is contained in:
Morb
2022-12-20 12:08:58 +03:00
committed by GitHub
parent 6decc09a49
commit 8a2a97d816
6 changed files with 57 additions and 44 deletions

View File

@@ -5,6 +5,7 @@ using Content.Server.Database;
using Content.Server.GameTicking;
using Content.Server.Preferences.Managers;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.GameTicking;
using Content.Shared.Players.PlayTimeTracking;
using Robust.Server.Player;
@@ -140,7 +141,7 @@ namespace Content.Server.Connection
// Corvax-Queue-Start
var isPrivileged = await HavePrivilegedJoin(e.UserId);
var isQueueEnabled = _cfg.GetCVar(CCVars.QueueEnabled);
var isQueueEnabled = _cfg.GetCVar(CCCVars.QueueEnabled);
if (_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !isPrivileged && !isQueueEnabled)
// Corvax-Queue-End
{

View File

@@ -1,6 +1,7 @@
using System.Linq;
using Content.Server.Connection;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.Corvax.JoinQueue;
using Prometheus;
using Robust.Server.Player;
@@ -52,7 +53,7 @@ public sealed class JoinQueueManager
{
_netManager.RegisterNetMessage<MsgQueueUpdate>();
_cfg.OnValueChanged(CCVars.QueueEnabled, OnQueueCVarChanged, true);
_cfg.OnValueChanged(CCCVars.QueueEnabled, OnQueueCVarChanged, true);
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
}

View File

@@ -4,6 +4,7 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using Content.Server.Maps;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.GameTicking;
using Robust.Shared.Configuration;
@@ -30,8 +31,8 @@ public sealed class RoundNotificationsSystem : EntitySystem
SubscribeLocalEvent<RoundStartedEvent>(OnRoundStarted);
SubscribeLocalEvent<RoundEndMessageEvent>(OnRoundEnd);
_config.OnValueChanged(CCVars.DiscordRoundWebhook, value => _discordWebhook = value, true);
_config.OnValueChanged(CCVars.DiscordRoundRoleId, value => _discordRoleId = value, true);
_config.OnValueChanged(CCCVars.DiscordRoundWebhook, value => _discordWebhook = value, true);
_config.OnValueChanged(CCCVars.DiscordRoundRoleId, value => _discordRoleId = value, true);
_sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("notifications");
}
@@ -120,4 +121,4 @@ public sealed class RoundNotificationsSystem : EntitySystem
{
}
}
}
}

View File

@@ -3,7 +3,7 @@ using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.Corvax.Sponsors;
using Robust.Shared.Configuration;
using Robust.Shared.Network;
@@ -26,7 +26,7 @@ public sealed class SponsorsManager
public void Initialize()
{
_sawmill = Logger.GetSawmill("sponsors");
_cfg.OnValueChanged(CCVars.SponsorsApiUrl, s => _apiUrl = s, true);
_cfg.OnValueChanged(CCCVars.SponsorsApiUrl, s => _apiUrl = s, true);
_netMgr.RegisterNetMessage<MsgSponsorInfo>();

View File

@@ -1389,7 +1389,6 @@ namespace Content.Shared.CCVar
/// </summary>
public static readonly CVarDef<string> InfoLinksBugReport =
CVarDef.Create("infolinks.bug_report", "", CVar.SERVER | CVar.REPLICATED);
/*
* CONFIG
*/
@@ -1422,41 +1421,5 @@ namespace Content.Shared.CCVar
/// </summary>
public static readonly CVarDef<bool> ConfigPresetDebug =
CVarDef.Create("config.preset_debug", true, CVar.SERVERONLY);
/**
* Corvax | RoundNotifications
*/
/// <summary>
/// URL of the Discord webhook which will send round status notifications.
/// </summary>
public static readonly CVarDef<string> DiscordRoundWebhook =
CVarDef.Create("discord.round_webhook", string.Empty, CVar.SERVERONLY);
/// <summary>
/// Discord ID of role which will be pinged on new round start message.
/// </summary>
public static readonly CVarDef<string> DiscordRoundRoleId =
CVarDef.Create("discord.round_roleid", string.Empty, CVar.SERVERONLY);
/**
* Corvax | Sponsors
*/
/// <summary>
/// URL of the sponsors server API.
/// </summary>
public static readonly CVarDef<string> SponsorsApiUrl =
CVarDef.Create("sponsor.api_url", "", CVar.SERVERONLY);
/*
* Corvax | Queue
*/
/// <summary>
/// Controls if the connections queue is enabled. If enabled stop kicking new players after `SoftMaxPlayers` cap and instead add them to queue.
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);
}
}

View File

@@ -0,0 +1,47 @@
using Robust.Shared.Configuration;
namespace Content.Shared.Corvax.CCCVars;
/// <summary>
/// Corvax modules console variables
/// </summary>
[CVarDefs]
// ReSharper disable once InconsistentNaming
public sealed class CCCVars
{
/**
* RoundNotifications
*/
/// <summary>
/// URL of the Discord webhook which will send round status notifications.
/// </summary>
public static readonly CVarDef<string> DiscordRoundWebhook =
CVarDef.Create("discord.round_webhook", string.Empty, CVar.SERVERONLY);
/// <summary>
/// Discord ID of role which will be pinged on new round start message.
/// </summary>
public static readonly CVarDef<string> DiscordRoundRoleId =
CVarDef.Create("discord.round_roleid", string.Empty, CVar.SERVERONLY);
/**
* Sponsors
*/
/// <summary>
/// URL of the sponsors server API.
/// </summary>
public static readonly CVarDef<string> SponsorsApiUrl =
CVarDef.Create("sponsor.api_url", "", CVar.SERVERONLY);
/*
* Queue
*/
/// <summary>
/// Controls if the connections queue is enabled. If enabled stop kicking new players after `SoftMaxPlayers` cap and instead add them to queue.
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);
}