The Great Formatting of 2022

This commit is contained in:
jvyden 2022-01-18 23:09:02 -05:00
parent 59cc7f02fb
commit 35f50f5f8c
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
162 changed files with 6609 additions and 6809 deletions

View file

@ -6,10 +6,10 @@ using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests namespace ProjectLighthouse.Tests.GameApiTests;
public class AuthenticationTests : LighthouseServerTest
{ {
public class AuthenticationTests : LighthouseServerTest
{
[Fact] [Fact]
public async Task ShouldReturnErrorOnNoPostData() public async Task ShouldReturnErrorOnNoPostData()
{ {
@ -63,5 +63,4 @@ namespace ProjectLighthouse.Tests.GameApiTests
Assert.False(response.IsSuccessStatusCode); Assert.False(response.IsSuccessStatusCode);
Assert.True(response.StatusCode == HttpStatusCode.Forbidden); Assert.True(response.StatusCode == HttpStatusCode.Forbidden);
} }
}
} }

View file

@ -6,10 +6,10 @@ using LBPUnion.ProjectLighthouse.Tests;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests namespace ProjectLighthouse.Tests.GameApiTests;
public class DatabaseTests : LighthouseServerTest
{ {
public class DatabaseTests : LighthouseServerTest
{
[DatabaseFact] [DatabaseFact]
public async Task CanCreateUserTwice() public async Task CanCreateUserTwice()
{ {
@ -24,5 +24,4 @@ namespace ProjectLighthouse.Tests.GameApiTests
await database.RemoveUser(userA); // Only remove userA since userA and userB are the same user await database.RemoveUser(userA); // Only remove userA since userA and userB are the same user
} }
}
} }

View file

@ -8,10 +8,10 @@ using LBPUnion.ProjectLighthouse.Tests;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests namespace ProjectLighthouse.Tests.GameApiTests;
public class MatchTests : LighthouseServerTest
{ {
public class MatchTests : LighthouseServerTest
{
private static readonly SemaphoreSlim semaphore = new(1, 1); private static readonly SemaphoreSlim semaphore = new(1, 1);
[DatabaseFact] [DatabaseFact]
@ -58,5 +58,4 @@ namespace ProjectLighthouse.Tests.GameApiTests
semaphore.Release(); semaphore.Release();
Assert.Equal(oldPlayerCount + 1, playerCount); Assert.Equal(oldPlayerCount + 1, playerCount);
} }
}
} }

View file

@ -9,10 +9,10 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Profiles;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests namespace ProjectLighthouse.Tests.GameApiTests;
public class SlotTests : LighthouseServerTest
{ {
public class SlotTests : LighthouseServerTest
{
[DatabaseFact] [DatabaseFact]
public async Task ShouldOnlyShowUsersLevels() public async Task ShouldOnlyShowUsersLevels()
{ {
@ -89,5 +89,4 @@ namespace ProjectLighthouse.Tests.GameApiTests
await database.SaveChangesAsync(); await database.SaveChangesAsync();
} }
}
} }

View file

@ -6,10 +6,10 @@ using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Tests; using LBPUnion.ProjectLighthouse.Tests;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests namespace ProjectLighthouse.Tests.GameApiTests;
public class UploadTests : LighthouseServerTest
{ {
public class UploadTests : LighthouseServerTest
{
public UploadTests() public UploadTests()
{ {
string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r"); string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r");
@ -55,5 +55,4 @@ namespace ProjectLighthouse.Tests.GameApiTests
Assert.False(response.StatusCode == HttpStatusCode.Forbidden); Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
Assert.True(response.IsSuccessStatusCode); Assert.True(response.IsSuccessStatusCode);
} }
}
} }

View file

@ -7,10 +7,10 @@ using LBPUnion.ProjectLighthouse.Types;
using OpenQA.Selenium; using OpenQA.Selenium;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.WebsiteTests namespace ProjectLighthouse.Tests.WebsiteTests;
public class AdminTests : LighthouseWebTest
{ {
public class AdminTests : LighthouseWebTest
{
public const string AdminPanelButtonXPath = "/html/body/div/header/div/div/div/a[2]"; public const string AdminPanelButtonXPath = "/html/body/div/header/div/div/div/a[2]";
[DatabaseFact] [DatabaseFact]
@ -60,5 +60,4 @@ namespace ProjectLighthouse.Tests.WebsiteTests
Assert.DoesNotContain("Admin Panel", this.Driver.FindElement(By.XPath(AdminPanelButtonXPath)).Text); Assert.DoesNotContain("Admin Panel", this.Driver.FindElement(By.XPath(AdminPanelButtonXPath)).Text);
} }
}
} }

View file

@ -9,10 +9,10 @@ using Microsoft.EntityFrameworkCore;
using OpenQA.Selenium; using OpenQA.Selenium;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.WebsiteTests namespace ProjectLighthouse.Tests.WebsiteTests;
public class AuthenticationTests : LighthouseWebTest
{ {
public class AuthenticationTests : LighthouseWebTest
{
[DatabaseFact] [DatabaseFact]
public async Task ShouldLoginWithPassword() public async Task ShouldLoginWithPassword()
{ {
@ -102,5 +102,4 @@ namespace ProjectLighthouse.Tests.WebsiteTests
await database.RemoveUser(user); await database.RemoveUser(user);
} }
}
} }

View file

@ -7,21 +7,21 @@ using OpenQA.Selenium;
using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Chrome;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.WebsiteTests namespace ProjectLighthouse.Tests.WebsiteTests;
[Collection(nameof(LighthouseWebTest))]
public class LighthouseWebTest : IDisposable
{ {
[Collection(nameof(LighthouseWebTest))]
public class LighthouseWebTest : IDisposable
{
public readonly IWebHost WebHost = new WebHostBuilder().UseKestrel().UseStartup<TestStartup>().UseWebRoot("StaticFiles").Build();
public readonly string BaseAddress; public readonly string BaseAddress;
public readonly IWebDriver Driver; public readonly IWebDriver Driver;
public readonly IWebHost WebHost = new WebHostBuilder().UseKestrel().UseStartup<TestStartup>().UseWebRoot("StaticFiles").Build();
public LighthouseWebTest() public LighthouseWebTest()
{ {
this.WebHost.Start(); this.WebHost.Start();
IServerAddressesFeature? serverAddressesFeature = WebHost.ServerFeatures.Get<IServerAddressesFeature>(); IServerAddressesFeature? serverAddressesFeature = this.WebHost.ServerFeatures.Get<IServerAddressesFeature>();
if (serverAddressesFeature == null) throw new ArgumentNullException(); if (serverAddressesFeature == null) throw new ArgumentNullException();
this.BaseAddress = serverAddressesFeature.Addresses.First(); this.BaseAddress = serverAddressesFeature.Addresses.First();
@ -46,5 +46,4 @@ namespace ProjectLighthouse.Tests.WebsiteTests
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
}
} }

View file

@ -9,10 +9,10 @@ using Microsoft.EntityFrameworkCore;
using OpenQA.Selenium; using OpenQA.Selenium;
using Xunit; using Xunit;
namespace ProjectLighthouse.Tests.WebsiteTests namespace ProjectLighthouse.Tests.WebsiteTests;
public class RegisterTests : LighthouseWebTest
{ {
public class RegisterTests : LighthouseWebTest
{
[DatabaseFact] [DatabaseFact]
public async Task ShouldRegister() public async Task ShouldRegister()
{ {
@ -80,5 +80,4 @@ namespace ProjectLighthouse.Tests.WebsiteTests
Assert.Contains("The username you've chosen is already taken.", this.Driver.PageSource); Assert.Contains("The username you've chosen is already taken.", this.Driver.PageSource);
} }
}
} }

View file

@ -2,28 +2,22 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Xunit; using Xunit;
namespace LBPUnion.ProjectLighthouse.Tests namespace LBPUnion.ProjectLighthouse.Tests;
public sealed class DatabaseFactAttribute : FactAttribute
{ {
public sealed class DatabaseFactAttribute : FactAttribute
{
private static readonly object migrateLock = new(); private static readonly object migrateLock = new();
public DatabaseFactAttribute() public DatabaseFactAttribute()
{ {
ServerSettings.Instance = new ServerSettings(); ServerSettings.Instance = new ServerSettings();
ServerSettings.Instance.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse"; ServerSettings.Instance.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
if (!ServerStatics.DbConnected) if (!ServerStatics.DbConnected) this.Skip = "Database not available";
{
this.Skip = "Database not available";
}
else else
{
lock(migrateLock) lock(migrateLock)
{ {
using Database database = new(); using Database database = new();
database.Database.Migrate(); database.Database.Migrate();
} }
} }
}
}
} }

View file

@ -4,10 +4,10 @@ using System.Text;
using LBPUnion.ProjectLighthouse.Types.Files; using LBPUnion.ProjectLighthouse.Types.Files;
using Xunit; using Xunit;
namespace LBPUnion.ProjectLighthouse.Tests namespace LBPUnion.ProjectLighthouse.Tests;
public class FileTypeTests
{ {
public class FileTypeTests
{
[Fact] [Fact]
public void ShouldRecognizeLevel() public void ShouldRecognizeLevel()
{ {
@ -57,5 +57,4 @@ namespace LBPUnion.ProjectLighthouse.Tests
LbpFile file = new(Encoding.ASCII.GetBytes("free pc only $900")); LbpFile file = new(Encoding.ASCII.GetBytes("free pc only $900"));
Assert.True(file.FileType == LbpFileType.Unknown); Assert.True(file.FileType == LbpFileType.Unknown);
} }
}
} }

View file

@ -11,11 +11,11 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.TestHost;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Tests namespace LBPUnion.ProjectLighthouse.Tests;
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public class LighthouseServerTest
{ {
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public class LighthouseServerTest
{
public readonly HttpClient Client; public readonly HttpClient Client;
public readonly TestServer Server; public readonly TestServer Server;
@ -26,10 +26,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
} }
public async Task<HttpResponseMessage> AuthenticateResponse(int number = -1, bool createUser = true) public async Task<HttpResponseMessage> AuthenticateResponse(int number = -1, bool createUser = true)
{ {
if (number == -1) if (number == -1) number = new Random().Next();
{
number = new Random().Next();
}
const string username = "unitTestUser"; const string username = "unitTestUser";
if (createUser) if (createUser)
@ -77,8 +74,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
public async Task<HttpResponseMessage> UploadFileRequest(string endpoint, string filePath) public async Task<HttpResponseMessage> UploadFileRequest(string endpoint, string filePath)
=> await this.Client.PostAsync(endpoint, new StringContent(await File.ReadAllTextAsync(filePath))); => await this.Client.PostAsync(endpoint, new StringContent(await File.ReadAllTextAsync(filePath)));
public async Task<HttpResponseMessage> UploadDataRequest(string endpoint, byte[] data) public async Task<HttpResponseMessage> UploadDataRequest(string endpoint, byte[] data) => await this.Client.PostAsync(endpoint, new ByteArrayContent(data));
=> await this.Client.PostAsync(endpoint, new ByteArrayContent(data));
public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath, string mmAuth) public async Task<HttpResponseMessage> AuthenticatedUploadFileRequest(string endpoint, string filePath, string mmAuth)
{ {
@ -95,5 +91,4 @@ namespace LBPUnion.ProjectLighthouse.Tests
requestMessage.Content = new ByteArrayContent(data); requestMessage.Content = new ByteArrayContent(data);
return await this.Client.SendAsync(requestMessage); return await this.Client.SendAsync(requestMessage);
} }
}
} }

View file

@ -2,10 +2,10 @@ using System.Collections.Generic;
using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Serialization;
using Xunit; using Xunit;
namespace LBPUnion.ProjectLighthouse.Tests namespace LBPUnion.ProjectLighthouse.Tests;
public class SerializerTests
{ {
public class SerializerTests
{
[Fact] [Fact]
public void BlankElementWorks() public void BlankElementWorks()
{ {
@ -39,5 +39,4 @@ namespace LBPUnion.ProjectLighthouse.Tests
LbpSerializer.Elements(new KeyValuePair<string, object>("test", "asd"), new KeyValuePair<string, object>("foo", "bar")) LbpSerializer.Elements(new KeyValuePair<string, object>("test", "asd"), new KeyValuePair<string, object>("foo", "bar"))
); );
} }
}
} }

View file

@ -3,13 +3,13 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class ClientConfigurationController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class ClientConfigurationController : ControllerBase
{
[HttpGet("network_settings.nws")] [HttpGet("network_settings.nws")]
[SuppressMessage("ReSharper", "StringLiteralTypo")] [SuppressMessage("ReSharper", "StringLiteralTypo")]
public IActionResult NetworkSettings() public IActionResult NetworkSettings()
@ -44,5 +44,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(ps.Serialize()); return this.Ok(ps.Serialize());
} }
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types.Categories;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class CollectionController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class CollectionController : ControllerBase
{
private readonly Database database; private readonly Database database;
public CollectionController(Database database) public CollectionController(Database database)
@ -116,5 +116,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
) )
); );
} }
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class CommentController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class CommentController : ControllerBase
{
private readonly Database database; private readonly Database database;
public CommentController(Database database) public CommentController(Database database)
{ {
@ -79,5 +79,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(); return this.Ok();
} }
}
} }

View file

@ -1,12 +1,11 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
public class DeveloperController : Controller
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
public class DeveloperController : Controller
{
[HttpGet("/developer_videos")] [HttpGet("/developer_videos")]
public IActionResult DeveloperVideos() => this.Ok(); public IActionResult DeveloperVideos() => this.Ok();
}
} }

View file

@ -7,13 +7,13 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
{
[ApiController] [ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")] [Route("LITTLEBIGPLANETPS3_XML/")]
// [Produces("text/plain")] // [Produces("text/plain")]
public class EnterLevelController : ControllerBase public class EnterLevelController : ControllerBase
{ {
private readonly Database database; private readonly Database database;
public EnterLevelController(Database database) public EnterLevelController(Database database)
@ -125,5 +125,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(); return this.Ok();
} }
}
} }

View file

@ -11,12 +11,12 @@ using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
public class FriendsController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
public class FriendsController : ControllerBase
{
private readonly Database database; private readonly Database database;
public FriendsController(Database database) public FriendsController(Database database)
@ -94,5 +94,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(LbpSerializer.StringElement("myFriends", friends)); return this.Ok(LbpSerializer.StringElement("myFriends", friends));
} }
}
} }

View file

@ -2,13 +2,13 @@ using System;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/tags")]
[Produces("text/plain")]
public class LevelTagsController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/tags")]
[Produces("text/plain")]
public class LevelTagsController : ControllerBase
{
[HttpGet] [HttpGet]
public IActionResult Get() public IActionResult Get()
{ {
@ -23,5 +23,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(string.Join(",", tags)); return this.Ok(string.Join(",", tags));
} }
}
} }

View file

@ -9,13 +9,13 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class ListController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class ListController : ControllerBase
{
private readonly Database database; private readonly Database database;
public ListController(Database database) public ListController(Database database)
{ {
@ -213,5 +213,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
#endregion #endregion
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/login")]
[Produces("text/xml")]
public class LoginController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/login")]
[Produces("text/xml")]
public class LoginController : ControllerBase
{
private readonly Database database; private readonly Database database;
public LoginController(Database database) public LoginController(Database database)
@ -150,5 +150,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
}.Serialize() }.Serialize()
); );
} }
}
} }

View file

@ -14,13 +14,13 @@ using LBPUnion.ProjectLighthouse.Types.Match;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class MatchController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class MatchController : ControllerBase
{
private readonly Database database; private readonly Database database;
public MatchController(Database database) public MatchController(Database database)
@ -139,5 +139,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok("[{\"StatusCode\":200}]"); return this.Ok("[{\"StatusCode\":200}]");
} }
}
} }

View file

@ -8,13 +8,13 @@ using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class MessageController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class MessageController : ControllerBase
{
private readonly Database database; private readonly Database database;
public MessageController(Database database) public MessageController(Database database)
@ -85,5 +85,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
Logger.Log($"{user.Username}: {loggedText}", LoggerLevelFilter.Instance); Logger.Log($"{user.Username}: {loggedText}", LoggerLevelFilter.Instance);
return this.Ok(loggedText); return this.Ok(loggedText);
} }
}
} }

View file

@ -2,13 +2,13 @@ using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.News; using LBPUnion.ProjectLighthouse.Types.News;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/news")]
[Produces("text/xml")]
public class NewsController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/news")]
[Produces("text/xml")]
public class NewsController : ControllerBase
{
[HttpGet] [HttpGet]
public IActionResult Get() public IActionResult Get()
{ {
@ -33,5 +33,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(LbpSerializer.StringElement("news", newsEntry)); return this.Ok(LbpSerializer.StringElement("news", newsEntry));
} }
}
} }

View file

