highscore fixes

This commit is contained in:
Spirtix 2023-11-26 16:01:39 +01:00
parent c5bc21e539
commit 385449c1e7
5 changed files with 88 additions and 6 deletions

View File

@ -82,6 +82,7 @@ methods = [
'ApplyPayout', 'ApplyPayout',
'RedeemMysteryBoxItems', 'RedeemMysteryBoxItems',
'SendRawGameData', 'SendRawGameData',
'GetGameData',
'GetGameDataByGame', 'GetGameDataByGame',
'GetGameDataByGameForDateRange', 'GetGameDataByGameForDateRange',
'GetTopAchievementPointUsers', 'GetTopAchievementPointUsers',

View File

@ -949,9 +949,10 @@ public class ContentController : Controller {
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("V2/ContentWebService.asmx/GetGameData")] [Route("V2/ContentWebService.asmx/GetGameData")]
public IActionResult GetGameData() { [VikingSession]
// TODO: This is a placeholder public IActionResult GetGameData(Viking viking, [FromForm] string gameDataRequest) {
return Ok(new GetGameDataResponse()); GetGameDataRequest request = XmlUtil.DeserializeXml<GetGameDataRequest>(gameDataRequest);
return Ok(gameDataService.GetGameDataForPlayer(viking, request));
} }
[HttpPost] [HttpPost]

View File

@ -0,0 +1,48 @@
using System.Xml.Serialization;
namespace sodoff.Schema;
[XmlRoot(ElementName = "GetGameDataRequest", Namespace = "")]
[Serializable]
public class GetGameDataRequest {
[XmlElement(ElementName = "ProductGroupID")]
public int? ProductGroupID { get; set; }
[XmlElement(ElementName = "UserID")]
public Guid? UserID { get; set; }
[XmlElement(ElementName = "GameID")]
public int? GameID { get; set; }
[XmlElement(ElementName = "GameLevelID")]
public int? GameLevelID { get; set; }
[XmlElement(ElementName = "DifficultlyID")]
public int? DifficultlyID { get; set; }
[XmlElement(ElementName = "IsMultiplayer")]
public bool? IsMultiplayer { get; set; }
[XmlElement(ElementName = "TopScoresOnly")]
public bool? TopScoresOnly { get; set; }
[XmlElement(ElementName = "AllProductGroups")]
public bool? AllProductGroups { get; set; }
[XmlElement(ElementName = "AllUsers")]
public bool? AllUsers { get; set; }
[XmlElement(ElementName = "KEY")]
public string Key { get; set; }
[XmlElement(ElementName = "CNT")]
public int? Count { get; set; }
[XmlElement(ElementName = "SC")]
public int? Score { get; set; }
[XmlElement(ElementName = "AO")]
public bool? AscendingOrder { get; set; }
[XmlElement(ElementName = "FBIDS")]
public List<long> FacebookUserIDs { get; set; }
}

View File

@ -4,6 +4,7 @@ namespace sodoff.Schema;
[XmlRoot(ElementName = "GetGameDataResponse", Namespace = "")] [XmlRoot(ElementName = "GetGameDataResponse", Namespace = "")]
[Serializable] [Serializable]
public class GetGameDataResponse public class GetGameDataResponse {
{ [XmlElement(ElementName = "GameDataSummaryList")]
public List<GameDataSummary> GameDataSummaryList { get; set; } = new List<GameDataSummary>();
} }

View File

@ -55,6 +55,37 @@ public class GameDataService {
return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData); return GetSummaryFromResponse(viking, isMultiplayer, difficulty, gameLevel, key, selectedData);
} }
public GetGameDataResponse GetGameDataForPlayer(Viking viking, GetGameDataRequest request) {
GetGameDataResponse response = new();
if (request.GameID is null)
return response;
var dbData = viking.GameData.Where(x => x.GameId == request.GameID)
.SelectMany(e => e.GameDataPairs)
.Select(x => new { x.Name, x.Value, x.GameData.DatePlayed, x.GameData.Win, x.GameData.Loss, x.GameData.IsMultiplayer, x.GameData.Difficulty, x.GameData.GameLevel });
foreach (var data in dbData) {
response.GameDataSummaryList.Add(new GameDataSummary {
GameID = (int)request.GameID,
IsMultiplayer = data.IsMultiplayer,
Difficulty = data.Difficulty,
GameLevel = data.GameLevel,
Key = data.Name,
GameDataList = new Schema.GameData[] {
new Schema.GameData {
IsMember = true,
Value = data.Value,
DatePlayed = data.DatePlayed,
Win = data.Win ? 1 : 0,
Loss = data.Loss ? 1 : 0,
UserID = viking.Uid
}
}
});
}
return response;
}
private GameDataSummary GetSummaryFromResponse(Viking viking, bool isMultiplayer, int difficulty, int gameLevel, string key, List<GameDataResponse> selectedData) { private GameDataSummary GetSummaryFromResponse(Viking viking, bool isMultiplayer, int difficulty, int gameLevel, string key, List<GameDataResponse> selectedData) {
GameDataSummary gameData = new(); GameDataSummary gameData = new();
gameData.IsMultiplayer = isMultiplayer; gameData.IsMultiplayer = isMultiplayer;
@ -87,7 +118,7 @@ public class GameDataService {
GameDataPair? dbPair = gameData.GameDataPairs.FirstOrDefault(x => x.Name == pair.Name); GameDataPair? dbPair = gameData.GameDataPairs.FirstOrDefault(x => x.Name == pair.Name);
if (dbPair == null) if (dbPair == null)
gameData.GameDataPairs.Add(pair); gameData.GameDataPairs.Add(pair);
else else if (dbPair.Value <= pair.Value)
dbPair.Value = pair.Value; dbPair.Value = pair.Value;
} }
} }