Separate LBP2/3/V earth decorations

Closes #66
This commit is contained in:
jvyden 2022-02-16 18:10:18 -05:00
commit 36ce61697f
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 122 additions and 14 deletions

View file

@ -61,8 +61,13 @@ public class UserController : ControllerBase
[HttpPost("updateUser")] [HttpPost("updateUser")]
public async Task<IActionResult> UpdateUser() public async Task<IActionResult> UpdateUser()
{ {
User? user = await this.database.UserFromGameRequest(this.Request); (User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
if (userAndToken == null) return this.StatusCode(403, "");
// ReSharper disable once PossibleInvalidOperationException
User user = userAndToken.Value.Item1;
GameToken gameToken = userAndToken.Value.Item2;
XmlReaderSettings settings = new() XmlReaderSettings settings = new()
{ {
@ -121,7 +126,32 @@ public class UserController : ControllerBase
} }
case "planets": case "planets":
{ {
user.PlanetHash = await reader.GetValueAsync(); switch (gameToken.GameVersion)
{
case GameVersion.LittleBigPlanet2: // LBP2 planets will apply to LBP3
{
user.PlanetHashLBP2 = await reader.GetValueAsync();
user.PlanetHashLBP3 = await reader.GetValueAsync();
break;
}
case GameVersion.LittleBigPlanet3: // LBP3 and vita can only apply to their own games, only set 1 here
{
user.PlanetHashLBP3 = await reader.GetValueAsync();
break;
}
case GameVersion.LittleBigPlanetVita:
{
user.PlanetHashLBPVita = await reader.GetValueAsync();
break;
}
case GameVersion.LittleBigPlanet1:
case GameVersion.LittleBigPlanetPSP:
case GameVersion.Unknown:
default: // The rest do not support custom earths.
{
throw new ArgumentException($"invalid gameVersion {gameToken.GameVersion} for setting earth");
}
}
break; break;
} }
case "yay2": case "yay2":
@ -129,16 +159,16 @@ public class UserController : ControllerBase
user.YayHash = await reader.GetValueAsync(); user.YayHash = await reader.GetValueAsync();
break; break;
} }
case "boo2":
{
user.BooHash = await reader.GetValueAsync();
break;
}
case "meh2": case "meh2":
{ {
user.MehHash = await reader.GetValueAsync(); user.MehHash = await reader.GetValueAsync();
break; break;
} }
case "boo2":
{
user.BooHash = await reader.GetValueAsync();
break;
}
} }
break; break;

View file

@ -0,0 +1,51 @@
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ProjectLighthouse.Migrations
{
[DbContext(typeof(Database))]
[Migration("20220216230824_AddEarthHashesForAllGames")]
public partial class AddEarthHashesForAllGames : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "PlanetHash",
table: "Users",
newName: "PlanetHashLBP2");
migrationBuilder.AddColumn<string>(
name: "PlanetHashLBP3",
table: "Users",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "PlanetHashLBPVita",
table: "Users",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PlanetHashLBP2",
table: "Users");
migrationBuilder.DropColumn(
name: "PlanetHashLBP3",
table: "Users");
migrationBuilder.RenameColumn(
name: "PlanetHashLBPVita",
table: "Users",
newName: "PlanetHash");
}
}
}

View file

@ -687,7 +687,13 @@ namespace ProjectLighthouse.Migrations
b.Property<string>("Pins") b.Property<string>("Pins")
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<string>("PlanetHash") b.Property<string>("PlanetHashLBP2")
.HasColumnType("longtext");
b.Property<string>("PlanetHashLBP3")
.HasColumnType("longtext");
b.Property<string>("PlanetHashLBPVita")
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<string>("Username") b.Property<string>("Username")

View file

@ -123,7 +123,13 @@ public class User
public string Pins { get; set; } = ""; public string Pins { get; set; } = "";
[JsonIgnore] [JsonIgnore]
public string PlanetHash { get; set; } = ""; public string PlanetHashLBP2 { get; set; } = "";
[JsonIgnore]
public string PlanetHashLBP3 { get; set; } = "";
[JsonIgnore]
public string PlanetHashLBPVita { get; set; } = "";
[JsonIgnore] [JsonIgnore]
public int Hearts { public int Hearts {
@ -170,8 +176,8 @@ public class User
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1) public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
{ {
string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) + string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) +
LbpSerializer.StringElement("game", this.Game) + LbpSerializer.StringElement("game", (int)gameVersion) +
this.SerializeSlots(gameVersion) + this.serializeSlots(gameVersion) +
LbpSerializer.StringElement("lists", this.Lists) + LbpSerializer.StringElement("lists", this.Lists) +
LbpSerializer.StringElement("lists_quota", ServerSettings.Instance.ListsQuota) + // technically not a part of the user but LBP expects it LbpSerializer.StringElement("lists_quota", ServerSettings.Instance.ListsQuota) + // technically not a part of the user but LBP expects it
LbpSerializer.StringElement("biography", this.Biography) + LbpSerializer.StringElement("biography", this.Biography) +
@ -185,7 +191,7 @@ public class User
LbpSerializer.StringElement("favouriteUserCount", this.HeartedUsers) + LbpSerializer.StringElement("favouriteUserCount", this.HeartedUsers) +
LbpSerializer.StringElement("lolcatftwCount", this.QueuedLevels) + LbpSerializer.StringElement("lolcatftwCount", this.QueuedLevels) +
LbpSerializer.StringElement("pins", this.Pins) + LbpSerializer.StringElement("pins", this.Pins) +
LbpSerializer.StringElement("planets", this.PlanetHash) + serializeEarth(gameVersion) +
LbpSerializer.BlankElement("photos") + LbpSerializer.BlankElement("photos") +
LbpSerializer.StringElement("heartCount", this.Hearts) + LbpSerializer.StringElement("heartCount", this.Hearts) +
LbpSerializer.StringElement("yay2", this.YayHash) + LbpSerializer.StringElement("yay2", this.YayHash) +
@ -195,6 +201,21 @@ public class User
return LbpSerializer.TaggedStringElement("user", user, "type", "user"); return LbpSerializer.TaggedStringElement("user", user, "type", "user");
} }
private string serializeEarth(GameVersion gameVersion)
{
return LbpSerializer.StringElement
(
"planets",
gameVersion switch
{
GameVersion.LittleBigPlanet2 => PlanetHashLBP2,
GameVersion.LittleBigPlanet3 => PlanetHashLBP3,
GameVersion.LittleBigPlanetVita => PlanetHashLBPVita,
_ => "", // other versions do not have custom planets
}
);
}
#region Slots #region Slots
/// <summary> /// <summary>
@ -226,7 +247,7 @@ public class User
"lbp2", "lbp3", "crossControl", "lbp2", "lbp3", "crossControl",
}; };
private string SerializeSlots(GameVersion gameVersion) private string serializeSlots(GameVersion gameVersion)
{ {
string slots = string.Empty; string slots = string.Empty;