mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 07:58:40 +00:00
parent
489da20395
commit
36ce61697f
4 changed files with 122 additions and 14 deletions
|
@ -61,8 +61,13 @@ public class UserController : ControllerBase
|
|||
[HttpPost("updateUser")]
|
||||
public async Task<IActionResult> UpdateUser()
|
||||
{
|
||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
(User, GameToken)? userAndToken = await this.database.UserAndGameTokenFromRequest(this.Request);
|
||||
|
||||
if (userAndToken == null) return this.StatusCode(403, "");
|
||||
|
||||
// ReSharper disable once PossibleInvalidOperationException
|
||||
User user = userAndToken.Value.Item1;
|
||||
GameToken gameToken = userAndToken.Value.Item2;
|
||||
|
||||
XmlReaderSettings settings = new()
|
||||
{
|
||||
|
@ -121,7 +126,32 @@ public class UserController : ControllerBase
|
|||
}
|
||||
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;
|
||||
}
|
||||
case "yay2":
|
||||
|
@ -129,16 +159,16 @@ public class UserController : ControllerBase
|
|||
user.YayHash = await reader.GetValueAsync();
|
||||
break;
|
||||
}
|
||||
case "boo2":
|
||||
{
|
||||
user.BooHash = await reader.GetValueAsync();
|
||||
break;
|
||||
}
|
||||
case "meh2":
|
||||
{
|
||||
user.MehHash = await reader.GetValueAsync();
|
||||
break;
|
||||
}
|
||||
case "boo2":
|
||||
{
|
||||
user.BooHash = await reader.GetValueAsync();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -687,7 +687,13 @@ namespace ProjectLighthouse.Migrations
|
|||
b.Property<string>("Pins")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PlanetHash")
|
||||
b.Property<string>("PlanetHashLBP2")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PlanetHashLBP3")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PlanetHashLBPVita")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Username")
|
||||
|
|
|
@ -123,7 +123,13 @@ public class User
|
|||
public string Pins { get; set; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public string PlanetHash { get; set; } = "";
|
||||
public string PlanetHashLBP2 { get; set; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public string PlanetHashLBP3 { get; set; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public string PlanetHashLBPVita { get; set; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public int Hearts {
|
||||
|
@ -170,8 +176,8 @@ public class User
|
|||
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
||||
{
|
||||
string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) +
|
||||
LbpSerializer.StringElement("game", this.Game) +
|
||||
this.SerializeSlots(gameVersion) +
|
||||
LbpSerializer.StringElement("game", (int)gameVersion) +
|
||||
this.serializeSlots(gameVersion) +
|
||||
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("biography", this.Biography) +
|
||||
|
@ -185,7 +191,7 @@ public class User
|
|||
LbpSerializer.StringElement("favouriteUserCount", this.HeartedUsers) +
|
||||
LbpSerializer.StringElement("lolcatftwCount", this.QueuedLevels) +
|
||||
LbpSerializer.StringElement("pins", this.Pins) +
|
||||
LbpSerializer.StringElement("planets", this.PlanetHash) +
|
||||
serializeEarth(gameVersion) +
|
||||
LbpSerializer.BlankElement("photos") +
|
||||
LbpSerializer.StringElement("heartCount", this.Hearts) +
|
||||
LbpSerializer.StringElement("yay2", this.YayHash) +
|
||||
|
@ -195,6 +201,21 @@ public class 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
|
||||
|
||||
/// <summary>
|
||||
|
@ -226,7 +247,7 @@ public class User
|
|||
"lbp2", "lbp3", "crossControl",
|
||||
};
|
||||
|
||||
private string SerializeSlots(GameVersion gameVersion)
|
||||
private string serializeSlots(GameVersion gameVersion)
|
||||
{
|
||||
string slots = string.Empty;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue