mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-11 06:18:39 +00:00
Merge remote-tracking branch 'lighthouse/main' into playlists
# Conflicts: # ProjectLighthouse/PlayerData/Profiles/User.cs
This commit is contained in:
commit
1d4d143519
87 changed files with 1223 additions and 208 deletions
|
@ -53,8 +53,11 @@ public class ListController : ControllerBase
|
|||
|
||||
return this.Ok
|
||||
(
|
||||
LbpSerializer.TaggedStringElement
|
||||
("slots", response, "total", this.database.QueuedLevels.Include(q => q.User).Count(q => q.User.Username == username))
|
||||
LbpSerializer.TaggedStringElement("slots", response, new Dictionary<string, object>
|
||||
{
|
||||
{ "total", await this.database.QueuedLevels.CountAsync(q => q.UserId == token.UserId) },
|
||||
{ "hint_start", pageStart + Math.Min(pageSize, 30) },
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -136,7 +139,7 @@ public class ListController : ControllerBase
|
|||
(
|
||||
LbpSerializer.TaggedStringElement("favouriteSlots", response, new Dictionary<string, object>
|
||||
{
|
||||
{ "total", this.database.HeartedLevels.Count(q => q.UserId == targetUser.UserId) },
|
||||
{ "total", await this.database.HeartedLevels.CountAsync(q => q.UserId == targetUser.UserId) },
|
||||
{ "hint_start", pageStart + Math.Min(pageSize, 30) },
|
||||
})
|
||||
);
|
||||
|
@ -225,7 +228,7 @@ public class ListController : ControllerBase
|
|||
(
|
||||
LbpSerializer.TaggedStringElement("favouriteUsers", response, new Dictionary<string, object>
|
||||
{
|
||||
{ "total", this.database.HeartedProfiles.Count(q => q.UserId == targetUser.UserId) },
|
||||
{ "total", await this.database.HeartedProfiles.CountAsync(q => q.UserId == targetUser.UserId) },
|
||||
{ "hint_start", pageStart + Math.Min(pageSize, 30) },
|
||||
})
|
||||
);
|
||||
|
|
|
@ -40,7 +40,8 @@ public class PublishController : ControllerBase
|
|||
GameToken gameToken = userAndToken.Value.Item2;
|
||||
|
||||
Slot? slot = await this.getSlotFromBody();
|
||||
if (slot == null) {
|
||||
if (slot == null)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, slot is null", LogArea.Publish);
|
||||
return this.BadRequest(); // if the level cant be parsed then it obviously cant be uploaded
|
||||
}
|
||||
|
@ -135,10 +136,21 @@ public class PublishController : ControllerBase
|
|||
return this.BadRequest();
|
||||
}
|
||||
|
||||
if (rootLevel.FileType != LbpFileType.Level)
|
||||
if (!slot.IsAdventurePlanet)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, rootLevel is not a level", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
if (rootLevel.FileType != LbpFileType.Level)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, rootLevel is not a level", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rootLevel.FileType != LbpFileType.Adventure)
|
||||
{
|
||||
Logger.Warn("Rejecting level upload, rootLevel is not a LBP 3 Adventure", LogArea.Publish);
|
||||
return this.BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
GameVersion slotVersion = FileHelper.ParseLevelVersion(rootLevel);
|
||||
|
@ -232,7 +244,7 @@ public class PublishController : ControllerBase
|
|||
|
||||
this.database.Slots.Add(slot);
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
|
||||
if (user.LevelVisibility == PrivacyType.All)
|
||||
{
|
||||
await WebhookHelper.SendWebhook("New level published!",
|
||||
|
|
|
@ -26,7 +26,8 @@ public class ScoreController : ControllerBase
|
|||
}
|
||||
|
||||
[HttpPost("scoreboard/{slotType}/{id:int}")]
|
||||
public async Task<IActionResult> SubmitScore(string slotType, int id, [FromQuery] bool lbp1 = false, [FromQuery] bool lbp2 = false, [FromQuery] bool lbp3 = false)
|
||||
[HttpPost("scoreboard/{slotType}/{id:int}/{childId:int}")]
|
||||
public async Task<IActionResult> SubmitScore(string slotType, int id, int childId, [FromQuery] bool lbp1 = false, [FromQuery] bool lbp2 = false, [FromQuery] bool lbp3 = false)
|
||||
{
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
@ -78,6 +79,7 @@ public class ScoreController : ControllerBase
|
|||
if (slotType == "developer") id = await SlotHelper.GetPlaceholderSlotId(this.database, id, SlotType.Developer);
|
||||
|
||||
score.SlotId = id;
|
||||
score.ChildSlotId = childId;
|
||||
|
||||
Slot? slot = this.database.Slots.FirstOrDefault(s => s.SlotId == score.SlotId);
|
||||
if (slot == null)
|
||||
|
@ -116,12 +118,13 @@ public class ScoreController : ControllerBase
|
|||
Type = score.Type,
|
||||
Points = score.Points,
|
||||
SlotId = score.SlotId,
|
||||
ChildSlotId = score.ChildSlotId,
|
||||
};
|
||||
|
||||
IQueryable<Score> existingScore = this.database.Scores.Where(s => s.SlotId == playerScore.SlotId)
|
||||
.Where(s => s.PlayerIdCollection == playerScore.PlayerIdCollection)
|
||||
.Where(s => s.Type == playerScore.Type);
|
||||
|
||||
.Where(s => s.ChildSlotId == 0 || s.ChildSlotId == childId)
|
||||
.Where(s => s.PlayerIdCollection == playerScore.PlayerIdCollection)
|
||||
.Where(s => s.Type == playerScore.Type);
|
||||
if (existingScore.Any())
|
||||
{
|
||||
Score first = existingScore.First(s => s.SlotId == playerScore.SlotId);
|
||||
|
@ -137,13 +140,14 @@ public class ScoreController : ControllerBase
|
|||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
string myRanking = this.getScores(score.SlotId, score.Type, username, -1, 5, "scoreboardSegment");
|
||||
string myRanking = this.getScores(score.SlotId, score.Type, username, -1, 5, "scoreboardSegment", childId: score.ChildSlotId);
|
||||
|
||||
return this.Ok(myRanking);
|
||||
}
|
||||
|
||||
[HttpGet("friendscores/{slotType}/{slotId:int}/{type:int}")]
|
||||
public async Task<IActionResult> FriendScores(string slotType, int slotId, int type, [FromQuery] int pageStart = -1, [FromQuery] int pageSize = 5)
|
||||
[HttpGet("friendscores/{slotType}/{slotId:int}/{childId:int}/{type:int}")]
|
||||
public async Task<IActionResult> FriendScores(string slotType, int slotId, int? childId, int type, [FromQuery] int pageStart = -1, [FromQuery] int pageSize = 5)
|
||||
{
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
@ -169,12 +173,13 @@ public class ScoreController : ControllerBase
|
|||
if (friendUsername != null) friendNames.Add(friendUsername);
|
||||
}
|
||||
|
||||
return this.Ok(this.getScores(slotId, type, username, pageStart, pageSize, "scores", friendNames.ToArray()));
|
||||
return this.Ok(this.getScores(slotId, type, username, pageStart, pageSize, "scores", friendNames.ToArray(), childId));
|
||||
}
|
||||
|
||||
[HttpGet("topscores/{slotType}/{slotId:int}/{type:int}")]
|
||||
[HttpGet("topscores/{slotType}/{slotId:int}/{childId:int}/{type:int}")]
|
||||
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
||||
public async Task<IActionResult> TopScores(string slotType, int slotId, int type, [FromQuery] int pageStart = -1, [FromQuery] int pageSize = 5)
|
||||
public async Task<IActionResult> TopScores(string slotType, int slotId, int? childId, int type, [FromQuery] int pageStart = -1, [FromQuery] int pageSize = 5)
|
||||
{
|
||||
GameToken? token = await this.database.GameTokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
@ -187,7 +192,7 @@ public class ScoreController : ControllerBase
|
|||
|
||||
if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer);
|
||||
|
||||
return this.Ok(this.getScores(slotId, type, username, pageStart, pageSize));
|
||||
return this.Ok(this.getScores(slotId, type, username, pageStart, pageSize, childId: childId));
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
||||
|
@ -199,7 +204,8 @@ public class ScoreController : ControllerBase
|
|||
int pageStart = -1,
|
||||
int pageSize = 5,
|
||||
string rootName = "scores",
|
||||
string[]? playerIds = null
|
||||
string[]? playerIds = null,
|
||||
int? childId = 0
|
||||
)
|
||||
{
|
||||
|
||||
|
@ -207,8 +213,9 @@ public class ScoreController : ControllerBase
|
|||
// var needed for Anonymous type returned from SELECT
|
||||
var rankedScores = this.database.Scores
|
||||
.Where(s => s.SlotId == slotId && s.Type == type)
|
||||
.AsEnumerable()
|
||||
.Where(s => s.ChildSlotId == 0 || s.ChildSlotId == childId)
|
||||
.Where(s => playerIds == null || playerIds.Any(id => s.PlayerIdCollection.Contains(id)))
|
||||
.AsEnumerable()
|
||||
.OrderByDescending(s => s.Points)
|
||||
.ThenBy(s => s.ScoreId)
|
||||
.ToList()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue