diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index c1746ac4b..f2f175258 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -36,7 +36,7 @@ namespace IW4MAdmin override public async Task OnClientConnected(EFClient clientFromLog) { Logger.WriteDebug($"Client slot #{clientFromLog.ClientNumber} now reserved"); - + try { EFClient client = await Manager.GetClientService().GetUnique(clientFromLog.NetworkId); @@ -94,18 +94,18 @@ namespace IW4MAdmin if (client.ClientNumber >= 0) { #endif - Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting..."); - await client.OnDisconnect(); - Clients[client.ClientNumber] = null; + Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting..."); + Clients[client.ClientNumber] = null; + await client.OnDisconnect(); - var e = new GameEvent() - { - Origin = client, - Owner = this, - Type = GameEvent.EventType.Disconnect - }; + var e = new GameEvent() + { + Origin = client, + Owner = this, + Type = GameEvent.EventType.Disconnect + }; - Manager.GetEventHandler().AddEvent(e); + Manager.GetEventHandler().AddEvent(e); #if DEBUG == true } #endif @@ -177,7 +177,7 @@ namespace IW4MAdmin if (E.Type == GameEvent.EventType.ChangePermission) { var newPermission = (Permission)E.Extra; - + if (newPermission < Permission.Moderator) { // remove banned or demoted privileged user @@ -268,7 +268,7 @@ namespace IW4MAdmin Expires = DateTime.UtcNow, Offender = E.Target, Offense = E.Data, - Punisher = E.Origin, + Punisher = E.Origin, When = DateTime.UtcNow, Link = E.Target.AliasLink }; @@ -468,8 +468,8 @@ namespace IW4MAdmin client.Score = origin.Score; // update their IP if it hasn't been set yet - if (client.IPAddress == null && - !client.IsBot && + if (client.IPAddress == null && + !client.IsBot && client.State == ClientState.Connected) { try diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 36820d559..af262669c 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -8,6 +8,7 @@ namespace SharedLibraryCore.Configuration { public class ApplicationConfiguration : IBaseConfiguration { + [LocalizedDisplayName("SETUP_ENABLE_WEBFRONT")] [LinkedConfiguration("WebfrontBindUrl", "ManualWebfrontUrl")] public bool EnableWebFront { get; set; } @@ -76,6 +77,7 @@ namespace SharedLibraryCore.Configuration public List GlobalRules { get; set; } [LocalizedDisplayName("WEBFRONT_CONFIGURATION_DISALLOWED_NAMES")] public List DisallowedClientNames { get; set; } + [UIHint("ServerConfiguration")] public List Servers { get; set; } diff --git a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs index ed06cde32..6790daf0f 100644 --- a/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs +++ b/SharedLibraryCore/Helpers/BaseConfigurationHandler.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using SharedLibraryCore.Interfaces; +using System; using System.IO; using System.Threading.Tasks; diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index cbc37178b..1ec4ca931 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -171,6 +171,12 @@ namespace SharedLibraryCore.Services // the alias is the same so we can just remove it if (oldAlias.AliasId != existingExactAlias.AliasId && oldAlias.AliasId > 0) { + await context.Clients + .Where(_client => _client.CurrentAliasId == oldAlias.AliasId) + .ForEachAsync(_client => _client.CurrentAliasId = existingExactAlias.AliasId); + + await context.SaveChangesAsync(); + entity.CurrentServer.Logger.WriteDebug($"[updatealias] {entity} has exact alias match, so we're going to try to remove aliasId {oldAlias.AliasId} with linkId {oldAlias.AliasId}"); context.Aliases.Remove(oldAlias); await context.SaveChangesAsync(); diff --git a/WebfrontCore/Controllers/ConfigurationController.cs b/WebfrontCore/Controllers/ConfigurationController.cs index 0a4dec0a3..ad812a0ab 100644 --- a/WebfrontCore/Controllers/ConfigurationController.cs +++ b/WebfrontCore/Controllers/ConfigurationController.cs @@ -2,10 +2,12 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Runtime.Serialization; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using SharedLibraryCore.Configuration; +using SharedLibraryCore.Interfaces; using WebfrontCore.ViewModels; namespace WebfrontCore.Controllers @@ -18,9 +20,24 @@ namespace WebfrontCore.Controllers } [HttpPost] - public IActionResult Edit(ApplicationConfiguration config) + public async Task Edit(ApplicationConfiguration newConfiguration) { - return View("Index", Manager.GetApplicationSettings().Configuration()); + var currentConfiguration = Manager.GetApplicationSettings().Configuration(); + + var newConfigurationProperties = newConfiguration.GetType().GetProperties(); + foreach (var property in currentConfiguration.GetType().GetProperties()) + { + var newProp = newConfigurationProperties.First(_prop => _prop.Name == property.Name); + var newPropValue = newProp.GetValue(newConfiguration); + + if (newPropValue != null && newProp.CanWrite) + { + property.SetValue(currentConfiguration, newPropValue); + } + } + + await Manager.GetApplicationSettings().Save(); + return View("Index", newConfiguration); } public IActionResult GetNewListItem(string propertyName, int itemCount) @@ -31,7 +48,7 @@ namespace WebfrontCore.Controllers var configInfo = new ConfigurationInfo() { Configuration = config, - PropertyValue = (IList)propertyInfo.GetValue(config), + PropertyValue = (IList)propertyInfo.GetValue(config) ?? new List(), PropertyInfo = propertyInfo, NewItemCount = itemCount }; diff --git a/WebfrontCore/Views/Configuration/Index.cshtml b/WebfrontCore/Views/Configuration/Index.cshtml index 01a5f75bb..3522dda28 100644 --- a/WebfrontCore/Views/Configuration/Index.cshtml +++ b/WebfrontCore/Views/Configuration/Index.cshtml @@ -5,6 +5,7 @@ string optionalText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["COMMAND_HELP_OPTIONAL"]; string advancedText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADVANCED"]; string addText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_ADD"]; + string saveText = SharedLibraryCore.Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CONFIGURATION_SAVE"]; var properties = Model.GetType().GetProperties(); @@ -47,10 +48,7 @@ if (property.PropertyType.Name == typeof(System.Boolean).Name) { - - - - var attributes = linkedPropertyNames.Length > 0 ? new { htmlAttributes = new { @class = "has-related-content", data_related_content = string.Join(',', linkedPropertyNames.Select(_id => $"#{_id}_content")) } } : null; + var attributes = linkedPropertyNames.Length > 0 ? new { htmlAttributes = new { @class = "has-related-content mb-0", data_related_content = string.Join(',', linkedPropertyNames.Select(_id => $"#{_id}_content")) } } : null;
@Html.Editor(property.Name, attributes) @Html.Label(property.Name, null, new { @class = "form-check-label ml-1" }) @@ -61,10 +59,10 @@ { if (hasLinkedParent(property)) { -
+
@if (linkedPropertyNames.Length == 0) { - @Html.Label(property.Name, null, new { @class = "pt-3" }) + @Html.Label(property.Name, null, new { @class = "" }) } @Html.Editor(property.Name, new { htmlAttributes = new { @class = $"form-group form-control bg-dark text-white-50 {(linkedPropertyNames.Length == 0 ? "mb-3" : "mb-0")}" } })
@@ -72,9 +70,9 @@ else { - @Html.Label(property.Name, null, new { @class = "bg-primary pl-3 pr-3 p-2 mb-0 mt-0 w-100" }) + @Html.Label(property.Name, null, new { @class = "bg-primary pl-3 pr-3 p-2 mb-0 w-100" })
- @Html.Editor(property.Name, new { htmlAttributes = new { @class = "form-control bg-dark text-white-50 mt-2", placeholder = isOptional(property) ? optionalText : "" } }) + @Html.Editor(property.Name, new { htmlAttributes = new { @class = "form-control bg-dark text-white-50 mt-3 mb-3", placeholder = isOptional(property) ? optionalText : "" } }) @addText
} @@ -84,152 +82,22 @@ { if (hasLinkedParent(property)) { -
- @Html.Label(property.Name, null, new { @class = "pt-3" }) +
+ @Html.Label(property.Name, null, new { @class = "mt-1" }) @Html.Editor(property.Name, new { htmlAttributes = new { @class = "form-group form-control bg-dark text-white-50 mb-0", placeholder = isOptional(property) ? optionalText : "" } })
} else { - + @Html.Label(property.Name, null, new { @class = "bg-primary pl-3 pr-3 p-2 mb-0 w-100" }) +
+ @Html.Editor(property.Name, new { htmlAttributes = new { @class = "form-group form-control bg-dark text-white-50 mb-0", placeholder = isOptional(property) ? optionalText : "" } }) +
} } } - - -
-
-
-
- - -
- -
-
-
- - - -
-
- - - -
-
- - -
- -
- -
- -
- - -
- -
-
-
- - - -
-
- - - -
-
- - -
- -
-
-
- - - -
-
- - -
- -
- -
- -
-
- @Html.EditorFor(model => model.WebfrontConnectionWhitelist, new { htmlAttributes = new { @class = "form-control bg-dark text-white-50 mb-2" } }) -
@addText
-
- -
-
@advancedText
-
-
-
- - - -
-
- - - -
-
- - - -
-
- - - -
-
- - - -
- -
- - - -
-
- - - -
-
- -
- -
+
diff --git a/WebfrontCore/Views/Configuration/_ListItem.cshtml b/WebfrontCore/Views/Configuration/_ListItem.cshtml index 9b1d1a819..6631a67c6 100644 --- a/WebfrontCore/Views/Configuration/_ListItem.cshtml +++ b/WebfrontCore/Views/Configuration/_ListItem.cshtml @@ -3,4 +3,4 @@ int index = Model.PropertyValue.Count + (Model.NewItemCount - Model.PropertyValue.Count); } - \ No newline at end of file + \ No newline at end of file diff --git a/WebfrontCore/Views/Shared/EditorTemplates/ServerConfiguration.cshtml b/WebfrontCore/Views/Shared/EditorTemplates/ServerConfiguration.cshtml new file mode 100644 index 000000000..7f59b3fcc --- /dev/null +++ b/WebfrontCore/Views/Shared/EditorTemplates/ServerConfiguration.cshtml @@ -0,0 +1,6 @@ +@model List +@Html.EditorFor(s => s) +@*@foreach (var server in Model) +{ + @Html.EditorFor(s => server.EventParserVersion); +}*@ \ No newline at end of file diff --git a/WebfrontCore/WebfrontCore.csproj b/WebfrontCore/WebfrontCore.csproj index 053ec4119..376374215 100644 --- a/WebfrontCore/WebfrontCore.csproj +++ b/WebfrontCore/WebfrontCore.csproj @@ -93,9 +93,5 @@ - - - -