diff --git a/README.md b/README.md index 847b040..8515af4 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Almost everything: - GetDefaultNameSuggestion - GetDetailedChildList - GetGameData +- GetGameDataByUser - GetImage - GetImageByUserId - GetItem diff --git a/mitm-redirect.py b/mitm-redirect.py index 360a213..fa938f2 100644 --- a/mitm-redirect.py +++ b/mitm-redirect.py @@ -84,6 +84,7 @@ methods = [ 'SendRawGameData', 'GetGameData', 'GetGameDataByGame', + 'GetGameDataByUser', 'GetGameDataByGameForDateRange', 'GetTopAchievementPointUsers', 'SetDisplayName', diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index d6cd09c..7c674d8 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -2076,6 +2076,14 @@ public class ContentController : Controller { public IActionResult GetGameDataByGame(Viking viking, [FromForm] int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, int score, bool buddyFilter, string apiKey) { return Ok(gameDataService.GetGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey)); } + + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/GetGameDataByUser")] // used in My Scores + [VikingSession(UseLock = true)] + public IActionResult GetGameDataByUser(Viking viking, [FromForm] int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, string apiKey) { + return Ok(gameDataService.GetGameDataByUser(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, apiKey)); + } [HttpPost] [Produces("application/xml")] diff --git a/src/Services/GameDataService.cs b/src/Services/GameDataService.cs index 5c64e0e..8814586 100644 --- a/src/Services/GameDataService.cs +++ b/src/Services/GameDataService.cs @@ -14,8 +14,11 @@ public class GameDataService { } public bool SaveGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string xmlDocumentData, bool win, bool loss) { + //TODO: save only unique scores; scores that the player hasn't hit yet, probably keep old date for existing scores + //or don't if you want ultra-unique scores (overwriting even the old score) Model.GameData? gameData = viking.GameData.FirstOrDefault(x => x.GameId == gameId && x.IsMultiplayer == isMultiplayer && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.Win == win && x.Loss == loss); - if (gameData == null) { + + if (gameData == null) { //comment this check to turn off ultra-unique scores (for now) gameData = new Model.GameData { GameId = gameId, IsMultiplayer = isMultiplayer, @@ -33,39 +36,46 @@ public class GameDataService { ctx.SaveChanges(); return true; } + + List GameDataResponseToList(IQueryable originalQuery, string key, int count, bool AscendingOrder, string apiKey) { + var query = originalQuery.SelectMany(e => e.GameDataPairs) + .Where(x => x.Name == key); + + if (AscendingOrder) + query = query.OrderBy(e => e.Value); + else + query = query.OrderByDescending(e => e.Value); + + uint gameVersion = ClientVersion.GetVersion(apiKey); + if (gameVersion <= ClientVersion.Max_OldJS) + // use DisplayName instead of Name + return query.Select(e => new GameDataResponse( + XmlUtil.DeserializeXml(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) + ).Take(count).ToList(); + else + return query.Select(e => new GameDataResponse( + e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) + ).Take(count).ToList(); + } public GameDataSummary GetGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey, DateTime? startDate = null, DateTime? endDate = null) { - // TODO: Buddy filter - List selectedData; IQueryable query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel); + + // TODO: Buddy filter if (startDate != null && endDate != null) query = query.Where(x => x.DatePlayed >= startDate.Value.ToUniversalTime() && x.DatePlayed <= endDate.Value.AddMinutes(2).ToUniversalTime()); - var query2 = query.SelectMany(e => e.GameDataPairs) - .Where(x => x.Name == key); + List selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey); - uint gameVersion = ClientVersion.GetVersion(apiKey); - if (gameVersion <= ClientVersion.Max_OldJS) { - // use DisplayName instead of Name - if (AscendingOrder) - selectedData = query2.OrderBy(e => e.Value).Select(e => new GameDataResponse( - XmlUtil.DeserializeXml(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) - ).Take(count).ToList(); - else - selectedData = query2.OrderByDescending(e => e.Value).Select(e => new GameDataResponse( - XmlUtil.DeserializeXml(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) - ).Take(count).ToList(); - } else { - if (AscendingOrder) - selectedData = query2.OrderBy(e => e.Value).Select(e => new GameDataResponse( - e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) - ).Take(count).ToList(); - else - selectedData = query2.OrderByDescending(e => e.Value).Select(e => new GameDataResponse( - e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, e.GameData.Win, e.GameData.Loss, e.Value) - ).Take(count).ToList(); - } + return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData); + } + + // ByUser for JumpStart's My Scores + public GameDataSummary GetGameDataByUser(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, string apiKey) { + IQueryable query = ctx.GameData.Where(x => x.GameId == gameId && x.IsMultiplayer == false && x.Difficulty == difficulty && x.GameLevel == gameLevel && x.VikingId == viking.Id); + + List selectedData = GameDataResponseToList(query, key, count, AscendingOrder, apiKey); return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData); }