IW4M-Admin/SharedLibraryCore/Configuration/ApplicationConfiguration.cs

210 lines
8.6 KiB
C#
Raw Normal View History

using SharedLibraryCore.Configuration.Attributes;
using SharedLibraryCore.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Newtonsoft.Json;
using static Data.Models.Client.EFClient;
2018-04-08 02:44:42 -04:00
namespace SharedLibraryCore.Configuration
{
public class ApplicationConfiguration : IBaseConfiguration
{
[LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")]
[ConfigurationLinked("WebfrontBindUrl", "ManualWebfrontUrl", "WebfrontPrimaryColor", "WebfrontSecondaryColor",
"WebfrontCustomBranding")]
public bool EnableWebFront { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BIND_URL")]
public string WebfrontBindUrl { get; set; }
[ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MANUAL_URL")]
public string ManualWebfrontUrl { get; set; }
[ConfigurationOptional]
2019-07-27 16:23:45 -04:00
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRIMARY_COLOR")]
public string WebfrontPrimaryColor { get; set; }
[ConfigurationOptional]
2019-07-27 16:23:45 -04:00
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SECONDARY_COLOR")]
public string WebfrontSecondaryColor { get; set; }
2019-07-27 16:23:45 -04:00
[ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_BRANDING")]
public string WebfrontCustomBranding { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_MULTIOWN")]
public bool EnableMultipleOwners { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_STEPPEDPRIV")]
public bool EnableSteppedHierarchy { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_USE_LOCAL_TRANSLATIONS")]
public bool UseLocalTranslations { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_IGNORE_BOTS")]
public bool IgnoreBots { get; set; }
2019-07-17 13:29:51 -04:00
[ConfigurationLinked("CustomSayName")]
[LocalizedDisplayName("SETUP_ENABLE_CUSTOMSAY")]
public bool EnableCustomSayName { get; set; }
[LocalizedDisplayName("SETUP_SAY_NAME")]
public string CustomSayName { get; set; }
[LocalizedDisplayName("SETUP_DISPLAY_SOCIAL")]
2019-07-17 13:29:51 -04:00
[ConfigurationLinked("SocialLinkAddress", "SocialLinkTitle")]
public bool EnableSocialLink { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_LINK")]
public string SocialLinkAddress { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_TITLE")]
public string SocialLinkTitle { get; set; }
[LocalizedDisplayName("SETUP_CONTACT_URI")]
public string ContactUri { get; set; }
[LocalizedDisplayName("SETUP_USE_CUSTOMENCODING")]
2019-07-17 13:29:51 -04:00
[ConfigurationLinked("CustomParserEncoding")]
public bool EnableCustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENCODING")]
2018-04-21 18:18:20 -04:00
public string CustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_WHITELIST")]
2019-07-17 13:29:51 -04:00
[ConfigurationLinked("WebfrontConnectionWhitelist")]
public bool EnableWebfrontConnectionWhitelist { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_WHITELIST_LIST")]
public string[] WebfrontConnectionWhitelist { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
2019-07-17 13:29:51 -04:00
[ConfigurationLinked("CustomLocale")]
public bool EnableCustomLocale { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
public string CustomLocale { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_COMMAND_PREFIX")]
public string CommandPrefix { get; set; } = "!";
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BROADCAST_COMMAND_PREFIX")]
public string BroadcastCommandPrefix { get; set; } = "@";
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_DB_PROVIDER")]
2018-09-23 20:45:54 -04:00
public string DatabaseProvider { get; set; } = "sqlite";
[ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CONNECTION_STRING")]
public string ConnectionString { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_RCON_POLLRATE")]
public int RConPollRate { get; set; } = 5000;
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAX_TB")]
public TimeSpan MaximumTempBanTime { get; set; } = new TimeSpan(24 * 30, 0, 0);
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")]
2019-08-02 19:04:34 -04:00
public bool EnableColorCodes { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
2018-03-14 14:22:04 -04:00
public int AutoMessagePeriod { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGES")]
public string[] AutoMessages { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_GLOBAL_RULES")]
public string[] GlobalRules { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_DISALLOWED_NAMES")]
public string[] DisallowedClientNames { get; set; } = new string[0];
2020-10-17 11:47:56 -04:00
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAP_CHANGE_DELAY")]
public int MapChangeDelaySeconds { get; set; } = 5;
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BAN_DURATIONS")]
public TimeSpan[] BanDurations { get; set; } = {
TimeSpan.FromHours(1),
TimeSpan.FromHours(6),
TimeSpan.FromDays(1),
TimeSpan.FromDays(2),
TimeSpan.FromDays(7),
TimeSpan.FromDays(30)
};
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRESET_BAN_REASONS")]
public Dictionary<string, string> PresetPenaltyReasons { get; set; } = new Dictionary<string, string>
{{"afk", "Away from keyboard"}, {"ci", "Connection interrupted. Reconnect"}};
[LocalizedDisplayName(("WEBFRONT_CONFIGURATION_ENABLE_PRIVILEGED_USER_PRIVACY"))]
public bool EnablePrivilegedUserPrivacy { get; set; }
public bool EnableImplicitAccountLinking { get; set; } = false;
public Dictionary<Permission, string> OverridePermissionLevelNames { get; set; } = Enum
.GetValues(typeof(Permission))
.Cast<Permission>()
.ToDictionary(perm => perm, perm => perm.ToString());
[UIHint("ServerConfiguration")]
public ServerConfiguration[] Servers { get; set; }
[ConfigurationIgnore] public int MinimumNameLength { get; set; } = 3;
[ConfigurationIgnore] public string Id { get; set; }
[ConfigurationIgnore] public string SubscriptionId { get; set; }
[Obsolete("Moved to DefaultSettings")]
[ConfigurationIgnore] public MapConfiguration[] Maps { get; set; }
[Obsolete("Moved to DefaultSettings")]
[ConfigurationIgnore] public QuickMessageConfiguration[] QuickMessages { get; set; }
[ConfigurationIgnore]
[JsonIgnore]
public string WebfrontUrl => string.IsNullOrEmpty(ManualWebfrontUrl)
? WebfrontBindUrl?.Replace("0.0.0.0", "127.0.0.1")
: ManualWebfrontUrl;
[ConfigurationIgnore] public bool IgnoreServerConnectionLost { get; set; }
[ConfigurationIgnore] public Uri MasterUrl { get; set; } = new Uri("http://api.raidmax.org:5000");
public IBaseConfiguration Generate()
{
var loc = Utilities.CurrentLocalization.LocalizationIndex;
2018-04-18 16:46:53 -04:00
Id = Guid.NewGuid().ToString();
EnableWebFront = Utilities.PromptBool(loc["SETUP_ENABLE_WEBFRONT"]);
EnableMultipleOwners = Utilities.PromptBool(loc["SETUP_ENABLE_MULTIOWN"]);
EnableSteppedHierarchy = Utilities.PromptBool(loc["SETUP_ENABLE_STEPPEDPRIV"]);
EnableCustomSayName = Utilities.PromptBool(loc["SETUP_ENABLE_CUSTOMSAY"]);
bool useCustomParserEncoding = Utilities.PromptBool(loc["SETUP_USE_CUSTOMENCODING"]);
if (useCustomParserEncoding)
{
CustomParserEncoding = Utilities.PromptString(loc["SETUP_ENCODING_STRING"]);
}
2018-04-21 18:18:20 -04:00
WebfrontBindUrl = "http://0.0.0.0:1624";
if (EnableCustomSayName)
{
CustomSayName = Utilities.PromptString(loc["SETUP_SAY_NAME"]);
}
EnableSocialLink = Utilities.PromptBool(loc["SETUP_DISPLAY_SOCIAL"]);
if (EnableSocialLink)
{
SocialLinkTitle = Utilities.PromptString(loc["SETUP_SOCIAL_TITLE"]);
SocialLinkAddress = Utilities.PromptString(loc["SETUP_SOCIAL_LINK"]);
}
RConPollRate = 5000;
AutoMessagePeriod = 60;
return this;
}
public string Name()
{
return "ApplicationConfiguration";
}
}
}