From 7614f1990749b155dc4c4483444a8fd9f18d89e3 Mon Sep 17 00:00:00 2001 From: FridiNaTor1 <32988388+FridiNaTor1@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:15:22 +0000 Subject: [PATCH 01/32] Added missing LBP 1, 2 and 3 title ids (#126) * Added missing LBP 1, 2 and 3 title ids Added missing Title IDs, these fixes LBP 2 from only showing LBP 1 levels, and reporting as LBP 1 on the server. And fixes LBP 3 from crashing. * Fix formatting * Tabs -> Spaces Co-authored-by: jvyden --- ProjectLighthouse/Helpers/GameVersionHelper.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Helpers/GameVersionHelper.cs b/ProjectLighthouse/Helpers/GameVersionHelper.cs index a1104644..f787a92b 100644 --- a/ProjectLighthouse/Helpers/GameVersionHelper.cs +++ b/ProjectLighthouse/Helpers/GameVersionHelper.cs @@ -26,6 +26,7 @@ public class GameVersionHelper "NPEA00147", "NPHG00033", "NPHG00035", + "NPEA00241", }; // https://serialstation.com/games/35e69aba-1872-4fd7-9d39-11ce75924040 @@ -46,6 +47,7 @@ public class GameVersionHelper "BCET70023", "BCES01694", "NPUA80662", + "NPEA00324", }; // https://www.serialstation.com/games/b62d53d9-fdff-4463-8134-64b81e1cbd50 @@ -76,6 +78,7 @@ public class GameVersionHelper "CUSA01077", "CUSA01304", "NPUA81116", + "NPEA00515", }; public static readonly string[] LittleBigPlanetVitaTitleIds = @@ -98,4 +101,4 @@ public class GameVersionHelper return GameVersion.LittleBigPlanet1; } -} \ No newline at end of file +} From 099d7255a25d3925b8f3eca587dca7ac63032458 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 23 Jan 2022 13:16:41 -0500 Subject: [PATCH 02/32] Take 6 photos on userpage --- ProjectLighthouse/Pages/UserPage.cshtml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse/Pages/UserPage.cshtml.cs b/ProjectLighthouse/Pages/UserPage.cshtml.cs index 4a5148ed..0fe8637f 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse/Pages/UserPage.cshtml.cs @@ -27,7 +27,7 @@ public class UserPage : BaseLayout this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId); if (this.ProfileUser == null) return this.NotFound(); - this.Photos = await this.Database.Photos.OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(5).ToListAsync(); + this.Photos = await this.Database.Photos.OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(6).ToListAsync(); this.Comments = await this.Database.Comments.Include (p => p.Poster) .Include(p => p.Target) @@ -43,4 +43,4 @@ public class UserPage : BaseLayout return this.Page(); } -} \ No newline at end of file +} From e96cee47afe6aca5dc5b139a5348b117460c9302 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 23 Jan 2022 14:07:43 -0500 Subject: [PATCH 03/32] Rewrite readme, add contributing guide --- CONTRIBUTING.md | 97 ++++++++++++++++++++++++++++++++++++++ README.md | 121 ++++++++---------------------------------------- 2 files changed, 116 insertions(+), 102 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..7f51791a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,97 @@ +# Contributing + +## Running + +Project Lighthouse requires a MySQL database. For Linux users running docker, one can be set up using +the `docker-compose.yml` file in the root of the project folder. + +Next, make sure the `LIGHTHOUSE_DB_CONNECTION_STRING` environment variable is set correctly. By default, it +is `server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse`. If you are running the database via the +above `docker-compose.yml` you shouldn't need to change this. For other development/especially production environments +you will need to change this. + +Once you've gotten MySQL running you can run Lighthouse. It will take care of the rest. + +## Connecting + +PS3 is difficult to set up, so I will be going over how to set up RPCS3 instead. A guide will be coming for PS3 closer +to release. You can also follow this guide if you want to learn how to modify your EBOOT. + +There are also community-provided guides in [the official LBP Union Discord](https://www.lbpunion.com/discord), which +you can follow at your own discretion. + +*Note: This requires a modified copy of RPCS3. You can find a working +version [on our GitHub](https://github.com/LBPUnion/rpcs3).* + +Start by getting a copy of LittleBigPlanet 1/2 installed. (Check the LittleBigPlanet 1 section, since you'll need to do +extra steps for your game to not crash upon entering pod computer). It can be digital (NPUA80472/NPUA80662) or disc ( +BCUS98148/BCUS98245). For those that don't, the [RPCS3 Quickstart Guide](https://rpcs3.net/quickstart) should cover it. + +Next, download [UnionPatcher](https://github.com/LBPUnion/UnionPatcher/). Binaries can be found by reading the README.md +file. + +You should have everything you need now, so open up RPCS3 and go to Utilities -> Decrypt PS3 Binaries. Point this +to `rpcs3/dev_hdd0/game/(title id)/USRDIR/EBOOT.BIN`. You can grab your title id by right clicking the game in RPCS3 and +clicking Copy Info -> Copy Serial. + +This should give you a file named `EBOOT.elf` in the same folder. Next, fire up UnionPatcher (making sure to select the +correct project to start, e.g. on Mac launch `UnionPatcher.Gui.MacOS`.) + +Now that you have your decrypted eboot, open UnionPatcher and select the `EBOOT.elf` you got earlier in the top box, +enter `http://localhost:10060/LITTLEBIGPLANETPS3_XML` in the second, and the output filename in the third. For this +guide I'll use `EBOOTlocalhost.elf`. + +Now, copy the `EBOOTlocalhost.elf` file to where you got your `EBOOT.elf` file from, and you're now good to go. + +To launch the game with the patched EBOOT, open up RPCS3, go to File, Boot SELF/ELF, and open up `EBOOTlocalhost.elf`. + +Assuming you are running the patched version of RPCS3, you patched the file correctly, the database is migrated, and +Lighthouse is running, the game should now connect. + +### LittleBigPlanet 1 + +For LittleBigPlanet 1 to work with RPCS3, follow the steps above normally. + +First, open your favourite hex editor. We recommend [HxD](https://mh-nexus.de/en/hxd/). + +Once you have a hex editor open, open your `EBOOTlocalhost.elf` file and search for the hex +values `73 63 65 4E 70 43 6F 6D 6D 65 72 63 65 32`. In HxD, this would be done by clicking on Search -> Replace, +clicking on the `Hex-values` tab, and entering the hex there. + +Then, you can zero it out by replacing it with `00 00 00 00 00 00 00 00 00 00 00 00 00 00`. + +What this does is remove all the references to the sceNpCommerce2 function. The function is used for purchasing DLC, +which is impossible on Lighthouse. The reason why it must be patched out is because RPCS3 doesn't support the function +at this moment. + +Then save the file, and your LBP1 EBOOT can now be used with RPCS3. + +Finally, take a break. Chances are that took a while. + +## Contributing Tips + +### Database migrations + +Some modifications may require updates to the database schema. You can automatically create a migration file by: + +1. Making sure the tools are installed. You can do this by running `dotnet tool restore`. +2. Making sure `LIGHTHOUSE_DB_CONNECTION_STRING` is set correctly. See the `Running` section for more details. +3. Modifying the database schema via the C# portion of the code. Do not modify the actual SQL database. +4. Running `dotnet ef migrations add --project ProjectLighthouse`. + +This process will create a migration file from the changes made in the C# code. + +The new migrations will automatically be applied upon starting Lighthouse. + +### Running tests + +You can run tests either through your IDE or by running `dotnet tests`. + +Keep in mind while running database tests (which most tests are) you need to have `LIGHTHOUSE_DB_CONNECTION_STRING` set. + +### Continuous Integration (CI) Tips + +- You can skip CI runs for a commit if you specify `[skip ci]` at the beginning of the commit name. This is useful for + formatting changes, etc. +- When creating your first pull request, CI will not run initially. A team member will have to approve you for use of + running CI on a pull request. This is because of GitHub policy. \ No newline at end of file diff --git a/README.md b/README.md index dbd1ee49..623a0947 100644 --- a/README.md +++ b/README.md @@ -1,121 +1,38 @@ # Project Lighthouse Project Lighthouse is a clean-room, open-source custom server for LittleBigPlanet. This is a project conducted by -the [LBP Union Ministry of Technology Research and Development team.](https://www.lbpunion.com/technology) For concerns -and inquiries about the project, please [contact us here.](https://www.lbpunion.com/contact) For general questions and -discussion about Project Lighthouse, please see +the [LBP Union Ministry of Technology Research and Development team](https://www.lbpunion.com/technology). + +For concerns and inquiries about the project, please contact us [here](https://www.lbpunion.com/contact). + +For general questions and discussion about Project Lighthouse, please see the [megathread](https://www.lbpunion.com/forum/union-hall/project-lighthouse-littlebigplanet-private-servers-megathread) on our forum. -## WARNING! +## DISCLAIMER -This is **beta software**, and thus is **not stable**. +This is **beta software**, and thus is **not stable nor is it secure**. -We're not responsible if someone hacks your machine and wipes your database. +While Project Lighthouse is in a mostly working state, **we ask that our software not be used in a production +environment until release**. -Make frequent backups, and be sure to report any vulnerabilities. +This is because we have not entirely nailed security down yet, and **your instance WILL get attacked** as a result. It's +happened before, and it'll happen again. + +Simply put, **Project Lighthouse is not ready for the general public yet**. + +In addition, we're not responsible if someone hacks your machine and wipes your database, so make frequent backups, and +be sure to report any vulnerabilities. Thank you in advance. ## Building This will be written when we're out of beta. Consider this your barrier to entry ;). -It is recommended to build with Release if you plan to use Lighthouse in a production environment. +It is recommended to build with `Release` if you plan to use Lighthouse in a production environment. -## Running +## Contributing -Lighthouse requires a MySQL database at this time. For Linux users running docker, one can be set up using -the `docker-compose.yml` file in the root of the project folder. - -Next, make sure the `LIGHTHOUSE_DB_CONNECTION_STRING` environment variable is set correctly. By default, it -is `server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse`. If you are running the database via the -above `docker-compose.yml` you shouldn't need to change this. For other development/especially production environments -you will need to change this. - -Once you've gotten MySQL running you can run Lighthouse. It will take care of the rest. - -## Connecting - -PS3 is difficult to set up, so I will be going over how to set up RPCS3 instead. A guide will be coming for PS3 closer -to release. You can also follow this guide if you want to learn how to modify your EBOOT. - -There are also community-provided guides in [the official LBP Union Discord](https://www.lbpunion.com/discord), which -you can follow at your own discretion. - -*Note: This requires a modified copy of RPCS3. You can find a working -version [on our GitHub](https://github.com/LBPUnion/rpcs3).* - -Start by getting a copy of LittleBigPlanet 1/2 installed. (Check the LittleBigPlanet 1 section, since you'll need to do -extra steps for your game to not crash upon entering pod computer). It can be digital (NPUA80472/NPUA80662) or disc ( -BCUS98148/BCUS98245). For those that don't, the [RPCS3 Quickstart Guide](https://rpcs3.net/quickstart) should cover it. - -Next, download [UnionPatcher](https://github.com/LBPUnion/UnionPatcher/). Binaries can be found by reading the README.md -file. - -You should have everything you need now, so open up RPCS3 and go to Utilities -> Decrypt PS3 Binaries. Point this -to `rpcs3/dev_hdd0/game/(title id)/USRDIR/EBOOT.BIN`. You can grab your title id by right clicking the game in RPCS3 and -clicking Copy Info -> Copy Serial. - -This should give you a file named `EBOOT.elf` in the same folder. Next, fire up UnionPatcher (making sure to select the -correct project to start, e.g. on Mac launch `UnionPatcher.Gui.MacOS`.) - -Now that you have your decrypted eboot, open UnionPatcher and select the `EBOOT.elf` you got earlier in the top box, -enter `http://localhost:10060/LITTLEBIGPLANETPS3_XML` in the second, and the output filename in the third. For this -guide I'll use `EBOOTlocalhost.elf`. - -Now, copy the `EBOOTlocalhost.elf` file to where you got your `EBOOT.elf` file from, and you're now good to go. - -To launch the game with the patched EBOOT, open up RPCS3, go to File, Boot SELF/ELF, and open up `EBOOTlocalhost.elf`. - -Assuming you are running the patched version of RPCS3, you patched the file correctly, the database is migrated, and -Lighthouse is running, the game should now connect. - -### LittleBigPlanet 1 - -For LittleBigPlanet 1 to work with RPCS3, follow the steps for LittleBigPlanet 2. - -First, open your favourite hex editor. We recommend [HxD](https://mh-nexus.de/en/hxd/). - -Once you have a hex editor open, open your `EBOOTlocalhost.elf` file and search for the hex -values `73 63 65 4E 70 43 6F 6D 6D 65 72 63 65 32`. In HxD, this would be done by clicking on Search -> Replace, -clicking on the `Hex-values` tab, and entering the hex there. - -Then, you can zero it out by replacing it with `00 00 00 00 00 00 00 00 00 00 00 00 00 00`. - -What this does is remove all the references to the sceNpCommerce2 function. The function is used for purchasing DLC, -which is impossible on Lighthouse. The reason why it must be patched out is because RPCS3 doesn't support the function -at this moment. - -Then save the file, and your LBP1 EBOOT can now be used with RPCS3. - -Finally, take a break. Chances are that took a while. - -## Contributing Tips - -### Database migrations - -Some modifications may require updates to the database schema. You can automatically create a migration file by: - -1. Making sure the tools are installed. You can do this by running `dotnet tool restore`. -2. Making sure `LIGHTHOUSE_DB_CONNECTION_STRING` is set correctly. See the `Running` section for more details. -3. Modifying the database schema via the C# portion of the code. Do not modify the actual SQL database. -4. Running `dotnet ef migrations add --project ProjectLighthouse`. - -This process will create a migration file from the changes made in the C# code. - -The new migrations will automatically be applied upon starting Lighthouse. - -### Running tests - -You can run tests either through your IDE or by running `dotnet tests`. - -Keep in mind while running database tests (which most tests are) you need to have `LIGHTHOUSE_DB_CONNECTION_STRING` set. - -### Continuous Integration (CI) Tips - -- You can skip CI runs for a commit if you specify `[skip ci]` at the beginning of the commit name. This is useful for - formatting changes, etc. -- When creating your first pull request, CI will not run initially. A team member will have to approve you for use of - running CI on a pull request. This is because of GitHub policy. +Please see `CONTRIBUTING.md` for more information. ## Compatibility across games and platforms From ef1e472ab00993d1f5dae70a9c62c5aed11be308 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 23 Jan 2022 14:13:29 -0500 Subject: [PATCH 04/32] reword some things in patch guide --- CONTRIBUTING.md | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f51791a..58cac488 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -## Running +## Setting up MySQL Project Lighthouse requires a MySQL database. For Linux users running docker, one can be set up using the `docker-compose.yml` file in the root of the project folder. @@ -17,25 +17,24 @@ Once you've gotten MySQL running you can run Lighthouse. It will take care of th PS3 is difficult to set up, so I will be going over how to set up RPCS3 instead. A guide will be coming for PS3 closer to release. You can also follow this guide if you want to learn how to modify your EBOOT. -There are also community-provided guides in [the official LBP Union Discord](https://www.lbpunion.com/discord), which -you can follow at your own discretion. - -*Note: This requires a modified copy of RPCS3. You can find a working +*Note: This requires a patched copy of RPCS3. You can find a working version [on our GitHub](https://github.com/LBPUnion/rpcs3).* Start by getting a copy of LittleBigPlanet 1/2 installed. (Check the LittleBigPlanet 1 section, since you'll need to do -extra steps for your game to not crash upon entering pod computer). It can be digital (NPUA80472/NPUA80662) or disc ( -BCUS98148/BCUS98245). For those that don't, the [RPCS3 Quickstart Guide](https://rpcs3.net/quickstart) should cover it. +extra steps for your game to not crash upon entering pod computer). -Next, download [UnionPatcher](https://github.com/LBPUnion/UnionPatcher/). Binaries can be found by reading the README.md +The game can be a digital copy (NPUA80472/NPUA80662) or a disc copy ( +BCUS98148/BCUS98245). + +Next, download [UnionPatcher](https://github.com/LBPUnion/UnionPatcher/). Binaries can be found by reading the `README.md` file. You should have everything you need now, so open up RPCS3 and go to Utilities -> Decrypt PS3 Binaries. Point this to `rpcs3/dev_hdd0/game/(title id)/USRDIR/EBOOT.BIN`. You can grab your title id by right clicking the game in RPCS3 and clicking Copy Info -> Copy Serial. -This should give you a file named `EBOOT.elf` in the same folder. Next, fire up UnionPatcher (making sure to select the -correct project to start, e.g. on Mac launch `UnionPatcher.Gui.MacOS`.) + +This should give you a file named `EBOOT.elf` in the same folder. This is your decrypted eboot. Now that you have your decrypted eboot, open UnionPatcher and select the `EBOOT.elf` you got earlier in the top box, enter `http://localhost:10060/LITTLEBIGPLANETPS3_XML` in the second, and the output filename in the third. For this @@ -46,7 +45,7 @@ Now, copy the `EBOOTlocalhost.elf` file to where you got your `EBOOT.elf` file f To launch the game with the patched EBOOT, open up RPCS3, go to File, Boot SELF/ELF, and open up `EBOOTlocalhost.elf`. Assuming you are running the patched version of RPCS3, you patched the file correctly, the database is migrated, and -Lighthouse is running, the game should now connect. +Project Lighthouse is running, the game should now connect and you may begin contributing! ### LittleBigPlanet 1 @@ -60,13 +59,10 @@ clicking on the `Hex-values` tab, and entering the hex there. Then, you can zero it out by replacing it with `00 00 00 00 00 00 00 00 00 00 00 00 00 00`. -What this does is remove all the references to the sceNpCommerce2 function. The function is used for purchasing DLC, -which is impossible on Lighthouse. The reason why it must be patched out is because RPCS3 doesn't support the function -at this moment. +What this does is remove all the references to the `sceNpCommerce2` function. The function is used for purchasing DLC, +which at this moment in time crashes RPCS3. -Then save the file, and your LBP1 EBOOT can now be used with RPCS3. - -Finally, take a break. Chances are that took a while. +After saving the file your LBP1 EBOOT can be used with RPCS3. ## Contributing Tips From ef84bf1d500be29073c43606deaafcabbd169ed2 Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 24 Jan 2022 13:40:39 -0500 Subject: [PATCH 05/32] Redesign the admin panel a little bit --- .../Website/Admin/AdminPanelController.cs | 13 --- .../Commands/TestWebhookCommand.cs | 22 ++++ .../Pages/Admin/AdminPanelPage.cshtml | 103 +++++++++--------- .../Pages/Admin/AdminPanelPage.cshtml.cs | 6 + .../AdminPanelStatisticPartial.cshtml | 17 +++ .../Types/AdminPanelStatistic.cs | 18 +++ 6 files changed, 116 insertions(+), 63 deletions(-) create mode 100644 ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs create mode 100644 ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml create mode 100644 ProjectLighthouse/Types/AdminPanelStatistic.cs diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs index c7e0e31a..d736fd44 100644 --- a/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminPanelController.cs @@ -1,7 +1,4 @@ #nullable enable -using System.Threading.Tasks; -using LBPUnion.ProjectLighthouse.Helpers; -using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin; @@ -16,14 +13,4 @@ public class AdminPanelController : ControllerBase { this.database = database; } - - [HttpGet("testWebhook")] - public async Task TestWebhook() - { - User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsAdmin) return this.NotFound(); - - await WebhookHelper.SendWebhook("Testing 123", "Someone is testing the Discord webhook from the admin panel."); - return this.Redirect("/admin"); - } } \ No newline at end of file diff --git a/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs b/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs new file mode 100644 index 00000000..93ed05b5 --- /dev/null +++ b/ProjectLighthouse/Maintenance/Commands/TestWebhookCommand.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using JetBrains.Annotations; +using LBPUnion.ProjectLighthouse.Helpers; + +namespace LBPUnion.ProjectLighthouse.Maintenance.Commands; + +[UsedImplicitly] +public class TestWebhookCommand : ICommand +{ + public async Task Run(string[] args) + { + await WebhookHelper.SendWebhook("Testing 123", "Someone is testing the Discord webhook from the admin panel."); + } + public string Name() => "Test Discord Webhook"; + public string[] Aliases() + => new[] + { + "testWebhook", "testDiscordWebhook", + }; + public string Arguments() => ""; + public int RequiredArgs() => 0; +} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml index cb28e826..97228b43 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml +++ b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml @@ -1,7 +1,8 @@ @page "/admin" @using LBPUnion.ProjectLighthouse.Helpers +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Maintenance -@using LBPUnion.ProjectLighthouse.Types.Settings +@using LBPUnion.ProjectLighthouse.Types @model LBPUnion.ProjectLighthouse.Pages.Admin.AdminPanelPage @{ @@ -9,61 +10,63 @@ Model.Title = "Admin Panel"; } - -
- View Users -
-
-@if (ServerSettings.Instance.DiscordWebhookEnabled) +@if (!this.Request.IsMobile()) { - -
- Test Discord Webhook -
-
+
+ @foreach (AdminPanelStatistic statistic in Model.Statistics) + { + @await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic) + } +
+
+} +else +{ + @foreach (AdminPanelStatistic statistic in Model.Statistics) + { + @await Html.PartialAsync("Partials/AdminPanelStatisticPartial", statistic) +
+ } }

