From f4460264c3b123dc87beb779677c0c609e77d74d Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 17:59:10 -0400 Subject: [PATCH 1/5] Add support for team picks --- ProjectLighthouse.sln.DotSettings | 1 + .../Controllers/SlotsController.cs | 15 + .../20211102215859_RenameTeamPick.Designer.cs | 460 ++++++++++++++++++ .../20211102215859_RenameTeamPick.cs | 23 + .../Migrations/DatabaseModelSnapshot.cs | 6 +- ProjectLighthouse/Types/Levels/Slot.cs | 4 +- 6 files changed, 504 insertions(+), 5 deletions(-) create mode 100644 ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.Designer.cs create mode 100644 ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.cs diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 8b093e41..020f7335 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -85,6 +85,7 @@ True True True + True True True True diff --git a/ProjectLighthouse/Controllers/SlotsController.cs b/ProjectLighthouse/Controllers/SlotsController.cs index ede1ae56..ac319fef 100644 --- a/ProjectLighthouse/Controllers/SlotsController.cs +++ b/ProjectLighthouse/Controllers/SlotsController.cs @@ -55,5 +55,20 @@ namespace LBPUnion.ProjectLighthouse.Controllers return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "hint_start", pageStart + Math.Min(pageSize, 30))); } + + [HttpGet("slots/mmpicks")] + public IActionResult TeamPickedSlots([FromQuery] int pageStart, [FromQuery] int pageSize) + { + IQueryable slots = this.database.Slots + .Where(s => s.TeamPick) + .Include(s => s.Creator) + .Include(s => s.Location) + .OrderByDescending(s => s.LastUpdated) + .Skip(pageStart - 1) + .Take(Math.Min(pageSize, 30)); + string response = Enumerable.Aggregate(slots, string.Empty, (current, slot) => current + slot.Serialize()); + + return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "hint_start", pageStart + Math.Min(pageSize, 30))); + } } } \ No newline at end of file diff --git a/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.Designer.cs b/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.Designer.cs new file mode 100644 index 00000000..34087d12 --- /dev/null +++ b/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.Designer.cs @@ -0,0 +1,460 @@ +// +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20211102215859_RenameTeamPick")] + partial class RenameTeamPick + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.11"); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.HeartedProfile", b => + { + b.Property("HeartedProfileId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("HeartedUserId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("HeartedProfileId"); + + b.HasIndex("HeartedUserId"); + + b.HasIndex("UserId"); + + b.ToTable("HeartedProfiles"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.HeartedLevel", b => + { + b.Property("HeartedLevelId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("HeartedLevelId"); + + b.HasIndex("SlotId"); + + b.HasIndex("UserId"); + + b.ToTable("HeartedLevels"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.QueuedLevel", b => + { + b.Property("QueuedLevelId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("QueuedLevelId"); + + b.HasIndex("SlotId"); + + b.HasIndex("UserId"); + + b.ToTable("QueuedLevels"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.Slot", b => + { + b.Property("SlotId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("AuthorLabels") + .HasColumnType("longtext"); + + b.Property("BackgroundHash") + .HasColumnType("longtext"); + + b.Property("CreatorId") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("longtext"); + + b.Property("FirstUploaded") + .HasColumnType("bigint"); + + b.Property("IconHash") + .HasColumnType("longtext"); + + b.Property("InitiallyLocked") + .HasColumnType("tinyint(1)"); + + b.Property("LastUpdated") + .HasColumnType("bigint"); + + b.Property("Lbp1Only") + .HasColumnType("tinyint(1)"); + + b.Property("LocationId") + .HasColumnType("int"); + + b.Property("MaximumPlayers") + .HasColumnType("int"); + + b.Property("MinimumPlayers") + .HasColumnType("int"); + + b.Property("MoveRequired") + .HasColumnType("tinyint(1)"); + + b.Property("Name") + .HasColumnType("longtext"); + + b.Property("ResourceCollection") + .HasColumnType("longtext"); + + b.Property("RootLevel") + .HasColumnType("longtext"); + + b.Property("Shareable") + .HasColumnType("int"); + + b.Property("SubLevel") + .HasColumnType("tinyint(1)"); + + b.Property("TeamPick") + .HasColumnType("tinyint(1)"); + + b.HasKey("SlotId"); + + b.HasIndex("CreatorId"); + + b.HasIndex("LocationId"); + + b.ToTable("Slots"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Comment", b => + { + b.Property("CommentId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Message") + .HasColumnType("longtext"); + + b.Property("PosterUserId") + .HasColumnType("int"); + + b.Property("TargetUserId") + .HasColumnType("int"); + + b.Property("ThumbsDown") + .HasColumnType("int"); + + b.Property("ThumbsUp") + .HasColumnType("int"); + + b.Property("Timestamp") + .HasColumnType("bigint"); + + b.HasKey("CommentId"); + + b.HasIndex("PosterUserId"); + + b.HasIndex("TargetUserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.LastMatch", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Timestamp") + .HasColumnType("bigint"); + + b.HasKey("UserId"); + + b.ToTable("LastMatches"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Location", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("X") + .HasColumnType("int"); + + b.Property("Y") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Locations"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b => + { + b.Property("ScoreId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("PlayerIdCollection") + .HasColumnType("longtext"); + + b.Property("Points") + .HasColumnType("int"); + + b.Property("SlotId") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("ScoreId"); + + b.HasIndex("SlotId"); + + b.ToTable("Scores"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Token", b => + { + b.Property("TokenId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserToken") + .HasColumnType("longtext"); + + b.HasKey("TokenId"); + + b.ToTable("Tokens"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.User", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Biography") + .HasColumnType("longtext"); + + b.Property("BooHash") + .HasColumnType("longtext"); + + b.Property("CommentCount") + .HasColumnType("int"); + + b.Property("CommentsEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("FavouriteSlotCount") + .HasColumnType("int"); + + b.Property("FavouriteUserCount") + .HasColumnType("int"); + + b.Property("Game") + .HasColumnType("int"); + + b.Property("HeartCount") + .HasColumnType("int"); + + b.Property("IconHash") + .HasColumnType("longtext"); + + b.Property("Lists") + .HasColumnType("int"); + + b.Property("LocationId") + .HasColumnType("int"); + + b.Property("LolCatFtwCount") + .HasColumnType("int"); + + b.Property("PhotosByMeCount") + .HasColumnType("int"); + + b.Property("PhotosWithMeCount") + .HasColumnType("int"); + + b.Property("Pins") + .HasColumnType("longtext"); + + b.Property("PlanetHash") + .HasColumnType("longtext"); + + b.Property("ReviewCount") + .HasColumnType("int"); + + b.Property("StaffChallengeBronzeCount") + .HasColumnType("int"); + + b.Property("StaffChallengeGoldCount") + .HasColumnType("int"); + + b.Property("StaffChallengeSilverCount") + .HasColumnType("int"); + + b.Property("Username") + .HasColumnType("longtext"); + + b.Property("YayHash") + .HasColumnType("longtext"); + + b.HasKey("UserId"); + + b.HasIndex("LocationId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.HeartedProfile", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "HeartedUser") + .WithMany() + .HasForeignKey("HeartedUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("HeartedUser"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.HeartedLevel", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.QueuedLevel", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Levels.Slot", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Creator") + .WithMany() + .HasForeignKey("CreatorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.Profiles.Location", "Location") + .WithMany() + .HasForeignKey("LocationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Location"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Profiles.Comment", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Poster") + .WithMany() + .HasForeignKey("PosterUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LBPUnion.ProjectLighthouse.Types.User", "Target") + .WithMany() + .HasForeignKey("TargetUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Poster"); + + b.Navigation("Target"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Score", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Levels.Slot", "Slot") + .WithMany() + .HasForeignKey("SlotId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Slot"); + }); + + modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.User", b => + { + b.HasOne("LBPUnion.ProjectLighthouse.Types.Profiles.Location", "Location") + .WithMany() + .HasForeignKey("LocationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Location"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.cs b/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.cs new file mode 100644 index 00000000..3a73f94a --- /dev/null +++ b/ProjectLighthouse/Migrations/20211102215859_RenameTeamPick.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace ProjectLighthouse.Migrations +{ + public partial class RenameTeamPick : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "MMPick", + table: "Slots", + newName: "TeamPick"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "TeamPick", + table: "Slots", + newName: "MMPick"); + } + } +} diff --git a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 90264313..40a9a518 100644 --- a/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -115,9 +115,6 @@ namespace ProjectLighthouse.Migrations b.Property("LocationId") .HasColumnType("int"); - b.Property("MMPick") - .HasColumnType("tinyint(1)"); - b.Property("MaximumPlayers") .HasColumnType("int"); @@ -142,6 +139,9 @@ namespace ProjectLighthouse.Migrations b.Property("SubLevel") .HasColumnType("tinyint(1)"); + b.Property("TeamPick") + .HasColumnType("tinyint(1)"); + b.HasKey("SlotId"); b.HasIndex("CreatorId"); diff --git a/ProjectLighthouse/Types/Levels/Slot.cs b/ProjectLighthouse/Types/Levels/Slot.cs index 79b9d2fe..45122764 100644 --- a/ProjectLighthouse/Types/Levels/Slot.cs +++ b/ProjectLighthouse/Types/Levels/Slot.cs @@ -93,7 +93,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels public long LastUpdated { get; set; } [XmlIgnore] - public bool MMPick { get; set; } + public bool TeamPick { get; set; } public string SerializeResources() { @@ -121,7 +121,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels LbpSerializer.StringElement("moveRequired", this.MoveRequired) + LbpSerializer.StringElement("firstPublished", this.FirstUploaded) + LbpSerializer.StringElement("lastUpdated", this.LastUpdated) + - LbpSerializer.StringElement("mmpick", this.MMPick); + LbpSerializer.StringElement("mmpick", this.TeamPick); return LbpSerializer.TaggedStringElement("slot", slotData, "type", "user"); } From dd91de3c8713c0430600452e8e35c23b2333d157 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 18:11:52 -0400 Subject: [PATCH 2/5] Fix boolean StringElement serialization --- ProjectLighthouse/Serialization/LbpSerializer.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ProjectLighthouse/Serialization/LbpSerializer.cs b/ProjectLighthouse/Serialization/LbpSerializer.cs index 1d2cfdaf..d1dcfdd9 100644 --- a/ProjectLighthouse/Serialization/LbpSerializer.cs +++ b/ProjectLighthouse/Serialization/LbpSerializer.cs @@ -16,6 +16,8 @@ namespace LBPUnion.ProjectLighthouse.Serialization public static string StringElement(KeyValuePair pair) => $"<{pair.Key}>{pair.Value}"; + public static string StringElement(string key, bool value) => $"<{key}>{value.ToString().ToLower()}"; + public static string StringElement(string key, object value) => $"<{key}>{value}"; public static string TaggedStringElement From e5a1ccb9e30bfc5ebeb925f07fa06386777ad725 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 18:39:59 -0400 Subject: [PATCH 3/5] Add framework for determining game version --- ProjectLighthouse.sln.DotSettings | 11 +++ .../Helpers/GameVersionHelper.cs | 90 +++++++++++++++++++ ProjectLighthouse/Types/GameVersion.cs | 10 +++ 3 files changed, 111 insertions(+) create mode 100644 ProjectLighthouse/Helpers/GameVersionHelper.cs create mode 100644 ProjectLighthouse/Types/GameVersion.cs diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 020f7335..bca9c610 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -76,6 +76,11 @@ True True True + True + True + True + True + True True True True @@ -86,8 +91,14 @@ True True True + True + True + True + True + True True True + True True True True \ No newline at end of file diff --git a/ProjectLighthouse/Helpers/GameVersionHelper.cs b/ProjectLighthouse/Helpers/GameVersionHelper.cs new file mode 100644 index 00000000..161a3831 --- /dev/null +++ b/ProjectLighthouse/Helpers/GameVersionHelper.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using LBPUnion.ProjectLighthouse.Types; + +namespace LBPUnion.ProjectLighthouse.Helpers +{ + public class GameVersionHelper + { + // https://www.serialstation.com/games/b89b4eb4-4e4c-4e54-b72b-f7f9dbfac125 + public readonly string[] LittleBigPlanet1TitleIds = + { + "BCES00141", + "BCAS20091", + "BCUS98208", + "BCAS20078", + "BCJS70009", + "BCES00611", + "BCUS98148", + "BCAS20058", + "BCJS30018", + "UCAS40262", + "BCET70011", + "BCUS98199", + "BCJB95003", + "NPUA70045", + "NPEA00241", + "NPEA00147", + "NPHG00033", + "NPHG00035", + }; + + // https://serialstation.com/games/35e69aba-1872-4fd7-9d39-11ce75924040 + public readonly string[] LittleBigPlanet2TitleIds = + { + "BCUS98249", + "BCES01086", + "BCAS20113", + "BCJS70024", + "BCAS20201", + "BCUS98245", + "BCES01345", + "BCJS30058", + "BCUS98372", + "BCES00850", + "BCES01346", + "BCUS90260", + "BCET70023", + "NPUA80662", + }; + + // https://www.serialstation.com/games/b62d53d9-fdff-4463-8134-64b81e1cbd50 + // includes PS4 games + public readonly string[] LittleBigPlanet3TitleIds = + { + "CUSA00063", + "CUSA00693", + "CUSA00473", + "CUSA00810", + "CUSA00473", + "CUSA01072", + "CUSA00738", + "PCJS50003", + "BCES02068", + "BCAS20322", + "BCJS30095", + "BCES01663", + "CUSA00063", + "BCUS98362", + "PCKS90007", + "PCAS00012", + "CUSA00601", + "CUSA00810", + "CUSA00762", + "PCAS20007", + "CUSA00473", + "CUSA01077", + "CUSA01304", + }; + + public GameVersion FromTitleId(string titleId) + { + if (this.LittleBigPlanet1TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet1; + if (this.LittleBigPlanet2TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet2; + if (this.LittleBigPlanet3TitleIds.Contains(titleId)) return GameVersion.LittleBigPlanet3; + + return GameVersion.Unknown; + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Types/GameVersion.cs b/ProjectLighthouse/Types/GameVersion.cs new file mode 100644 index 00000000..aed9d0c4 --- /dev/null +++ b/ProjectLighthouse/Types/GameVersion.cs @@ -0,0 +1,10 @@ +namespace LBPUnion.ProjectLighthouse.Types +{ + public enum GameVersion + { + LittleBigPlanet1, + LittleBigPlanet2, + LittleBigPlanet3, + Unknown, + } +} \ No newline at end of file From cd19afc5777804a22793e20b2b49ee615b138336 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 19:06:45 -0400 Subject: [PATCH 4/5] Fix test failures --- .../Tests/AuthenticationTests.cs | 2 +- ProjectLighthouse/Controllers/MatchController.cs | 2 +- ProjectLighthouse/Helpers/FileHelper.cs | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs b/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs index 87bdf599..893648e0 100644 --- a/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs +++ b/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs @@ -49,7 +49,7 @@ namespace LBPUnion.ProjectLighthouse.Tests { LoginResult loginResult = await this.Authenticate(); - HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/eula", loginResult.AuthTicket); + HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/announce", loginResult.AuthTicket); string responseContent = await response.Content.ReadAsStringAsync(); Assert.True(response.IsSuccessStatusCode); diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index 81fe97e0..ddf4de8f 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -45,7 +45,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers "[{\"StatusCode\":200},{\"Players\":[{\"PlayerId\":\"literally1984\",\"matching_res\":0},{\"PlayerId\":\"jvyden\",\"matching_res\":1}],\"Slots\":[[5,0]],\"RoomState\":\"E_ROOM_IN_POD\",\"HostMood\":\"E_MOOD_EVERYONE\",\"LevelCompletionEstimate\":0,\"PassedNoJoinPoint\":0,\"MoveConnected\":false,\"Location\":[\"127.0.0.1\"],\"BuildVersion\":289,\"Language\":1,\"FirstSeenTimestamp\":1427331263756,\"LastSeenTimestamp\":1635112546000,\"GameId\":1,\"NatType\":2,\"Friends\":[],\"Blocked\":[],\"RecentlyLeft\":[],\"FailedJoin\":[]}]" ); - if (bodyString[0] != '[') return this.BadRequest(); + if (bodyString.Length == 0 || bodyString[0] != '[') return this.BadRequest(); IMatchData? matchData; try diff --git a/ProjectLighthouse/Helpers/FileHelper.cs b/ProjectLighthouse/Helpers/FileHelper.cs index 2b05f6f1..e81fe118 100644 --- a/ProjectLighthouse/Helpers/FileHelper.cs +++ b/ProjectLighthouse/Helpers/FileHelper.cs @@ -37,9 +37,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers public static LbpFileType DetermineFileType(byte[] data) { + if (data.Length == 0) return LbpFileType.Unknown; // Can't be anything if theres no data. + using MemoryStream ms = new(data); using BinaryReader reader = new(ms); + // Determine if file is a FARC (File Archive). + // Needs to be done before anything else that determines the type by the header + // because this determines the type by the footer. + string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4)); + if (footer == "FARC") return LbpFileType.FileArchive; + byte[] header = reader.ReadBytes(3); return Encoding.ASCII.GetString(header) switch @@ -57,11 +65,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers private static LbpFileType determineFileTypePartTwoWeirdName(BinaryReader reader) { reader.BaseStream.Position = 0; - - // Determine if file is FARC - string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4)); - if (footer == "FARC") return LbpFileType.FileArchive; - + // Determine if file is JPEG byte[] header = reader.ReadBytes(9); From f3f01ec45efe8716780135100e131f49cac5ec6b Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 19:07:06 -0400 Subject: [PATCH 5/5] Make CI run on pull_request --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0248ba60..0d369ebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -on: [ push ] +on: [ push, pull_request ] name: Continuous Integration # Inspired by osu! lazer's CI