add preset rules, configurable time spans, and separate rule shortcut for issue #180

This commit is contained in:
RaidMax 2020-12-31 18:48:58 -06:00
parent 5a288dafc1
commit 5cb2d05f33
3 changed files with 154 additions and 76 deletions

View File

@ -1,6 +1,7 @@
using SharedLibraryCore.Configuration.Attributes; using SharedLibraryCore.Configuration.Attributes;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace SharedLibraryCore.Configuration namespace SharedLibraryCore.Configuration
@ -8,63 +9,79 @@ namespace SharedLibraryCore.Configuration
public class ApplicationConfiguration : IBaseConfiguration public class ApplicationConfiguration : IBaseConfiguration
{ {
[LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")] [LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")]
[ConfigurationLinked("WebfrontBindUrl", "ManualWebfrontUrl", "WebfrontPrimaryColor", "WebfrontSecondaryColor", "WebfrontCustomBranding")] [ConfigurationLinked("WebfrontBindUrl", "ManualWebfrontUrl", "WebfrontPrimaryColor", "WebfrontSecondaryColor",
"WebfrontCustomBranding")]
public bool EnableWebFront { get; set; } public bool EnableWebFront { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_BIND_URL")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_BIND_URL")]
public string WebfrontBindUrl { get; set; } public string WebfrontBindUrl { get; set; }
[ConfigurationOptional] [ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MANUAL_URL")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_MANUAL_URL")]
public string ManualWebfrontUrl { get; set; } public string ManualWebfrontUrl { get; set; }
[ConfigurationOptional] [ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRIMARY_COLOR")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_PRIMARY_COLOR")]
public string WebfrontPrimaryColor { get; set; } public string WebfrontPrimaryColor { get; set; }
[ConfigurationOptional] [ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_SECONDARY_COLOR")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_SECONDARY_COLOR")]
public string WebfrontSecondaryColor { get; set; } public string WebfrontSecondaryColor { get; set; }
[ConfigurationOptional] [ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_BRANDING")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_BRANDING")]
public string WebfrontCustomBranding { get; set; } public string WebfrontCustomBranding { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_MULTIOWN")] [LocalizedDisplayName("SETUP_ENABLE_MULTIOWN")]
public bool EnableMultipleOwners { get; set; } public bool EnableMultipleOwners { get; set; }
[LocalizedDisplayName("SETUP_ENABLE_STEPPEDPRIV")] [LocalizedDisplayName("SETUP_ENABLE_STEPPEDPRIV")]
public bool EnableSteppedHierarchy { get; set; } public bool EnableSteppedHierarchy { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_USE_LOCAL_TRANSLATIONS")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_USE_LOCAL_TRANSLATIONS")]
public bool UseLocalTranslations { get; set; } public bool UseLocalTranslations { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_IGNORE_BOTS")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_IGNORE_BOTS")]
public bool IgnoreBots { get; set; } public bool IgnoreBots { get; set; }
[ConfigurationLinked("CustomSayName")] [ConfigurationLinked("CustomSayName")]
[LocalizedDisplayName("SETUP_ENABLE_CUSTOMSAY")] [LocalizedDisplayName("SETUP_ENABLE_CUSTOMSAY")]
public bool EnableCustomSayName { get; set; } public bool EnableCustomSayName { get; set; }
[LocalizedDisplayName("SETUP_SAY_NAME")] [LocalizedDisplayName("SETUP_SAY_NAME")]
public string CustomSayName { get; set; } public string CustomSayName { get; set; }
[LocalizedDisplayName("SETUP_DISPLAY_SOCIAL")] [LocalizedDisplayName("SETUP_DISPLAY_SOCIAL")]
[ConfigurationLinked("SocialLinkAddress", "SocialLinkTitle")] [ConfigurationLinked("SocialLinkAddress", "SocialLinkTitle")]
public bool EnableSocialLink { get; set; } public bool EnableSocialLink { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_LINK")] [LocalizedDisplayName("SETUP_SOCIAL_LINK")]
public string SocialLinkAddress { get; set; } public string SocialLinkAddress { get; set; }
[LocalizedDisplayName("SETUP_SOCIAL_TITLE")] [LocalizedDisplayName("SETUP_SOCIAL_TITLE")]
public string SocialLinkTitle { get; set; } public string SocialLinkTitle { get; set; }
[LocalizedDisplayName("SETUP_CONTACT_URI")] [LocalizedDisplayName("SETUP_CONTACT_URI")]
public string ContactUri { get; set; } public string ContactUri { get; set; }
[LocalizedDisplayName("SETUP_USE_CUSTOMENCODING")] [LocalizedDisplayName("SETUP_USE_CUSTOMENCODING")]
[ConfigurationLinked("CustomParserEncoding")] [ConfigurationLinked("CustomParserEncoding")]
public bool EnableCustomParserEncoding { get; set; } public bool EnableCustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENCODING")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENCODING")]
public string CustomParserEncoding { get; set; } public string CustomParserEncoding { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_WHITELIST")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_WHITELIST")]
[ConfigurationLinked("WebfrontConnectionWhitelist")] [ConfigurationLinked("WebfrontConnectionWhitelist")]
public bool EnableWebfrontConnectionWhitelist { get; set; } public bool EnableWebfrontConnectionWhitelist { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_WHITELIST_LIST")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_WHITELIST_LIST")]
public string[] WebfrontConnectionWhitelist { get; set; } = new string[0]; public string[] WebfrontConnectionWhitelist { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
[ConfigurationLinked("CustomLocale")] [ConfigurationLinked("CustomLocale")]
public bool EnableCustomLocale { get; set; } public bool EnableCustomLocale { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_CUSTOM_LOCALE")]
public string CustomLocale { get; set; } public string CustomLocale { get; set; }
@ -76,42 +93,63 @@ namespace SharedLibraryCore.Configuration
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_DB_PROVIDER")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_DB_PROVIDER")]
public string DatabaseProvider { get; set; } = "sqlite"; public string DatabaseProvider { get; set; } = "sqlite";
[ConfigurationOptional] [ConfigurationOptional]
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_CONNECTION_STRING")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_CONNECTION_STRING")]
public string ConnectionString { get; set; } public string ConnectionString { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_RCON_POLLRATE")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_RCON_POLLRATE")]
public int RConPollRate { get; set; } = 5000; public int RConPollRate { get; set; } = 5000;
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAX_TB")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAX_TB")]
public TimeSpan MaximumTempBanTime { get; set; } = new TimeSpan(24 * 30, 0, 0); public TimeSpan MaximumTempBanTime { get; set; } = new TimeSpan(24 * 30, 0, 0);
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_ENABLE_COLOR_CODES")]
public bool EnableColorCodes { get; set; } public bool EnableColorCodes { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGE_PERIOD")]
public int AutoMessagePeriod { get; set; } public int AutoMessagePeriod { get; set; }
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGES")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_AUTOMESSAGES")]
public string[] AutoMessages { get; set; } = new string[0]; public string[] AutoMessages { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_GLOBAL_RULES")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_GLOBAL_RULES")]
public string[] GlobalRules { get; set; } = new string[0]; public string[] GlobalRules { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_DISALLOWED_NAMES")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_DISALLOWED_NAMES")]
public string[] DisallowedClientNames { get; set; } = new string[0]; public string[] DisallowedClientNames { get; set; } = new string[0];
[LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAP_CHANGE_DELAY")] [LocalizedDisplayName("WEBFRONT_CONFIGURATION_MAP_CHANGE_DELAY")]
public int MapChangeDelaySeconds { get; set; } = 5; public int MapChangeDelaySeconds { get; set; } = 5;
[UIHint("ServerConfiguration")]
[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(31)
};
[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"}};
[UIHint("ServerConfiguration")]
public ServerConfiguration[] Servers { get; set; } public ServerConfiguration[] Servers { get; set; }
[ConfigurationIgnore] public string Id { get; set; }
[ConfigurationIgnore] public string SubscriptionId { get; set; }
[ConfigurationIgnore] public MapConfiguration[] Maps { get; set; }
[ConfigurationIgnore] public QuickMessageConfiguration[] QuickMessages { get; set; }
[ConfigurationIgnore] [ConfigurationIgnore]
public string Id { get; set; } public string WebfrontUrl => string.IsNullOrEmpty(ManualWebfrontUrl)
[ConfigurationIgnore] ? WebfrontBindUrl?.Replace("0.0.0.0", "127.0.0.1")
public string SubscriptionId { get; set; } : ManualWebfrontUrl;
[ConfigurationIgnore]
public MapConfiguration[] Maps { get; set; } [ConfigurationIgnore] public bool IgnoreServerConnectionLost { get; set; }
[ConfigurationIgnore] [ConfigurationIgnore] public Uri MasterUrl { get; set; } = new Uri("http://api.raidmax.org:5000");
public QuickMessageConfiguration[] QuickMessages { get; set; }
[ConfigurationIgnore]
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() public IBaseConfiguration Generate()
{ {

View File

@ -1003,6 +1003,12 @@ namespace SharedLibraryCore
public static string FindRuleForReason(this string reason, ApplicationConfiguration appConfig, Server server) public static string FindRuleForReason(this string reason, ApplicationConfiguration appConfig, Server server)
{ {
// allow for penalty presets
if (appConfig.PresetPenaltyReasons?.ContainsKey(reason.ToLower()) ?? false)
{
return appConfig.PresetPenaltyReasons[reason.ToLower()];
}
var regex = Regex.Match(reason, @"(rule|serverrule)(\d+)", RegexOptions.IgnoreCase); var regex = Regex.Match(reason, @"(rule|serverrule)(\d+)", RegexOptions.IgnoreCase);
if (!regex.Success) if (!regex.Success)
{ {

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -25,9 +26,10 @@ namespace WebfrontCore.Controllers
private readonly string _unflagCommandName; private readonly string _unflagCommandName;
private readonly string _setLevelCommandName; private readonly string _setLevelCommandName;
public ActionController(IManager manager, IEnumerable<IManagerCommand> registeredCommands) : base(manager) public ActionController(IManager manager, IEnumerable<IManagerCommand> registeredCommands,
ApplicationConfiguration appConfig) : base(manager)
{ {
_appConfig = manager.GetApplicationSettings().Configuration(); _appConfig = appConfig;
foreach (var cmd in registeredCommands) foreach (var cmd in registeredCommands)
{ {
@ -73,23 +75,33 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name = "Reason", Name = "Reason",
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
}, },
new InputInfo() new InputInfo()
{ {
Name ="Duration", Name = "PresetReason",
Label=Localization["WEBFRONT_ACTION_LABEL_DURATION"], Type = "select",
Type="select", Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
Values = new Dictionary<string, string>() Values = GetPresetPenaltyReasons()
{ },
{"1", $"1 {Localization["GLOBAL_TIME_HOUR"]}" }, new InputInfo()
{"2", $"6 {Localization["GLOBAL_TIME_HOURS"]}" }, {
{"3", $"1 {Localization["GLOBAL_TIME_DAY"]}" }, Name = "Duration",
{"4", $"2 {Localization["GLOBAL_TIME_DAYS"]}" }, Label = Localization["WEBFRONT_ACTION_LABEL_DURATION"],
{"5", $"1 {Localization["GLOBAL_TIME_WEEK"]}" }, Type = "select",
{"6", $"{Localization["WEBFRONT_ACTION_SELECTION_PERMANENT"]}" }, Values = _appConfig.BanDurations
} .Select((item, index) => new
{
Id = (index + 1).ToString(),
Value = item.HumanizeForCurrentCulture()
}
)
.Append(new
{
Id = (_appConfig.BanDurations.Length + 1).ToString(),
Value = Localization["WEBFRONT_ACTION_SELECTION_PERMANENT"]
}).ToDictionary(duration => duration.Id, duration => duration.Value),
} }
}, },
Action = "BanAsync", Action = "BanAsync",
@ -99,34 +111,24 @@ namespace WebfrontCore.Controllers
return View("_ActionForm", info); return View("_ActionForm", info);
} }
public async Task<IActionResult> BanAsync(int targetId, string Reason, int Duration) public async Task<IActionResult> BanAsync(int targetId, string reason, int duration, string presetReason = null)
{ {
string duration = string.Empty; var fallthroughReason = presetReason ?? reason;
string command;
var loc = Utilities.CurrentLocalization.LocalizationIndex; // permanent
if (duration > _appConfig.BanDurations.Length)
switch (Duration)
{ {
case 1: command = $"{_appConfig.CommandPrefix}{_banCommandName} @{targetId} {fallthroughReason}";
duration = $"1{loc["GLOBAL_TIME_HOURS"][0]}"; }
break; // temporary ban
case 2: else
duration = $"6{loc["GLOBAL_TIME_HOURS"][0]}"; {
break; var durationSpan = _appConfig.BanDurations[duration - 1];
case 3: var durationValue = durationSpan.TotalHours.ToString(CultureInfo.InvariantCulture) +
duration = $"1{loc["GLOBAL_TIME_DAYS"][0]}"; Localization["GLOBAL_TIME_HOURS"][0];
break; command =
case 4: $"{_appConfig.CommandPrefix}{_tempbanCommandName} @{targetId} {durationValue} {fallthroughReason}";
duration = $"2{loc["GLOBAL_TIME_DAYS"][0]}";
break;
case 5:
duration = $"1{loc["GLOBAL_TIME_WEEKS"][0]}";
break;
} }
string command = Duration == 6 ?
$"{_appConfig.CommandPrefix}{_banCommandName} @{targetId} {Reason}" :
$"{_appConfig.CommandPrefix}{_tempbanCommandName} @{targetId} {duration} {Reason}";
var server = Manager.GetServers().First(); var server = Manager.GetServers().First();
@ -147,8 +149,8 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name = "Reason", Name = "Reason",
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
} }
}, },
Action = "UnbanAsync", Action = "UnbanAsync",
@ -197,7 +199,7 @@ namespace WebfrontCore.Controllers
public async Task<IActionResult> LoginAsync(int clientId, string password) public async Task<IActionResult> LoginAsync(int clientId, string password)
{ {
return await Task.FromResult(RedirectToAction("LoginAsync", "Account", new { clientId, password })); return await Task.FromResult(RedirectToAction("LoginAsync", "Account", new {clientId, password}));
} }
public IActionResult EditForm() public IActionResult EditForm()
@ -210,14 +212,14 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name ="level", Name = "level",
Label=Localization["WEBFRONT_PROFILE_LEVEL"], Label = Localization["WEBFRONT_PROFILE_LEVEL"],
Type="select", Type = "select",
Values = Enum.GetValues(typeof(Permission)).OfType<Permission>() Values = Enum.GetValues(typeof(Permission)).OfType<Permission>()
.Where(p => p <= Client.Level) .Where(p => p <= Client.Level)
.Where(p => p != Permission.Banned) .Where(p => p != Permission.Banned)
.Where(p => p != Permission.Flagged) .Where(p => p != Permission.Flagged)
.ToDictionary(p => p.ToString(), p=> p.ToLocalizedLevelName()) .ToDictionary(p => p.ToString(), p => p.ToLocalizedLevelName())
}, },
}, },
Action = "EditAsync", Action = "EditAsync",
@ -255,7 +257,10 @@ namespace WebfrontCore.Controllers
public string GenerateLoginTokenAsync() public string GenerateLoginTokenAsync()
{ {
var state = Manager.TokenAuthenticator.GenerateNextToken(Client.NetworkId); var state = Manager.TokenAuthenticator.GenerateNextToken(Client.NetworkId);
return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"], state.Token, $"{state.RemainingTime} {Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}", Client.ClientId); return string.Format(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_GENERATETOKEN_SUCCESS"],
state.Token,
$"{state.RemainingTime} {Utilities.CurrentLocalization.LocalizationIndex["GLOBAL_MINUTES"]}",
Client.ClientId);
} }
public IActionResult ChatForm(long id) public IActionResult ChatForm(long id)
@ -321,9 +326,16 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name = "reason", Name = "reason",
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
} },
new InputInfo()
{
Name = "PresetReason",
Type = "select",
Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
Values = GetPresetPenaltyReasons()
},
}, },
Action = "FlagAsync", Action = "FlagAsync",
ShouldRefresh = true ShouldRefresh = true
@ -332,14 +344,14 @@ namespace WebfrontCore.Controllers
return View("_ActionForm", info); return View("_ActionForm", info);
} }
public async Task<IActionResult> FlagAsync(int targetId, string reason) public async Task<IActionResult> FlagAsync(int targetId, string reason, string presetReason = null)
{ {
var server = Manager.GetServers().First(); var server = Manager.GetServers().First();
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{ {
serverId = server.EndPoint, serverId = server.EndPoint,
command = $"{_appConfig.CommandPrefix}{_flagCommandName} @{targetId} {reason}" command = $"{_appConfig.CommandPrefix}{_flagCommandName} @{targetId} {presetReason ?? reason}"
})); }));
} }
@ -353,8 +365,8 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name = "reason", Name = "reason",
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
} }
}, },
Action = "UnflagAsync", Action = "UnflagAsync",
@ -385,8 +397,15 @@ namespace WebfrontCore.Controllers
{ {
new InputInfo() new InputInfo()
{ {
Name = "reason", Name = "reason",
Label = Localization["WEBFRONT_ACTION_LABEL_REASON"], Label = Localization["WEBFRONT_ACTION_LABEL_REASON"],
},
new InputInfo()
{
Name = "PresetReason",
Type = "select",
Label = Localization["WEBFRONT_ACTION_LABEL_PRESET_REASON"],
Values = GetPresetPenaltyReasons()
}, },
new InputInfo() new InputInfo()
{ {
@ -402,7 +421,7 @@ namespace WebfrontCore.Controllers
return View("_ActionForm", info); return View("_ActionForm", info);
} }
public async Task<IActionResult> KickAsync(int targetId, string reason) public async Task<IActionResult> KickAsync(int targetId, string reason, string presetReason = null)
{ {
var client = Manager.GetActiveClients().FirstOrDefault(_client => _client.ClientId == targetId); var client = Manager.GetActiveClients().FirstOrDefault(_client => _client.ClientId == targetId);
@ -414,8 +433,23 @@ namespace WebfrontCore.Controllers
return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new return await Task.FromResult(RedirectToAction("ExecuteAsync", "Console", new
{ {
serverId = client.CurrentServer.EndPoint, serverId = client.CurrentServer.EndPoint,
command = $"{_appConfig.CommandPrefix}{_kickCommandName} {client.ClientNumber} {reason}" command = $"{_appConfig.CommandPrefix}{_kickCommandName} {client.ClientNumber} {presetReason ?? reason}"
})); }));
} }
private Dictionary<string, string> GetPresetPenaltyReasons() => _appConfig.PresetPenaltyReasons.Values
.Concat(_appConfig.GlobalRules)
.Concat(_appConfig.Servers.SelectMany(server => server.Rules))
.Distinct()
.Select((value, index) => new
{
Value = value
})
// this is used for the default empty optional value
.Prepend(new
{
Value = ""
})
.ToDictionary(item => item.Value, item => item.Value);
} }
} }