@ -13,13 +13,13 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class PhotosController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class PhotosController : ControllerBase
{
private readonly Database database; private readonly Database database;
public PhotosController(Database database) public PhotosController(Database database)
@ -53,10 +53,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
photo.CreatorId = user.UserId; photo.CreatorId = user.UserId;
photo.Creator = user; photo.Creator = user;
if (photo.Subjects.Count > 4) if (photo.Subjects.Count > 4) return this.BadRequest();
{
return this.BadRequest();
}
foreach (PhotoSubject subject in photo.Subjects) foreach (PhotoSubject subject in photo.Subjects)
{ {
@ -76,10 +73,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
List<int> subjectUserIds = new(4); List<int> subjectUserIds = new(4);
foreach (PhotoSubject subject in photo.Subjects) foreach (PhotoSubject subject in photo.Subjects)
{ {
if (subjectUserIds.Contains(subject.UserId)) if (subjectUserIds.Contains(subject.UserId)) return this.BadRequest();
{
return this.BadRequest();
}
subjectUserIds.Add(subject.UserId); subjectUserIds.Add(subject.UserId);
} }
@ -156,5 +151,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
return this.Ok(); return this.Ok();
} }
}
} }

View file

@ -13,13 +13,13 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class PublishController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class PublishController : ControllerBase
{
private readonly Database database; private readonly Database database;
public PublishController(Database database) public PublishController(Database database)
@ -190,5 +190,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return slot; return slot;
} }
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types.Files;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IOFile = System.IO.File; using IOFile = System.IO.File;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Produces("text/xml")]
[Route("LITTLEBIGPLANETPS3_XML")]
public class ResourcesController : ControllerBase
{ {
[ApiController]
[Produces("text/xml")]
[Route("LITTLEBIGPLANETPS3_XML")]
public class ResourcesController : ControllerBase
{
[HttpPost("showModerated")] [HttpPost("showModerated")]
public IActionResult ShowModerated() => this.Ok(LbpSerializer.BlankElement("resources")); public IActionResult ShowModerated() => this.Ok(LbpSerializer.BlankElement("resources"));
@ -85,5 +85,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
await IOFile.WriteAllBytesAsync(path, file.Data); await IOFile.WriteAllBytesAsync(path, file.Data);
return this.Ok(); return this.Ok();
} }
}
} }

View file

@ -13,13 +13,13 @@ using LBPUnion.ProjectLighthouse.Types.Reviews;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class ReviewController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class ReviewController : ControllerBase
{
private readonly Database database; private readonly Database database;
public ReviewController(Database database) public ReviewController(Database database)
@ -327,5 +327,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return review; return review;
} }
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class ScoreController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class ScoreController : ControllerBase
{
private readonly Database database; private readonly Database database;
public ScoreController(Database database) public ScoreController(Database database)
@ -120,10 +120,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
); );
// Find your score, since even if you aren't in the top list your score is pinned // Find your score, since even if you aren't in the top list your score is pinned
var myScore = rankedScores.Where var myScore = rankedScores.Where(rs => rs.Score.PlayerIdCollection.Contains(user.Username)).OrderByDescending(rs => rs.Score.Points).FirstOrDefault();
(rs => rs.Score.PlayerIdCollection.Contains(user.Username))
.OrderByDescending(rs => rs.Score.Points)
.FirstOrDefault();
// Paginated viewing: if not requesting pageStart, get results around user // Paginated viewing: if not requesting pageStart, get results around user
var pagedScores = rankedScores.Skip(pageStart != -1 || myScore == null ? pageStart - 1 : myScore.Rank - 3).Take(Math.Min(pageSize, 30)); var pagedScores = rankedScores.Skip(pageStart != -1 || myScore == null ? pageStart - 1 : myScore.Rank - 3).Take(Math.Min(pageSize, 30));
@ -161,5 +158,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return res; return res;
} }
}
} }

View file

@ -7,13 +7,13 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class SearchController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class SearchController : ControllerBase
{
private readonly Database database; private readonly Database database;
public SearchController(Database database) public SearchController(Database database)
{ {
@ -50,5 +50,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count())); return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
} }
}
} }

View file

@ -11,13 +11,13 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class SlotsController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class SlotsController : ControllerBase
{
private readonly Database database; private readonly Database database;
public SlotsController(Database database) public SlotsController(Database database)
{ {
@ -93,7 +93,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
public async Task<IActionResult> Lbp1CoolSlots([FromQuery] int page) public async Task<IActionResult> Lbp1CoolSlots([FromQuery] int page)
{ {
const int pageSize = 30; const int pageSize = 30;
return await CoolSlots((page - 1) * pageSize, pageSize); return await this.CoolSlots((page - 1) * pageSize, pageSize);
} }
[HttpGet("slots/lbp2cool")] [HttpGet("slots/lbp2cool")]
@ -110,7 +110,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
int _pageStart = pageStart; int _pageStart = pageStart;
if (page != null) _pageStart = (int)page * 30; if (page != null) _pageStart = (int)page * 30;
// bit of a better placeholder until we can track average user interaction with /stream endpoint // bit of a better placeholder until we can track average user interaction with /stream endpoint
return await ThumbsSlots(_pageStart, Math.Min(pageSize, 30), gameFilterType, players, move, "thisWeek"); return await this.ThumbsSlots(_pageStart, Math.Min(pageSize, 30), gameFilterType, players, move, "thisWeek");
} }
[HttpGet("slots")] [HttpGet("slots")]
@ -232,7 +232,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{ {
Random rand = new(); Random rand = new();
IEnumerable<Slot> slots = FilterByRequest(gameFilterType, dateFilterType) IEnumerable<Slot> slots = this.FilterByRequest(gameFilterType, dateFilterType)
.AsEnumerable() .AsEnumerable()
.OrderByDescending(s => s.Thumbsup) .OrderByDescending(s => s.Thumbsup)
.ThenBy(_ => rand.Next()) .ThenBy(_ => rand.Next())
@ -257,14 +257,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{ {
Random rand = new(); Random rand = new();
IEnumerable<Slot> slots = FilterByRequest(gameFilterType, dateFilterType) IEnumerable<Slot> slots = this.FilterByRequest(gameFilterType, dateFilterType)
.AsEnumerable() .AsEnumerable()
.OrderByDescending .OrderByDescending
( (
s => s =>
{ {
// probably not the best way to do this? // probably not the best way to do this?
return GetGameFilter(gameFilterType) switch return this.GetGameFilter(gameFilterType) switch
{ {
GameVersion.LittleBigPlanet1 => s.PlaysLBP1Unique, GameVersion.LittleBigPlanet1 => s.PlaysLBP1Unique,
GameVersion.LittleBigPlanet2 => s.PlaysLBP2Unique, GameVersion.LittleBigPlanet2 => s.PlaysLBP2Unique,
@ -296,7 +296,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{ {
Random rand = new(); Random rand = new();
IEnumerable<Slot> slots = FilterByRequest(gameFilterType, dateFilterType) IEnumerable<Slot> slots = this.FilterByRequest(gameFilterType, dateFilterType)
.AsEnumerable() .AsEnumerable()
.OrderByDescending(s => s.Hearts) .OrderByDescending(s => s.Hearts)
.ThenBy(_ => rand.Next()) .ThenBy(_ => rand.Next())
@ -332,24 +332,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers
_ => 0, _ => 0,
}; };
GameVersion gameVersion = GetGameFilter(gameFilterType); GameVersion gameVersion = this.GetGameFilter(gameFilterType);
IQueryable<Slot> whereSlots; IQueryable<Slot> whereSlots;
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (gameFilterType == "both") if (gameFilterType == "both")
{
// Get game versions less than the current version // Get game versions less than the current version
// Needs support for LBP3 ("both" = LBP1+2) // Needs support for LBP3 ("both" = LBP1+2)
whereSlots = this.database.Slots.Where(s => s.GameVersion <= gameVersion && s.FirstUploaded >= oldestTime); whereSlots = this.database.Slots.Where(s => s.GameVersion <= gameVersion && s.FirstUploaded >= oldestTime);
}
else else
{
// Get game versions exactly equal to gamefiltertype // Get game versions exactly equal to gamefiltertype
whereSlots = this.database.Slots.Where(s => s.GameVersion == gameVersion && s.FirstUploaded >= oldestTime); whereSlots = this.database.Slots.Where(s => s.GameVersion == gameVersion && s.FirstUploaded >= oldestTime);
}
return whereSlots.Include(s => s.Creator).Include(s => s.Location); return whereSlots.Include(s => s.Creator).Include(s => s.Location);
} }
}
} }

View file

@ -3,13 +3,13 @@ using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class StatisticsController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class StatisticsController : ControllerBase
{
private readonly Database database; private readonly Database database;
public StatisticsController(Database database) public StatisticsController(Database database)
{ {
@ -35,5 +35,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpGet("planetStats/totalLevelCount")] [HttpGet("planetStats/totalLevelCount")]
public async Task<IActionResult> TotalLevelCount() => this.Ok((await StatisticsHelper.SlotCount()).ToString()); public async Task<IActionResult> TotalLevelCount() => this.Ok((await StatisticsHelper.SlotCount()).ToString());
}
} }

View file

@ -1,13 +1,12 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class StoreController : Controller
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class StoreController : Controller
{
[HttpGet("promotions")] [HttpGet("promotions")]
public IActionResult Promotions() => this.Ok(); public IActionResult Promotions() => this.Ok();
}
} }

View file

@ -12,13 +12,13 @@ using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers namespace LBPUnion.ProjectLighthouse.Controllers;
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class UserController : ControllerBase
{ {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
public class UserController : ControllerBase
{
private readonly Database database; private readonly Database database;
public UserController(Database database) public UserController(Database database)
@ -188,5 +188,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return this.Ok("[{\"StatusCode\":200}]"); return this.Ok("[{\"StatusCode\":200}]");
} }
}
} }

View file

@ -6,12 +6,12 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin;
[ApiController]
[Route("admin/slot/{id:int}")]
public class AdminSlotController : ControllerBase
{ {
[ApiController]
[Route("admin/slot/{id:int}")]
public class AdminSlotController : ControllerBase
{
private readonly Database database; private readonly Database database;
public AdminSlotController(Database database) public AdminSlotController(Database database)
@ -69,5 +69,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin
return this.Ok(); return this.Ok();
} }
}
} }

