From e13c10344c49eea150063556d6f8c612b486c840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=99=E7=A9=8F=E9=9D=84?= <170472707+seionmoya@users.noreply.github.com> Date: Mon, 18 Nov 2024 14:46:47 +0100 Subject: [PATCH 1/5] Refactor Fuyu.Backend.EFT --- .../Http/AccountCustomizationController.cs | 11 +- .../Http/AchievementListController.cs | 11 +- .../Http/AchievementStatisticController.cs | 12 +- .../Controllers/Http/BuildsListController.cs | 11 +- .../Http/CheckVersionController.cs | 11 +- .../ClientInsuranceItemsListCostController.cs | 9 +- .../Http/ClientItemsPriceController.cs | 9 +- .../Http/CustomizationController.cs | 9 +- .../Http/CustomizationStorageController.cs | 9 +- .../Controllers/Http/FilesController.cs | 11 +- .../Controllers/Http/FriendListController.cs | 11 +- .../Http/FriendRequestListInboxController.cs | 11 +- .../Http/FriendRequestListOutboxController.cs | 11 +- .../Http/FuyuGameLoginController.cs | 13 +- .../Http/FuyuGameRegisterController.cs | 11 +- .../Http/GameBotGenerateController.cs | 9 +- .../Controllers/Http/GameConfigController.cs | 17 ++- .../Http/GameKeepaliveController.cs | 11 +- .../Controllers/Http/GameLogoutController.cs | 11 +- .../Controllers/Http/GameModeController.cs | 12 +- .../Http/GameProfileCreateController.cs | 10 +- .../Http/GameProfileItemsMovingController.cs | 9 +- .../Http/GameProfileListController.cs | 9 +- .../GameProfileNicknameReservedController.cs | 9 +- .../GameProfileNicknameValidateController.cs | 9 +- .../Http/GameProfileSelectController.cs | 11 +- .../Controllers/Http/GameStartController.cs | 11 +- .../Http/GameVersionValidateController.cs | 11 +- .../Http/GetMetricsConfigController.cs | 9 +- .../Http/GetTraderAssortController.cs | 12 +- .../Controllers/Http/GlobalsController.cs | 11 +- .../Http/HandbookTemplatesController.cs | 11 +- .../Http/HideoutAreasController.cs | 11 +- .../HideoutProductionRecipesController.cs | 11 +- .../Http/HideoutQteListController.cs | 11 +- .../Http/HideoutSettingsController.cs | 10 +- .../Controllers/Http/ItemsController.cs | 11 +- .../Controllers/Http/LanguagesController.cs | 9 +- .../Http/LocalGameWeatherController.cs | 11 +- .../Controllers/Http/LocaleController.cs | 8 +- .../Controllers/Http/LocationsController.cs | 9 +- .../Http/MailDialogListController.cs | 11 +- .../Http/MatchGroupCurrentController.cs | 11 +- .../Http/MatchGroupExitFromMenuController.cs | 11 +- .../MatchGroupInviteCancelAllController.cs | 11 +- .../Http/MatchLocalEndController.cs | 14 ++- .../Http/MatchLocalStartController.cs | 11 +- .../Controllers/Http/MenuLocaleController.cs | 9 +- .../Http/NotifierChannelCreateController.cs | 12 +- .../Http/ProfileSettingsController.cs | 11 +- .../Http/ProfileStatusController.cs | 11 +- .../Controllers/Http/PutMetricsController.cs | 11 +- .../Controllers/Http/QuestListController.cs | 11 +- .../Http/RaidConfigurationController.cs | 11 +- ...epeatableQuestActivityPeriodsController.cs | 11 +- .../Controllers/Http/ServerListController.cs | 9 +- .../Controllers/Http/SettingsController.cs | 11 +- .../Controllers/Http/SurveyController.cs | 11 +- .../Http/TraderSettingsController.cs | 9 +- .../Controllers/Http/WeatherController.cs | 11 +- Fuyu.Backend.EFT/Networking/EftHttpContext.cs | 111 ++++++++++++++++++ .../Networking/EftHttpController.cs | 69 +++++++++++ .../Services/ETagService.cs | 12 +- Fuyu.Common/Networking/HttpContext.cs | 84 ++----------- Fuyu.Common/Networking/HttpResponse.cs | 3 - Fuyu.Common/Networking/WebRouterContext.cs | 15 +++ .../EndToEnd/BackendTest.cs | 2 +- .../Networking/EftHttpClient.cs | 23 ++-- 68 files changed, 620 insertions(+), 339 deletions(-) create mode 100644 Fuyu.Backend.EFT/Networking/EftHttpContext.cs create mode 100644 Fuyu.Backend.EFT/Networking/EftHttpController.cs rename {Fuyu.Backend.BSG => Fuyu.Backend.EFT}/Services/ETagService.cs (79%) rename {Fuyu.Common => Tests/Fuyu.Tests.Backend.EFT}/Networking/EftHttpClient.cs (66%) diff --git a/Fuyu.Backend.EFT/Controllers/Http/AccountCustomizationController.cs b/Fuyu.Backend.EFT/Controllers/Http/AccountCustomizationController.cs index 6392c1ea..32d03569 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/AccountCustomizationController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/AccountCustomizationController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class AccountCustomizationController : HttpController + public class AccountCustomizationController : EftHttpController { public AccountCustomizationController() : base("/client/account/customization") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetAccountCustomization()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetAccountCustomization(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/AchievementListController.cs b/Fuyu.Backend.EFT/Controllers/Http/AchievementListController.cs index 4eba5c9c..fc9e7e78 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/AchievementListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/AchievementListController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class AchievementListController : HttpController + public class AchievementListController : EftHttpController { public AchievementListController() : base("/client/achievement/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetAchievementList()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetAchievementList(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/AchievementStatisticController.cs b/Fuyu.Backend.EFT/Controllers/Http/AchievementStatisticController.cs index ef0bcd5f..8eb6bdfc 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/AchievementStatisticController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/AchievementStatisticController.cs @@ -1,21 +1,25 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class AchievementStatisticController : HttpController + public class AchievementStatisticController : EftHttpController { public AchievementStatisticController() : base("/client/achievement/statistic") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var json = EftOrm.GetAchievementStatistic(); var response = Json.Parse>(json); - return context.SendJsonAsync(Json.Stringify(response)); + + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/BuildsListController.cs b/Fuyu.Backend.EFT/Controllers/Http/BuildsListController.cs index df129fec..b603b621 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/BuildsListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/BuildsListController.cs @@ -1,12 +1,12 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.IO; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class BuildsListController : HttpController + public class BuildsListController : EftHttpController { private readonly ResponseBody _response; @@ -16,9 +16,12 @@ public BuildsListController() : base("/client/builds/list") _response = Json.Parse>(json); } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(Json.Stringify(_response)); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = Json.Stringify(_response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/CheckVersionController.cs b/Fuyu.Backend.EFT/Controllers/Http/CheckVersionController.cs index 46bf5b8b..b7138f06 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/CheckVersionController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/CheckVersionController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class CheckVersionController : HttpController + public class CheckVersionController : EftHttpController { public CheckVersionController() : base("/client/checkVersion") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new CheckVersionResponse() @@ -22,7 +24,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/ClientInsuranceItemsListCostController.cs b/Fuyu.Backend.EFT/Controllers/Http/ClientInsuranceItemsListCostController.cs index bb2bc0c9..f905bcea 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ClientInsuranceItemsListCostController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ClientInsuranceItemsListCostController.cs @@ -4,19 +4,19 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Requests; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class ClientInsuranceItemsListCostController : HttpController + public class ClientInsuranceItemsListCostController : EftHttpController { public ClientInsuranceItemsListCostController() : base("/client/insurance/items/list/cost") { } - public override Task RunAsync(HttpContext context, InsuranceCostRequest body) + public override Task RunAsync(EftHttpContext context, InsuranceCostRequest body) { var profile = EftOrm.GetActiveProfile(context.GetSessionId()); var items = profile.Pmc.Inventory.Items.FindAll(i => body.ItemIds.Contains(i.Id)); @@ -44,7 +44,8 @@ public override Task RunAsync(HttpContext context, InsuranceCostRequest body) response.errmsg = "One or more items could not be found on the backend"; } - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } diff --git a/Fuyu.Backend.EFT/Controllers/Http/ClientItemsPriceController.cs b/Fuyu.Backend.EFT/Controllers/Http/ClientItemsPriceController.cs index 15947b2a..7256629b 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ClientItemsPriceController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ClientItemsPriceController.cs @@ -5,14 +5,14 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Trading; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Collections; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public partial class ClientItemsPriceController : HttpController + public partial class ClientItemsPriceController : EftHttpController { [GeneratedRegex(@"^/client/items/prices(/(?[A-Za-z0-9]+))?$")] private static partial Regex PathExpression(); @@ -21,7 +21,7 @@ public ClientItemsPriceController() : base(PathExpression()) { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var parameters = context.GetPathParameters(this); var profile = EftOrm.GetActiveProfile(context.GetSessionId()); @@ -55,7 +55,8 @@ public override Task RunAsync(HttpContext context) response.data = new Dictionary(); } - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } diff --git a/Fuyu.Backend.EFT/Controllers/Http/CustomizationController.cs b/Fuyu.Backend.EFT/Controllers/Http/CustomizationController.cs index 08016d12..9fb6a730 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/CustomizationController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/CustomizationController.cs @@ -2,18 +2,18 @@ using System.Collections.Generic; using Fuyu.Backend.BSG.Models.Customization; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class CustomizationController : HttpController + public class CustomizationController : EftHttpController { public CustomizationController() : base("/client/customization") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var customizations = EftOrm.GetCustomizations(); var response = new ResponseBody>() @@ -21,7 +21,8 @@ public override Task RunAsync(HttpContext context) data = customizations }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/CustomizationStorageController.cs b/Fuyu.Backend.EFT/Controllers/Http/CustomizationStorageController.cs index df4dccae..9c383b3d 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/CustomizationStorageController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/CustomizationStorageController.cs @@ -1,17 +1,17 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class CustomizationStorageController : HttpController + public class CustomizationStorageController : EftHttpController { public CustomizationStorageController() : base("/client/trading/customization/storage") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var sessionId = context.GetSessionId(); var profile = EftOrm.GetActiveProfile(sessionId); @@ -25,7 +25,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/FilesController.cs b/Fuyu.Backend.EFT/Controllers/Http/FilesController.cs index aa0d0a57..87d202c2 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FilesController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FilesController.cs @@ -2,12 +2,12 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.IO; -using Fuyu.Common.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public partial class FilesController : HttpController + public partial class FilesController : EftHttpController { [GeneratedRegex(@"^/files/(?.+)$")] private static partial Regex PathExpression(); @@ -16,7 +16,7 @@ public FilesController() : base(PathExpression()) { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var parameters = context.GetPathParameters(this); var path = parameters["path"]; @@ -28,7 +28,10 @@ public override Task RunAsync(HttpContext context) { var buffer = Resx.GetBytes("eft", resourceLocation); - return context.SendBinaryAsync(buffer, $"image/{extension}", false); + // NOTE: file handling is done in UnityWebRequestTexture.GetTexture + // instead of EFT's own HTTP client + // -- seionmoya, 2024-11-18 + return context.SendBinaryAsync(buffer, $"image/{extension}", false, false); } catch (Exception ex) { diff --git a/Fuyu.Backend.EFT/Controllers/Http/FriendListController.cs b/Fuyu.Backend.EFT/Controllers/Http/FriendListController.cs index 6ccfefa6..82e6be99 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FriendListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FriendListController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class FriendListController : HttpController + public class FriendListController : EftHttpController { public FriendListController() : base("/client/friend/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new FriendListResponse() @@ -23,7 +25,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListInboxController.cs b/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListInboxController.cs index 2398384a..21e11644 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListInboxController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListInboxController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class FriendRequestListInboxController : HttpController + public class FriendRequestListInboxController : EftHttpController { public FriendRequestListInboxController() : base("/client/friend/request/list/inbox") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = [] }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListOutboxController.cs b/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListOutboxController.cs index 5bba9c73..bff1c9b4 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListOutboxController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FriendRequestListOutboxController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class FriendRequestListOutboxController : HttpController + public class FriendRequestListOutboxController : EftHttpController { public FriendRequestListOutboxController() : base("/client/friend/request/list/outbox") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = [] }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/FuyuGameLoginController.cs b/Fuyu.Backend.EFT/Controllers/Http/FuyuGameLoginController.cs index 9fc98afc..d81a3c86 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FuyuGameLoginController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FuyuGameLoginController.cs @@ -1,19 +1,19 @@ using System.Threading.Tasks; -using Fuyu.Backend.EFT.Services; using Fuyu.Backend.Common.Models.Requests; using Fuyu.Backend.Common.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; +using Fuyu.Backend.EFT.Services; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class FuyuGameLoginController : HttpController + public class FuyuGameLoginController : EftHttpController { public FuyuGameLoginController() : base("/fuyu/game/login") { } - public override Task RunAsync(HttpContext context, FuyuGameLoginRequest request) + public override Task RunAsync(EftHttpContext context, FuyuGameLoginRequest request) { var sessionId = AccountService.LoginAccount(request.AccountId); var response = new FuyuGameLoginResponse() @@ -21,7 +21,10 @@ public override Task RunAsync(HttpContext context, FuyuGameLoginRequest request) SessionId = sessionId }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + // NOTE: no need for encryption, request runs internal + // -- seionmoya, 2024-11-18 + return context.SendJsonAsync(text, false, false); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/FuyuGameRegisterController.cs b/Fuyu.Backend.EFT/Controllers/Http/FuyuGameRegisterController.cs index f6160858..70bff128 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/FuyuGameRegisterController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/FuyuGameRegisterController.cs @@ -1,19 +1,19 @@ using System.Threading.Tasks; using Fuyu.Backend.Common.Models.Requests; using Fuyu.Backend.Common.Models.Responses; +using Fuyu.Backend.EFT.Networking; using Fuyu.Backend.EFT.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class FuyuGameRegisterController : HttpController + public class FuyuGameRegisterController : EftHttpController { public FuyuGameRegisterController() : base("/fuyu/game/register") { } - public override Task RunAsync(HttpContext context, FuyuGameRegisterRequest request) + public override Task RunAsync(EftHttpContext context, FuyuGameRegisterRequest request) { var accountId = AccountService.RegisterAccount(request.Username, request.Edition); var response = new FuyuGameRegisterResponse() @@ -21,7 +21,10 @@ public override Task RunAsync(HttpContext context, FuyuGameRegisterRequest reque AccountId = accountId }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + // NOTE: no need for encryption, request runs internal + // -- seionmoya, 2024-11-18 + return context.SendJsonAsync(text, false, false); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameBotGenerateController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameBotGenerateController.cs index 8a2cc645..f40049b3 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameBotGenerateController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameBotGenerateController.cs @@ -2,19 +2,19 @@ using Fuyu.Backend.BSG.Models.Profiles; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Requests; +using Fuyu.Backend.EFT.Networking; using Fuyu.Backend.EFT.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameBotGenerateController : HttpController + public class GameBotGenerateController : EftHttpController { public GameBotGenerateController() : base("/client/game/bot/generate") { } - public override Task RunAsync(HttpContext context, GameBotGenerateRequest request) + public override Task RunAsync(EftHttpContext context, GameBotGenerateRequest request) { var profiles = BotService.GetBots(request.conditions); var response = new ResponseBody() @@ -22,7 +22,8 @@ public override Task RunAsync(HttpContext context, GameBotGenerateRequest reques data = profiles }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameConfigController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameConfigController.cs index 0fdead99..6b1e63d0 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameConfigController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameConfigController.cs @@ -1,23 +1,25 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Servers; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameConfigController : HttpController + public class GameConfigController : EftHttpController { public GameConfigController() : base("/client/game/config") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var response = new ResponseBody { data = new GameConfigResponse() { + // TODO: don't use hardcoded path + // --seionmoya, 2024-11-18 backend = new Backends() { Lobby = "http://localhost:8010", @@ -26,18 +28,25 @@ public override Task RunAsync(HttpContext context) Main = "http://localhost:8010", RagFair = "http://localhost:8010" }, + // TODO: generate this + // --seionmoya, 2024-11-18 utc_time = 1724450891.010541, reportAvailable = true, + // TODO: handle this + // --seionmoya, 2024-11-18 purchasedGames = new PurchasedGames() { eft = true, arena = true }, + // TODO: handle this + // --seionmoya, 2024-11-18 isGameSynced = true } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameKeepaliveController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameKeepaliveController.cs index a5b97926..c4a9673b 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameKeepaliveController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameKeepaliveController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameKeepaliveController : HttpController + public class GameKeepaliveController : EftHttpController { public GameKeepaliveController() : base("/client/game/keepalive") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody { data = new GameKeepaliveResponse() @@ -22,7 +24,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameLogoutController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameLogoutController.cs index a45a3a4c..b5e9dd23 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameLogoutController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameLogoutController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameLogoutController : HttpController + public class GameLogoutController : EftHttpController { public GameLogoutController() : base("/client/game/logout") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new GameLogoutResponse() @@ -21,7 +23,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameModeController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameModeController.cs index d23df4a5..e4328f47 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameModeController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameModeController.cs @@ -2,23 +2,24 @@ using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Requests; using Fuyu.Backend.BSG.Models.Accounts; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameModeController : HttpController + public class GameModeController : EftHttpController { public GameModeController() : base("/client/game/mode") { } - public override Task RunAsync(HttpContext context, ClientGameModeRequest body) + public override Task RunAsync(EftHttpContext context, ClientGameModeRequest body) { var account = EftOrm.GetAccount(context.GetSessionId()); if (body.SessionMode == null) { + // wiped profile body.SessionMode = ESessionMode.Pve; } @@ -26,6 +27,8 @@ public override Task RunAsync(HttpContext context, ClientGameModeRequest body) var response = new ResponseBody() { + // TODO: don't use hardcoded address + // --seionmoya, 2024-11-18 data = new GameModeResponse() { GameMode = body.SessionMode, @@ -33,7 +36,8 @@ public override Task RunAsync(HttpContext context, ClientGameModeRequest body) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileCreateController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileCreateController.cs index 773f2687..c34a0d0b 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileCreateController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileCreateController.cs @@ -1,8 +1,8 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Requests; +using Fuyu.Backend.EFT.Networking; using Fuyu.Backend.EFT.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http @@ -10,17 +10,18 @@ namespace Fuyu.Backend.EFT.Controllers.Http // TODO: // * move code into TemplateTable and ProfileService // -- seionmoya, 2024/09/02 - public class GameProfileCreateController : HttpController + public class GameProfileCreateController : EftHttpController { public GameProfileCreateController() : base("/client/game/profile/create") { } - public override Task RunAsync(HttpContext context, GameProfileCreateRequest request) + public override Task RunAsync(EftHttpContext context, GameProfileCreateRequest request) { var sessionId = context.GetSessionId(); var account = EftOrm.GetAccount(sessionId); var pmcId = ProfileService.WipeProfile(account, request.side, request.headId, request.voiceId); + var response = new ResponseBody() { data = new GameProfileCreateResponse() @@ -29,7 +30,8 @@ public override Task RunAsync(HttpContext context, GameProfileCreateRequest requ } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileItemsMovingController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileItemsMovingController.cs index e36171fa..3932eef8 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileItemsMovingController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileItemsMovingController.cs @@ -4,12 +4,12 @@ using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Networking; using Fuyu.Backend.EFT.Controllers.ItemEvents; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameProfileItemsMovingController : HttpController + public class GameProfileItemsMovingController : EftHttpController { public ItemEventRouter ItemEventRouter { get; } = new ItemEventRouter(); @@ -41,7 +41,7 @@ public GameProfileItemsMovingController() : base("/client/game/profile/items/mov ItemEventRouter.AddController(); } - public override async Task RunAsync(HttpContext context, JObject request) + public override async Task RunAsync(EftHttpContext context, JObject request) { if (!request.ContainsKey("data")) { @@ -82,7 +82,8 @@ public override async Task RunAsync(HttpContext context, JObject request) data = itemEventResponse }; - await context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + await context.SendJsonAsync(text, true, true); } } } diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileListController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileListController.cs index 5d6d6118..98aada87 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileListController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Profiles; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameProfileListController : HttpController + public class GameProfileListController : EftHttpController { public GameProfileListController() : base("/client/game/profile/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var sessionId = context.GetSessionId(); var profile = EftOrm.GetActiveProfile(sessionId); @@ -32,7 +32,8 @@ public override Task RunAsync(HttpContext context) data = profiles }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameReservedController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameReservedController.cs index ddb03069..08564781 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameReservedController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameReservedController.cs @@ -1,17 +1,17 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameProfileNicknameReservedController : HttpController + public class GameProfileNicknameReservedController : EftHttpController { public GameProfileNicknameReservedController() : base("/client/game/profile/nickname/reserved") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var sessionId = context.GetSessionId(); var account = EftOrm.GetAccount(sessionId); @@ -21,7 +21,8 @@ public override Task RunAsync(HttpContext context) data = account.Username }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameValidateController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameValidateController.cs index 4301873c..09fa04e5 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameValidateController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileNicknameValidateController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Requests; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameProfileNicknameValidateController : HttpController + public class GameProfileNicknameValidateController : EftHttpController { public GameProfileNicknameValidateController() : base("/client/game/profile/nickname/validate") { } - public override Task RunAsync(HttpContext context, GameProfileNicknameValidateRequest request) + public override Task RunAsync(EftHttpContext context, GameProfileNicknameValidateRequest request) { // TODO: // * validate nickname usage @@ -26,7 +26,8 @@ public override Task RunAsync(HttpContext context, GameProfileNicknameValidateRe } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameProfileSelectController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameProfileSelectController.cs index e6a89cc3..3fe91708 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameProfileSelectController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameProfileSelectController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameProfileSelectController : HttpController + public class GameProfileSelectController : EftHttpController { public GameProfileSelectController() : base("/client/game/profile/select") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new ProfileSelectResponse() @@ -21,7 +23,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameStartController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameStartController.cs index 004ac89e..e6a71e67 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameStartController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameStartController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameStartController : HttpController + public class GameStartController : EftHttpController { public GameStartController() : base("/client/game/start") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new GameStartResponse() @@ -21,7 +23,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GameVersionValidateController.cs b/Fuyu.Backend.EFT/Controllers/Http/GameVersionValidateController.cs index 31d387c5..36a93101 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GameVersionValidateController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GameVersionValidateController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GameVersionValidateController : HttpController + public class GameVersionValidateController : EftHttpController { public GameVersionValidateController() : base("/client/game/version/validate") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GetMetricsConfigController.cs b/Fuyu.Backend.EFT/Controllers/Http/GetMetricsConfigController.cs index d8ed486d..33a8de8f 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GetMetricsConfigController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GetMetricsConfigController.cs @@ -1,17 +1,17 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GetMetricsConfigController : HttpController + public class GetMetricsConfigController : EftHttpController { public GetMetricsConfigController() : base("/client/getMetricsConfig") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var response = new ResponseBody() { @@ -26,7 +26,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/GetTraderAssortController.cs b/Fuyu.Backend.EFT/Controllers/Http/GetTraderAssortController.cs index 45e13345..ed88c1b9 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GetTraderAssortController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GetTraderAssortController.cs @@ -2,12 +2,12 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Trading; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public partial class GetTraderAssortController : HttpController + public partial class GetTraderAssortController : EftHttpController { [GeneratedRegex("/client/trading/api/getTraderAssort/(?[A-Za-z0-9]+)")] private static partial Regex PathExpression(); @@ -16,10 +16,13 @@ public GetTraderAssortController() : base(PathExpression()) { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var parameters = context.GetPathParameters(this); var traderId = parameters["traderId"]; + + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody { data = new TraderAssort @@ -32,7 +35,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } diff --git a/Fuyu.Backend.EFT/Controllers/Http/GlobalsController.cs b/Fuyu.Backend.EFT/Controllers/Http/GlobalsController.cs index 096bc475..befc54e6 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/GlobalsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/GlobalsController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class GlobalsController : HttpController + public class GlobalsController : EftHttpController { public GlobalsController() : base("/client/globals") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetGlobals()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetGlobals(); + return context.SendJsonAsync(text); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/HandbookTemplatesController.cs b/Fuyu.Backend.EFT/Controllers/Http/HandbookTemplatesController.cs index b144f4d9..ca9404c1 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/HandbookTemplatesController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/HandbookTemplatesController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class HandbookTemplatesController : HttpController + public class HandbookTemplatesController : EftHttpController { public HandbookTemplatesController() : base("/client/handbook/templates") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetHandbook()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetHandbook(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/HideoutAreasController.cs b/Fuyu.Backend.EFT/Controllers/Http/HideoutAreasController.cs index 77abba06..f18810db 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/HideoutAreasController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/HideoutAreasController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class HideoutAreasController : HttpController + public class HideoutAreasController : EftHttpController { public HideoutAreasController() : base("/client/hideout/areas") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetHideoutAreas()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetHideoutAreas(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/HideoutProductionRecipesController.cs b/Fuyu.Backend.EFT/Controllers/Http/HideoutProductionRecipesController.cs index dea8f8f0..dd3b70ed 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/HideoutProductionRecipesController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/HideoutProductionRecipesController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class HideoutProductionRecipesController : HttpController + public class HideoutProductionRecipesController : EftHttpController { public HideoutProductionRecipesController() : base("/client/hideout/production/recipes") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetHideoutProductionRecipes()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetHideoutProductionRecipes(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/HideoutQteListController.cs b/Fuyu.Backend.EFT/Controllers/Http/HideoutQteListController.cs index 651b8cf5..cfe597f3 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/HideoutQteListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/HideoutQteListController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class HideoutQteListController : HttpController + public class HideoutQteListController : EftHttpController { public HideoutQteListController() : base("/client/hideout/qte/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetHideoutQteList()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetHideoutQteList(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/HideoutSettingsController.cs b/Fuyu.Backend.EFT/Controllers/Http/HideoutSettingsController.cs index c1dab6a3..6b13b688 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/HideoutSettingsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/HideoutSettingsController.cs @@ -1,21 +1,23 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class HideoutSettingsController : HttpController + public class HideoutSettingsController : EftHttpController { public HideoutSettingsController() : base("/client/hideout/settings") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var json = EftOrm.GetHideoutSettings(); var response = Json.Parse>(json); - return context.SendJsonAsync(Json.Stringify(response)); + + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/ItemsController.cs b/Fuyu.Backend.EFT/Controllers/Http/ItemsController.cs index 5bee6759..01061b7c 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ItemsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ItemsController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class ItemsController : HttpController + public class ItemsController : EftHttpController { public ItemsController() : base("/client/items") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetItems()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetItems(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/LanguagesController.cs b/Fuyu.Backend.EFT/Controllers/Http/LanguagesController.cs index 8c51c90d..fdc4c2f7 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/LanguagesController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/LanguagesController.cs @@ -1,18 +1,18 @@ using System.Collections.Generic; using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class LanguagesController : HttpController + public class LanguagesController : EftHttpController { public LanguagesController() : base("/client/languages") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var languages = EftOrm.GetLanguages(); var response = new ResponseBody> @@ -20,7 +20,8 @@ public override Task RunAsync(HttpContext context) data = languages }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/LocalGameWeatherController.cs b/Fuyu.Backend.EFT/Controllers/Http/LocalGameWeatherController.cs index 11308643..1430dcb7 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/LocalGameWeatherController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/LocalGameWeatherController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class LocalGameWeatherController : HttpController + public class LocalGameWeatherController : EftHttpController { public LocalGameWeatherController() : base("/client/localGame/weather") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetLocalWeather()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetLocalWeather(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/LocaleController.cs b/Fuyu.Backend.EFT/Controllers/Http/LocaleController.cs index acf647dd..a0e2db82 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/LocaleController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/LocaleController.cs @@ -2,12 +2,12 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Backend.BSG.Services; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; +using Fuyu.Backend.EFT.Services; namespace Fuyu.Backend.EFT.Controllers.Http { - public partial class LocaleController : HttpController + public partial class LocaleController : EftHttpController { [GeneratedRegex("^/client/locale/(?[a-z]+(-[a-z]+)?)$")] private static partial Regex PathExpression(); @@ -16,7 +16,7 @@ public LocaleController() : base(PathExpression()) { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var parameters = context.GetPathParameters(this); diff --git a/Fuyu.Backend.EFT/Controllers/Http/LocationsController.cs b/Fuyu.Backend.EFT/Controllers/Http/LocationsController.cs index fe622fd4..59f6dd53 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/LocationsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/LocationsController.cs @@ -1,23 +1,24 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Locations; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class LocationsController : HttpController + public class LocationsController : EftHttpController { public LocationsController() : base("/client/locations") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var json = EftOrm.GetLocations(); var locations = Json.Parse>(json); var response = Json.Stringify(locations); - return context.SendJsonAsync(response); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MailDialogListController.cs b/Fuyu.Backend.EFT/Controllers/Http/MailDialogListController.cs index 3a7035fb..b7a96301 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MailDialogListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MailDialogListController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MailDialogListController : HttpController + public class MailDialogListController : EftHttpController { public MailDialogListController() : base("/client/mail/dialog/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody { data = [] }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupCurrentController.cs b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupCurrentController.cs index 1ab334d3..68f930ae 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupCurrentController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupCurrentController.cs @@ -1,18 +1,20 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MatchGroupCurrentController : HttpController + public class MatchGroupCurrentController : EftHttpController { public MatchGroupCurrentController() : base("/client/match/group/current") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new MatchGroupCurrentResponse() @@ -22,7 +24,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupExitFromMenuController.cs b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupExitFromMenuController.cs index 932b0491..5cf52f3a 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupExitFromMenuController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupExitFromMenuController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MatchGroupExitFromMenuController : HttpController + public class MatchGroupExitFromMenuController : EftHttpController { public MatchGroupExitFromMenuController() : base("/client/match/group/exit_from_menu") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupInviteCancelAllController.cs b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupInviteCancelAllController.cs index da035d88..ed96ad15 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MatchGroupInviteCancelAllController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MatchGroupInviteCancelAllController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MatchGroupInviteCancelAllController : HttpController + public class MatchGroupInviteCancelAllController : EftHttpController { public MatchGroupInviteCancelAllController() : base("/client/match/group/invite/cancel-all") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = true }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MatchLocalEndController.cs b/Fuyu.Backend.EFT/Controllers/Http/MatchLocalEndController.cs index 1a547620..914f3648 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MatchLocalEndController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MatchLocalEndController.cs @@ -2,26 +2,29 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Requests; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MatchLocalEndController : HttpController + public class MatchLocalEndController : EftHttpController { public MatchLocalEndController() : base("/client/match/local/end") { } - public override Task RunAsync(HttpContext context, MatchLocalEndRequest body) + public override Task RunAsync(EftHttpContext context, MatchLocalEndRequest body) { var sessionId = context.GetSessionId(); var profile = EftOrm.GetActiveProfile(sessionId); + // TODO: move this to a service + // --seionmoya, 2024-11-18 + // NOTE: This data is not present in what the client sends as one of BSG's anticheat measures // which prevents your inraid inventory info from knowing what is in someone's stash - // so I have to manually add the existing data that should be there which I think is ;ess effort + // so I have to manually add the existing data that should be there which I think is less effort // than manually taking the data that we want from the client's request // -- nexus4880, 2024-10-14 body.results.profile.Info.LowerNickname = profile.Pmc.Info.LowerNickname; @@ -47,7 +50,8 @@ public override Task RunAsync(HttpContext context, MatchLocalEndRequest body) data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MatchLocalStartController.cs b/Fuyu.Backend.EFT/Controllers/Http/MatchLocalStartController.cs index 5b31aa87..e7db6196 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MatchLocalStartController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MatchLocalStartController.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Requests; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.IO; -using Fuyu.Common.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class MatchLocalStartController : HttpController + public class MatchLocalStartController : EftHttpController { private readonly Dictionary _locations; @@ -28,11 +28,14 @@ public MatchLocalStartController() : base("/client/match/local/start") }; } - public override Task RunAsync(HttpContext context, MatchLocalStartRequest request) + public override Task RunAsync(EftHttpContext context, MatchLocalStartRequest request) { + // TODO: generate this + // --seionmoya, 2024-11-18 var location = request.location; - return context.SendJsonAsync(_locations[location]); + var text = _locations[location]; + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/MenuLocaleController.cs b/Fuyu.Backend.EFT/Controllers/Http/MenuLocaleController.cs index 40358baa..fee0b43b 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/MenuLocaleController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/MenuLocaleController.cs @@ -1,12 +1,12 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public partial class MenuLocaleController : HttpController + public partial class MenuLocaleController : EftHttpController { [GeneratedRegex("^/client/menu/locale/(?[a-z]+(-[a-z]+)?)$")] private static partial Regex PathExpression(); @@ -15,7 +15,7 @@ public MenuLocaleController() : base(PathExpression()) { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var parameters = context.GetPathParameters(this); @@ -26,7 +26,8 @@ public override Task RunAsync(HttpContext context) data = locale }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } diff --git a/Fuyu.Backend.EFT/Controllers/Http/NotifierChannelCreateController.cs b/Fuyu.Backend.EFT/Controllers/Http/NotifierChannelCreateController.cs index a2d54680..bfdc011f 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/NotifierChannelCreateController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/NotifierChannelCreateController.cs @@ -1,20 +1,23 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class NotifierChannelCreateController : HttpController + public class NotifierChannelCreateController : EftHttpController { public NotifierChannelCreateController() : base("/client/notifier/channel/create") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var channelId = SimpleId.Generate(64); + + // TODO: don't hardcode address + // --seionmoya, 2024-11-18 var response = new ResponseBody { data = new NotifierChannelCreateResponse() @@ -26,7 +29,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/ProfileSettingsController.cs b/Fuyu.Backend.EFT/Controllers/Http/ProfileSettingsController.cs index 0f9de2e6..ee383fe0 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ProfileSettingsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ProfileSettingsController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class ProfileSettingsController : HttpController + public class ProfileSettingsController : EftHttpController { public ProfileSettingsController() : base("/client/profile/settings") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = true }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/ProfileStatusController.cs b/Fuyu.Backend.EFT/Controllers/Http/ProfileStatusController.cs index 75145f8c..4fb32439 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ProfileStatusController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ProfileStatusController.cs @@ -1,23 +1,25 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Multiplayer; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class ProfileStatusController : HttpController + public class ProfileStatusController : EftHttpController { public ProfileStatusController() : base("/client/profile/status") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var sessionId = context.GetSessionId(); var profile = EftOrm.GetActiveProfile(sessionId); + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = new ProfileStatusResponse() @@ -47,7 +49,8 @@ public override Task RunAsync(HttpContext context) } }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/PutMetricsController.cs b/Fuyu.Backend.EFT/Controllers/Http/PutMetricsController.cs index afd8b1eb..171b6cd5 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/PutMetricsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/PutMetricsController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class PutMetricsController : HttpController + public class PutMetricsController : EftHttpController { public PutMetricsController() : base("/client/putMetrics") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/QuestListController.cs b/Fuyu.Backend.EFT/Controllers/Http/QuestListController.cs index fcf1c540..2aca6ac2 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/QuestListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/QuestListController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class QuestListController : HttpController + public class QuestListController : EftHttpController { public QuestListController() : base("/client/quest/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetQuest()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetQuest(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/RaidConfigurationController.cs b/Fuyu.Backend.EFT/Controllers/Http/RaidConfigurationController.cs index 2d2612da..f26f280e 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/RaidConfigurationController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/RaidConfigurationController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class RaidConfigurationController : HttpController + public class RaidConfigurationController : EftHttpController { public RaidConfigurationController() : base("/client/raid/configuration") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: handle this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/RepeatableQuestActivityPeriodsController.cs b/Fuyu.Backend.EFT/Controllers/Http/RepeatableQuestActivityPeriodsController.cs index 19c6ada9..d5c6dce4 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/RepeatableQuestActivityPeriodsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/RepeatableQuestActivityPeriodsController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class RepeatableQuestActivityPeriodsController : HttpController + public class RepeatableQuestActivityPeriodsController : EftHttpController { public RepeatableQuestActivityPeriodsController() : base("/client/repeatalbeQuests/activityPeriods") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody { data = [] }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/ServerListController.cs b/Fuyu.Backend.EFT/Controllers/Http/ServerListController.cs index bfa903e3..97e3c08f 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/ServerListController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/ServerListController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Servers; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class ServerListController : HttpController + public class ServerListController : EftHttpController { public ServerListController() : base("/client/server/list") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var response = new ResponseBody() { @@ -25,7 +25,8 @@ public override Task RunAsync(HttpContext context) ] }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/SettingsController.cs b/Fuyu.Backend.EFT/Controllers/Http/SettingsController.cs index 4621286c..ed85b935 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/SettingsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/SettingsController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class SettingsController : HttpController + public class SettingsController : EftHttpController { public SettingsController() : base("/client/settings") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetSettings()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetSettings(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/SurveyController.cs b/Fuyu.Backend.EFT/Controllers/Http/SurveyController.cs index 13167309..44b2fe29 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/SurveyController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/SurveyController.cs @@ -1,24 +1,27 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class SurveyController : HttpController + public class SurveyController : EftHttpController { public SurveyController() : base("/client/survey") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { + // TODO: generate this + // --seionmoya, 2024-11-18 var response = new ResponseBody() { data = null }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/TraderSettingsController.cs b/Fuyu.Backend.EFT/Controllers/Http/TraderSettingsController.cs index 4dc04fc1..023c7230 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/TraderSettingsController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/TraderSettingsController.cs @@ -2,25 +2,26 @@ using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; using Fuyu.Backend.BSG.Models.Trading; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.EFT.Controllers.Http { - public class TraderSettingsController : HttpController + public class TraderSettingsController : EftHttpController { public TraderSettingsController() : base("/client/trading/api/traderSettings") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { var response = new ResponseBody> { data = TraderDatabase.GetTraderTemplates().Values }; - return context.SendJsonAsync(Json.Stringify(response)); + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Controllers/Http/WeatherController.cs b/Fuyu.Backend.EFT/Controllers/Http/WeatherController.cs index 6a4d20bb..38fe2d2a 100644 --- a/Fuyu.Backend.EFT/Controllers/Http/WeatherController.cs +++ b/Fuyu.Backend.EFT/Controllers/Http/WeatherController.cs @@ -1,17 +1,20 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.EFT.Networking; namespace Fuyu.Backend.EFT.Controllers.Http { - public class WeatherController : HttpController + public class WeatherController : EftHttpController { public WeatherController() : base("/client/weather") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(EftHttpContext context) { - return context.SendJsonAsync(EftOrm.GetWeather()); + // TODO: generate this + // --seionmoya, 2024-11-18 + var text = EftOrm.GetWeather(); + return context.SendJsonAsync(text, true, true); } } } \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Networking/EftHttpContext.cs b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs new file mode 100644 index 00000000..365e9d32 --- /dev/null +++ b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs @@ -0,0 +1,111 @@ +using System.IO; +using System.IO.Compression; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Fuyu.Common.Compression; +using Fuyu.Common.Networking; + +namespace Fuyu.Backend.EFT.Networking +{ + public class EftHttpContext : HttpContext + { + public EftHttpContext(HttpListenerRequest request, HttpListenerResponse response) : base(request, response) + { + } + + public override byte[] GetBinary() + { + using (var ms = new MemoryStream()) + { + Request.InputStream.CopyTo(ms); + + var body = ms.ToArray(); + var encryption = GetEncryption(); + + if (encryption != string.Empty) + { + switch (encryption) + { + case "aes": + // TODO: handle AES-192 encryption + // body = CryptographyService.DecryptAes(body); + break; + + default: + throw new InvalidDataException(encryption); + } + } + + if (MemoryZlib.IsCompressed(body)) + { + body = MemoryZlib.Decompress(body); + } + + return body; + } + } + + protected Task SendAsync(byte[] data, string mime, HttpStatusCode status, bool zipped, bool encrypted) + { + bool hasData = !(data == null); + + // Used for postman debugging by Nexus4880 + // -- seionmoya, 2024-11-18 +#if DEBUG + if (Request.Headers["X-Require-Plaintext"] != null) + { + zipped = false; + encrypted = false; + } +#endif + + if (hasData && zipped) + { + data = MemoryZlib.Compress(data, CompressionLevel.SmallestSize); + } + + if (hasData && encrypted) + { + // TODO: handle X-Encryption: aes + /* + Response.Headers.Add("X-Encryption", "aes"); + data = CryptographyService.EncryptAes(data); + */ + encrypted = false; + } + + return SendAsync(data, mime, status); + } + + public Task SendBinaryAsync(byte[] data, string mime, bool zipped, bool encrypted) + { + return SendAsync(data, mime, HttpStatusCode.OK, zipped, encrypted); + } + + public Task SendJsonAsync(string text, bool zipped, bool encrypted) + { + var encoded = Encoding.UTF8.GetBytes(text); + var mime = zipped || encrypted + ? "application/octet-stream" + : "application/json; charset=utf-8"; + + return SendAsync(encoded, mime, HttpStatusCode.OK, zipped, encrypted); + } + + public string GetEncryption() + { + return Request.Headers["X-Encryption"]; + } + + public string GetETag() + { + return Request.Headers["If-None-Match"]; + } + + public string GetSessionId() + { + return Request.Cookies["PHPSESSID"].Value; + } + } +} \ No newline at end of file diff --git a/Fuyu.Backend.EFT/Networking/EftHttpController.cs b/Fuyu.Backend.EFT/Networking/EftHttpController.cs new file mode 100644 index 00000000..7ace76dd --- /dev/null +++ b/Fuyu.Backend.EFT/Networking/EftHttpController.cs @@ -0,0 +1,69 @@ +using System; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Fuyu.Common.Networking; + +namespace Fuyu.Backend.EFT.Networking +{ + public abstract class EftHttpController : HttpController + { + protected EftHttpController(Regex pattern) : base(pattern) + { + // match dynamic paths + } + + protected EftHttpController(string path) : base(path) + { + // match static paths + } + + public override Task RunAsync(HttpContext context) + { + // NOTE: assumes HttpController can be safely downcasted into EftHttpControler + // -- seionmoya, 2024-11-18 + var downcast = (EftHttpContext)context; + + return RunAsync(downcast); + } + + public abstract Task RunAsync(EftHttpContext context); + } + + public abstract class EftHttpController : EftHttpController where TRequest : class + { + protected EftHttpController(Regex pattern) : base(pattern) + { + // match dynamic paths + } + + protected EftHttpController(string path) : base(path) + { + // match static paths + } + + public override Task RunAsync(EftHttpContext context) + { + // TODO: + // - Use better exception type + // -- seionmoya, 2024-10-13 + if (!context.HasBody()) + { + throw new Exception("Request does not contain body."); + } + + var body = context.GetJson(); + + // TODO: + // - Use better exception type + // -- seionmoya, 2024-10-13 + if (body == null) + { + throw new Exception("Body could not be parsed as TRequest."); + } + + return RunAsync(context, body); + } + + public abstract Task RunAsync(EftHttpContext context, TRequest body); + } +} diff --git a/Fuyu.Backend.BSG/Services/ETagService.cs b/Fuyu.Backend.EFT/Services/ETagService.cs similarity index 79% rename from Fuyu.Backend.BSG/Services/ETagService.cs rename to Fuyu.Backend.EFT/Services/ETagService.cs index 1c8fa2a9..8058ca1d 100644 --- a/Fuyu.Backend.BSG/Services/ETagService.cs +++ b/Fuyu.Backend.EFT/Services/ETagService.cs @@ -3,15 +3,15 @@ using System.Text; using System.Threading.Tasks; using Fuyu.Backend.BSG.Models.Responses; +using Fuyu.Backend.EFT.Networking; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; -namespace Fuyu.Backend.BSG.Services +namespace Fuyu.Backend.EFT.Services { public class ETagService { - public static uint GetUIntETag(HttpContext context) + public static uint GetUIntETag(EftHttpContext context) { var value = context.GetETag(); @@ -39,7 +39,7 @@ public static bool IsCacheInvalid(uint cached, uint crc) return cached == 0u || cached != crc; } - public static Task SendCachedAsync(HttpContext context, ResponseBody response) + public static Task SendCachedAsync(EftHttpContext context, ResponseBody response) { var cached = GetUIntETag(context); var crc = GetCrc(response.data); @@ -48,7 +48,9 @@ public static Task SendCachedAsync(HttpContext context, ResponseBody< { // outdated client cache response.crc = crc; - return context.SendJsonAsync(Json.Stringify(response)); + + var text = Json.Stringify(response); + return context.SendJsonAsync(text, true, true); } else { diff --git a/Fuyu.Common/Networking/HttpContext.cs b/Fuyu.Common/Networking/HttpContext.cs index 4c2a0f73..f1ee7c22 100644 --- a/Fuyu.Common/Networking/HttpContext.cs +++ b/Fuyu.Common/Networking/HttpContext.cs @@ -1,9 +1,7 @@ using System.IO; -using System.IO.Compression; using System.Net; using System.Text; using System.Threading.Tasks; -using Fuyu.Common.Compression; using Fuyu.Common.Serialization; namespace Fuyu.Common.Networking @@ -14,74 +12,30 @@ public HttpContext(HttpListenerRequest request, HttpListenerResponse response) : { } - public bool HasBody() - { - return Request.HasEntityBody; - } - - public byte[] GetBinary() + public virtual byte[] GetBinary() { using (var ms = new MemoryStream()) { Request.InputStream.CopyTo(ms); - - var body = ms.ToArray(); - - if (MemoryZlib.IsCompressed(body)) - { - body = MemoryZlib.Decompress(body); - } - - return body; + return ms.ToArray(); } } - public string GetText() + public virtual string GetText() { var body = GetBinary(); return Encoding.UTF8.GetString(body); } - public T GetJson() + public virtual T GetJson() { var json = GetText(); return Json.Parse(json); } - public string GetETag() + protected virtual Task SendAsync(byte[] data, string mime, HttpStatusCode status) { - return Request.Headers["If-None-Match"]; - } - - public string GetSessionId() - { - return Request.Cookies["PHPSESSID"].Value; - } - - protected Task SendAsync(byte[] data, string mime, HttpStatusCode status, bool zipped = true) - { - bool hasData = !(data is null); - - // used for plaintext debugging - if (Request.Headers["fuyu-debug"] != null) - { - zipped = false; - } - - if (hasData && zipped) - { - // NOTE: CompressionLevel.SmallestSize does not exist in - // .NET 5 and below. - // -- seionmoya, 2024-10-07 - -#if NET6_0_OR_GREATER - var level = CompressionLevel.SmallestSize; -#else - var level = CompressionLevel.Optimal; -#endif - - data = MemoryZlib.Compress(data, level); - } + bool hasData = !(data == null); Response.StatusCode = (int)status; Response.ContentType = mime; @@ -101,34 +55,20 @@ protected Task SendAsync(byte[] data, string mime, HttpStatusCode status, bool z } } - public Task SendStatus(HttpStatusCode status) + public virtual Task SendStatus(HttpStatusCode status) { - return SendAsync(null, "plain/text", status, false); + return SendAsync(null, "plain/text", status); } - public Task SendBinaryAsync(byte[] data, string mime, bool zipped = true) + public virtual Task SendBinaryAsync(byte[] data, string mime) { - return SendAsync(data, mime, HttpStatusCode.OK, zipped); + return SendAsync(data, mime, HttpStatusCode.OK); } - public Task SendJsonAsync(string text, bool zipped = true) + public virtual Task SendJsonAsync(string text) { var encoded = Encoding.UTF8.GetBytes(text); - var mime = zipped - ? "application/octet-stream" - : "application/json; charset=utf-8"; - - return SendAsync(encoded, mime, HttpStatusCode.OK, zipped); - } - - public void Close() - { - Response.Close(); - } - - public override string ToString() - { - return $"{GetType().Name}:{Path}(HasBody:{HasBody()})"; + return SendAsync(encoded, "application/json; charset=utf-8", HttpStatusCode.OK); } } } \ No newline at end of file diff --git a/Fuyu.Common/Networking/HttpResponse.cs b/Fuyu.Common/Networking/HttpResponse.cs index 3add7a24..0a5bed04 100644 --- a/Fuyu.Common/Networking/HttpResponse.cs +++ b/Fuyu.Common/Networking/HttpResponse.cs @@ -4,9 +4,6 @@ namespace Fuyu.Common.Networking { public class HttpResponse { - // TODO: - // * use enum instead - // -- seionmoya, 2024/09/19 public HttpStatusCode Status; // TODO: diff --git a/Fuyu.Common/Networking/WebRouterContext.cs b/Fuyu.Common/Networking/WebRouterContext.cs index 80382e79..4fcef7b0 100644 --- a/Fuyu.Common/Networking/WebRouterContext.cs +++ b/Fuyu.Common/Networking/WebRouterContext.cs @@ -36,5 +36,20 @@ public Dictionary GetPathParameters(IRoutable routable) return result; } + + public bool HasBody() + { + return Request.HasEntityBody; + } + + public void Close() + { + Response.Close(); + } + + public override string ToString() + { + return $"{GetType().Name}:{Path}(HasBody:{HasBody()})"; + } } } \ No newline at end of file diff --git a/Tests/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs b/Tests/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs index 763dcb90..49408ff5 100644 --- a/Tests/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs +++ b/Tests/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs @@ -12,8 +12,8 @@ using Fuyu.Backend.EFT; using Fuyu.Backend.EFT.Servers; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; +using Fuyu.Tests.Backend.EFT.Networking; using AccountService = Fuyu.Backend.Core.Services.AccountService; namespace Fuyu.Tests.Backend.EFT.EndToEnd diff --git a/Fuyu.Common/Networking/EftHttpClient.cs b/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs similarity index 66% rename from Fuyu.Common/Networking/EftHttpClient.cs rename to Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs index 3967a6ef..1889e8cf 100644 --- a/Fuyu.Common/Networking/EftHttpClient.cs +++ b/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs @@ -3,15 +3,15 @@ using System.Net.Http; using Fuyu.Common.Compression; -namespace Fuyu.Common.Networking +namespace Fuyu.Tests.Backend.EFT.Networking { - public class EftHttpClient : HttpClient + public class EftHttpClient : Fuyu.Common.Networking.HttpClient { - public readonly string Cookie; + public readonly string _sessionId; public EftHttpClient(string address, string sessionId) : base(address) { - Cookie = $"PHPSESSID={sessionId}"; + _sessionId = sessionId; } protected override byte[] OnSendBody(byte[] body) @@ -19,14 +19,7 @@ protected override byte[] OnSendBody(byte[] body) // NOTE: CompressionLevel.SmallestSize does not exist in // .NET 5 and below. // -- seionmoya, 2024-10-07 - -#if NET6_0_OR_GREATER - var level = CompressionLevel.SmallestSize; -#else - var level = CompressionLevel.Optimal; -#endif - - return MemoryZlib.Compress(body, level); + return MemoryZlib.Compress(body, CompressionLevel.SmallestSize); } protected override byte[] OnReceiveBody(byte[] body) @@ -47,10 +40,8 @@ protected override HttpRequestMessage GetNewRequest(HttpMethod method, string pa RequestUri = new Uri(Address + path), }; - if (!string.IsNullOrWhiteSpace(Cookie)) - { - request.Headers.Add("Cookie", Cookie); - } + request.Headers.Add("X-Encryption", "aes"); + request.Headers.Add("Cookie", $"PHPSESSID={_sessionId}"); return request; } From 1c1f3cb7a9cad2dcb88905839b4d242a911de0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=99=E7=A9=8F=E9=9D=84?= <170472707+seionmoya@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:15:17 +0100 Subject: [PATCH 2/5] Refactor Fuyu.Backend.Core --- .../Controllers/AccountGamesController.cs | 6 +- .../Controllers/AccountLoginController.cs | 6 +- .../Controllers/AccountLogoutController.cs | 6 +- .../Controllers/AccountRegisterController.cs | 6 +- .../AccountRegisterGameController.cs | 6 +- .../Networking/CoreHttpContext.cs | 93 +++++++++++++++++++ .../Networking/CoreHttpController.cs | 69 ++++++++++++++ Fuyu.Backend.Core/Services/RequestService.cs | 10 +- Fuyu.Backend.EFT/Networking/EftHttpContext.cs | 2 +- Fuyu.Common/Networking/HttpContext.cs | 2 +- .../Networking/CoreHttpClient.cs | 46 +++++++++ Fuyu.Launcher.Core/Services/RequestService.cs | 20 ++-- .../Networking/EftHttpClient.cs | 3 - 13 files changed, 237 insertions(+), 38 deletions(-) create mode 100644 Fuyu.Backend.Core/Networking/CoreHttpContext.cs create mode 100644 Fuyu.Backend.Core/Networking/CoreHttpController.cs create mode 100644 Fuyu.Launcher.Core/Networking/CoreHttpClient.cs diff --git a/Fuyu.Backend.Core/Controllers/AccountGamesController.cs b/Fuyu.Backend.Core/Controllers/AccountGamesController.cs index dd6ac723..c57dc433 100644 --- a/Fuyu.Backend.Core/Controllers/AccountGamesController.cs +++ b/Fuyu.Backend.Core/Controllers/AccountGamesController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.Core.Models.Responses; +using Fuyu.Backend.Core.Networking; using Fuyu.Backend.Core.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.Core.Controllers { - public class AccountGamesController : HttpController + public class AccountGamesController : CoreHttpController { public AccountGamesController() : base("/account/games") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(CoreHttpContext context) { var sessionId = context.GetSessionId(); var result = AccountService.GetGames(sessionId); diff --git a/Fuyu.Backend.Core/Controllers/AccountLoginController.cs b/Fuyu.Backend.Core/Controllers/AccountLoginController.cs index d9850611..a395dcdf 100644 --- a/Fuyu.Backend.Core/Controllers/AccountLoginController.cs +++ b/Fuyu.Backend.Core/Controllers/AccountLoginController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.Core.Models.Requests; +using Fuyu.Backend.Core.Networking; using Fuyu.Backend.Core.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.Core.Controllers { - public class AccountLoginController : HttpController + public class AccountLoginController : CoreHttpController { public AccountLoginController() : base("/account/login") { } - public override Task RunAsync(HttpContext context, AccountLoginRequest body) + public override Task RunAsync(CoreHttpContext context, AccountLoginRequest body) { var response = AccountService.LoginAccount(body.Username, body.Password); diff --git a/Fuyu.Backend.Core/Controllers/AccountLogoutController.cs b/Fuyu.Backend.Core/Controllers/AccountLogoutController.cs index a5df1447..0996dcb2 100644 --- a/Fuyu.Backend.Core/Controllers/AccountLogoutController.cs +++ b/Fuyu.Backend.Core/Controllers/AccountLogoutController.cs @@ -1,15 +1,15 @@ using System.Threading.Tasks; -using Fuyu.Common.Networking; +using Fuyu.Backend.Core.Networking; namespace Fuyu.Backend.Core.Controllers { - public class AccountLogoutController : HttpController + public class AccountLogoutController : CoreHttpController { public AccountLogoutController() : base("/account/logout") { } - public override Task RunAsync(HttpContext context) + public override Task RunAsync(CoreHttpContext context) { var sessionId = context.GetSessionId(); CoreOrm.RemoveSession(sessionId); diff --git a/Fuyu.Backend.Core/Controllers/AccountRegisterController.cs b/Fuyu.Backend.Core/Controllers/AccountRegisterController.cs index a262a5fe..5b5925a2 100644 --- a/Fuyu.Backend.Core/Controllers/AccountRegisterController.cs +++ b/Fuyu.Backend.Core/Controllers/AccountRegisterController.cs @@ -1,19 +1,19 @@ using System.Threading.Tasks; using Fuyu.Backend.Core.Models.Requests; using Fuyu.Backend.Core.Models.Responses; +using Fuyu.Backend.Core.Networking; using Fuyu.Backend.Core.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.Core.Controllers { - public class AccountRegisterController : HttpController + public class AccountRegisterController : CoreHttpController { public AccountRegisterController() : base("/account/register") { } - public override Task RunAsync(HttpContext context, AccountRegisterRequest request) + public override Task RunAsync(CoreHttpContext context, AccountRegisterRequest request) { var result = AccountService.RegisterAccount(request.Username, request.Password); var response = new AccountRegisterResponse() diff --git a/Fuyu.Backend.Core/Controllers/AccountRegisterGameController.cs b/Fuyu.Backend.Core/Controllers/AccountRegisterGameController.cs index befc41c0..2fba9074 100644 --- a/Fuyu.Backend.Core/Controllers/AccountRegisterGameController.cs +++ b/Fuyu.Backend.Core/Controllers/AccountRegisterGameController.cs @@ -1,18 +1,18 @@ using System.Threading.Tasks; using Fuyu.Backend.Core.Models.Requests; +using Fuyu.Backend.Core.Networking; using Fuyu.Backend.Core.Services; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; namespace Fuyu.Backend.Core.Controllers { - public class AccountRegisterGameController : HttpController + public class AccountRegisterGameController : CoreHttpController { public AccountRegisterGameController() : base("/account/register/game") { } - public override Task RunAsync(HttpContext context, AccountRegisterGameRequest request) + public override Task RunAsync(CoreHttpContext context, AccountRegisterGameRequest request) { var sessionId = context.GetSessionId(); var result = AccountService.RegisterGame(sessionId, request.Game, request.Edition); diff --git a/Fuyu.Backend.Core/Networking/CoreHttpContext.cs b/Fuyu.Backend.Core/Networking/CoreHttpContext.cs new file mode 100644 index 00000000..fa45295f --- /dev/null +++ b/Fuyu.Backend.Core/Networking/CoreHttpContext.cs @@ -0,0 +1,93 @@ +using System.IO; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Fuyu.Common.Networking; + +namespace Fuyu.Backend.Core.Networking +{ + public class CoreHttpContext : HttpContext + { + public CoreHttpContext(HttpListenerRequest request, HttpListenerResponse response) : base(request, response) + { + } + + public override byte[] GetBinary() + { + using (var ms = new MemoryStream()) + { + Request.InputStream.CopyTo(ms); + + var body = ms.ToArray(); + var encryption = GetEncryption(); + + if (encryption != string.Empty) + { + switch (encryption) + { + case "aes": + // TODO: handle AES-192 encryption + // body = CryptographyService.DecryptAes(body); + break; + + default: + throw new InvalidDataException(encryption); + } + } + + return body; + } + } + + protected Task SendAsync(byte[] data, string mime, HttpStatusCode status, bool encrypted) + { + var hasData = !(data == null); + + // Used for postman debugging by Nexus4880 + // -- seionmoya, 2024-11-18 +#if DEBUG + if (Request.Headers["X-Require-Plaintext"] != null) + { + encrypted = false; + } +#endif + + if (hasData && encrypted) + { + // TODO: handle X-Encryption: aes + /* + Response.Headers.Add("X-Encryption", "aes"); + data = CryptographyService.EncryptAes(data); + */ + encrypted = false; + } + + return SendAsync(data, mime, status); + } + + public Task SendBinaryAsync(byte[] data, string mime, bool encrypted) + { + return SendAsync(data, mime, HttpStatusCode.OK, encrypted); + } + + public Task SendJsonAsync(string text, bool encrypted) + { + var encoded = Encoding.UTF8.GetBytes(text); + var mime = encrypted + ? "application/octet-stream" + : "application/json; charset=utf-8"; + + return SendAsync(encoded, mime, HttpStatusCode.OK, encrypted); + } + + public string GetEncryption() + { + return Request.Headers["X-Encryption"]; + } + + public string GetSessionId() + { + return Request.Cookies["Session"].Value; + } + } +} \ No newline at end of file diff --git a/Fuyu.Backend.Core/Networking/CoreHttpController.cs b/Fuyu.Backend.Core/Networking/CoreHttpController.cs new file mode 100644 index 00000000..646d52e9 --- /dev/null +++ b/Fuyu.Backend.Core/Networking/CoreHttpController.cs @@ -0,0 +1,69 @@ +using System; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Fuyu.Common.Networking; + +namespace Fuyu.Backend.Core.Networking +{ + public abstract class CoreHttpController : HttpController + { + protected CoreHttpController(Regex pattern) : base(pattern) + { + // match dynamic paths + } + + protected CoreHttpController(string path) : base(path) + { + // match static paths + } + + public override Task RunAsync(HttpContext context) + { + // NOTE: assumes HttpController can be safely downcasted into CoreHttpControler + // -- seionmoya, 2024-11-18 + var downcast = (CoreHttpContext)context; + + return RunAsync(downcast); + } + + public abstract Task RunAsync(CoreHttpContext context); + } + + public abstract class CoreHttpController : CoreHttpController where TRequest : class + { + protected CoreHttpController(Regex pattern) : base(pattern) + { + // match dynamic paths + } + + protected CoreHttpController(string path) : base(path) + { + // match static paths + } + + public override Task RunAsync(CoreHttpContext context) + { + // TODO: + // - Use better exception type + // -- seionmoya, 2024-10-13 + if (!context.HasBody()) + { + throw new Exception("Request does not contain body."); + } + + var body = context.GetJson(); + + // TODO: + // - Use better exception type + // -- seionmoya, 2024-10-13 + if (body == null) + { + throw new Exception("Body could not be parsed as TRequest."); + } + + return RunAsync(context, body); + } + + public abstract Task RunAsync(CoreHttpContext context, TRequest body); + } +} diff --git a/Fuyu.Backend.Core/Services/RequestService.cs b/Fuyu.Backend.Core/Services/RequestService.cs index 3d3dbcc3..604ed5bc 100644 --- a/Fuyu.Backend.Core/Services/RequestService.cs +++ b/Fuyu.Backend.Core/Services/RequestService.cs @@ -19,9 +19,8 @@ static RequestService() // TODO: // * get address from config // -- seionmoya, 2024/09/08 - _httpClients.Set("fuyu", new EftHttpClient("http://localhost:8000", string.Empty)); - _httpClients.Set("eft", new EftHttpClient("http://localhost:8010", string.Empty)); - _httpClients.Set("arena", new EftHttpClient("http://localhost:8020", string.Empty)); + _httpClients.Set("eft", new HttpClient("http://localhost:8010")); + _httpClients.Set("arena", new HttpClient("http://localhost:8020")); } private static T2 HttpPost(string id, string path, T1 request) @@ -41,11 +40,6 @@ private static T2 HttpPost(string id, string path, T1 request) return responseValue; } - public static void CreateSession(string id, string address, string sessionId) - { - _httpClients.Set(id, new EftHttpClient(address, sessionId)); - } - public static int RegisterGame(string game, string username, string edition) { var request = new FuyuGameRegisterRequest() diff --git a/Fuyu.Backend.EFT/Networking/EftHttpContext.cs b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs index 365e9d32..b360352c 100644 --- a/Fuyu.Backend.EFT/Networking/EftHttpContext.cs +++ b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs @@ -48,7 +48,7 @@ public override byte[] GetBinary() protected Task SendAsync(byte[] data, string mime, HttpStatusCode status, bool zipped, bool encrypted) { - bool hasData = !(data == null); + var hasData = !(data == null); // Used for postman debugging by Nexus4880 // -- seionmoya, 2024-11-18 diff --git a/Fuyu.Common/Networking/HttpContext.cs b/Fuyu.Common/Networking/HttpContext.cs index f1ee7c22..6490d89a 100644 --- a/Fuyu.Common/Networking/HttpContext.cs +++ b/Fuyu.Common/Networking/HttpContext.cs @@ -35,7 +35,7 @@ public virtual T GetJson() protected virtual Task SendAsync(byte[] data, string mime, HttpStatusCode status) { - bool hasData = !(data == null); + var hasData = !(data == null); Response.StatusCode = (int)status; Response.ContentType = mime; diff --git a/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs b/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs new file mode 100644 index 00000000..fd8dfe36 --- /dev/null +++ b/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs @@ -0,0 +1,46 @@ +using System; +using System.IO.Compression; +using System.Net.Http; +using Fuyu.Common.Compression; + +namespace Fuyu.Launcher.Core.Networking +{ + public class CoreHttpClient : Fuyu.Common.Networking.HttpClient + { + public readonly string _sessionId; + + public CoreHttpClient(string address, string sessionId) : base(address) + { + _sessionId = sessionId; + } + + protected override byte[] OnSendBody(byte[] body) + { + return MemoryZlib.Compress(body, CompressionLevel.SmallestSize); + } + + protected override byte[] OnReceiveBody(byte[] body) + { + if (MemoryZlib.IsCompressed(body)) + { + body = MemoryZlib.Decompress(body); + } + + return body; + } + + protected override HttpRequestMessage GetNewRequest(HttpMethod method, string path) + { + var request = new HttpRequestMessage() + { + Method = method, + RequestUri = new Uri(Address + path), + }; + + request.Headers.Add("X-Encryption", "aes"); + request.Headers.Add("Cookie", $"Session={_sessionId}"); + + return request; + } + } +} \ No newline at end of file diff --git a/Fuyu.Launcher.Core/Services/RequestService.cs b/Fuyu.Launcher.Core/Services/RequestService.cs index b982a110..20684079 100644 --- a/Fuyu.Launcher.Core/Services/RequestService.cs +++ b/Fuyu.Launcher.Core/Services/RequestService.cs @@ -8,22 +8,22 @@ using Fuyu.Backend.Core.Models.Responses; using Fuyu.Common.Collections; using Fuyu.Common.Hashing; -using Fuyu.Common.Networking; using Fuyu.Common.Serialization; +using Fuyu.Launcher.Core.Networking; namespace Fuyu.Launcher.Core.Services { public static class RequestService { - private static ThreadDictionary _httpClients; + private static ThreadDictionary _httpClients; static RequestService() { - _httpClients = new ThreadDictionary(); + _httpClients = new ThreadDictionary(); - _httpClients.Set("fuyu", new EftHttpClient(SettingsService.FuyuAddress, string.Empty)); - _httpClients.Set("eft", new EftHttpClient(SettingsService.EftAddress, string.Empty)); - _httpClients.Set("arena", new EftHttpClient(SettingsService.ArenaAddress, string.Empty)); + _httpClients.Set("fuyu", new CoreHttpClient(SettingsService.FuyuAddress, string.Empty)); + _httpClients.Set("eft", new CoreHttpClient(SettingsService.EftAddress, string.Empty)); + _httpClients.Set("arena", new CoreHttpClient(SettingsService.ArenaAddress, string.Empty)); } private static void HttpPut(string id, string path, T1 request) @@ -58,14 +58,14 @@ private static T2 HttpPost(string id, string path, T1 request) public static void ResetSessions() { - _httpClients.Set("fuyu", new EftHttpClient(SettingsService.FuyuAddress, string.Empty)); - _httpClients.Set("eft", new EftHttpClient(SettingsService.EftAddress, string.Empty)); - _httpClients.Set("arena", new EftHttpClient(SettingsService.ArenaAddress, string.Empty)); + _httpClients.Set("fuyu", new CoreHttpClient(SettingsService.FuyuAddress, string.Empty)); + _httpClients.Set("eft", new CoreHttpClient(SettingsService.EftAddress, string.Empty)); + _httpClients.Set("arena", new CoreHttpClient(SettingsService.ArenaAddress, string.Empty)); } public static void CreateSession(string id, string address, string sessionId) { - _httpClients.Set(id, new EftHttpClient(address, sessionId)); + _httpClients.Set(id, new CoreHttpClient(address, sessionId)); } public static ERegisterStatus RegisterAccount(string username, string password) diff --git a/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs b/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs index 1889e8cf..996dbc17 100644 --- a/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs +++ b/Tests/Fuyu.Tests.Backend.EFT/Networking/EftHttpClient.cs @@ -16,9 +16,6 @@ public EftHttpClient(string address, string sessionId) : base(address) protected override byte[] OnSendBody(byte[] body) { - // NOTE: CompressionLevel.SmallestSize does not exist in - // .NET 5 and below. - // -- seionmoya, 2024-10-07 return MemoryZlib.Compress(body, CompressionLevel.SmallestSize); } From ff976c3aa85904daf6e9d83d478a382fd7659304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=99=E7=A9=8F=E9=9D=84?= <170472707+seionmoya@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:16:18 +0100 Subject: [PATCH 3/5] Update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 95528654..e2c4b113 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ See `Documentation/CONTRIBUTING.md` for more information on standards. ## Requirements - .NET 8.0 SDK +- WebView 2 Runtime ### Supported IDEs From a16865c93c529fdcdc9499d8a15e70cbcacd2206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=99=E7=A9=8F=E9=9D=84?= <170472707+seionmoya@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:40:31 +0100 Subject: [PATCH 4/5] Monkey-wrench downcast --- Fuyu.Backend.Core/Networking/CoreHttpController.cs | 5 +---- Fuyu.Backend.EFT/Networking/EftHttpController.cs | 5 +---- Fuyu.Common/Networking/WebRouterContext.cs | 4 ++-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Fuyu.Backend.Core/Networking/CoreHttpController.cs b/Fuyu.Backend.Core/Networking/CoreHttpController.cs index 646d52e9..d38f4fc1 100644 --- a/Fuyu.Backend.Core/Networking/CoreHttpController.cs +++ b/Fuyu.Backend.Core/Networking/CoreHttpController.cs @@ -19,10 +19,7 @@ protected CoreHttpController(string path) : base(path) public override Task RunAsync(HttpContext context) { - // NOTE: assumes HttpController can be safely downcasted into CoreHttpControler - // -- seionmoya, 2024-11-18 - var downcast = (CoreHttpContext)context; - + var downcast = new CoreHttpContext(context.Request, context.Response); return RunAsync(downcast); } diff --git a/Fuyu.Backend.EFT/Networking/EftHttpController.cs b/Fuyu.Backend.EFT/Networking/EftHttpController.cs index 7ace76dd..c6da930f 100644 --- a/Fuyu.Backend.EFT/Networking/EftHttpController.cs +++ b/Fuyu.Backend.EFT/Networking/EftHttpController.cs @@ -19,10 +19,7 @@ protected EftHttpController(string path) : base(path) public override Task RunAsync(HttpContext context) { - // NOTE: assumes HttpController can be safely downcasted into EftHttpControler - // -- seionmoya, 2024-11-18 - var downcast = (EftHttpContext)context; - + var downcast = new EftHttpContext(context.Request, context.Response); return RunAsync(downcast); } diff --git a/Fuyu.Common/Networking/WebRouterContext.cs b/Fuyu.Common/Networking/WebRouterContext.cs index 4fcef7b0..7f20591e 100644 --- a/Fuyu.Common/Networking/WebRouterContext.cs +++ b/Fuyu.Common/Networking/WebRouterContext.cs @@ -5,8 +5,8 @@ namespace Fuyu.Common.Networking { public class WebRouterContext : IRouterContext { - protected readonly HttpListenerRequest Request; - protected readonly HttpListenerResponse Response; + public readonly HttpListenerRequest Request; + public readonly HttpListenerResponse Response; public string Path { get; } public WebRouterContext(HttpListenerRequest request, HttpListenerResponse response) From 08f0bdf35b058166d20c47dd780e3022db84b8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=99=E7=A9=8F=E9=9D=84?= <170472707+seionmoya@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:59:32 +0100 Subject: [PATCH 5/5] Fix launcher<->backend comminucation --- Fuyu.Backend.Core/Networking/CoreHttpContext.cs | 2 +- Fuyu.Backend.EFT/Networking/EftHttpContext.cs | 2 +- Fuyu.Launcher.Core/Networking/CoreHttpClient.cs | 16 ---------------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Fuyu.Backend.Core/Networking/CoreHttpContext.cs b/Fuyu.Backend.Core/Networking/CoreHttpContext.cs index fa45295f..5da2df10 100644 --- a/Fuyu.Backend.Core/Networking/CoreHttpContext.cs +++ b/Fuyu.Backend.Core/Networking/CoreHttpContext.cs @@ -21,7 +21,7 @@ public override byte[] GetBinary() var body = ms.ToArray(); var encryption = GetEncryption(); - if (encryption != string.Empty) + if (!string.IsNullOrWhiteSpace(encryption)) { switch (encryption) { diff --git a/Fuyu.Backend.EFT/Networking/EftHttpContext.cs b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs index b360352c..0c26c59e 100644 --- a/Fuyu.Backend.EFT/Networking/EftHttpContext.cs +++ b/Fuyu.Backend.EFT/Networking/EftHttpContext.cs @@ -23,7 +23,7 @@ public override byte[] GetBinary() var body = ms.ToArray(); var encryption = GetEncryption(); - if (encryption != string.Empty) + if (!string.IsNullOrWhiteSpace(encryption)) { switch (encryption) { diff --git a/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs b/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs index fd8dfe36..1a31531a 100644 --- a/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs +++ b/Fuyu.Launcher.Core/Networking/CoreHttpClient.cs @@ -1,7 +1,6 @@ using System; using System.IO.Compression; using System.Net.Http; -using Fuyu.Common.Compression; namespace Fuyu.Launcher.Core.Networking { @@ -14,21 +13,6 @@ public CoreHttpClient(string address, string sessionId) : base(address) _sessionId = sessionId; } - protected override byte[] OnSendBody(byte[] body) - { - return MemoryZlib.Compress(body, CompressionLevel.SmallestSize); - } - - protected override byte[] OnReceiveBody(byte[] body) - { - if (MemoryZlib.IsCompressed(body)) - { - body = MemoryZlib.Decompress(body); - } - - return body; - } - protected override HttpRequestMessage GetNewRequest(HttpMethod method, string path) { var request = new HttpRequestMessage()