mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 14:11:29 +00:00
Fix vita slot counts
This commit is contained in:
parent
8eccfe316d
commit
740a7f7803
4 changed files with 48 additions and 17 deletions
|
@ -69,8 +69,13 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
[HttpGet("myFriends")]
|
||||
public async Task<IActionResult> MyFriends()
|
||||
{
|
||||
User? user = await this.database.UserFromRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
(User, Token)? userAndToken = await this.database.UserAndTokenFromRequest(this.Request);
|
||||
|
||||
if (userAndToken == null) return this.StatusCode(403, "");
|
||||
|
||||
// ReSharper disable once PossibleInvalidOperationException
|
||||
User user = userAndToken.Value.Item1;
|
||||
Token token = userAndToken.Value.Item2;
|
||||
|
||||
if (!FriendHelper.FriendIdsByUserId.TryGetValue(user.UserId, out int[]? friendIds) || friendIds == null)
|
||||
{
|
||||
|
@ -83,7 +88,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
User? friend = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.UserId == friendId);
|
||||
if (friend == null) continue;
|
||||
|
||||
friends += friend.Serialize();
|
||||
friends += friend.Serialize(token.GameVersion);
|
||||
}
|
||||
|
||||
return this.Ok(LbpSerializer.StringElement("myFriends", friends));
|
||||
|
|
|
@ -152,8 +152,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
#region Users
|
||||
|
||||
[HttpGet("favouriteUsers/{username}")]
|
||||
public IActionResult GetFavouriteUsers(string username)
|
||||
public async Task<IActionResult> GetFavouriteUsers(string username)
|
||||
{
|
||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
IEnumerable<HeartedProfile> heartedProfiles = this.database.HeartedProfiles.Include
|
||||
(q => q.User)
|
||||
.Include(q => q.HeartedUser)
|
||||
|
@ -161,7 +164,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
.Where(q => q.User.Username == username)
|
||||
.AsEnumerable();
|
||||
|
||||
string response = heartedProfiles.Aggregate(string.Empty, (current, q) => current + q.HeartedUser.Serialize());
|
||||
string response = heartedProfiles.Aggregate(string.Empty, (current, q) => current + q.HeartedUser.Serialize(token.GameVersion));
|
||||
|
||||
return this.Ok(LbpSerializer.TaggedStringElement("favouriteUsers", response, "total", 1));
|
||||
}
|
||||
|
|
|
@ -26,26 +26,35 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
this.database = database;
|
||||
}
|
||||
|
||||
public async Task<string> GetSerializedUser(string username)
|
||||
public async Task<string> GetSerializedUser(string username, GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
||||
{
|
||||
|
||||
User? user = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.Username == username);
|
||||
return user?.Serialize();
|
||||
return user?.Serialize(gameVersion);
|
||||
}
|
||||
|
||||
[HttpGet("user/{username}")]
|
||||
public async Task<IActionResult> GetUser(string username) {
|
||||
string? user = await this.GetSerializedUser(username);
|
||||
public async Task<IActionResult> GetUser(string username)
|
||||
{
|
||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
string? user = await this.GetSerializedUser(username, token.GameVersion);
|
||||
if (user == null) return this.NotFound();
|
||||
|
||||
return this.Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("users")]
|
||||
public async Task<IActionResult> GetUserAlt([FromQuery] string[] u)
|
||||
{
|
||||
Token? token = await this.database.TokenFromRequest(this.Request);
|
||||
if (token == null) return this.StatusCode(403, "");
|
||||
|
||||
List<string> serializedUsers = new();
|
||||
foreach (string userId in u)
|
||||
{
|
||||
serializedUsers.Add(await this.GetSerializedUser(userId));
|
||||
serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
|
||||
}
|
||||
|
||||
string serialized = serializedUsers.Aggregate(string.Empty, (current, u) => u == null ? current : current + u);
|
||||
|
|
|
@ -93,11 +93,11 @@ namespace LBPUnion.ProjectLighthouse.Types
|
|||
}
|
||||
}
|
||||
|
||||
public string Serialize()
|
||||
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
||||
{
|
||||
string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) +
|
||||
LbpSerializer.StringElement("game", this.Game) +
|
||||
this.SerializeSlots() +
|
||||
this.SerializeSlots(gameVersion == GameVersion.LittleBigPlanetVita) +
|
||||
LbpSerializer.StringElement("lists", this.Lists) +
|
||||
LbpSerializer.StringElement("lists_quota", ServerSettings.ListsQuota) + // technically not a part of the user but LBP expects it
|
||||
LbpSerializer.StringElement("biography", this.Biography) +
|
||||
|
@ -149,18 +149,32 @@ namespace LBPUnion.ProjectLighthouse.Types
|
|||
"lbp2", "lbp3", "crossControl",
|
||||
};
|
||||
|
||||
private string SerializeSlots()
|
||||
private string SerializeSlots(bool isVita = false)
|
||||
{
|
||||
string slots = string.Empty;
|
||||
|
||||
slots += LbpSerializer.StringElement("lbp1UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet1));
|
||||
slots += LbpSerializer.StringElement("lbp2UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet2));
|
||||
slots += LbpSerializer.StringElement("lbp3UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet3));
|
||||
string[] slotTypesLocal;
|
||||
|
||||
if (isVita)
|
||||
{
|
||||
slots += LbpSerializer.StringElement("lbp2UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanetVita));
|
||||
slotTypesLocal = new[]
|
||||
{
|
||||
"lbp2",
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
slots += LbpSerializer.StringElement("lbp1UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet1));
|
||||
slots += LbpSerializer.StringElement("lbp2UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet2));
|
||||
slots += LbpSerializer.StringElement("lbp3UsedSlots", this.GetUsedSlotsForGame(GameVersion.LittleBigPlanet3));
|
||||
slotTypesLocal = slotTypes;
|
||||
}
|
||||
|
||||
slots += LbpSerializer.StringElement("entitledSlots", ServerSettings.EntitledSlots);
|
||||
slots += LbpSerializer.StringElement("freeSlots", this.FreeSlots);
|
||||
|
||||
foreach (string slotType in slotTypes)
|
||||
foreach (string slotType in slotTypesLocal)
|
||||
{
|
||||
slots += LbpSerializer.StringElement(slotType + "EntitledSlots", ServerSettings.EntitledSlots);
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue