diff --git a/ProjectLighthouse.Tests.GameApiTests/AuthenticationTests.cs b/ProjectLighthouse.Tests.GameApiTests/AuthenticationTests.cs index 68a10d13..29279fdd 100644 --- a/ProjectLighthouse.Tests.GameApiTests/AuthenticationTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/AuthenticationTests.cs @@ -47,7 +47,7 @@ public class AuthenticationTests : LighthouseServerTest LoginResult loginResult = await this.Authenticate(); HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/enterLevel/420", loginResult.AuthTicket); - string responseContent = await response.Content.ReadAsStringAsync(); + await response.Content.ReadAsStringAsync(); Assert.False(response.StatusCode == HttpStatusCode.Forbidden); } @@ -59,4 +59,4 @@ public class AuthenticationTests : LighthouseServerTest Assert.False(response.IsSuccessStatusCode); Assert.True(response.StatusCode == HttpStatusCode.Forbidden); } -} +} \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/Api/SlotEndpoints.cs b/ProjectLighthouse/Controllers/Api/SlotEndpoints.cs index 909f9a95..fe1a1b7a 100644 --- a/ProjectLighthouse/Controllers/Api/SlotEndpoints.cs +++ b/ProjectLighthouse/Controllers/Api/SlotEndpoints.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; diff --git a/ProjectLighthouse/Controllers/Api/UserEndpoints.cs b/ProjectLighthouse/Controllers/Api/UserEndpoints.cs index 63510326..e30f7285 100644 --- a/ProjectLighthouse/Controllers/Api/UserEndpoints.cs +++ b/ProjectLighthouse/Controllers/Api/UserEndpoints.cs @@ -50,7 +50,7 @@ public class UserEndpoints : ApiEndpointController [HttpGet("user/{id:int}/status")] [ProducesResponseType(typeof(UserStatus), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetUserStatus(int id) + public IActionResult GetUserStatus(int id) { UserStatus userStatus = new(this.database, id); diff --git a/ProjectLighthouse/Controllers/GameApi/ClientConfigurationController.cs b/ProjectLighthouse/Controllers/GameApi/ClientConfigurationController.cs index 26eb534e..e446a657 100644 --- a/ProjectLighthouse/Controllers/GameApi/ClientConfigurationController.cs +++ b/ProjectLighthouse/Controllers/GameApi/ClientConfigurationController.cs @@ -25,7 +25,7 @@ public class ClientConfigurationController : ControllerBase public async Task NetworkSettings() { GameToken? token = await this.database.GameTokenFromRequest(this.Request); - if (token == null) return null; + if (token == null) return this.StatusCode(403, ""); HostString hostname = this.Request.Host; return this.Ok diff --git a/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs b/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs index 7292ff67..425f59b0 100644 --- a/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs +++ b/ProjectLighthouse/Controllers/GameApi/Slots/SearchController.cs @@ -47,7 +47,7 @@ public class SearchController : ControllerBase ( s => s.Name.ToLower().Contains(keyword) || s.Description.ToLower().Contains(keyword) || - s.Creator.Username.ToLower().Contains(keyword) || + s.Creator!.Username.ToLower().Contains(keyword) || s.SlotId.ToString().Equals(keyword) ); diff --git a/ProjectLighthouse/Controllers/GameApi/StatisticsController.cs b/ProjectLighthouse/Controllers/GameApi/StatisticsController.cs index 47d4b4f0..6c29615c 100644 --- a/ProjectLighthouse/Controllers/GameApi/StatisticsController.cs +++ b/ProjectLighthouse/Controllers/GameApi/StatisticsController.cs @@ -10,12 +10,6 @@ namespace LBPUnion.ProjectLighthouse.Controllers.GameApi; [Produces("text/plain")] public class StatisticsController : ControllerBase { - private readonly Database database; - public StatisticsController(Database database) - { - this.database = database; - } - [HttpGet("playersInPodCount")] [HttpGet("totalPlayerCount")] public async Task TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatches()).ToString()!); diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminUserController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminUserController.cs index 13f2a4d5..629996ca 100644 --- a/ProjectLighthouse/Controllers/Website/Admin/AdminUserController.cs +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminUserController.cs @@ -24,7 +24,7 @@ public class AdminUserController : ControllerBase if (user == null || !user.IsAdmin) return this.NotFound(); User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id); - ; + if (targetedUser == null) return this.NotFound(); targetedUser.Banned = false; diff --git a/ProjectLighthouse/Helpers/CaptchaHelper.cs b/ProjectLighthouse/Helpers/CaptchaHelper.cs index 3008b084..4b124333 100644 --- a/ProjectLighthouse/Helpers/CaptchaHelper.cs +++ b/ProjectLighthouse/Helpers/CaptchaHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Net.Http; using System.Threading.Tasks; using LBPUnion.ProjectLighthouse.Types.Settings; @@ -14,6 +15,7 @@ public static class CaptchaHelper BaseAddress = new Uri("https://hcaptcha.com"), }; + [SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")] public static async Task Verify(string token) { if (!ServerSettings.Instance.HCaptchaEnabled) return true; diff --git a/ProjectLighthouse/Helpers/HashHelper.cs b/ProjectLighthouse/Helpers/HashHelper.cs index 3cfe3a2a..7d8434a9 100644 --- a/ProjectLighthouse/Helpers/HashHelper.cs +++ b/ProjectLighthouse/Helpers/HashHelper.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; -using System.Runtime.Intrinsics.Arm; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -23,17 +22,17 @@ public static class HashHelper public static IEnumerable GenerateRandomBytes(int count) { byte[] b = new byte[count]; - - lock (RandomHelper.random) + + lock(RandomHelper.random) { RandomHelper.random.NextBytes(b); } - + return b; } /// - /// Generates a random SHA256 & BCrypted token + /// Generates a random SHA256 and BCrypted token /// /// The token as a string. public static string GenerateAuthToken() @@ -75,7 +74,7 @@ public static class HashHelper public static string Sha1Hash(string str) => Sha1Hash(Encoding.UTF8.GetBytes(str)); - public static string Sha1Hash(byte[] bytes) => BitConverter.ToString(SHA1.Create().ComputeHash(bytes)).Replace("-",""); + public static string Sha1Hash(byte[] bytes) => BitConverter.ToString(SHA1.Create().ComputeHash(bytes)).Replace("-", ""); public static string BCryptHash(string str) => BCrypt.Net.BCrypt.HashPassword(str); diff --git a/ProjectLighthouse/Helpers/ImageHelper.cs b/ProjectLighthouse/Helpers/ImageHelper.cs index 7801af3b..5beabd82 100644 --- a/ProjectLighthouse/Helpers/ImageHelper.cs +++ b/ProjectLighthouse/Helpers/ImageHelper.cs @@ -30,6 +30,7 @@ public static class ImageHelper LbpFileType.Texture => TextureToPNG(hash, reader), LbpFileType.Png => PNGToPNG(hash, data), LbpFileType.Jpeg => JPGToPNG(hash, data), + // ReSharper disable once UnreachableSwitchArmDueToIntegerAnalysis _ => false, }; } @@ -57,16 +58,10 @@ public static class ImageHelper int[] compressed = new int[chunks]; int[] decompressed = new int[chunks]; - int decompressedSize = 0; - int compressedSize = 0; - for(int i = 0; i < chunks; ++i) { compressed[i] = reader.ReadUInt16BE(); decompressed[i] = reader.ReadUInt16BE(); - - decompressedSize += decompressed[i]; - compressedSize += compressed[i]; } using MemoryStream ms = new(); diff --git a/ProjectLighthouse/Helpers/InfluxHelper.cs b/ProjectLighthouse/Helpers/InfluxHelper.cs index ea266efb..0799047d 100644 --- a/ProjectLighthouse/Helpers/InfluxHelper.cs +++ b/ProjectLighthouse/Helpers/InfluxHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using InfluxDB.Client; @@ -54,6 +55,7 @@ public static class InfluxHelper } } + [SuppressMessage("ReSharper", "FunctionNeverReturns")] public static async Task StartLogging() { await Client.ReadyAsync(); diff --git a/ProjectLighthouse/Helpers/ResourceHelper.cs b/ProjectLighthouse/Helpers/ResourceHelper.cs index 389155bd..77a88378 100644 --- a/ProjectLighthouse/Helpers/ResourceHelper.cs +++ b/ProjectLighthouse/Helpers/ResourceHelper.cs @@ -1,9 +1,5 @@ using System; using System.IO; -using System.Linq; -using Kettu; -using LBPUnion.ProjectLighthouse.Logging; -using LBPUnion.ProjectLighthouse.Types.Settings; namespace LBPUnion.ProjectLighthouse.Helpers; @@ -11,8 +7,7 @@ public static class ResourceHelper { public static string readManifestFile(string fileName) { - using Stream stream = - typeof(Program).Assembly.GetManifestResourceStream($"{typeof(Program).Namespace}.{fileName}"); + using Stream stream = typeof(Program).Assembly.GetManifestResourceStream($"{typeof(Program).Namespace}.{fileName}"); using StreamReader reader = new(stream ?? throw new Exception("The assembly or manifest resource is null.")); return reader.ReadToEnd().Trim(); diff --git a/ProjectLighthouse/Helpers/VersionHelper.cs b/ProjectLighthouse/Helpers/VersionHelper.cs index 0e229ccb..c32d8aa8 100644 --- a/ProjectLighthouse/Helpers/VersionHelper.cs +++ b/ProjectLighthouse/Helpers/VersionHelper.cs @@ -1,5 +1,3 @@ -using System; -using System.IO; using System.Linq; using Kettu; using LBPUnion.ProjectLighthouse.Logging; @@ -65,8 +63,8 @@ public static class VersionHelper public const string Build = #if DEBUG - "Debug"; - #elif RELEASE + "Debug"; + #elif RELEASE "Release"; #else "Unknown"; diff --git a/ProjectLighthouse/Maintenance/MaintenanceJobs/CleanupBrokenPhotosMaintenanceJob.cs b/ProjectLighthouse/Maintenance/MaintenanceJobs/CleanupBrokenPhotosMaintenanceJob.cs index 7af922b2..2c4996df 100644 --- a/ProjectLighthouse/Maintenance/MaintenanceJobs/CleanupBrokenPhotosMaintenanceJob.cs +++ b/ProjectLighthouse/Maintenance/MaintenanceJobs/CleanupBrokenPhotosMaintenanceJob.cs @@ -89,7 +89,8 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob $"{nameof(noHashesExist)}: {noHashesExist}, " + $"{nameof(largeHashIsInvalidFile)}: {largeHashIsInvalidFile}, " + $"{nameof(tooManyPhotoSubjects)}: {tooManyPhotoSubjects}" + - $"{nameof(duplicatePhotoSubjects)}: {duplicatePhotoSubjects}" + $"{nameof(duplicatePhotoSubjects)}: {duplicatePhotoSubjects}" + + $"{nameof(takenInTheFuture)}: {takenInTheFuture}" ); this.database.Photos.Remove(photo); diff --git a/ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs b/ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs index baa515dc..f955956f 100644 --- a/ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Admin/AdminPanelUsersPage.cshtml.cs @@ -11,10 +11,9 @@ namespace LBPUnion.ProjectLighthouse.Pages.Admin; public class AdminPanelUsersPage : BaseLayout { - public int UserCount; - public List Users; + public List Users = new(); public AdminPanelUsersPage(Database database) : base(database) {} diff --git a/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs b/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs index 4ec8bd8e..4c40f4f9 100644 --- a/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs +++ b/ProjectLighthouse/Pages/CompleteEmailVerificationPage.cshtml.cs @@ -1,6 +1,5 @@ #nullable enable using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Profiles.Email; @@ -12,10 +11,10 @@ namespace LBPUnion.ProjectLighthouse.Pages; public class CompleteEmailVerificationPage : BaseLayout { - public CompleteEmailVerificationPage([NotNull] Database database) : base(database) + public CompleteEmailVerificationPage(Database database) : base(database) {} - public string? Error = null; + public string? Error; public async Task OnGet(string token) { diff --git a/ProjectLighthouse/Pages/Debug/FilterTestPage.cshtml.cs b/ProjectLighthouse/Pages/Debug/FilterTestPage.cshtml.cs index 804cf19b..84b5c2ec 100644 --- a/ProjectLighthouse/Pages/Debug/FilterTestPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Debug/FilterTestPage.cshtml.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Threading.Tasks; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Pages.Layouts; using Microsoft.AspNetCore.Mvc; @@ -11,10 +10,10 @@ public class FilterTestPage : BaseLayout public FilterTestPage(Database database) : base(database) {} - public string? FilteredText = null; - public string? Text = null; + public string? FilteredText; + public string? Text; - public async Task OnGet(string? text = null) + public IActionResult OnGet(string? text = null) { #if !DEBUG return this.NotFound(); diff --git a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml index 6a16b67c..9b5e0a3c 100644 --- a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml +++ b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml @@ -50,6 +50,7 @@

