diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 08168c6..2c52423 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -2126,7 +2126,7 @@ public class ContentController : Controller { [Route("ContentWebService.asmx/GetPeriodicGameDataByGame")] // used by Math Blaster and WoJS (probably from 24 hours ago to now) [VikingSession(UseLock = true)] public IActionResult GetPeriodicGameDataByGame(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.GetDailyGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey)); + return Ok(gameDataService.GetGameData(viking, gameId, isMultiplayer, difficulty, gameLevel, key, count, AscendingOrder, buddyFilter, apiKey, DateTime.Now.AddHours(-24), DateTime.Now)); } [HttpPost] diff --git a/src/Model/GameDataPair.cs b/src/Model/GameDataPair.cs index 7e029e5..9543936 100644 --- a/src/Model/GameDataPair.cs +++ b/src/Model/GameDataPair.cs @@ -7,6 +7,5 @@ public class GameDataPair { public int GameDataId { get; set; } public string Name { get; set; } = null!; public int Value { get; set; } - public int DailyValue { get; set; } public virtual GameData GameData { get; set; } = null!; } diff --git a/src/Services/GameDataService.cs b/src/Services/GameDataService.cs index 2faa29a..cd18f2d 100644 --- a/src/Services/GameDataService.cs +++ b/src/Services/GameDataService.cs @@ -31,9 +31,9 @@ public class GameDataService { viking.GameData.Add(gameData); } - - SavePairs(gameData, xmlDocumentData); gameData.DatePlayed = DateTime.UtcNow; + SavePairs(gameData, xmlDocumentData); + ctx.SaveChanges(); return true; @@ -72,33 +72,6 @@ public class GameDataService { return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData); } - - public GameDataSummary GetDailyGameData(Viking viking, int gameId, bool isMultiplayer, int difficulty, int gameLevel, string key, int count, bool AscendingOrder, bool buddyFilter, string apiKey) { - IQueryable query = ctx.GameData - .Where(x => - x.GameId == gameId && x.IsMultiplayer == false && - x.Difficulty == difficulty && x.GameLevel == gameLevel && - x.DatePlayed.Date == DateTime.UtcNow.Date - ).SelectMany(e => e.GameDataPairs).Where(x => x.Name == key); - - // TODO: Buddy filter - - if (AscendingOrder) query = query.OrderBy(e => e.Value); - else query = query.OrderByDescending(e => e.Value); - - List selectedData; - if (ClientVersion.GetVersion(apiKey) <= ClientVersion.Max_OldJS) - // use DisplayName instead of Name - selectedData = query.Select(e => new GameDataResponse( - XmlUtil.DeserializeXml(e.GameData.Viking.AvatarSerialized).DisplayName, e.GameData.Viking.Uid, e.GameData.DatePlayed, false, false, e.DailyValue) - ).Take(count).ToList(); - else - selectedData = query.Select(e => new GameDataResponse( - e.GameData.Viking.Name, e.GameData.Viking.Uid, e.GameData.DatePlayed, false, false, e.DailyValue) - ).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) { @@ -170,20 +143,12 @@ public class GameDataService { private void SavePairs(Model.GameData gameData, string xmlDocumentData) { foreach (var pair in GetGameDataPairs(xmlDocumentData)) { GameDataPair? dbPair = gameData.GameDataPairs.FirstOrDefault(x => x.Name == pair.Name); - - // If Name == "time" then (existing <= incoming) needs to be false (effectively (existing > incoming), as time should function). - // if Name is anything else, then second condition as normal. - bool newBest = (dbPair == null) || ((pair.Name == "time") != (dbPair.Value <= pair.Value)); - - if (dbPair == null) { + if (dbPair == null) gameData.GameDataPairs.Add(pair); - dbPair = pair; - } else if (newBest) dbPair.Value = pair.Value; - - if ( - newBest || // Surpassed Score (or Unset) - gameData.DatePlayed.Date != DateTime.UtcNow.Date // Another Day - ) dbPair.DailyValue = pair.Value; + else if (pair.Name == "time" && dbPair.Value > pair.Value) + dbPair.Value = pair.Value; + else if (pair.Name != "time" && dbPair.Value <= pair.Value) + dbPair.Value = pair.Value; } }