View file

@ -4,12 +4,12 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin;
[ApiController]
[Route("admin/user/{id:int}")]
public class AdminUserController : ControllerBase
{ {
[ApiController]
[Route("admin/user/{id:int}")]
public class AdminUserController : ControllerBase
{
private readonly Database database; private readonly Database database;
public AdminUserController(Database database) public AdminUserController(Database database)
@ -33,5 +33,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
return this.Redirect($"/user/{targetedUser.UserId}"); return this.Redirect($"/user/{targetedUser.UserId}");
} }
}
} }

View file

@ -1,10 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website.Debug; namespace LBPUnion.ProjectLighthouse.Controllers.Website.Debug;

View file

@ -7,12 +7,12 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth;
[ApiController]
[Route("/authentication")]
public class AuthenticationController : ControllerBase
{ {
[ApiController]
[Route("/authentication")]
public class AuthenticationController : ControllerBase
{
private readonly Database database; private readonly Database database;
public AuthenticationController(Database database) public AuthenticationController(Database database)
@ -87,5 +87,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth
return this.Redirect("~/authentication"); return this.Redirect("~/authentication");
} }
}
} }

View file

@ -4,12 +4,12 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth;
[ApiController]
[Route("/authentication")]
public class AutoApprovalController : ControllerBase
{ {
[ApiController]
[Route("/authentication")]
public class AutoApprovalController : ControllerBase
{
private readonly Database database; private readonly Database database;
public AutoApprovalController(Database database) public AutoApprovalController(Database database)
@ -63,5 +63,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website.ExternalAuth
return this.Redirect("/authentication/autoApprovals"); return this.Redirect("/authentication/autoApprovals");
} }
}
} }

View file

@ -10,12 +10,12 @@ using Microsoft.EntityFrameworkCore;
// TODO: Clean up this file // TODO: Clean up this file
// - jvyden // - jvyden
namespace LBPUnion.ProjectLighthouse.Controllers.Website namespace LBPUnion.ProjectLighthouse.Controllers.Website;
[ApiController]
[Route("slot/{id:int}")]
public class SlotPageController : ControllerBase
{ {
[ApiController]
[Route("slot/{id:int}")]
public class SlotPageController : ControllerBase
{
private readonly Database database; private readonly Database database;
public SlotPageController(Database database) public SlotPageController(Database database)
@ -86,5 +86,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
return this.Redirect(callbackUrl); return this.Redirect(callbackUrl);
} }
}
} }

View file

@ -4,12 +4,12 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Controllers.Website namespace LBPUnion.ProjectLighthouse.Controllers.Website;
[ApiController]
[Route("user/{id:int}")]
public class UserPageController : ControllerBase
{ {
[ApiController]
[Route("user/{id:int}")]
public class UserPageController : ControllerBase
{
private readonly Database database; private readonly Database database;
public UserPageController(Database database) public UserPageController(Database database)
@ -44,5 +44,4 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
return this.Redirect("~/user/" + id); return this.Redirect("~/user/" + id);
} }
}
} }

View file

@ -13,10 +13,10 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse namespace LBPUnion.ProjectLighthouse;
public class Database : DbContext
{ {
public class Database : DbContext
{
public DbSet<User> Users { get; set; } public DbSet<User> Users { get; set; }
public DbSet<Location> Locations { get; set; } public DbSet<Location> Locations { get; set; }
public DbSet<Slot> Slots { get; set; } public DbSet<Slot> Slots { get; set; }
@ -97,8 +97,7 @@ namespace LBPUnion.ProjectLighthouse
public async Task HeartUser(User user, User heartedUser) public async Task HeartUser(User user, User heartedUser)
{ {
HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) return; if (heartedProfile != null) return;
this.HeartedProfiles.Add this.HeartedProfiles.Add
@ -115,8 +114,7 @@ namespace LBPUnion.ProjectLighthouse
public async Task UnheartUser(User user, User heartedUser) public async Task UnheartUser(User user, User heartedUser)
{ {
HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync HeartedProfile? heartedProfile = await this.HeartedProfiles.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) this.HeartedProfiles.Remove(heartedProfile); if (heartedProfile != null) this.HeartedProfiles.Remove(heartedProfile);
await this.SaveChangesAsync(); await this.SaveChangesAsync();
@ -295,5 +293,4 @@ namespace LBPUnion.ProjectLighthouse
if (saveChanges) await this.SaveChangesAsync(); if (saveChanges) await this.SaveChangesAsync();
} }
#nullable disable #nullable disable
}
} }

View file

@ -2,10 +2,10 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
namespace LBPUnion.ProjectLighthouse namespace LBPUnion.ProjectLighthouse;
public class FakeRemoteIPAddressMiddleware
{ {
public class FakeRemoteIPAddressMiddleware
{
private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1"); private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1");
private readonly RequestDelegate next; private readonly RequestDelegate next;
@ -20,5 +20,4 @@ namespace LBPUnion.ProjectLighthouse
await this.next(httpContext); await this.next(httpContext);
} }
}
} }

View file

@ -6,10 +6,10 @@ using System.IO.Pipelines;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class BinaryHelper
{ {
public static class BinaryHelper
{
public static string ReadString(BinaryReader reader) public static string ReadString(BinaryReader reader)
{ {
List<byte> readBytes = new(); List<byte> readBytes = new();
@ -61,5 +61,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
return data.ToArray(); return data.ToArray();
} }
}
} }

View file

@ -1,10 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using LBPUnion.ProjectLighthouse.Types.Categories; using LBPUnion.ProjectLighthouse.Types.Categories;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class CollectionHelper
{ {
public static class CollectionHelper
{
public static readonly List<Category> Categories = new(); public static readonly List<Category> Categories = new();
static CollectionHelper() static CollectionHelper()
@ -17,5 +17,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
using Database database = new(); using Database database = new();
foreach (DatabaseCategory category in database.CustomCategories) Categories.Add(new CustomCategory(category)); foreach (DatabaseCategory category in database.CustomCategories) Categories.Add(new CustomCategory(category));
} }
}
} }

View file

@ -1,9 +1,9 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class DeniedAuthenticationHelper
{ {
public static class DeniedAuthenticationHelper
{
public static readonly Dictionary<string, long> IPAddressAndNameDeniedAt = new(); public static readonly Dictionary<string, long> IPAddressAndNameDeniedAt = new();
public static readonly Dictionary<string, int> AttemptsByIPAddressAndName = new(); public static readonly Dictionary<string, int> AttemptsByIPAddressAndName = new();
@ -34,5 +34,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
return attempts; return attempts;
} }
}
} }

View file

@ -1,7 +1,7 @@
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class EulaHelper
{ {
public static class EulaHelper
{
public const string License = @" public const string License = @"
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@ -15,5 +15,4 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>."; along with this program. If not, see <https://www.gnu.org/licenses/>.";
}
} }