Best rooms for each game version

@foreach (GameVersion version in Enum.GetValues()) { +#nullable enable if (version == GameVersion.LittleBigPlanet1 || version == GameVersion.LittleBigPlanetPSP || version == GameVersion.Unknown) continue; FindBestRoomResponse? response = RoomHelper.FindBestRoom(null, version, null, null, null); diff --git a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml.cs b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml.cs index 370c2d24..ae3b0341 100644 --- a/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml.cs +++ b/ProjectLighthouse/Pages/Debug/RoomVisualizerPage.cshtml.cs @@ -1,26 +1,21 @@ #nullable enable -using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; -using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; namespace LBPUnion.ProjectLighthouse.Pages.Debug; public class RoomVisualizerPage : BaseLayout { - public RoomVisualizerPage([NotNull] Database database) : base(database) + public RoomVisualizerPage(Database database) : base(database) {} - public async Task OnGet() + public IActionResult OnGet() { #if !DEBUG User? user = this.Database.UserFromWebRequest(this.Request); if (user == null || !user.IsAdmin) return this.NotFound(); + #endif return this.Page(); - #else - return this.Page(); - #endif } } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs b/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs index bb1d745a..3836a6f2 100644 --- a/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs +++ b/ProjectLighthouse/Pages/ExternalAuth/AuthenticationPage.cshtml.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Net; -using System.Threading.Tasks; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Settings; @@ -14,13 +13,13 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth; public class AuthenticationPage : BaseLayout { - public List AuthenticationAttempts; + public List AuthenticationAttempts = new(); public IPAddress? IpAddress; public AuthenticationPage(Database database) : base(database) {} - public async Task OnGet() + public IActionResult OnGet() { if (!ServerSettings.Instance.UseExternalAuth) return this.NotFound(); if (this.User == null) return this.StatusCode(403, ""); diff --git a/ProjectLighthouse/Pages/ExternalAuth/ManageUserApprovedIpAddressesPage.cshtml.cs b/ProjectLighthouse/Pages/ExternalAuth/ManageUserApprovedIpAddressesPage.cshtml.cs index bd70b6c3..ff58bd98 100644 --- a/ProjectLighthouse/Pages/ExternalAuth/ManageUserApprovedIpAddressesPage.cshtml.cs +++ b/ProjectLighthouse/Pages/ExternalAuth/ManageUserApprovedIpAddressesPage.cshtml.cs @@ -11,8 +11,8 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth; public class ManageUserApprovedIpAddressesPage : BaseLayout { + public List ApprovedIpAddresses = new(); - public List ApprovedIpAddresses; public ManageUserApprovedIpAddressesPage(Database database) : base(database) {} diff --git a/ProjectLighthouse/Pages/LandingPage.cshtml.cs b/ProjectLighthouse/Pages/LandingPage.cshtml.cs index 0d23a58e..5bc14fb4 100644 --- a/ProjectLighthouse/Pages/LandingPage.cshtml.cs +++ b/ProjectLighthouse/Pages/LandingPage.cshtml.cs @@ -15,7 +15,7 @@ public class LandingPage : BaseLayout { public int AuthenticationAttemptsCount; - public List PlayersOnline; + public List PlayersOnline = new(); public int PlayersOnlineCount; public LandingPage(Database database) : base(database) diff --git a/ProjectLighthouse/Pages/LoginForm.cshtml.cs b/ProjectLighthouse/Pages/LoginForm.cshtml.cs index 86cb9b9f..496c27d7 100644 --- a/ProjectLighthouse/Pages/LoginForm.cshtml.cs +++ b/ProjectLighthouse/Pages/LoginForm.cshtml.cs @@ -21,7 +21,7 @@ public class LoginForm : BaseLayout public LoginForm(Database database) : base(database) {} - public string Error { get; private set; } + public string? Error { get; private set; } [UsedImplicitly] public async Task OnPost(string username, string password) @@ -111,9 +111,5 @@ public class LoginForm : BaseLayout } [UsedImplicitly] - public async Task OnGet() - { - this.Error = string.Empty; - return this.Page(); - } + public IActionResult OnGet() => this.Page(); } \ No newline at end of file diff --git a/ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs b/ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs index 62b5129e..ce26ed6b 100644 --- a/ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs +++ b/ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs @@ -13,7 +13,7 @@ public class PasswordResetPage : BaseLayout public PasswordResetPage(Database database) : base(database) {} - public string Error { get; private set; } + public string? Error { get; private set; } [UsedImplicitly] public async Task OnPost(string password, string confirmPassword) diff --git a/ProjectLighthouse/Pages/PasswordResetRequiredPage.cshtml.cs b/ProjectLighthouse/Pages/PasswordResetRequiredPage.cshtml.cs index 9739b4d3..a7a0998a 100644 --- a/ProjectLighthouse/Pages/PasswordResetRequiredPage.cshtml.cs +++ b/ProjectLighthouse/Pages/PasswordResetRequiredPage.cshtml.cs @@ -1,6 +1,4 @@ #nullable enable -using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; @@ -9,12 +7,12 @@ namespace LBPUnion.ProjectLighthouse.Pages; public class PasswordResetRequiredPage : BaseLayout { - public PasswordResetRequiredPage([NotNull] Database database) : base(database) + public PasswordResetRequiredPage(Database database) : base(database) {} public bool WasResetRequest { get; private set; } - public async Task OnGet() + public IActionResult OnGet() { User? user = this.Database.UserFromWebRequest(this.Request); if (user == null) return this.Redirect("~/login"); diff --git a/ProjectLighthouse/Pages/PhotosPage.cshtml.cs b/ProjectLighthouse/Pages/PhotosPage.cshtml.cs index dcf8cef0..b35b0b6e 100644 --- a/ProjectLighthouse/Pages/PhotosPage.cshtml.cs +++ b/ProjectLighthouse/Pages/PhotosPage.cshtml.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Settings; @@ -21,10 +20,10 @@ public class PhotosPage : BaseLayout public int PhotoCount; - public List Photos; + public List Photos = new(); - public string SearchValue; - public PhotosPage([NotNull] Database database) : base(database) + public string? SearchValue; + public PhotosPage(Database database) : base(database) {} public async Task OnGet([FromRoute] int pageNumber, [FromQuery] string? name) @@ -33,15 +32,18 @@ public class PhotosPage : BaseLayout this.SearchValue = name.Replace(" ", string.Empty); - this.PhotoCount = await this.Database.Photos.CountAsync(p => p.Creator.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue)); + this.PhotoCount = await this.Database.Photos.Include + (p => p.Creator) + .CountAsync(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue)); this.PageNumber = pageNumber; this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize)); if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); - this.Photos = await this.Database.Photos.Include(p => p.Creator) - .Where(p => p.Creator.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue)) + this.Photos = await this.Database.Photos.Include + (p => p.Creator) + .Where(p => p.Creator!.Username.Contains(this.SearchValue) || p.PhotoSubjectCollection.Contains(this.SearchValue)) .OrderByDescending(p => p.Timestamp) .Skip(pageNumber * ServerStatics.PageSize) .Take(ServerStatics.PageSize) diff --git a/ProjectLighthouse/Pages/ReportsPage.cshtml.cs b/ProjectLighthouse/Pages/ReportsPage.cshtml.cs index 54c7423d..265dcec3 100644 --- a/ProjectLighthouse/Pages/ReportsPage.cshtml.cs +++ b/ProjectLighthouse/Pages/ReportsPage.cshtml.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Reports; @@ -23,12 +22,12 @@ public class ReportsPage : BaseLayout public int ReportCount; - public List Reports; + public List Reports = new(); - public string SearchValue; + public string SearchValue = ""; - public ReportsPage([NotNull] Database database) : base(database) - { } + public ReportsPage(Database database) : base(database) + {} public async Task OnGet([FromRoute] int pageNumber, [FromQuery] string? name) { @@ -43,7 +42,7 @@ public class ReportsPage : BaseLayout this.ReportCount = await this.Database.Reports.Include(r => r.ReportingPlayer).CountAsync(r => r.ReportingPlayer.Username.Contains(this.SearchValue)); this.PageNumber = pageNumber; - this.PageAmount = Math.Max(1, (int) Math.Ceiling((double) this.ReportCount / ServerStatics.PageSize)); + this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.ReportCount / ServerStatics.PageSize)); if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/admin/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); @@ -57,11 +56,11 @@ public class ReportsPage : BaseLayout foreach (GriefReport r in this.Reports) { - r.XmlPlayers = (ReportPlayer[]) JsonSerializer.Deserialize(r.Players, typeof(ReportPlayer[]))!; + r.XmlPlayers = (ReportPlayer[])JsonSerializer.Deserialize(r.Players, typeof(ReportPlayer[]))!; r.XmlBounds = new Marqee() { - Rect = (Rectangle) JsonSerializer.Deserialize(r.Bounds, typeof(Rectangle))!, + Rect = (Rectangle)JsonSerializer.Deserialize(r.Bounds, typeof(Rectangle))!, }; } diff --git a/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml b/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml index 09e0f2dc..f50b713a 100644 --- a/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml +++ b/ProjectLighthouse/Pages/SendVerificationEmailPage.cshtml @@ -7,7 +7,7 @@ }

An email address on your account has been set, but hasn't been verified yet.

-

To verify it, check the email sent to @Model.User.EmailAddress and click the link in the email.

+

To verify it, check the email sent to @Model.User?.EmailAddress and click the link in the email.

Resend email
diff --git a/ProjectLighthouse/Pages/SetEmailForm.cshtml b/ProjectLighthouse/Pages/SetEmailForm.cshtml index 3bac01b4..2333e837 100644 --- a/ProjectLighthouse/Pages/SetEmailForm.cshtml +++ b/ProjectLighthouse/Pages/SetEmailForm.cshtml @@ -21,7 +21,7 @@ - + } diff --git a/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs b/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs index 1b39d592..73fa9224 100644 --- a/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs +++ b/ProjectLighthouse/Pages/SetEmailForm.cshtml.cs @@ -19,7 +19,7 @@ public class SetEmailForm : BaseLayout public SetEmailForm(Database database) : base(database) {} - public EmailSetToken EmailToken; + public EmailSetToken? EmailToken; public async Task OnGet(string? token = null) { diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml.cs b/ProjectLighthouse/Pages/SlotPage.cshtml.cs index 893683db..dee4e672 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse/Pages/SlotPage.cshtml.cs @@ -15,13 +15,13 @@ namespace LBPUnion.ProjectLighthouse.Pages; public class SlotPage : BaseLayout { - public List Comments; - public List Reviews; + public List Comments = new(); + public List Reviews = new(); public readonly bool CommentsEnabled = ServerSettings.Instance.LevelCommentsEnabled; public readonly bool ReviewsEnabled = ServerSettings.Instance.LevelReviewsEnabled; - public Slot Slot; + public Slot? Slot; public SlotPage(Database database) : base(database) {} diff --git a/ProjectLighthouse/Pages/SlotsPage.cshtml.cs b/ProjectLighthouse/Pages/SlotsPage.cshtml.cs index 4687223a..0e15b011 100644 --- a/ProjectLighthouse/Pages/SlotsPage.cshtml.cs +++ b/ProjectLighthouse/Pages/SlotsPage.cshtml.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Settings; @@ -21,11 +20,11 @@ public class SlotsPage : BaseLayout public int SlotCount; - public List Slots; + public List Slots = new(); - public string SearchValue; + public string? SearchValue; - public SlotsPage([NotNull] Database database) : base(database) + public SlotsPage(Database database) : base(database) {} public async Task OnGet([FromRoute] int pageNumber, [FromQuery] string? name) diff --git a/ProjectLighthouse/Pages/UsersPage.cshtml.cs b/ProjectLighthouse/Pages/UsersPage.cshtml.cs index ce2a3e22..637df312 100644 --- a/ProjectLighthouse/Pages/UsersPage.cshtml.cs +++ b/ProjectLighthouse/Pages/UsersPage.cshtml.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using JetBrains.Annotations; using LBPUnion.ProjectLighthouse.Pages.Layouts; using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types.Settings; @@ -20,11 +19,11 @@ public class UsersPage : BaseLayout public int UserCount; - public List Users; + public List Users = new(); - public string SearchValue; + public string? SearchValue; - public UsersPage([NotNull] Database database) : base(database) + public UsersPage(Database database) : base(database) {} public async Task OnGet([FromRoute] int pageNumber, [FromQuery] string? name) diff --git a/ProjectLighthouse/Types/Files/LbpFile.cs b/ProjectLighthouse/Types/Files/LbpFile.cs index b3cad5e3..af35d621 100644 --- a/ProjectLighthouse/Types/Files/LbpFile.cs +++ b/ProjectLighthouse/Types/Files/LbpFile.cs @@ -19,7 +19,7 @@ public class LbpFile public readonly string Hash; - public LbpFile(byte[] data, string? hash = null) + public LbpFile(byte[] data) { this.Data = data; @@ -34,6 +34,6 @@ public class LbpFile byte[] data = File.ReadAllBytes(path); - return new LbpFile(data, hash); + return new LbpFile(data); } } \ No newline at end of file diff --git a/ProjectLighthouse/Types/Reports/Rectangle.cs b/ProjectLighthouse/Types/Reports/Rectangle.cs index 24757bc0..66a8116c 100644 --- a/ProjectLighthouse/Types/Reports/Rectangle.cs +++ b/ProjectLighthouse/Types/Reports/Rectangle.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Xml.Serialization; -using LBPUnion.ProjectLighthouse.Serialization; -using Newtonsoft.Json; +using System.Xml.Serialization; namespace LBPUnion.ProjectLighthouse.Types.Reports; diff --git a/ProjectLighthouse/Types/Settings/ServerSettings.cs b/ProjectLighthouse/Types/Settings/ServerSettings.cs index fc356ac8..d0f10b2a 100644 --- a/ProjectLighthouse/Types/Settings/ServerSettings.cs +++ b/ProjectLighthouse/Types/Settings/ServerSettings.cs @@ -14,6 +14,8 @@ public class ServerSettings { public const int CurrentConfigVersion = 26; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE! private static FileSystemWatcher fileWatcher; + + // ReSharper disable once NotNullMemberIsNotInitialized static ServerSettings() { if (ServerStatics.IsUnitTesting) return; // Unit testing, we don't want to read configurations here since the tests will provide their own diff --git a/ProjectLighthouse/Types/Settings/ServerStatics.cs b/ProjectLighthouse/Types/Settings/ServerStatics.cs index 62c2a7b5..dacc34f0 100644 --- a/ProjectLighthouse/Types/Settings/ServerStatics.cs +++ b/ProjectLighthouse/Types/Settings/ServerStatics.cs @@ -26,10 +26,10 @@ public static class ServerStatics } } - public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit")); + public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName!.StartsWith("xunit")); #if DEBUG - public static readonly bool IsDebug = true; + public static readonly bool IsDebug = true; #else public static readonly bool IsDebug = false; #endif diff --git a/ProjectLighthouse/Types/Tickets/NPTicket.cs b/ProjectLighthouse/Types/Tickets/NPTicket.cs index 5f948a1c..91d76629 100644 --- a/ProjectLighthouse/Types/Tickets/NPTicket.cs +++ b/ProjectLighthouse/Types/Tickets/NPTicket.cs @@ -16,9 +16,9 @@ namespace LBPUnion.ProjectLighthouse.Types.Tickets; /// public class NPTicket { - public string Username { get; set; } + public string? Username { get; set; } - private Version ticketVersion { get; set; } + private Version? ticketVersion { get; set; } public Platform Platform { get; set; } @@ -26,7 +26,7 @@ public class NPTicket public ulong IssuedDate { get; set; } public ulong ExpireDate { get; set; } - private string titleId { get; set; } + private string? titleId { get; set; } public GameVersion GameVersion { get; set; } @@ -111,9 +111,11 @@ public class NPTicket default: throw new NotImplementedException(); } + if (npTicket.titleId == null) throw new ArgumentNullException($"{nameof(npTicket)}.{nameof(npTicket.titleId)}"); + // 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 + // We need to chop this to get the titleId we're looking for 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 diff --git a/ProjectLighthouse/Types/User.cs b/ProjectLighthouse/Types/User.cs index c64ea394..b73fcecb 100644 --- a/ProjectLighthouse/Types/User.cs +++ b/ProjectLighthouse/Types/User.cs @@ -11,9 +11,11 @@ namespace LBPUnion.ProjectLighthouse.Types; public class User { + #nullable enable [NotMapped] [JsonIgnore] private Database? _database; + #nullable disable [NotMapped] [JsonIgnore]