Commands

-
- @foreach (ICommand command in MaintenanceHelper.Commands) - { -
-
-

@command.Name()

-
-
- -


- - -
-
-
- } -
+@foreach (ICommand command in MaintenanceHelper.Commands) +{ +
+

@command.Name()

+
+ @if (command.RequiredArgs() > 0) + { +
+ +
+
+
+ } + + +
+
+}

Maintenance Jobs

Warning: Interrupting Lighthouse during maintenance may leave the database in an unclean state.

-
- @foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs) - { -
-
-

@job.Name()

-

@job.Description()

-
- - -
-
-
- } -
\ No newline at end of file +@foreach (IMaintenanceJob job in MaintenanceHelper.MaintenanceJobs) +{ +
+

@job.Name()

+

@job.Description()

+
+ + +
+
+} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs index 4df3a805..92e5a5b0 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Admin/AdminPanelPage.cshtml.cs @@ -15,12 +15,18 @@ public class AdminPanelPage : BaseLayout public AdminPanelPage(Database database) : base(database) {} + public List Statistics = new(); + public async Task OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob) { User? user = this.Database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); if (!user.IsAdmin) return this.NotFound(); + this.Statistics.Add(new AdminPanelStatistic("Users", await StatisticsHelper.UserCount(), "users")); + this.Statistics.Add(new AdminPanelStatistic("Slots", await StatisticsHelper.SlotCount())); + this.Statistics.Add(new AdminPanelStatistic("Photos", await StatisticsHelper.PhotoCount())); + if (!string.IsNullOrEmpty(command)) { args ??= ""; diff --git a/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml b/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml new file mode 100644 index 00000000..4acff434 --- /dev/null +++ b/ProjectLighthouse/Pages/Partials/AdminPanelStatisticPartial.cshtml @@ -0,0 +1,17 @@ +@model LBPUnion.ProjectLighthouse.Types.AdminPanelStatistic + +
+
+ @if (Model.ViewAllEndpoint != null) + { +

+ @Model.StatisticNamePlural +

+ } + else + { +

@Model.StatisticNamePlural

+ } +

@Model.Count

+
+
\ No newline at end of file diff --git a/ProjectLighthouse/Types/AdminPanelStatistic.cs b/ProjectLighthouse/Types/AdminPanelStatistic.cs new file mode 100644 index 00000000..eaa668a7 --- /dev/null +++ b/ProjectLighthouse/Types/AdminPanelStatistic.cs @@ -0,0 +1,18 @@ +#nullable enable + +namespace LBPUnion.ProjectLighthouse.Types; + +public struct AdminPanelStatistic +{ + public AdminPanelStatistic(string statisticNamePlural, int count, string? viewAllEndpoint = null) + { + this.StatisticNamePlural = statisticNamePlural; + this.Count = count; + this.ViewAllEndpoint = viewAllEndpoint; + } + + public readonly string StatisticNamePlural; + public readonly int Count; + + public readonly string? ViewAllEndpoint; +} \ No newline at end of file From 7081b725a831b3cedc33e26ed0365b1384db4436 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 27 Jan 2022 16:50:08 -0500 Subject: [PATCH 06/32] Implement PSN ticket reading --- .gitignore | 1 + .../LighthouseServerTest.cs | 3 +- .../Controllers/LoginController.cs | 28 ++-- ProjectLighthouse/Database.cs | 15 +-- .../Extensions/BinaryReaderExtensions.cs | 4 + ProjectLighthouse/Types/LoginData.cs | 45 ------- ProjectLighthouse/Types/Platform.cs | 3 + ProjectLighthouse/Types/Tickets/DataHeader.cs | 7 + ProjectLighthouse/Types/Tickets/DataType.cs | 11 ++ ProjectLighthouse/Types/Tickets/NPTicket.cs | 125 ++++++++++++++++++ .../Types/Tickets/SectionHeader.cs | 7 + .../Types/Tickets/SectionType.cs | 7 + .../Types/Tickets/TicketReader.cs | 61 +++++++++ ProjectLighthouse/Types/Version.cs | 17 +++ 14 files changed, 266 insertions(+), 68 deletions(-) delete mode 100644 ProjectLighthouse/Types/LoginData.cs create mode 100644 ProjectLighthouse/Types/Tickets/DataHeader.cs create mode 100644 ProjectLighthouse/Types/Tickets/DataType.cs create mode 100644 ProjectLighthouse/Types/Tickets/NPTicket.cs create mode 100644 ProjectLighthouse/Types/Tickets/SectionHeader.cs create mode 100644 ProjectLighthouse/Types/Tickets/SectionType.cs create mode 100644 ProjectLighthouse/Types/Tickets/TicketReader.cs create mode 100644 ProjectLighthouse/Types/Version.cs diff --git a/.gitignore b/.gitignore index 1e2fd1a7..d6ee8a61 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ gitVersion.txt gitRemotes.txt gitUnpushed.txt logs/* +npTicket* # MSBuild stuff bin/ diff --git a/ProjectLighthouse.Tests/LighthouseServerTest.cs b/ProjectLighthouse.Tests/LighthouseServerTest.cs index 6a926c23..7b37d188 100644 --- a/ProjectLighthouse.Tests/LighthouseServerTest.cs +++ b/ProjectLighthouse.Tests/LighthouseServerTest.cs @@ -37,7 +37,8 @@ public class LighthouseServerTest await database.CreateUser($"{username}{number}", HashHelper.BCryptHash($"unitTestPassword{number}")); } - string stringContent = $"{LoginData.UsernamePrefix}{username}{number}{(char)0x00}"; + //TODO: generate actual tickets + string stringContent = $"unitTestTicket{username}{number}"; HttpResponseMessage response = await this.Client.PostAsync ($"/LITTLEBIGPLANETPS3_XML/login?titleID={GameVersionHelper.LittleBigPlanet2TitleIds[0]}", new StringContent(stringContent)); diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs index 04a9d7df..c063e814 100644 --- a/ProjectLighthouse/Controllers/LoginController.cs +++ b/ProjectLighthouse/Controllers/LoginController.cs @@ -8,8 +8,10 @@ using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Settings; +using LBPUnion.ProjectLighthouse.Types.Tickets; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using IOFile = System.IO.File; namespace LBPUnion.ProjectLighthouse.Controllers; @@ -26,25 +28,29 @@ public class LoginController : ControllerBase } [HttpPost] - public async Task Login([FromQuery] string? titleId) + public async Task Login() { - titleId ??= ""; + MemoryStream ms = new(); + await this.Request.Body.CopyToAsync(ms); + byte[] loginData = ms.ToArray(); - string body = await new StreamReader(this.Request.Body).ReadToEndAsync(); + #if DEBUG + await IOFile.WriteAllBytesAsync($"npTicket-{TimestampHelper.TimestampMillis}.txt", loginData); + #endif - LoginData? loginData; + NPTicket? npTicket; try { - loginData = LoginData.CreateFromString(body); + npTicket = NPTicket.CreateFromBytes(loginData); } catch { - loginData = null; + npTicket = null; } - if (loginData == null) + if (npTicket == null) { - Logger.Log("loginData was null, rejecting login", LoggerLevelLogin.Instance); + Logger.Log("npTicket was null, rejecting login", LoggerLevelLogin.Instance); return this.BadRequest(); } @@ -60,11 +66,11 @@ public class LoginController : ControllerBase // Get an existing token from the IP & username GameToken? token = await this.database.GameTokens.Include (t => t.User) - .FirstOrDefaultAsync(t => t.UserLocation == ipAddress && t.User.Username == loginData.Username && !t.Used); + .FirstOrDefaultAsync(t => t.UserLocation == ipAddress && t.User.Username == npTicket.Username && !t.Used); if (token == null) // If we cant find an existing token, try to generate a new one { - token = await this.database.AuthenticateUser(loginData, ipAddress, titleId); + token = await this.database.AuthenticateUser(npTicket, ipAddress); if (token == null) { Logger.Log("unable to find/generate a token, rejecting login", LoggerLevelLogin.Instance); @@ -129,7 +135,7 @@ public class LoginController : ControllerBase return this.StatusCode(403, ""); } - Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client ({titleId})", LoggerLevelLogin.Instance); + Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client", LoggerLevelLogin.Instance); // After this point we are now considering this session as logged in. // We just logged in with the token. Mark it as used so someone else doesnt try to use it, diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 844fd6e5..365319fd 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -1,15 +1,14 @@ using System; using System.Linq; using System.Threading.Tasks; -using Kettu; using LBPUnion.ProjectLighthouse.Helpers; -using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Categories; using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Reviews; using LBPUnion.ProjectLighthouse.Types.Settings; +using LBPUnion.ProjectLighthouse.Types.Tickets; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; @@ -67,9 +66,9 @@ public class Database : DbContext } #nullable enable - public async Task AuthenticateUser(LoginData loginData, string userLocation, string titleId = "") + public async Task AuthenticateUser(NPTicket npTicket, string userLocation) { - User? user = await this.Users.FirstOrDefaultAsync(u => u.Username == loginData.Username); + User? user = await this.Users.FirstOrDefaultAsync(u => u.Username == npTicket.Username); if (user == null) return null; GameToken gameToken = new() @@ -78,15 +77,9 @@ public class Database : DbContext User = user, UserId = user.UserId, UserLocation = userLocation, - GameVersion = GameVersionHelper.FromTitleId(titleId), + GameVersion = npTicket.GameVersion, }; - if (gameToken.GameVersion == GameVersion.Unknown) - { - Logger.Log($"Unknown GameVersion for TitleId {titleId}", LoggerLevelLogin.Instance); - return null; - } - this.GameTokens.Add(gameToken); await this.SaveChangesAsync(); diff --git a/ProjectLighthouse/Helpers/Extensions/BinaryReaderExtensions.cs b/ProjectLighthouse/Helpers/Extensions/BinaryReaderExtensions.cs index feacec19..4a83bf42 100644 --- a/ProjectLighthouse/Helpers/Extensions/BinaryReaderExtensions.cs +++ b/ProjectLighthouse/Helpers/Extensions/BinaryReaderExtensions.cs @@ -23,6 +23,10 @@ public static class BinaryReaderExtensions public static int ReadInt32BE(this BinaryReader binRdr) => BitConverter.ToInt32(binRdr.ReadBytesRequired(sizeof(int)).Reverse(), 0); + public static ulong ReadUInt64BE(this BinaryReader binRdr) => BitConverter.ToUInt32(binRdr.ReadBytesRequired(sizeof(ulong)).Reverse(), 0); + + public static long ReadInt64BE(this BinaryReader binRdr) => BitConverter.ToInt32(binRdr.ReadBytesRequired(sizeof(long)).Reverse(), 0); + public static byte[] ReadBytesRequired(this BinaryReader binRdr, int byteCount) { byte[] result = binRdr.ReadBytes(byteCount); diff --git a/ProjectLighthouse/Types/LoginData.cs b/ProjectLighthouse/Types/LoginData.cs deleted file mode 100644 index ac57ac78..00000000 --- a/ProjectLighthouse/Types/LoginData.cs +++ /dev/null @@ -1,45 +0,0 @@ -#nullable enable -using System; -using System.IO; -using System.Text; -using LBPUnion.ProjectLighthouse.Helpers; - -namespace LBPUnion.ProjectLighthouse.Types; - -/// -/// The data sent from POST /LOGIN. -/// -public class LoginData -{ - - public static readonly string UsernamePrefix = Encoding.ASCII.GetString - ( - new byte[] - { - 0x04, 0x00, 0x20, - } - ); - - public string Username { get; set; } = null!; - - /// - /// Converts a X-I-5 Ticket into `LoginData`. - /// https://www.psdevwiki.com/ps3/X-I-5-Ticket - /// - public static LoginData? CreateFromString(string str) - { - str = str.Replace("\b", ""); // Remove backspace characters - - using MemoryStream ms = new(Encoding.ASCII.GetBytes(str)); - using BinaryReader reader = new(ms); - - if (!str.Contains(UsernamePrefix)) return null; - - LoginData loginData = new(); - - reader.BaseStream.Position = str.IndexOf(UsernamePrefix, StringComparison.Ordinal) + UsernamePrefix.Length; - loginData.Username = BinaryHelper.ReadString(reader).Replace("\0", string.Empty); - - return loginData; - } -} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Platform.cs b/ProjectLighthouse/Types/Platform.cs index 74fb1608..b863f285 100644 --- a/ProjectLighthouse/Types/Platform.cs +++ b/ProjectLighthouse/Types/Platform.cs @@ -5,4 +5,7 @@ public enum Platform PS3 = 0, RPCS3 = 1, Vita = 2, + PSP = 3, + UnitTest = 4, + Unknown = -1, } \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/DataHeader.cs b/ProjectLighthouse/Types/Tickets/DataHeader.cs new file mode 100644 index 00000000..940f980c --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/DataHeader.cs @@ -0,0 +1,7 @@ +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +public struct DataHeader +{ + public DataType Type; + public ushort Length; +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/DataType.cs b/ProjectLighthouse/Types/Tickets/DataType.cs new file mode 100644 index 00000000..92da0543 --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/DataType.cs @@ -0,0 +1,11 @@ +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +public enum DataType : byte +{ + Empty = 0x00, + UInt32 = 0x01, + UInt64 = 0x02, + String = 0x04, + Timestamp = 0x07, + Binary = 0x08, +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs new file mode 100644 index 00000000..dd1f1f3b --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -0,0 +1,125 @@ +#nullable enable +using System; +using System.IO; +using System.Text; +using Kettu; +using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Helpers.Extensions; +using LBPUnion.ProjectLighthouse.Logging; +using LBPUnion.ProjectLighthouse.Types.Settings; + +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +/// +/// A PSN ticket, typically sent from PS3/RPCN +/// +public class NPTicket +{ + public string Username { get; set; } + + private Version ticketVersion { get; set; } + + public Platform Platform { get; set; } + + public uint IssuerId { get; set; } + public ulong IssuedDate { get; set; } + public ulong ExpireDate { get; set; } + + public GameVersion GameVersion { get; set; } + + /// + /// https://www.psdevwiki.com/ps3/X-I-5-Ticket + /// + public static NPTicket? CreateFromBytes(byte[] data) + { + #if DEBUG + if (data[0] == 'u' && ServerStatics.IsUnitTesting) + { + string dataStr = Encoding.UTF8.GetString(data); + if (dataStr.StartsWith("unitTestTicket")) + { + NPTicket npTicket = new() + { + IssuerId = 0, + ticketVersion = new Version(0, 0), + Platform = Platform.UnitTest, + GameVersion = GameVersion.LittleBigPlanet2, + ExpireDate = 0, + IssuedDate = 0, + }; + + npTicket.Username = dataStr.Substring(14); + + return npTicket; + } + } + #endif + try + { + NPTicket npTicket = new(); + using MemoryStream ms = new(data); + using TicketReader reader = new(ms); + + npTicket.ticketVersion = reader.ReadTicketVersion(); + + reader.ReadBytes(4); // Skip header + + reader.ReadUInt16BE(); // Ticket length, we don't care about this + + if (npTicket.ticketVersion != "2.1") throw new NotImplementedException(); + + #if DEBUG + SectionHeader bodyHeader = reader.ReadSectionHeader(); + Logger.Log($"bodyHeader.Type is {bodyHeader.Type}", LoggerLevelLogin.Instance); + #else + reader.ReadSectionHeader(); + #endif + + reader.ReadTicketString(); // "Serial id", but its apparently not what we're looking for + + npTicket.IssuerId = reader.ReadTicketUInt32(); + npTicket.IssuedDate = reader.ReadTicketUInt64(); + npTicket.ExpireDate = reader.ReadTicketUInt64(); + + reader.ReadTicketUInt64(); // PSN User id, we don't care about this + + npTicket.Username = reader.ReadTicketString(); + + reader.ReadTicketString(); // Country + reader.ReadTicketString(); // Domain + + // Title ID, kinda.. + // Data: "UP9000-BCUS98245_00 + string titleId = reader.ReadTicketString(); + titleId = titleId.Substring(7); // Trim UP9000- + titleId = titleId.Substring(0, titleId.Length - 3); // Trim _00 at the end + + #if DEBUG + Logger.Log($"titleId is {titleId}", LoggerLevelLogin.Instance); + #endif + + npTicket.GameVersion = GameVersionHelper.FromTitleId(titleId); // Finally, convert it to GameVersion + + // Production PSN Issuer ID: 0x100 + // RPCN Issuer ID: 0x33333333 + npTicket.Platform = npTicket.IssuerId switch + { + 0x100 => Platform.PS3, + 0x33333333 => Platform.RPCS3, + _ => Platform.Unknown, + }; + + if (npTicket.Platform == Platform.Unknown) + { + Logger.Log($"", LoggerLevelLogin.Instance); + return null; + } + + return npTicket; + } + catch + { + return null; + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/SectionHeader.cs b/ProjectLighthouse/Types/Tickets/SectionHeader.cs new file mode 100644 index 00000000..5242fe59 --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/SectionHeader.cs @@ -0,0 +1,7 @@ +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +public struct SectionHeader +{ + public SectionType Type; + public ushort Length; +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/SectionType.cs b/ProjectLighthouse/Types/Tickets/SectionType.cs new file mode 100644 index 00000000..c7bb43a5 --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/SectionType.cs @@ -0,0 +1,7 @@ +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +public enum SectionType : byte +{ + Body = 0x00, + Footer = 0x02, +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Tickets/TicketReader.cs b/ProjectLighthouse/Types/Tickets/TicketReader.cs new file mode 100644 index 00000000..47256adb --- /dev/null +++ b/ProjectLighthouse/Types/Tickets/TicketReader.cs @@ -0,0 +1,61 @@ +using System.Diagnostics; +using System.IO; +using System.Text; +using JetBrains.Annotations; +using LBPUnion.ProjectLighthouse.Helpers.Extensions; + +namespace LBPUnion.ProjectLighthouse.Types.Tickets; + +public class TicketReader : BinaryReader +{ + public TicketReader([NotNull] Stream input) : base(input) + {} + + public Version ReadTicketVersion() => new(this.ReadByte() >> 4, this.ReadByte()); + + public SectionHeader ReadSectionHeader() + { + this.ReadByte(); + + SectionHeader sectionHeader = new(); + sectionHeader.Type = (SectionType)this.ReadByte(); + sectionHeader.Length = this.ReadUInt16BE(); + + return sectionHeader; + } + + public DataHeader ReadDataHeader() + { + DataHeader dataHeader = new(); + dataHeader.Type = (DataType)this.ReadUInt16BE(); + dataHeader.Length = this.ReadUInt16BE(); + + return dataHeader; + } + + public byte[] ReadTicketBinary() + { + DataHeader dataHeader = this.ReadDataHeader(); + Debug.Assert(dataHeader.Type == DataType.Binary || dataHeader.Type == DataType.String); + + return this.ReadBytes(dataHeader.Length); + } + + public string ReadTicketString() => Encoding.UTF8.GetString(this.ReadTicketBinary()).TrimEnd('\0'); + + public uint ReadTicketUInt32() + { + DataHeader dataHeader = this.ReadDataHeader(); + Debug.Assert(dataHeader.Type == DataType.UInt32); + + return this.ReadUInt32BE(); + } + + public ulong ReadTicketUInt64() + { + DataHeader dataHeader = this.ReadDataHeader(); + Debug.Assert(dataHeader.Type == DataType.UInt64 || dataHeader.Type == DataType.Timestamp); + + return this.ReadUInt64BE(); + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/Version.cs b/ProjectLighthouse/Types/Version.cs new file mode 100644 index 00000000..eb9f3649 --- /dev/null +++ b/ProjectLighthouse/Types/Version.cs @@ -0,0 +1,17 @@ +namespace LBPUnion.ProjectLighthouse.Types; + +public class Version +{ + public int Major { get; set; } + public int Minor { get; set; } + + public Version(int major, int minor) + { + this.Major = major; + this.Minor = minor; + } + + public override string ToString() => $"{this.Major}.{this.Minor}"; + + public static implicit operator string(Version v) => v.ToString(); +} \ No newline at end of file From e1bad4ead3f849728bcf3df5698ca0af2a5c1505 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 27 Jan 2022 16:51:31 -0500 Subject: [PATCH 07/32] Make authentication attempts use npticket platform --- ProjectLighthouse/Controllers/LoginController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse/Controllers/LoginController.cs b/ProjectLighthouse/Controllers/LoginController.cs index c063e814..0cb7246e 100644 --- a/ProjectLighthouse/Controllers/LoginController.cs +++ b/ProjectLighthouse/Controllers/LoginController.cs @@ -116,7 +116,7 @@ public class LoginController : ControllerBase GameTokenId = token.TokenId, Timestamp = TimestampHelper.Timestamp, IPAddress = ipAddress, - Platform = token.GameVersion == GameVersion.LittleBigPlanetVita ? Platform.Vita : Platform.PS3, // TODO: properly identify RPCS3 + Platform = npTicket.Platform, }; this.database.AuthenticationAttempts.Add(authAttempt); From 480fb4b0406bc81ebddb9fcb6ec6fcab279d0721 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 27 Jan 2022 16:52:45 -0500 Subject: [PATCH 08/32] Add logging to npTicket reading if platform/gameVersion could not be determined --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index dd1f1f3b..4b33b623 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -111,7 +111,13 @@ public class NPTicket if (npTicket.Platform == Platform.Unknown) { - Logger.Log($"", LoggerLevelLogin.Instance); + Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); + return null; + } + + if (npTicket.GameVersion == GameVersion.Unknown) + { + Logger.Log($"Could not determine game version from title id {titleId}", LoggerLevelLogin.Instance); return null; } From 95fd98be5d47e41250f5b6c534d6e97efe03bdd5 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 27 Jan 2022 16:53:18 -0500 Subject: [PATCH 09/32] Do not default to GameVersion.LittleBigPlanet1 if titleId cant be found --- ProjectLighthouse/Helpers/GameVersionHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse/Helpers/GameVersionHelper.cs b/ProjectLighthouse/Helpers/GameVersionHelper.cs index f787a92b..f13d1a15 100644 --- a/ProjectLighthouse/Helpers/GameVersionHelper.cs +++ b/ProjectLighthouse/Helpers/GameVersionHelper.cs @@ -99,6 +99,6 @@ public class GameVersionHelper if (LittleBigPlanetVitaTitleIds.Contains(titleId)) return GameVersion.LittleBigPlanetVita; if (LittleBigPlanetPSPTitleIds.Contains(titleId)) return GameVersion.LittleBigPlanetPSP; - return GameVersion.LittleBigPlanet1; + return GameVersion.Unknown; } -} +} \ No newline at end of file From 9cb165ce677f5432a3e6d1618485d2f400ab6d66 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 28 Jan 2022 15:26:18 -0500 Subject: [PATCH 10/32] Make slot cards not use inline css --- .../Pages/Partials/SlotCardPartial.cshtml | 14 +++---- ProjectLighthouse/StaticFiles/css/styles.css | 40 ++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml index 27ecbc10..182ee6c0 100644 --- a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml @@ -27,23 +27,23 @@ string iconHash = Model.IconHash; if (string.IsNullOrWhiteSpace(iconHash) || iconHash.StartsWith('g')) iconHash = ServerSettings.Instance.MissingIconHash; } -
-
+
+
-
+
@if (showLink) { -

+

@slotName

} else { -

+

@slotName

} -
+
@Model.Hearts @Model.Plays @Model.Thumbsup @@ -59,7 +59,7 @@ Created by @Model.Creator?.Username for @Model.GameVersion.ToPrettyString()

-
+

@if (user != null) { diff --git a/ProjectLighthouse/StaticFiles/css/styles.css b/ProjectLighthouse/StaticFiles/css/styles.css index 18d37154..0c84d1c2 100644 --- a/ProjectLighthouse/StaticFiles/css/styles.css +++ b/ProjectLighthouse/StaticFiles/css/styles.css @@ -18,4 +18,42 @@ div.statsUnderTitle > span { #lighthouse-debug-info > p { margin-bottom: 1px; -} \ No newline at end of file +} + +/*#region Slot cards*/ + +.slotCard { + display: flex; + width: 100%; +} + +.slotCardIcon { + margin-right: 10px; + height: 100px; + width: 100px; + background-size: cover; + background-position: center; + border-radius: 100%; +} + +.slotCardStats { + height: fit-content; + vertical-align: center; + align-self: center +} + +.slotCardStats > .statsUnderTitle { + margin-bottom: 10px; +} + +.slotCardStats > h1, +.slotCardStats > h2 { + margin-bottom: 2px; +} + +.slotCardButtons { + height: 100px; + margin-left: auto; +} + +/*#endregion Slot cards*/ \ No newline at end of file From e0cc1da084081381c50b6f82f847e4b2c23f5e54 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 28 Jan 2022 15:43:24 -0500 Subject: [PATCH 11/32] Shrink slot icon on mobile --- .../Pages/Partials/SlotCardPartial.cshtml | 6 +++++- ProjectLighthouse/Pages/SlotPage.cshtml | 4 ++++ ProjectLighthouse/Pages/SlotsPage.cshtml | 4 ++++ ProjectLighthouse/StaticFiles/css/styles.css | 10 ++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml index 182ee6c0..353828d8 100644 --- a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml @@ -10,6 +10,7 @@ await using Database database = new(); string slotName = string.IsNullOrEmpty(Model.Name) ? "Unnamed Level" : Model.Name; + bool isMobile = (bool?)ViewData["IsMobile"] ?? false; bool isQueued = false; bool isHearted = false; @@ -28,7 +29,10 @@ if (string.IsNullOrWhiteSpace(iconHash) || iconHash.StartsWith('g')) iconHash = ServerSettings.Instance.MissingIconHash; }
-
+ @{ + int size = isMobile ? 50 : 100; + } +
@if (showLink) diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml b/ProjectLighthouse/Pages/SlotPage.cshtml index 63feb595..4be38e74 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml +++ b/ProjectLighthouse/Pages/SlotPage.cshtml @@ -1,4 +1,5 @@ @page "/slot/{id:int}" +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @model LBPUnion.ProjectLighthouse.Pages.SlotPage @{ @@ -20,6 +21,9 @@ { "ShowLink", false }, + { + "IsMobile", Model.Request.IsMobile() + }, })
diff --git a/ProjectLighthouse/Pages/SlotsPage.cshtml b/ProjectLighthouse/Pages/SlotsPage.cshtml index ad5b8180..41b5947a 100644 --- a/ProjectLighthouse/Pages/SlotsPage.cshtml +++ b/ProjectLighthouse/Pages/SlotsPage.cshtml @@ -1,4 +1,5 @@ @page "/slots/{pageNumber:int}" +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Types.Levels @model LBPUnion.ProjectLighthouse.Pages.SlotsPage @@ -23,6 +24,9 @@ { "ShowLink", true }, + { + "IsMobile", Model.Request.IsMobile() + }, })
} diff --git a/ProjectLighthouse/StaticFiles/css/styles.css b/ProjectLighthouse/StaticFiles/css/styles.css index 0c84d1c2..8d5ca005 100644 --- a/ProjectLighthouse/StaticFiles/css/styles.css +++ b/ProjectLighthouse/StaticFiles/css/styles.css @@ -29,8 +29,6 @@ div.statsUnderTitle > span { .slotCardIcon { margin-right: 10px; - height: 100px; - width: 100px; background-size: cover; background-position: center; border-radius: 100%; @@ -53,7 +51,15 @@ div.statsUnderTitle > span { .slotCardButtons { height: 100px; + display: flex; + flex-direction: column; + align-items: center; margin-left: auto; } +.slotCardButtons > a { + margin-bottom: 5px !important; + vertical-align: center; +} + /*#endregion Slot cards*/ \ No newline at end of file From b13dea6306daba804a6b966fa89008377adc11e8 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 28 Jan 2022 15:59:00 -0500 Subject: [PATCH 12/32] Rename slotCard to Card and use in UserCardPartial --- .../Pages/Partials/SlotCardPartial.cshtml | 10 ++-- .../Pages/Partials/UserCardPartial.cshtml | 12 ++-- ProjectLighthouse/Pages/SlotsPage.cshtml | 3 +- ProjectLighthouse/Pages/UserPage.cshtml | 4 ++ ProjectLighthouse/Pages/UsersPage.cshtml | 5 ++ ProjectLighthouse/StaticFiles/css/styles.css | 59 ++++++++++++------- 6 files changed, 62 insertions(+), 31 deletions(-) diff --git a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml index 353828d8..45e31797 100644 --- a/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/SlotCardPartial.cshtml @@ -28,13 +28,13 @@ string iconHash = Model.IconHash; if (string.IsNullOrWhiteSpace(iconHash) || iconHash.StartsWith('g')) iconHash = ServerSettings.Instance.MissingIconHash; } -
+
@{ int size = isMobile ? 50 : 100; } -
+
-
+
@if (showLink) {

@@ -47,7 +47,7 @@ @slotName

} -
+
@Model.Hearts @Model.Plays @Model.Thumbsup @@ -63,7 +63,7 @@ Created by @Model.Creator?.Username for @Model.GameVersion.ToPrettyString()

-
+

@if (user != null) { diff --git a/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml b/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml index 49c1779c..8a66290f 100644 --- a/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml +++ b/ProjectLighthouse/Pages/Partials/UserCardPartial.cshtml @@ -3,12 +3,16 @@ @{ bool showLink = (bool?)ViewData["ShowLink"] ?? false; + bool isMobile = (bool?)ViewData["IsMobile"] ?? false; } -
-
+
+ @{ + int size = isMobile ? 50 : 100; + } +
-
+
@if (showLink) {

@@ -24,7 +28,7 @@

@Model.Status

-
+
@Model.Hearts @Model.Comments @Model.UsedSlots / @ServerSettings.Instance.EntitledSlots diff --git a/ProjectLighthouse/Pages/SlotsPage.cshtml b/ProjectLighthouse/Pages/SlotsPage.cshtml index 41b5947a..c3aa545c 100644 --- a/ProjectLighthouse/Pages/SlotsPage.cshtml +++ b/ProjectLighthouse/Pages/SlotsPage.cshtml @@ -12,6 +12,7 @@ @foreach (Slot slot in Model.Slots) { + bool isMobile = Model.Request.IsMobile();
@await Html.PartialAsync("Partials/SlotCardPartial", slot, new ViewDataDictionary(ViewData) { @@ -25,7 +26,7 @@ "ShowLink", true }, { - "IsMobile", Model.Request.IsMobile() + "IsMobile", isMobile }, })
diff --git a/ProjectLighthouse/Pages/UserPage.cshtml b/ProjectLighthouse/Pages/UserPage.cshtml index 31669ecb..8c1db838 100644 --- a/ProjectLighthouse/Pages/UserPage.cshtml +++ b/ProjectLighthouse/Pages/UserPage.cshtml @@ -1,6 +1,7 @@ @page "/user/{userId:int}" @using System.IO @using System.Web +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Types @using LBPUnion.ProjectLighthouse.Types.Profiles @model LBPUnion.ProjectLighthouse.Pages.UserPage @@ -43,6 +44,9 @@ { "ShowLink", false }, + { + "IsMobile", Model.Request.IsMobile() + }, })
diff --git a/ProjectLighthouse/Pages/UsersPage.cshtml b/ProjectLighthouse/Pages/UsersPage.cshtml index f2d16ec2..3e3ab35f 100644 --- a/ProjectLighthouse/Pages/UsersPage.cshtml +++ b/ProjectLighthouse/Pages/UsersPage.cshtml @@ -1,4 +1,5 @@ @page "/users/{pageNumber:int}" +@using LBPUnion.ProjectLighthouse.Helpers.Extensions @using LBPUnion.ProjectLighthouse.Types @model LBPUnion.ProjectLighthouse.Pages.UsersPage @@ -11,12 +12,16 @@ @foreach (User user in Model.Users) { + bool isMobile = Model.Request.IsMobile();
@await Html.PartialAsync("Partials/UserCardPartial", user, new ViewDataDictionary(ViewData) { { "ShowLink", true }, + { + "IsMobile", isMobile + }, })
} diff --git a/ProjectLighthouse/StaticFiles/css/styles.css b/ProjectLighthouse/StaticFiles/css/styles.css index 8d5ca005..f122599d 100644 --- a/ProjectLighthouse/StaticFiles/css/styles.css +++ b/ProjectLighthouse/StaticFiles/css/styles.css @@ -8,48 +8,36 @@ div.main { flex: 1; } -div.statsUnderTitle > i { - margin-right: 2px; -} - -div.statsUnderTitle > span { - margin-right: 5px; -} - #lighthouse-debug-info > p { margin-bottom: 1px; } -/*#region Slot cards*/ +/*#region Cards*/ -.slotCard { +.card { display: flex; width: 100%; } -.slotCardIcon { +.cardIcon { margin-right: 10px; background-size: cover; background-position: center; border-radius: 100%; } -.slotCardStats { +.cardStats { height: fit-content; vertical-align: center; align-self: center } -.slotCardStats > .statsUnderTitle { - margin-bottom: 10px; -} - -.slotCardStats > h1, -.slotCardStats > h2 { +.cardStats > h1, +.cardStats > h2 { margin-bottom: 2px; } -.slotCardButtons { +.cardButtons { height: 100px; display: flex; flex-direction: column; @@ -57,9 +45,38 @@ div.statsUnderTitle > span { margin-left: auto; } -.slotCardButtons > a { +.cardButtons > a { margin-bottom: 5px !important; vertical-align: center; } -/*#endregion Slot cards*/ \ No newline at end of file +.cardStatsUnderTitle { + margin-bottom: 10px; +} + +div.cardStatsUnderTitle > i { + margin-right: 2px; +} + +div.cardStatsUnderTitle > span { + margin-right: 5px; +} + +/*#region Slot cards*/ + +.slotCardIcon { + border-radius: 100%; +} + +/*#endregion Slot cards*/ + +/*#region User cards*/ + +.userCardIcon { + border-radius: .28571429rem; +} + + +/*#endregion User cards*/ + +/*#endregion Cards*/ \ No newline at end of file From 4c95c2bea66361d7e0780e875c7bfaad6e066981 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 14:35:09 -0500 Subject: [PATCH 13/32] Better npTicket logging --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 28 ++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 4b33b623..5262fdfa 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Text; +using System.Text.Json; using Kettu; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Helpers.Extensions; @@ -89,8 +90,9 @@ public class NPTicket reader.ReadTicketString(); // Domain // Title ID, kinda.. - // Data: "UP9000-BCUS98245_00 - string titleId = reader.ReadTicketString(); + // Data: UP9000-BCUS98245_00 + // We need to chop this to get the titleId we're looking for + string titleId = reader.ReadTicketString(); // Read the string titleId = titleId.Substring(7); // Trim UP9000- titleId = titleId.Substring(0, titleId.Length - 3); // Trim _00 at the end @@ -121,10 +123,30 @@ public class NPTicket return null; } + #if DEBUG + Logger.Log("npTicket data:", LoggerLevelLogin.Instance); + foreach (string line in JsonSerializer.Serialize(npTicket).Split('\n')) + { + Logger.Log(line, LoggerLevelLogin.Instance); + } + #endif + return npTicket; } - catch + catch(Exception e) { + Logger.Log("Failed to read npTicket!", LoggerLevelLogin.Instance); + Logger.Log("Either this is spam data, or the more likely that this is a bug.", LoggerLevelLogin.Instance); + Logger.Log + ( + "Please report the following exception to our issue tracker at https://github.com/LBPUnion/project-lighthouse/issues", + LoggerLevelLogin.Instance + ); + + foreach (string line in e.ToDetailedException().Split('\n')) + { + Logger.Log(line, LoggerLevelLogin.Instance); + } return null; } } From f26cfaa7fc44bf943b62d7667806157b6fb8617e Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 14:38:58 -0500 Subject: [PATCH 14/32] Log unimplemented ticket version --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 5262fdfa..aa5158e4 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -33,13 +33,14 @@ public class NPTicket /// public static NPTicket? CreateFromBytes(byte[] data) { + NPTicket npTicket = new(); #if DEBUG if (data[0] == 'u' && ServerStatics.IsUnitTesting) { string dataStr = Encoding.UTF8.GetString(data); if (dataStr.StartsWith("unitTestTicket")) { - NPTicket npTicket = new() + npTicket = new NPTicket { IssuerId = 0, ticketVersion = new Version(0, 0), @@ -57,7 +58,6 @@ public class NPTicket #endif try { - NPTicket npTicket = new(); using MemoryStream ms = new(data); using TicketReader reader = new(ms); @@ -133,13 +133,24 @@ public class NPTicket return npTicket; } + catch(NotImplementedException) + { + Logger.Log($"The ticket version {npTicket.ticketVersion} is not implemented yet.", LoggerLevelLogin.Instance); + Logger.Log + ( + "Please let us know that this is a ticket version that is actually used on our issue tracker at https://github.com/LBPUnion/project-lighthouse/issues !", + LoggerLevelLogin.Instance + ); + + return null; + } catch(Exception e) { Logger.Log("Failed to read npTicket!", LoggerLevelLogin.Instance); Logger.Log("Either this is spam data, or the more likely that this is a bug.", LoggerLevelLogin.Instance); Logger.Log ( - "Please report the following exception to our issue tracker at https://github.com/LBPUnion/project-lighthouse/issues", + "Please report the following exception to our issue tracker at https://github.com/LBPUnion/project-lighthouse/issues!", LoggerLevelLogin.Instance ); From 66e954e5f510dde131d528b3b592b39ec1f9c821 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 14:51:18 -0500 Subject: [PATCH 15/32] Read 3.0 tickets --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 86 +++++++++++++-------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index aa5158e4..80873883 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -26,8 +26,34 @@ public class NPTicket public ulong IssuedDate { get; set; } public ulong ExpireDate { get; set; } + private string titleId { get; set; } + public GameVersion GameVersion { get; set; } + private static void Read21Ticket(NPTicket npTicket, TicketReader reader) + { + reader.ReadTicketString(); // "Serial id", but its apparently not what we're looking for + + npTicket.IssuerId = reader.ReadTicketUInt32(); + npTicket.IssuedDate = reader.ReadTicketUInt64(); + npTicket.ExpireDate = reader.ReadTicketUInt64(); + + reader.ReadTicketUInt64(); // PSN User id, we don't care about this + + npTicket.Username = reader.ReadTicketString(); + + reader.ReadTicketString(); // Country + reader.ReadTicketString(); // Domain + + npTicket.titleId = reader.ReadTicketString(); + } + + // Function is here for future use incase we ever need to read more from the ticket + private static void Read30Ticket(NPTicket npTicket, TicketReader reader) + { + Read21Ticket(npTicket, reader); + } + /// /// https://www.psdevwiki.com/ps3/X-I-5-Ticket /// @@ -67,7 +93,16 @@ public class NPTicket reader.ReadUInt16BE(); // Ticket length, we don't care about this - if (npTicket.ticketVersion != "2.1") throw new NotImplementedException(); + switch (npTicket.ticketVersion) + { + case "2.1": + Read21Ticket(npTicket, reader); + break; + case "3.0": + Read30Ticket(npTicket, reader); + break; + default: throw new NotImplementedException(); + } #if DEBUG SectionHeader bodyHeader = reader.ReadSectionHeader(); @@ -76,31 +111,30 @@ public class NPTicket reader.ReadSectionHeader(); #endif - reader.ReadTicketString(); // "Serial id", but its apparently not what we're looking for + if (npTicket.Platform == Platform.Unknown) + { + Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); + return null; + } - npTicket.IssuerId = reader.ReadTicketUInt32(); - npTicket.IssuedDate = reader.ReadTicketUInt64(); - npTicket.ExpireDate = reader.ReadTicketUInt64(); - - reader.ReadTicketUInt64(); // PSN User id, we don't care about this - - npTicket.Username = reader.ReadTicketString(); - - reader.ReadTicketString(); // Country - reader.ReadTicketString(); // Domain - - // Title ID, kinda.. - // Data: UP9000-BCUS98245_00 + // We already read the title id, however we need to do some post-processing to get what we want. + // Current data: UP9000-BCUS98245_00 // We need to chop this to get the titleId we're looking for - string titleId = reader.ReadTicketString(); // Read the string - titleId = titleId.Substring(7); // Trim UP9000- - titleId = titleId.Substring(0, titleId.Length - 3); // Trim _00 at the end + npTicket.titleId = npTicket.titleId.Substring(7); // Trim UP9000- + npTicket.titleId = npTicket.titleId.Substring(0, npTicket.titleId.Length - 3); // Trim _00 at the end + // Data now (hopefully): BCUS98245 #if DEBUG - Logger.Log($"titleId is {titleId}", LoggerLevelLogin.Instance); + Logger.Log($"titleId is {npTicket.titleId}", LoggerLevelLogin.Instance); #endif - npTicket.GameVersion = GameVersionHelper.FromTitleId(titleId); // Finally, convert it to GameVersion + npTicket.GameVersion = GameVersionHelper.FromTitleId(npTicket.titleId); // Finally, convert it to GameVersion + + if (npTicket.GameVersion == GameVersion.Unknown) + { + Logger.Log($"Could not determine game version from title id {npTicket.titleId}", LoggerLevelLogin.Instance); + return null; + } // Production PSN Issuer ID: 0x100 // RPCN Issuer ID: 0x33333333 @@ -111,18 +145,6 @@ public class NPTicket _ => Platform.Unknown, }; - if (npTicket.Platform == Platform.Unknown) - { - Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); - return null; - } - - if (npTicket.GameVersion == GameVersion.Unknown) - { - Logger.Log($"Could not determine game version from title id {titleId}", LoggerLevelLogin.Instance); - return null; - } - #if DEBUG Logger.Log("npTicket data:", LoggerLevelLogin.Instance); foreach (string line in JsonSerializer.Serialize(npTicket).Split('\n')) From b51ddec029f65ef9803a32ee7d5160da5658bba9 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 14:58:45 -0500 Subject: [PATCH 16/32] Assert if gameVersion is vita and platform is not vita --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 80873883..426df2d4 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Diagnostics; using System.IO; using System.Text; using System.Text.Json; @@ -145,6 +146,11 @@ public class NPTicket _ => Platform.Unknown, }; + if (npTicket.GameVersion == GameVersion.LittleBigPlanetVita) + { + Debug.Assert(npTicket.Platform == Platform.Vita); + } + #if DEBUG Logger.Log("npTicket data:", LoggerLevelLogin.Instance); foreach (string line in JsonSerializer.Serialize(npTicket).Split('\n')) From 3e6a80cc32acf9b1a3fc47d5ca722c8ba710b900 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 15:36:48 -0500 Subject: [PATCH 17/32] Fix reading in wrong order --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 426df2d4..a03bfb2a 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -94,6 +94,13 @@ public class NPTicket reader.ReadUInt16BE(); // Ticket length, we don't care about this + #if DEBUG + SectionHeader bodyHeader = reader.ReadSectionHeader(); + Logger.Log($"bodyHeader.Type is {bodyHeader.Type}", LoggerLevelLogin.Instance); + #else + reader.ReadSectionHeader(); + #endif + switch (npTicket.ticketVersion) { case "2.1": @@ -105,13 +112,6 @@ public class NPTicket default: throw new NotImplementedException(); } - #if DEBUG - SectionHeader bodyHeader = reader.ReadSectionHeader(); - Logger.Log($"bodyHeader.Type is {bodyHeader.Type}", LoggerLevelLogin.Instance); - #else - reader.ReadSectionHeader(); - #endif - if (npTicket.Platform == Platform.Unknown) { Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); From bf4b957da1dcdcdaa230ee9a0d13ac4e5977e142 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 15:46:21 -0500 Subject: [PATCH 18/32] Change platform assert to log --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index a03bfb2a..1284ef53 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -1,6 +1,5 @@ #nullable enable using System; -using System.Diagnostics; using System.IO; using System.Text; using System.Text.Json; @@ -112,12 +111,6 @@ public class NPTicket default: throw new NotImplementedException(); } - if (npTicket.Platform == Platform.Unknown) - { - Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); - return null; - } - // We already read the title id, however we need to do some post-processing to get what we want. // Current data: UP9000-BCUS98245_00 // We need to chop this to get the titleId we're looking for @@ -146,10 +139,18 @@ public class NPTicket _ => Platform.Unknown, }; + if (npTicket.Platform == Platform.Unknown) + { + Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); + return null; + } + + #if DEBUG if (npTicket.GameVersion == GameVersion.LittleBigPlanetVita) { - Debug.Assert(npTicket.Platform == Platform.Vita); + Logger.Log($"Platform for vita ticket is {npTicket.Platform}", LoggerLevelLogin.Instance); } + #endif #if DEBUG Logger.Log("npTicket data:", LoggerLevelLogin.Instance); From 89932af6e70a030d0ac15c7a0473651e63131bcf Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 30 Jan 2022 15:56:32 -0500 Subject: [PATCH 19/32] Force platform to be vita if titleid is a vita game --- ProjectLighthouse/Types/Tickets/NPTicket.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 1284ef53..5f948a1c 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -139,19 +139,14 @@ public class NPTicket _ => Platform.Unknown, }; + if (npTicket.Platform == Platform.PS3 && npTicket.GameVersion == GameVersion.LittleBigPlanetVita) npTicket.Platform = Platform.Vita; + if (npTicket.Platform == Platform.Unknown) { Logger.Log($"Could not determine platform from IssuerId {npTicket.IssuerId} decimal", LoggerLevelLogin.Instance); return null; } - #if DEBUG - if (npTicket.GameVersion == GameVersion.LittleBigPlanetVita) - { - Logger.Log($"Platform for vita ticket is {npTicket.Platform}", LoggerLevelLogin.Instance); - } - #endif - #if DEBUG Logger.Log("npTicket data:", LoggerLevelLogin.Instance); foreach (string line in JsonSerializer.Serialize(npTicket).Split('\n')) From df7bb7d356f6364b88b45723b49fadade92dc4c3 Mon Sep 17 00:00:00 2001 From: Slendy Date: Sun, 30 Jan 2022 21:25:53 -0600 Subject: [PATCH 20/32] Added basic search functionality and fixed some bugs --- .../Controllers/ResourcesController.cs | 5 +++++ ProjectLighthouse/Helpers/WebhookHelper.cs | 2 +- ProjectLighthouse/Pages/LoginForm.cshtml | 9 +++++---- ProjectLighthouse/Pages/PhotosPage.cshtml | 12 ++++++++++-- ProjectLighthouse/Pages/PhotosPage.cshtml.cs | 15 ++++++++++----- ProjectLighthouse/Pages/RegisterForm.cshtml | 17 ++++++++++------- ProjectLighthouse/Pages/SlotsPage.cshtml | 12 ++++++++++-- ProjectLighthouse/Pages/SlotsPage.cshtml.cs | 16 +++++++++++----- ProjectLighthouse/Pages/UsersPage.cshtml | 12 ++++++++++-- ProjectLighthouse/Pages/UsersPage.cshtml.cs | 15 +++++++++------ 10 files changed, 81 insertions(+), 34 deletions(-) diff --git a/ProjectLighthouse/Controllers/ResourcesController.cs b/ProjectLighthouse/Controllers/ResourcesController.cs index f9ff9346..47e7f26d 100644 --- a/ProjectLighthouse/Controllers/ResourcesController.cs +++ b/ProjectLighthouse/Controllers/ResourcesController.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -56,6 +57,10 @@ public class ResourcesController : ControllerBase { string path = $"png/{hash}.png"; + if (!IOFile.Exists("png")) + { + FileHelper.EnsureDirectoryCreated(Path.Combine(Environment.CurrentDirectory, "png")); + } if (IOFile.Exists(path)) { return this.File(IOFile.OpenRead(path), "image/png"); diff --git a/ProjectLighthouse/Helpers/WebhookHelper.cs b/ProjectLighthouse/Helpers/WebhookHelper.cs index c624fc45..9d0ea1c2 100644 --- a/ProjectLighthouse/Helpers/WebhookHelper.cs +++ b/ProjectLighthouse/Helpers/WebhookHelper.cs @@ -7,7 +7,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers; public static class WebhookHelper { - private static readonly DiscordWebhookClient client = new(ServerSettings.Instance.DiscordWebhookUrl); + private static readonly DiscordWebhookClient client = (ServerSettings.Instance.DiscordWebhookEnabled ? new DiscordWebhookClient(ServerSettings.Instance.DiscordWebhookUrl) : null); public static readonly Color UnionColor = new(0, 140, 255); public static Task SendWebhook(EmbedBuilder builder) => SendWebhook(builder.Build()); diff --git a/ProjectLighthouse/Pages/LoginForm.cshtml b/ProjectLighthouse/Pages/LoginForm.cshtml index ede86b66..b04b21bc 100644 --- a/ProjectLighthouse/Pages/LoginForm.cshtml +++ b/ProjectLighthouse/Pages/LoginForm.cshtml @@ -11,9 +11,9 @@