diff --git a/Core/Routers/ItemEventRouter.cs b/Core/Routers/ItemEventRouter.cs index 2bbd86be..38b79796 100644 --- a/Core/Routers/ItemEventRouter.cs +++ b/Core/Routers/ItemEventRouter.cs @@ -50,16 +50,18 @@ namespace Core.Routers var pmcData = _profileHelper.GetPmcProfile(sessionID); var eventRouter = _itemEventRouters.FirstOrDefault((r) => r.CanHandle(body.Action)); - if (eventRouter is not null) + if (eventRouter is null) { - _logger.Debug("event: ${ body.Action}"); - await eventRouter.HandleItemEvent(body.Action, pmcData, body, sessionID, output); - if (output.Warnings.Count > 0) { - break; - } - } else { _logger.Error(_localisationService.GetText("event-unhandled_event", body.Action)); _logger.WriteToLogFile(body); + + continue; + } + + _logger.Debug("event: ${ body.Action}"); + await eventRouter.HandleItemEvent(body.Action, pmcData, body, sessionID, output); + if (output.Warnings.Count > 0) { + break; } } diff --git a/Core/Servers/Http/SptHttpListener.cs b/Core/Servers/Http/SptHttpListener.cs index 4cd41357..02ede66e 100644 --- a/Core/Servers/Http/SptHttpListener.cs +++ b/Core/Servers/Http/SptHttpListener.cs @@ -169,9 +169,9 @@ public class SptHttpListener : IHttpListener var output = _router.GetResponse(req, sessionID, body, out var deserializedObject); /* route doesn't exist or response is not properly set up */ if (string.IsNullOrEmpty(output)) { - _logger.Error(_localisationService.GetText("unhandled_response", req.Path)); + _logger.Error(_localisationService.GetText("unhandled_response", req.Path.ToString())); _logger.Info(_jsonUtil.Serialize(deserializedObject)); - output = _httpResponseUtil.GetBody(null, 404, $"UNHANDLED RESPONSE: {req.Path}"); + output = _httpResponseUtil.GetBody(null, 404, $"UNHANDLED RESPONSE: {req.Path.ToString()}"); } /* TODO: REQUEST LOGGER if (ProgramStatics.ENTRY_TYPE !== EntryType.RELEASE) { diff --git a/Core/Services/I18nService.cs b/Core/Services/I18nService.cs index dc3b96ef..5fae4b8d 100644 --- a/Core/Services/I18nService.cs +++ b/Core/Services/I18nService.cs @@ -1,4 +1,4 @@ -using Core.Utils; +using Core.Utils; using Core.Utils.Extensions; namespace Core.Services; @@ -84,26 +84,33 @@ public class I18nService return value; } + public string GetLocalised(string key) + { + return GetLocalised(key); + } + public string GetLocalised(string key, object? args) { var rawLocalizedString = GetLocalised(key); if (args == null) + { return rawLocalizedString; - if (args is string value) - { - return rawLocalizedString.Replace("%s", value); } - else + + foreach (var propertyInfo in args.GetType().GetProperties()) { - foreach (var propertyInfo in args.GetType().GetProperties()) + var localizedName = $"{{{{{propertyInfo.GetJsonName()}}}}}"; + if (rawLocalizedString.Contains(localizedName)) { - var localizedName = $"{{{{{propertyInfo.GetJsonName()}}}}}"; - if (rawLocalizedString.Contains(localizedName)) - { - rawLocalizedString.Replace(localizedName, propertyInfo.GetValue(args, null)?.ToString() ?? string.Empty); - } + rawLocalizedString.Replace(localizedName, propertyInfo.GetValue(args, null)?.ToString() ?? string.Empty); } - return rawLocalizedString; } + return rawLocalizedString; + } + + public string GetLocalised(string key, T value) where T : IConvertible + { + var rawLocalizedString = GetLocalised(key); + return rawLocalizedString.Replace("%s", value.ToString()); } } diff --git a/Core/Services/LocalisationService.cs b/Core/Services/LocalisationService.cs index 5519da87..67cf4935 100644 --- a/Core/Services/LocalisationService.cs +++ b/Core/Services/LocalisationService.cs @@ -1,4 +1,4 @@ -using Core.Utils; +using Core.Utils; using Core.Annotations; using Core.Models.Utils; using Core.Servers; @@ -40,7 +40,14 @@ public class LocalisationService public string GetText(string key, object? args = null) { - return _i18nService.GetLocalised(key, args); + return args is null + ? _i18nService.GetLocalised(key) + : _i18nService.GetLocalised(key, args); + } + + public string GetText(string key, T value) where T :IConvertible + { + return _i18nService.GetLocalised(key, value); } public ICollection GetKeys()