View file

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
// https://stackoverflow.com/a/8039737
public static class ExceptionExtensions
{ {
// https://stackoverflow.com/a/8039737
public static class ExceptionExtensions
{
public static string ToDetailedException(this Exception exception) public static string ToDetailedException(this Exception exception)
{ {
PropertyInfo[] properties = exception.GetType().GetProperties(); PropertyInfo[] properties = exception.GetType().GetProperties();
@ -24,5 +24,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers.Extensions
return string.Join("\n", fields); return string.Join("\n", fields);
} }
}
} }

View file

@ -2,14 +2,13 @@ using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
// yoinked and adapted from https://stackoverflow.com/a/68641796
public static class RequestExtensions
{ {
// yoinked and adapted from https://stackoverflow.com/a/68641796
public static class RequestExtensions
{
private static readonly Regex mobileCheck = new private static readonly Regex mobileCheck = new
("Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled); ("Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString()); public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString());
}
} }

View file

@ -1,10 +1,9 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
public static class StringExtensions
{ {
public static class StringExtensions
{
public static string ToFileName(this string text) => Path.GetInvalidFileNameChars().Aggregate(text, (current, c) => current.Replace(c.ToString(), "")); public static string ToFileName(this string text) => Path.GetInvalidFileNameChars().Aggregate(text, (current, c) => current.Replace(c.ToString(), ""));
}
} }

View file

@ -5,10 +5,10 @@ using System.Text;
using LBPUnion.ProjectLighthouse.Types.Files; using LBPUnion.ProjectLighthouse.Types.Files;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class FileHelper
{ {
public static class FileHelper
{
public static readonly string ResourcePath = Path.Combine(Environment.CurrentDirectory, "r"); public static readonly string ResourcePath = Path.Combine(Environment.CurrentDirectory, "r");
public static string GetResourcePath(string hash) => Path.Combine(ResourcePath, hash); public static string GetResourcePath(string hash) => Path.Combine(ResourcePath, hash);
@ -99,5 +99,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
} }
public static string[] ResourcesNotUploaded(params string[] hashes) => hashes.Where(hash => !ResourceExists(hash)).ToArray(); public static string[] ResourcesNotUploaded(params string[] hashes) => hashes.Where(hash => !ResourceExists(hash)).ToArray();
}
} }

View file

@ -2,13 +2,12 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
[NotMapped]
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
public static class FriendHelper
{ {
[NotMapped]
[SuppressMessage("ReSharper", "CollectionNeverQueried.Global")]
public static class FriendHelper
{
public static readonly Dictionary<int, int[]> FriendIdsByUserId = new(); public static readonly Dictionary<int, int[]> FriendIdsByUserId = new();
public static readonly Dictionary<int, int[]> BlockedIdsByUserId = new(); public static readonly Dictionary<int, int[]> BlockedIdsByUserId = new();
}
} }

View file

@ -1,10 +1,10 @@
using System.Linq; using System.Linq;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public class GameVersionHelper
{ {
public class GameVersionHelper
{
// https://www.serialstation.com/games/b89b4eb4-4e4c-4e54-b72b-f7f9dbfac125 // https://www.serialstation.com/games/b89b4eb4-4e4c-4e54-b72b-f7f9dbfac125
public static readonly string[] LittleBigPlanet1TitleIds = public static readonly string[] LittleBigPlanet1TitleIds =
{ {
@ -98,5 +98,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
return GameVersion.LittleBigPlanet1; return GameVersion.LittleBigPlanet1;
} }
}
} }

View file

@ -6,11 +6,11 @@ using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class HashHelper
{ {
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class HashHelper
{
private static readonly SHA1 sha1 = SHA1.Create(); private static readonly SHA1 sha1 = SHA1.Create();
private static readonly SHA256 sha256 = SHA256.Create(); private static readonly SHA256 sha256 = SHA256.Create();
private static readonly Random random = new(); private static readonly Random random = new();
@ -79,5 +79,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
#endregion #endregion
}
} }

View file

@ -6,10 +6,10 @@ using Kettu;
using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class InfluxHelper
{ {
public static class InfluxHelper
{
public static readonly InfluxDBClient Client = InfluxDBClientFactory.Create(ServerSettings.Instance.InfluxUrl, ServerSettings.Instance.InfluxToken); public static readonly InfluxDBClient Client = InfluxDBClientFactory.Create(ServerSettings.Instance.InfluxUrl, ServerSettings.Instance.InfluxToken);
public static async void Log() public static async void Log()
@ -46,5 +46,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
t.Name = "InfluxDB Logger"; t.Name = "InfluxDB Logger";
t.Start(); t.Start();
} }
}
} }

View file

@ -5,10 +5,10 @@ using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class LastContactHelper
{ {
public static class LastContactHelper
{
private static readonly Database database = new(); private static readonly Database database = new();
public static async Task SetLastContact(User user, GameVersion gameVersion) public static async Task SetLastContact(User user, GameVersion gameVersion)
@ -31,5 +31,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
await database.SaveChangesAsync(); await database.SaveChangesAsync();
} }
}
} }

View file

@ -6,10 +6,10 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Maintenance; using LBPUnion.ProjectLighthouse.Maintenance;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class MaintenanceHelper
{ {
public static class MaintenanceHelper
{
static MaintenanceHelper() static MaintenanceHelper()
{ {
@ -33,10 +33,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{ {
if (args.Length < 1) if (args.Length < 1)
throw new Exception throw new Exception
( ("This should never happen. " + "If it did, its because you tried to run a command before validating that the user actually wants to run one.");
"This should never happen. " +
"If it did, its because you tried to run a command before validating that the user actually wants to run one."
);
string baseCmd = args[0]; string baseCmd = args[0];
args = args.Skip(1).ToArray(); args = args.Skip(1).ToArray();
@ -66,5 +63,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{ {
await job.Run(); await job.Run();
} }
}
} }

View file

@ -7,10 +7,10 @@ using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using LBPUnion.ProjectLighthouse.Types.Match; using LBPUnion.ProjectLighthouse.Types.Match;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class MatchHelper
{ {
public static class MatchHelper
{
public static readonly Dictionary<int, string?> UserLocations = new(); public static readonly Dictionary<int, string?> UserLocations = new();
public static readonly Dictionary<int, List<int>?> UserRecentlyDivedIn = new(); public static readonly Dictionary<int, List<int>?> UserRecentlyDivedIn = new();
@ -72,5 +72,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
_ => null, _ => null,
}; };
} }
}
} }

View file

@ -8,10 +8,10 @@ using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Match; using LBPUnion.ProjectLighthouse.Types.Match;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public class RoomHelper
{ {
public class RoomHelper
{
public static readonly List<Room> Rooms = new(); public static readonly List<Room> Rooms = new();
public static readonly RoomSlot PodSlot = new() public static readonly RoomSlot PodSlot = new()
@ -87,7 +87,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
} }
if (user != null) if (user != null)
{
response.Players.Add response.Players.Add
( (
new Player new Player
@ -96,12 +95,8 @@ namespace LBPUnion.ProjectLighthouse.Helpers
User = user, User = user,
} }
); );
}
if (location == null) if (location == null) response.Locations.Add(location);
{
response.Locations.Add(location);
}
response.Slots = new List<List<int>> response.Slots = new List<List<int>>
{ {
@ -151,9 +146,8 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static Room? FindRoomByUser(User user, GameVersion roomVersion, bool createIfDoesNotExist = false) public static Room? FindRoomByUser(User user, GameVersion roomVersion, bool createIfDoesNotExist = false)
{ {
lock(Rooms) lock(Rooms)
{ foreach (Room room in Rooms.Where(room => room.Players.Any(player => user == player)))
foreach (Room room in Rooms.Where(room => room.Players.Any(player => user == player))) return room; return room;
}
return createIfDoesNotExist ? CreateRoom(user, roomVersion) : null; return createIfDoesNotExist ? CreateRoom(user, roomVersion) : null;
} }
@ -187,5 +181,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
Rooms.RemoveAll(r => r.Players.Count > 4); // Remove obviously bogus rooms Rooms.RemoveAll(r => r.Players.Count > 4); // Remove obviously bogus rooms
} }
} }
}
} }

View file

