From 0ef87a61ff50fc5ff119e1d6f8ab1e6a2f142fa1 Mon Sep 17 00:00:00 2001 From: rpaciorek Date: Mon, 14 Aug 2023 12:36:33 +0000 Subject: [PATCH] basic support for 1.13.0 client (#15) - add GetUnselectedPetByTypes - block update avatar in calls SetAvatar from too old clients - add support for call GetUserProfileByUserID with viking apiToken --- README.md | 1 + mitm-redirect.py | 1 + src/Controllers/Common/ContentController.cs | 50 +++++++++++++++++++++ src/Controllers/Common/ProfileController.cs | 4 +- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4310174..1b30f3f 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Then run School of Dragons. - GetUserUpcomingMissionState - GetUserCompletedMissionState - GetChildList +- GetUnselectedPetByTypes - UseInventory #### Implemented enough (probably) diff --git a/mitm-redirect.py b/mitm-redirect.py index aee9f44..ceb71ae 100644 --- a/mitm-redirect.py +++ b/mitm-redirect.py @@ -66,6 +66,7 @@ methods = [ 'SetNextItemState', 'SetUserRoom', 'GetChildList', + 'GetUnselectedPetByTypes', 'GetUserGameCurrency', 'SetAchievementByEntityIDs', 'UseInventory' diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 78cc670..fc183f1 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -262,6 +262,23 @@ public class ContentController : Controller { }); } + AvatarData avatarData = XmlUtil.DeserializeXml(contentXML); + foreach (AvatarDataPart part in avatarData.Part) { + if (part.PartType == "Version") { + if (part.Offsets[0].X < 6 || part.Offsets[0].X == 6 && part.Offsets[0].Y < 1) { + // do not allow to save avatar data from old clients (avatar data version < 6.1) ... it's broke profile on 3.31 + // but return as true to trick the client to avoid re-show change viking name dialog + // TODO: maybe better set pair AvatarNameCustomizationDone -> 1 (in "2017" pairs) and return error here? + return Ok(new SetAvatarResult { + Success = true, + DisplayName = viking.Name, + StatusCode = AvatarValidationResult.Valid + }); + } + break; + } + } + viking.AvatarSerialized = contentXML; ctx.SaveChanges(); @@ -402,6 +419,39 @@ public class ContentController : Controller { return dragons; } + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/GetUnselectedPetByTypes")] + public RaisedPetData[]? GetUnselectedPetByTypes([FromForm] string apiToken, [FromForm] string petTypeIDs, [FromForm] bool active) { + Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking; + if (viking is null) { + return null; + } + + RaisedPetData[] dragons = viking.Dragons + .Where(d => d.RaisedPetData is not null) + .Select(GetRaisedPetDataFromDragon) + .ToArray(); + + if (dragons.Length == 0) { + return null; + } + + List filteredDragons = new List(); + int[] petTypeIDsInt = Array.ConvertAll(petTypeIDs.Split(','), s => int.Parse(s)); + foreach (RaisedPetData dragon in dragons) { + if (petTypeIDsInt.Contains(dragon.PetTypeID)) { + filteredDragons.Add(dragon); + } + } + + if (filteredDragons.Count == 0) { + return null; + } + + return filteredDragons.ToArray(); + } + [HttpPost] [Produces("application/xml")] [Route("ContentWebService.asmx/GetSelectedRaisedPet")] diff --git a/src/Controllers/Common/ProfileController.cs b/src/Controllers/Common/ProfileController.cs index cdfd7d5..4f8df71 100644 --- a/src/Controllers/Common/ProfileController.cs +++ b/src/Controllers/Common/ProfileController.cs @@ -16,8 +16,8 @@ public class ProfileController : Controller { [Produces("application/xml")] [Route("ProfileWebService.asmx/GetUserProfileByUserID")] public IActionResult GetUserProfileByUserID([FromForm] string apiToken, [FromForm] string userId) { - User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User; - if (user is null) { + Session session = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken); + if (session?.User is null && session?.Viking is null) { // TODO: what response for not logged in? return Ok(); }