mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Removed the Interfaces folder. * All objects inside the GameObjects subfolders are now in the GameObjects namespace. * Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces. * Simplified Robust.client.Graphics namespace. * Automated remove redundant using statements.
61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Robust.Server.Console.Commands
|
|
{
|
|
[UsedImplicitly]
|
|
internal sealed class CVarCommand : SharedCVarCommand, IConsoleCommand
|
|
{
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length < 1 || args.Length > 2)
|
|
{
|
|
shell.WriteLine("Must provide exactly one or two arguments.");
|
|
return;
|
|
}
|
|
|
|
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
|
var name = args[0];
|
|
|
|
if (name == "?")
|
|
{
|
|
var cvars = configManager.GetRegisteredCVars();
|
|
shell.WriteLine(string.Join("\n", cvars));
|
|
return;
|
|
}
|
|
|
|
if (!configManager.IsCVarRegistered(name))
|
|
{
|
|
shell.WriteLine($"CVar '{name}' is not registered. Use 'cvar ?' to get a list of all registered CVars.");
|
|
return;
|
|
}
|
|
|
|
if (args.Length == 1)
|
|
{
|
|
// Read CVar
|
|
var value = configManager.GetCVar<object>(name);
|
|
shell.WriteLine(value.ToString()!);
|
|
}
|
|
else
|
|
{
|
|
// Write CVar
|
|
var value = args[1];
|
|
var type = configManager.GetCVarType(name);
|
|
try
|
|
{
|
|
var parsed = ParseObject(type, value);
|
|
configManager.SetCVar(name, parsed);
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
shell.WriteLine($"Input value is in incorrect format for type {type}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|