@ -2,10 +2,10 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class StatisticsHelper
{ {
public static class StatisticsHelper
{
private static readonly Database database = new(); private static readonly Database database = new();
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync(); public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync();
@ -15,5 +15,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static async Task<int> MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick); public static async Task<int> MMPicksCount() => await database.Slots.CountAsync(s => s.TeamPick);
public static async Task<int> PhotoCount() => await database.Photos.CountAsync(); public static async Task<int> PhotoCount() => await database.Photos.CountAsync();
}
} }

View file

@ -1,12 +1,11 @@
using System; using System;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class TimeHelper
{ {
public static class TimeHelper
{
public static long UnixTimeMilliseconds() => DateTimeOffset.Now.ToUnixTimeMilliseconds(); public static long UnixTimeMilliseconds() => DateTimeOffset.Now.ToUnixTimeMilliseconds();
public static long UnixTimeSeconds() => DateTimeOffset.Now.ToUnixTimeSeconds(); public static long UnixTimeSeconds() => DateTimeOffset.Now.ToUnixTimeSeconds();
}
} }
// 1397109686193 // 1397109686193

View file

@ -1,11 +1,10 @@
using System; using System;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class TimestampHelper
{ {
public static class TimestampHelper
{
public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds; public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
}
} }

View file

@ -5,10 +5,10 @@ using Kettu;
using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
namespace LBPUnion.ProjectLighthouse.Helpers namespace LBPUnion.ProjectLighthouse.Helpers;
public static class VersionHelper
{ {
public static class VersionHelper
{
static VersionHelper() static VersionHelper()
{ {
try try
@ -79,5 +79,4 @@ namespace LBPUnion.ProjectLighthouse.Helpers
#else #else
"Unknown"; "Unknown";
#endif #endif
}
} }

View file

@ -3,10 +3,10 @@ using Kettu;
using LBPUnion.ProjectLighthouse.Helpers.Extensions; using LBPUnion.ProjectLighthouse.Helpers.Extensions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
public class AspNetToKettuLogger : ILogger
{ {
public class AspNetToKettuLogger : ILogger
{
public IDisposable BeginScope<TState>(TState state) => NullScope.Instance; public IDisposable BeginScope<TState>(TState state) => NullScope.Instance;
public bool IsEnabled(LogLevel logLevel) => true; public bool IsEnabled(LogLevel logLevel) => true;
@ -20,5 +20,4 @@ namespace LBPUnion.ProjectLighthouse.Logging
string[] lines = exception.ToDetailedException().Replace("\r", "").Split("\n"); string[] lines = exception.ToDetailedException().Replace("\r", "").Split("\n");
foreach (string line in lines) Logger.Log(line, loggerLevel); foreach (string line in lines) Logger.Log(line, loggerLevel);
} }
}
} }

View file

@ -1,16 +1,15 @@
using System; using System;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
[ProviderAlias("Kettu")]
public class AspNetToKettuLoggerProvider : ILoggerProvider, IDisposable
{ {
[ProviderAlias("Kettu")]
public class AspNetToKettuLoggerProvider : ILoggerProvider, IDisposable
{
public void Dispose() public void Dispose()
{ {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
public ILogger CreateLogger(string categoryName) => new AspNetToKettuLogger(); public ILogger CreateLogger(string categoryName) => new AspNetToKettuLogger();
}
} }

View file

@ -4,10 +4,10 @@ using Kettu;
using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types.Settings; using LBPUnion.ProjectLighthouse.Types.Settings;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
public class InfluxLogger : LoggerBase
{ {
public class InfluxLogger : LoggerBase
{
public override bool AllowMultiple => false; public override bool AllowMultiple => false;
public override void Send(LoggerLine line) public override void Send(LoggerLine line)
@ -23,5 +23,4 @@ namespace LBPUnion.ProjectLighthouse.Logging
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point); writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
} }
}
} }

View file

@ -4,10 +4,10 @@ using Kettu;
using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Helpers.Extensions; using LBPUnion.ProjectLighthouse.Helpers.Extensions;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
public class LighthouseFileLogger : LoggerBase
{ {
public class LighthouseFileLogger : LoggerBase
{
private static readonly string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs"); private static readonly string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs");
public override bool AllowMultiple => false; public override bool AllowMultiple => false;
@ -28,5 +28,4 @@ namespace LBPUnion.ProjectLighthouse.Logging
catch(IOException) {} // windows, ya goofed catch(IOException) {} // windows, ya goofed
} }
}
} }

View file

@ -1,81 +1,80 @@
using Kettu; using Kettu;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
public class LoggerLevelStartup : LoggerLevel
{ {
public class LoggerLevelStartup : LoggerLevel
{
public static readonly LoggerLevelStartup Instance = new(); public static readonly LoggerLevelStartup Instance = new();
public override string Name => "Startup"; public override string Name => "Startup";
} }
public class LoggerLevelDatabase : LoggerLevel public class LoggerLevelDatabase : LoggerLevel
{ {
public static readonly LoggerLevelDatabase Instance = new(); public static readonly LoggerLevelDatabase Instance = new();
public override string Name => "Database"; public override string Name => "Database";
} }
public class LoggerLevelHttp : LoggerLevel public class LoggerLevelHttp : LoggerLevel
{ {
public static readonly LoggerLevelHttp Instance = new(); public static readonly LoggerLevelHttp Instance = new();
public override string Name => "HTTP"; public override string Name => "HTTP";
} }
public class LoggerLevelFilter : LoggerLevel public class LoggerLevelFilter : LoggerLevel
{ {
public static readonly LoggerLevelFilter Instance = new(); public static readonly LoggerLevelFilter Instance = new();
public override string Name => "Filter"; public override string Name => "Filter";
} }
public class LoggerLevelLogin : LoggerLevel public class LoggerLevelLogin : LoggerLevel
{ {
public static readonly LoggerLevelLogin Instance = new(); public static readonly LoggerLevelLogin Instance = new();
public override string Name => "Login"; public override string Name => "Login";
} }
public class LoggerLevelResources : LoggerLevel public class LoggerLevelResources : LoggerLevel
{ {
public static readonly LoggerLevelResources Instance = new(); public static readonly LoggerLevelResources Instance = new();
public override string Name => "Resources"; public override string Name => "Resources";
} }
public class LoggerLevelMatch : LoggerLevel public class LoggerLevelMatch : LoggerLevel
{ {
public static readonly LoggerLevelMatch Instance = new(); public static readonly LoggerLevelMatch Instance = new();
public override string Name => "Match"; public override string Name => "Match";
} }
public class LoggerLevelPhotos : LoggerLevel public class LoggerLevelPhotos : LoggerLevel
{ {
public static readonly LoggerLevelPhotos Instance = new(); public static readonly LoggerLevelPhotos Instance = new();
public override string Name => "Photos"; public override string Name => "Photos";
} }
public class LoggerLevelConfig : LoggerLevel public class LoggerLevelConfig : LoggerLevel
{ {
public static readonly LoggerLevelConfig Instance = new(); public static readonly LoggerLevelConfig Instance = new();
public override string Name => "Config"; public override string Name => "Config";
} }
public class LoggerLevelInflux : LoggerLevel public class LoggerLevelInflux : LoggerLevel
{ {
public static readonly LoggerLevelInflux Instance = new(); public static readonly LoggerLevelInflux Instance = new();
public override string Name => "Influx"; public override string Name => "Influx";
} }
public class LoggerLevelAspNet : LoggerLevel public class LoggerLevelAspNet : LoggerLevel
{ {
public LoggerLevelAspNet(LogLevel level) public LoggerLevelAspNet(LogLevel level)
{ {
this.Channel = level.ToString(); this.Channel = level.ToString();
} }
public override string Name => "AspNet"; public override string Name => "AspNet";
} }
public class LoggerLevelCategory : LoggerLevel public class LoggerLevelCategory : LoggerLevel
{ {
public static readonly LoggerLevelCategory Instance = new(); public static readonly LoggerLevelCategory Instance = new();
public override string Name => "Category"; public override string Name => "Category";
}
} }

View file

