TShock/TShockAPI/Configuration/ServerSideConfig.cs
Lucas Nicodemus 61e36d0abd
Move GiveItemsDirectly config item to tshock config
Due to an issue that stops the SSC config persister thing from working,
I moved the config item that's new back to the config file. I tried
applying the patches from
https://github.com/Pryaxis/TShock/pull/2354/commits but these didn't
actually resolve the issue. I'm keeping the commits here but I'm not
sure they help.

The core problem is this: if you add a new config file item to the ssc
config, the ssc config is overwritten with the default config items
instead of being merged automatically with the new items. This is a
critical issue as it means that SSC is disabled on all servers that had
it enabled and results in "data misplacement" which is alarming enough
to cause users to think they had data loss, which is not ideal.

Until the issue with the SSC config is resolved, I'm not willing or
confident to change it.
2022-10-31 16:18:39 -07:00

130 lines
4.4 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
TShock, a server mod for Terraria
Copyright (C) 2011-2019 Pryaxis & TShock Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace TShockAPI.Configuration
{
/// <summary>
/// Settings used to configure server side characters
/// </summary>
public class SscSettings
{
/// <summary>
/// Enable server side characters, causing client data to be saved on the server instead of the client.
/// </summary>
[Description("Enable server side characters, causing client data to be saved on the server instead of the client.")]
public bool Enabled = false;
/// <summary>
/// How often SSC should save, in minutes.
/// </summary>
[Description("How often SSC should save, in minutes.")]
public int ServerSideCharacterSave = 5;
/// <summary>
/// Time, in milliseconds, to disallow discarding items after logging in when ServerSideCharacters is ON.
/// </summary>
[Description("Time, in milliseconds, to disallow discarding items after logging in when ServerSideCharacters is ON.")]
public int LogonDiscardThreshold = 250;
/// <summary>
/// The starting default health for new players when SSC is enabled.
/// </summary>
[Description("The starting default health for new players when SSC is enabled.")]
public int StartingHealth = 100;
/// <summary>
/// The starting default mana for new players when SSC is enabled.
/// </summary>
[Description("The starting default mana for new players when SSC is enabled.")]
public int StartingMana = 20;
/// <summary>
/// The starting default inventory for new players when SSC is enabled.
/// </summary>
[Description("The starting default inventory for new players when SSC is enabled.")]
public List<NetItem> StartingInventory = new List<NetItem>();
/// <summary>
/// Warns players that they have the bypass SSC permission enabled. To disable warning, turn this off.
/// </summary>
[Description("Warns players and the console if a player has the tshock.ignore.ssc permission with data in the SSC table.")]
public bool WarnPlayersAboutBypassPermission = true;
}
/// <summary>
/// Configuration for the server side characters system
/// </summary>
public class ServerSideConfig : ConfigFile<SscSettings>
{
/// <summary>
/// Upgrades the configuration file from the old format if required, then reads and returns the currently configured <see cref="SscSettings"/>
/// </summary>
/// <param name="json"></param>
/// <param name="incompleteSettings"></param>
/// <returns></returns>
public override SscSettings ConvertJson(string json, out bool incompleteSettings)
{
var settings = FileTools.LoadConfigAndCheckForChanges<SscSettings>(json, out incompleteSettings);
Settings = settings;
OnConfigRead?.Invoke(this);
return settings;
}
/// <summary>
/// Dumps all configuration options to a text file in Markdown format
/// </summary>
public static void DumpDescriptions()
{
var sb = new StringBuilder();
var defaults = new SscSettings();
foreach (var field in defaults.GetType().GetFields().OrderBy(f => f.Name))
{
if (field.IsStatic)
continue;
var name = field.Name;
var type = field.FieldType.Name;
var descattr =
field.GetCustomAttributes(false).FirstOrDefault(o => o is DescriptionAttribute) as DescriptionAttribute;
var desc = descattr != null && !string.IsNullOrWhiteSpace(descattr.Description) ? descattr.Description : "None";
var def = field.GetValue(defaults);
sb.AppendLine("## {0} ".SFormat(name));
sb.AppendLine("{0}".SFormat(desc));
sb.AppendLine("* **Field type**: `{0}`".SFormat(type));
sb.AppendLine("* **Default**: `{0}`".SFormat(def));
sb.AppendLine();
}
File.WriteAllText("docs/ssc-config.md", sb.ToString());
}
}
}