@ -1,9 +1,9 @@
using System; using System;
namespace LBPUnion.ProjectLighthouse.Logging namespace LBPUnion.ProjectLighthouse.Logging;
public class NullScope : IDisposable
{ {
public class NullScope : IDisposable
{
private NullScope() private NullScope()
{} {}
@ -13,5 +13,4 @@ namespace LBPUnion.ProjectLighthouse.Logging
{ {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
}
} }

View file

@ -7,11 +7,11 @@ using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Maintenance.Commands;
[UsedImplicitly]
public class CreateUserCommand : ICommand
{ {
[UsedImplicitly]
public class CreateUserCommand : ICommand
{
private readonly Database _database = new(); private readonly Database _database = new();
public async Task Run(string[] args) public async Task Run(string[] args)
@ -50,5 +50,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
public string Arguments() => "<OnlineID> <Password>"; public string Arguments() => "<OnlineID> <Password>";
public int RequiredArgs() => 2; public int RequiredArgs() => 2;
}
} }

View file

@ -5,11 +5,11 @@ using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Maintenance.Commands;
[UsedImplicitly]
public class DeleteUserCommand : ICommand
{ {
[UsedImplicitly]
public class DeleteUserCommand : ICommand
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Delete User"; public string Name() => "Delete User";
public string[] Aliases() public string[] Aliases()
@ -36,5 +36,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
await this.database.RemoveUser(user); await this.database.RemoveUser(user);
} }
}
} }

View file

@ -5,11 +5,11 @@ using JetBrains.Annotations;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Maintenance.Commands;
[UsedImplicitly]
public class MakeUserAdminCommand : ICommand
{ {
[UsedImplicitly]
public class MakeUserAdminCommand : ICommand
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Make User Admin"; public string Name() => "Make User Admin";
@ -41,5 +41,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"The user {user.Username} (id: {user.UserId}) is now an admin."); Console.WriteLine($"The user {user.Username} (id: {user.UserId}) is now an admin.");
} }
}
} }

View file

@ -6,11 +6,11 @@ using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Maintenance.Commands;
[UsedImplicitly]
public class ResetPasswordCommand : ICommand
{ {
[UsedImplicitly]
public class ResetPasswordCommand : ICommand
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Reset Password"; public string Name() => "Reset Password";
public string[] Aliases() public string[] Aliases()
@ -45,5 +45,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"The password for user {user.Username} (id: {user.UserId}) has been reset."); Console.WriteLine($"The password for user {user.Username} (id: {user.UserId}) has been reset.");
} }
}
} }

View file

@ -5,10 +5,10 @@ using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands namespace LBPUnion.ProjectLighthouse.Maintenance.Commands;
public class WipeTokensForUserCommand : ICommand
{ {
public class WipeTokensForUserCommand : ICommand
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Wipe tokens for user"; public string Name() => "Wipe tokens for user";
@ -41,5 +41,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"Deleted all tokens for {user.Username} (id: {user.UserId})."); Console.WriteLine($"Deleted all tokens for {user.Username} (id: {user.UserId}).");
} }
}
} }

View file

@ -1,9 +1,9 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LBPUnion.ProjectLighthouse.Maintenance namespace LBPUnion.ProjectLighthouse.Maintenance;
public interface ICommand
{ {
public interface ICommand
{
public string FirstAlias => this.Aliases()[0]; public string FirstAlias => this.Aliases()[0];
public Task Run(string[] args); public Task Run(string[] args);
@ -15,5 +15,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance
public string Arguments(); public string Arguments();
public int RequiredArgs(); public int RequiredArgs();
}
} }

View file

@ -1,13 +1,12 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LBPUnion.ProjectLighthouse.Maintenance namespace LBPUnion.ProjectLighthouse.Maintenance;
public interface IMaintenanceJob
{ {
public interface IMaintenanceJob
{
public Task Run(); public Task Run();
public string Name(); public string Name();
public string Description(); public string Description();
}
} }

View file

@ -7,10 +7,10 @@ using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Files; using LBPUnion.ProjectLighthouse.Types.Files;
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs;
public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
{ {
public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Cleanup Broken Photos"; public string Name() => "Cleanup Broken Photos";
public string Description() => "Deletes all photos that have missing assets or invalid photo subjects."; public string Description() => "Deletes all photos that have missing assets or invalid photo subjects.";
@ -88,5 +88,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
} }
}
} }

View file

@ -4,10 +4,10 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types.Profiles; using LBPUnion.ProjectLighthouse.Types.Profiles;
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs;
public class CleanupUnusedLocationsMaintenanceJob : IMaintenanceJob
{ {
public class CleanupUnusedLocationsMaintenanceJob : IMaintenanceJob
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Cleanup Unused Locations"; public string Name() => "Cleanup Unused Locations";
public string Description() => "Cleanup unused locations in the database."; public string Description() => "Cleanup unused locations in the database.";
@ -29,5 +29,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
} }
}
} }

View file

@ -1,10 +1,10 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs;
public class DeleteAllTokensMaintenanceJob : IMaintenanceJob
{ {
public class DeleteAllTokensMaintenanceJob : IMaintenanceJob
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Delete ALL Tokens"; public string Name() => "Delete ALL Tokens";
@ -18,5 +18,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
Console.WriteLine("Deleted ALL tokens."); Console.WriteLine("Deleted ALL tokens.");
} }
}
} }

View file

@ -2,10 +2,10 @@ using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs;
public class FixAllBrokenPlayerRequirementsMaintenanceJob : IMaintenanceJob
{ {
public class FixAllBrokenPlayerRequirementsMaintenanceJob : IMaintenanceJob
{
private readonly Database database = new(); private readonly Database database = new();
public string Name() => "Fix All Broken Player Requirements"; public string Name() => "Fix All Broken Player Requirements";
@ -27,5 +27,4 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
Console.WriteLine($"Fixed {count} broken player requirements."); Console.WriteLine($"Fixed {count} broken player requirements.");
} }
}
} }

View file

@ -10,10 +10,10 @@ namespace LBPUnion.ProjectLighthouse.Pages.Admin;
public class AdminBanUserPage : BaseLayout public class AdminBanUserPage : BaseLayout
{ {
public AdminBanUserPage(Database database) : base(database)
{}
public User? TargetedUser; public User? TargetedUser;
public AdminBanUserPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int id) public async Task<IActionResult> OnGet([FromRoute] int id)
{ {

View file

@ -11,12 +11,12 @@ namespace LBPUnion.ProjectLighthouse.Pages.Admin;
public class AdminPanelUsersPage : BaseLayout public class AdminPanelUsersPage : BaseLayout
{ {
public AdminPanelUsersPage(Database database) : base(database)
{}
public int UserCount; public int UserCount;
public List<User> Users; public List<User> Users;
public AdminPanelUsersPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet() public async Task<IActionResult> OnGet()
{ {

View file

@ -9,10 +9,10 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth;
public class AuthenticationPage : BaseLayout
{ {
public class AuthenticationPage : BaseLayout
{
public List<AuthenticationAttempt> AuthenticationAttempts; public List<AuthenticationAttempt> AuthenticationAttempts;
@ -35,5 +35,4 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
return this.Page(); return this.Page();
} }
}
} }

View file

@ -7,14 +7,14 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth;
public class ManageUserApprovedIpAddressesPage : BaseLayout
{ {
public class ManageUserApprovedIpAddressesPage : BaseLayout
{
public ManageUserApprovedIpAddressesPage(Database database) : base(database)
{}
public List<UserApprovedIpAddress> ApprovedIpAddresses; public List<UserApprovedIpAddress> ApprovedIpAddresses;
public ManageUserApprovedIpAddressesPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet() public async Task<IActionResult> OnGet()
{ {
@ -25,5 +25,4 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
return this.Page(); return this.Page();
} }
}
} }

View file

@ -9,15 +9,15 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class LandingPage : BaseLayout
{ {
public class LandingPage : BaseLayout
{ public int AuthenticationAttemptsCount;
public List<User> PlayersOnline; public List<User> PlayersOnline;
public int PlayersOnlineCount; public int PlayersOnlineCount;
public int AuthenticationAttemptsCount;
public LandingPage(Database database) : base(database) public LandingPage(Database database) : base(database)
{} {}
@ -30,16 +30,13 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.PlayersOnlineCount = await StatisticsHelper.RecentMatches(); this.PlayersOnlineCount = await StatisticsHelper.RecentMatches();
if (user != null) if (user != null)
{
this.AuthenticationAttemptsCount = await this.Database.AuthenticationAttempts.Include this.AuthenticationAttemptsCount = await this.Database.AuthenticationAttempts.Include
(a => a.GameToken) (a => a.GameToken)
.CountAsync(a => a.GameToken.UserId == user.UserId); .CountAsync(a => a.GameToken.UserId == user.UserId);
}
List<int> userIds = await this.Database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync(); List<int> userIds = await this.Database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync();
this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync(); this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync();
return this.Page(); return this.Page();
} }
}
} }

View file

@ -3,16 +3,10 @@ using System.Collections.Generic;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
namespace LBPUnion.ProjectLighthouse.Pages.Layouts namespace LBPUnion.ProjectLighthouse.Pages.Layouts;
{
public class BaseLayout : PageModel
{
public BaseLayout(Database database)
{
this.Database = database;
}
public bool IsMobile; public class BaseLayout : PageModel
{
public readonly Database Database; public readonly Database Database;
@ -24,13 +18,19 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
}; };
public readonly List<PageNavigationItem> NavigationItemsRight = new(); public readonly List<PageNavigationItem> NavigationItemsRight = new();
public string Description = string.Empty;
public bool IsMobile;
public bool ShowTitleInPage = true; public bool ShowTitleInPage = true;
public string Title = string.Empty; public string Title = string.Empty;
public string Description = string.Empty;
private User? user; private User? user;
public BaseLayout(Database database)
{
this.Database = database;
}
public new User? User { public new User? User {
get { get {
@ -40,5 +40,4 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
} }
set => this.user = value; set => this.user = value;
} }
}
} }

View file

@ -9,10 +9,10 @@ using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class LoginForm : BaseLayout
{ {
public class LoginForm : BaseLayout
{
public LoginForm(Database database) : base(database) public LoginForm(Database database) : base(database)
{} {}
@ -79,5 +79,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.Error = string.Empty; this.Error = string.Empty;
return this.Page(); return this.Page();
} }
}
} }

View file

@ -4,10 +4,10 @@ using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class LogoutPage : BaseLayout
{ {
public class LogoutPage : BaseLayout
{
public LogoutPage(Database database) : base(database) public LogoutPage(Database database) : base(database)
{} {}
public async Task<IActionResult> OnGet() public async Task<IActionResult> OnGet()
@ -22,5 +22,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -6,10 +6,10 @@ using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class PasswordResetPage : BaseLayout
{ {
public class PasswordResetPage : BaseLayout
{
public PasswordResetPage(Database database) : base(database) public PasswordResetPage(Database database) : base(database)
{} {}
@ -49,5 +49,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -5,10 +5,10 @@ using LBPUnion.ProjectLighthouse.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class PasswordResetRequiredPage : BaseLayout
{ {
public class PasswordResetRequiredPage : BaseLayout
{
public PasswordResetRequiredPage([NotNull] Database database) : base(database) public PasswordResetRequiredPage([NotNull] Database database) : base(database)
{} {}
@ -22,5 +22,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -10,17 +10,17 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class PhotosPage : BaseLayout
{ {
public class PhotosPage : BaseLayout
{ public int PageAmount;
public int PageNumber; public int PageNumber;
public int PhotoCount; public int PhotoCount;
public int PageAmount;
public List<Photo> Photos; public List<Photo> Photos;
public PhotosPage([NotNull] Database database) : base(database) public PhotosPage([NotNull] Database database) : base(database)
{} {}
@ -32,10 +32,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.PageNumber = pageNumber; this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize); this.PageAmount = (int)Math.Ceiling((double)this.PhotoCount / ServerStatics.PageSize);
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
{
return this.Redirect($"/photos/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
}
this.Photos = await this.Database.Photos.Include this.Photos = await this.Database.Photos.Include
(p => p.Creator) (p => p.Creator)
@ -46,5 +43,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -8,10 +8,10 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class RegisterForm : BaseLayout
{ {
public class RegisterForm : BaseLayout
{
public RegisterForm(Database database) : base(database) public RegisterForm(Database database) : base(database)
{} {}
@ -74,5 +74,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -6,10 +6,10 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class SlotPage : BaseLayout
{ {
public class SlotPage : BaseLayout
{
public Slot Slot; public Slot Slot;
public SlotPage([NotNull] Database database) : base(database) public SlotPage([NotNull] Database database) : base(database)
@ -24,5 +24,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -10,17 +10,17 @@ using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class SlotsPage : BaseLayout
{ {
public class SlotsPage : BaseLayout
{ public int PageAmount;
public int PageNumber; public int PageNumber;
public int SlotCount; public int SlotCount;
public int PageAmount;
public List<Slot> Slots; public List<Slot> Slots;
public SlotsPage([NotNull] Database database) : base(database) public SlotsPage([NotNull] Database database) : base(database)
{} {}
@ -32,10 +32,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.PageNumber = pageNumber; this.PageNumber = pageNumber;
this.PageAmount = (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize); this.PageAmount = (int)Math.Ceiling((double)this.SlotCount / ServerStatics.PageSize);
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
{
return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
}
this.Slots = await this.Database.Slots.Include this.Slots = await this.Database.Slots.Include
(p => p.Creator) (p => p.Creator)
@ -46,5 +43,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -125,9 +125,9 @@
@foreach (Comment comment in Model.Comments!) @foreach (Comment comment in Model.Comments!)
{ {
DateTimeOffset timestamp = DateTimeOffset.FromUnixTimeSeconds(comment.Timestamp / 1000); DateTimeOffset timestamp = DateTimeOffset.FromUnixTimeSeconds(comment.Timestamp / 1000);
StringWriter messageWriter = new StringWriter(); StringWriter messageWriter = new();
HttpUtility.HtmlDecode(comment.Message, messageWriter); HttpUtility.HtmlDecode(comment.Message, messageWriter);
String decodedMessage = messageWriter.ToString(); string decodedMessage = messageWriter.ToString();
<div> <div>
<b><a href="/user/@comment.PosterUserId">@comment.Poster.Username</a>: </b> <b><a href="/user/@comment.PosterUserId">@comment.Poster.Username</a>: </b>
<span>@decodedMessage</span> <span>@decodedMessage</span>

View file

@ -8,10 +8,10 @@ using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Pages namespace LBPUnion.ProjectLighthouse.Pages;
public class UserPage : BaseLayout
{ {
public class UserPage : BaseLayout
{
public List<Comment>? Comments; public List<Comment>? Comments;
public bool IsProfileUserHearted; public bool IsProfileUserHearted;
@ -43,5 +43,4 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page(); return this.Page();
} }
}
} }

View file

@ -12,10 +12,10 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace LBPUnion.ProjectLighthouse namespace LBPUnion.ProjectLighthouse;
public static class Program
{ {
public static class Program
{
public static void Main(string[] args) public static void Main(string[] args)
{ {
if (args.Length != 0 && args[0] == "--wait-for-debugger") if (args.Length != 0 && args[0] == "--wait-for-debugger")
@ -112,5 +112,4 @@ namespace LBPUnion.ProjectLighthouse
logging.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, AspNetToKettuLoggerProvider>()); logging.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, AspNetToKettuLoggerProvider>());
} }
); );
}
} }

View file

@ -1,13 +1,12 @@
using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Formatters;
namespace LBPUnion.ProjectLighthouse.Serialization namespace LBPUnion.ProjectLighthouse.Serialization;
public class JsonOutputFormatter : StringOutputFormatter
{ {
public class JsonOutputFormatter : StringOutputFormatter
{
public JsonOutputFormatter() public JsonOutputFormatter()
{ {
this.SupportedMediaTypes.Add("text/json"); this.SupportedMediaTypes.Add("text/json");
this.SupportedMediaTypes.Add("application/json"); this.SupportedMediaTypes.Add("application/json");
} }
}
} }

View file

@ -2,16 +2,16 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
namespace LBPUnion.ProjectLighthouse.Serialization namespace LBPUnion.ProjectLighthouse.Serialization;
/// <summary>
/// LBP doesn't like the XML serializer by C# that much, and it cant be controlled that much (cant have two root
/// elements),
/// so I wrote my own crappy one.
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class LbpSerializer
{ {
/// <summary>
/// LBP doesn't like the XML serializer by C# that much, and it cant be controlled that much (cant have two root
/// elements),
/// so I wrote my own crappy one.
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class LbpSerializer
{
public static string BlankElement(string key) => $"<{key}></{key}>"; public static string BlankElement(string key) => $"<{key}></{key}>";
public static string StringElement(KeyValuePair<string, object> pair) => $"<{pair.Key}>{pair.Value}</{pair.Key}>"; public static string StringElement(KeyValuePair<string, object> pair) => $"<{pair.Key}>{pair.Value}</{pair.Key}>";
@ -32,5 +32,4 @@ namespace LBPUnion.ProjectLighthouse.Serialization
public static string Elements public static string Elements
(params KeyValuePair<string, object>[] pairs) (params KeyValuePair<string, object>[] pairs)
=> pairs.Aggregate(string.Empty, (current, pair) => current + StringElement(pair)); => pairs.Aggregate(string.Empty, (current, pair) => current + StringElement(pair));
}
} }

Some files were not shown because too many files have changed in this diff Show more