Rename root namespace to LBPUnion.ProjectLighthouse

This commit is contained in:
jvyden 2021-10-20 21:41:58 -04:00
parent 20b35ec95f
commit 581e6bac2a
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
58 changed files with 178 additions and 162 deletions

View file

@ -1,12 +1,12 @@
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Types.Settings;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public sealed class DatabaseFact : FactAttribute {
public DatabaseFact() {
ServerSettings.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
if(!ServerSettings.DbConnected) Skip = "Database not available";
if(!ServerSettings.DbConnected) this.Skip = "Database not available";
else {
using Database database = new();
database.Database.Migrate();

View file

@ -3,12 +3,12 @@ using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public class LighthouseTest {
public readonly TestServer Server;
@ -41,7 +41,7 @@ namespace ProjectLighthouse.Tests {
return (LoginResult)serializer.Deserialize(new StringReader(responseContent))!;
}
public Task<HttpResponseMessage> AuthenticatedRequest(string endpoint, string mmAuth) => AuthenticatedRequest(endpoint, mmAuth, HttpMethod.Get);
public Task<HttpResponseMessage> AuthenticatedRequest(string endpoint, string mmAuth) => this.AuthenticatedRequest(endpoint, mmAuth, HttpMethod.Get);
public Task<HttpResponseMessage> AuthenticatedRequest(string endpoint, string mmAuth, HttpMethod method) {
using var requestMessage = new HttpRequestMessage(method, endpoint);

View file

@ -6,6 +6,10 @@
<IsPackable>false</IsPackable>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<AssemblyName>LBPUnion.ProjectLighthouse.Tests</AssemblyName>
<RootNamespace>LBPUnion.ProjectLighthouse.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>

View file

@ -1,11 +1,11 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Settings;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class AuthenticationTests : LighthouseTest {
[Fact]
public async Task ShouldReturnErrorOnNoPostData() {
@ -43,7 +43,7 @@ namespace ProjectLighthouse.Tests {
public async Task CanUseToken() {
LoginResult loginResult = await this.Authenticate();
HttpResponseMessage response = await AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/eula", loginResult.AuthTicket);
HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/eula", loginResult.AuthTicket);
string responseContent = await response.Content.ReadAsStringAsync();
Assert.True(response.IsSuccessStatusCode);

View file

@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class DatabaseTests : LighthouseTest {
[DatabaseFact]
public async Task CanCreateUserTwice() {

View file

@ -1,10 +1,10 @@
using System;
using System.IO;
using System.Text;
using ProjectLighthouse.Types.Files;
using LBPUnion.ProjectLighthouse.Types.Files;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class FileTypeTests {
[Fact]
public void ShouldRecognizeLevel() {

View file

@ -2,10 +2,10 @@ using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class MatchTests : LighthouseTest {
private static readonly SemaphoreSlim semaphore = new(1, 1);
@ -14,7 +14,7 @@ namespace ProjectLighthouse.Tests {
LoginResult loginResult = await this.Authenticate();
await semaphore.WaitAsync();
HttpResponseMessage result = await AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
Assert.True(result.IsSuccessStatusCode);
semaphore.Release();
@ -29,7 +29,7 @@ namespace ProjectLighthouse.Tests {
int oldPlayerCount = await this.GetPlayerCount();
HttpResponseMessage result = await AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
Assert.True(result.IsSuccessStatusCode);
int playerCount = await this.GetPlayerCount();

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class SerializerTests : LighthouseTest {
[Fact]
public void BlankElementWorks() {

View file

@ -1,10 +1,10 @@
using System.Threading.Tasks;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Levels;
using ProjectLighthouse.Types.Profiles;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class SlotTests : LighthouseTest {
[DatabaseFact]
public async Task ShouldOnlyShowUsersLevels() {

View file

@ -4,7 +4,7 @@ using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
namespace ProjectLighthouse.Tests {
namespace LBPUnion.ProjectLighthouse.Tests {
public class UploadTests : LighthouseTest {
public UploadTests() {
string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r");
@ -13,31 +13,31 @@ namespace ProjectLighthouse.Tests {
[Fact]
public async Task ShouldNotAcceptScript() {
HttpResponseMessage response = await UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/scriptTest", "ExampleFiles/TestScript.ff");
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/scriptTest", "ExampleFiles/TestScript.ff");
Assert.False(response.IsSuccessStatusCode);
}
[Fact]
public async Task ShouldNotAcceptFarc() {
HttpResponseMessage response = await UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/farcTest", "ExampleFiles/TestFarc.farc");
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/farcTest", "ExampleFiles/TestFarc.farc");
Assert.False(response.IsSuccessStatusCode);
}
[Fact]
public async Task ShouldNotAcceptGarbage() {
HttpResponseMessage response = await UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/garbageTest", "ExampleFiles/TestGarbage.bin");
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/garbageTest", "ExampleFiles/TestGarbage.bin");
Assert.False(response.IsSuccessStatusCode);
}
[Fact]
public async Task ShouldAcceptTexture() {
HttpResponseMessage response = await UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/textureTest", "ExampleFiles/TestTexture.tex");
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/textureTest", "ExampleFiles/TestTexture.tex");
Assert.True(response.IsSuccessStatusCode);
}
[Fact]
public async Task ShouldAcceptLevel() {
HttpResponseMessage response = await UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/levelTest", "ExampleFiles/TestLevel.lvl");
HttpResponseMessage response = await this.UploadFileRequest("/LITTLEBIGPLANETPS3_XML/upload/levelTest", "ExampleFiles/TestLevel.lvl");
Assert.True(response.IsSuccessStatusCode);
}
}

View file

@ -1,8 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Types.Settings;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]

View file

@ -3,13 +3,13 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Profiles;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
@ -21,7 +21,7 @@ namespace ProjectLighthouse.Controllers {
[HttpGet("userComments/{username}")]
public async Task<IActionResult> GetComments(string username) {
List<Comment> comments = await database.Comments
List<Comment> comments = await this.database.Comments
.Include(c => c.Target)
.Include(c => c.Poster)
.Where(c => c.Target.Username == username)
@ -33,25 +33,25 @@ namespace ProjectLighthouse.Controllers {
[HttpPost("postUserComment/{username}")]
public async Task<IActionResult> PostComment(string username) {
Request.Body.Position = 0;
string bodyString = await new StreamReader(Request.Body).ReadToEndAsync();
this.Request.Body.Position = 0;
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
XmlSerializer serializer = new(typeof(Comment));
Comment comment = (Comment)serializer.Deserialize(new StringReader(bodyString));
User poster = await database.UserFromRequest(Request);
User poster = await this.database.UserFromRequest(this.Request);
if(poster == null) return this.StatusCode(403, "");
User target = await database.Users.FirstOrDefaultAsync(u => u.Username == username);
User target = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if(comment == null || target == null) return this.BadRequest();
comment.PosterUserId = poster.UserId;
comment.TargetUserId = target.UserId;
database.Comments.Add(comment);
await database.SaveChangesAsync();
this.database.Comments.Add(comment);
await this.database.SaveChangesAsync();
return this.Ok();
}
}

View file

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/enterLevel")]
// [Produces("text/plain")]

View file

@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Levels;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]

View file

@ -1,8 +1,8 @@
using System;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Types.Levels;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/tags")]
[Produces("text/plain")]

View file

@ -1,11 +1,11 @@
#nullable enable
using System.IO;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Settings;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/login")]
[Produces("text/xml")]
@ -18,7 +18,7 @@ namespace ProjectLighthouse.Controllers {
[HttpPost]
public async Task<IActionResult> Login() {
string body = await new StreamReader(Request.Body).ReadToEndAsync();
string body = await new StreamReader(this.Request.Body).ReadToEndAsync();
LoginData loginData;
try {
@ -28,7 +28,7 @@ namespace ProjectLighthouse.Controllers {
return this.BadRequest();
}
Token? token = await database.AuthenticateUser(loginData);
Token? token = await this.database.AuthenticateUser(loginData);
if(token == null) return this.StatusCode(403, "");

View file

@ -1,13 +1,13 @@
#nullable enable
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Helpers;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Profiles;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]

View file

@ -1,8 +1,8 @@
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Types;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
@ -14,13 +14,13 @@ namespace ProjectLighthouse.Controllers {
[HttpGet("eula")]
public async Task<IActionResult> Eula() {
User user = await this.database.UserFromRequest(Request);
User user = await this.database.UserFromRequest(this.Request);
return user == null ? this.StatusCode(403, "") : this.Ok($"You are logged in as user {user.Username} (id {user.UserId})");
}
[HttpGet("announce")]
public IActionResult Announce() {
return Ok("");
return this.Ok("");
}
[HttpGet("notification")]

View file

@ -1,8 +1,8 @@
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.News;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types.News;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/news")]
[Produces("text/xml")]

View file

@ -2,15 +2,15 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Helpers;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Levels;
using ProjectLighthouse.Types.Profiles;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
@ -42,7 +42,7 @@ namespace ProjectLighthouse.Controllers {
/// </summary>
[HttpPost("publish")]
public async Task<IActionResult> Publish() {
User user = await database.UserFromRequest(Request);
User user = await this.database.UserFromRequest(this.Request);
if(user == null) return this.StatusCode(403, "");
Slot slot = await this.GetSlotFromBody();
@ -52,34 +52,34 @@ namespace ProjectLighthouse.Controllers {
X = 0,
Y = 0,
};
database.Locations.Add(l);
await database.SaveChangesAsync();
this.database.Locations.Add(l);
await this.database.SaveChangesAsync();
slot.LocationId = l.Id;
slot.CreatorId = user.UserId;
database.Slots.Add(slot);
await database.SaveChangesAsync();
this.database.Slots.Add(slot);
await this.database.SaveChangesAsync();
return this.Ok(slot.Serialize());
}
[HttpPost("unpublish/{id:int}")]
public async Task<IActionResult> Unpublish(int id) {
Slot slot = await database.Slots
Slot slot = await this.database.Slots
.Include(s => s.Location)
.FirstOrDefaultAsync(s => s.SlotId == id);
database.Locations.Remove(slot.Location);
database.Slots.Remove(slot);
this.database.Locations.Remove(slot.Location);
this.database.Slots.Remove(slot);
await database.SaveChangesAsync();
await this.database.SaveChangesAsync();
return this.Ok();
}
public async Task<Slot> GetSlotFromBody() {
Request.Body.Position = 0;
string bodyString = await new StreamReader(Request.Body).ReadToEndAsync();
this.Request.Body.Position = 0;
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
XmlSerializer serializer = new(typeof(Slot));
Slot slot = (Slot)serializer.Deserialize(new StringReader(bodyString));

View file

@ -3,14 +3,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Files;
using Microsoft.AspNetCore.Mvc;
using ProjectLighthouse.Helpers;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Files;
using IOFile = System.IO.File;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
@ -23,7 +23,7 @@ namespace ProjectLighthouse.Controllers {
[HttpPost("filterResources")]
[HttpPost("showNotUploaded")]
public async Task<IActionResult> FilterResources() {
string bodyString = await new StreamReader(Request.Body).ReadToEndAsync();
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
XmlSerializer serializer = new(typeof(ResourceList));
ResourceList resourceList = (ResourceList)serializer.Deserialize(new StringReader(bodyString));
@ -57,7 +57,7 @@ namespace ProjectLighthouse.Controllers {
FileHelper.EnsureDirectoryCreated(assetsDirectory);
if(FileHelper.ResourceExists(hash)) this.Ok(); // no reason to fail if it's already uploaded
LbpFile file = new(Encoding.ASCII.GetBytes(await new StreamReader(Request.Body).ReadToEndAsync()));
LbpFile file = new(Encoding.ASCII.GetBytes(await new StreamReader(this.Request.Body).ReadToEndAsync()));
if(!FileHelper.IsFileSafe(file)) return this.UnprocessableEntity();

View file

@ -1,12 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types.Levels;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]

View file

@ -1,11 +1,11 @@
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types.Levels;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
@ -18,7 +18,7 @@ namespace ProjectLighthouse.Controllers {
[HttpGet("slots/by")]
public IActionResult SlotsBy([FromQuery] string u) {
string response = Enumerable.Aggregate(
database.Slots
this.database.Slots
.Include(s => s.Creator)
.Include(s => s.Location)
.Where(s => s.Creator.Username == u)

View file

@ -3,12 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Profiles;
namespace ProjectLighthouse.Controllers {
namespace LBPUnion.ProjectLighthouse.Controllers {
[ApiController]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/xml")]
@ -20,7 +20,7 @@ namespace ProjectLighthouse.Controllers {
[HttpGet("user/{username}")]
public async Task<IActionResult> GetUser(string username) {
User user = await database.Users
User user = await this.database.Users
.Include(u => u.Location)
.FirstOrDefaultAsync(u => u.Username == username);
@ -36,7 +36,7 @@ namespace ProjectLighthouse.Controllers {
[HttpPost("updateUser")]
public async Task<IActionResult> UpdateUser() {
User user = await database.UserFromRequest(Request);
User user = await this.database.UserFromRequest(this.Request);
if(user == null) return this.StatusCode(403, "");
@ -62,7 +62,7 @@ namespace ProjectLighthouse.Controllers {
// </updateUser>
//
// if you find a way to make it not stupid feel free to replace this
using(XmlReader reader = XmlReader.Create(Request.Body, settings)) {
using(XmlReader reader = XmlReader.Create(this.Request.Body, settings)) {
List<string> path = new(); // you can think of this as a file path in the XML, like <updateUser> -> <location> -> <x>
while(await reader.ReadAsync()) {
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
@ -105,7 +105,7 @@ namespace ProjectLighthouse.Controllers {
// the way location on a user card works is stupid and will not save with the way below as-is, so we do the following:
if(locationChanged) { // only modify the database if we modify here
Location l = await database.Locations.Where(l => l.Id == user.LocationId).FirstOrDefaultAsync(); // find the location in the database again
Location l = await this.database.Locations.Where(l => l.Id == user.LocationId).FirstOrDefaultAsync(); // find the location in the database again
// set the location in the database to the one we modified above
l.X = user.Location.X;
@ -114,7 +114,7 @@ namespace ProjectLighthouse.Controllers {
// now both are in sync, and will update in the database.
}
if(database.ChangeTracker.HasChanges()) await database.SaveChangesAsync(); // save the user to the database if we changed anything
if(this.database.ChangeTracker.HasChanges()) await this.database.SaveChangesAsync(); // save the user to the database if we changed anything
return this.Ok();
}
}

View file

@ -1,14 +1,14 @@
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Helpers;
using ProjectLighthouse.Types;
using ProjectLighthouse.Types.Levels;
using ProjectLighthouse.Types.Profiles;
using ProjectLighthouse.Types.Settings;
namespace ProjectLighthouse {
namespace LBPUnion.ProjectLighthouse {
public class Database : DbContext {
public DbSet<User> Users { get; set; }
public DbSet<Location> Locations { get; set; }
@ -27,7 +27,7 @@ namespace ProjectLighthouse {
public async Task<User> CreateUser(string username) {
User user;
if((user = await Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null)
if((user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null)
return user;
Location l = new(); // store to get id after submitting
@ -64,9 +64,9 @@ namespace ProjectLighthouse {
}
public async Task<User?> UserFromAuthToken(string authToken) {
Token? token = await Tokens.FirstOrDefaultAsync(t => t.UserToken == authToken);
Token? token = await this.Tokens.FirstOrDefaultAsync(t => t.UserToken == authToken);
if(token == null) return null;
return await Users
return await this.Users
.Include(u => u.Location)
.FirstOrDefaultAsync(u => u.UserId == token.UserId);
}
@ -76,7 +76,7 @@ namespace ProjectLighthouse {
return null;
}
return await UserFromAuthToken(mmAuth);
return await this.UserFromAuthToken(mmAuth);
}
#nullable disable
}

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
namespace ProjectLighthouse.Helpers {
namespace LBPUnion.ProjectLighthouse.Helpers {
public static class BinaryHelper {
public static string ReadString(BinaryReader reader) {
List<byte> readBytes = new();

View file

@ -2,9 +2,9 @@ using System;
using System.IO;
using System.Linq;
using System.Text;
using ProjectLighthouse.Types.Files;
using LBPUnion.ProjectLighthouse.Types.Files;
namespace ProjectLighthouse.Helpers {
namespace LBPUnion.ProjectLighthouse.Helpers {
public static class FileHelper {
public static readonly string ResourcePath = Path.Combine(Environment.CurrentDirectory, "r");

View file

@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;
namespace ProjectLighthouse.Helpers {
namespace LBPUnion.ProjectLighthouse.Helpers {
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class HashHelper {
// private static readonly SHA1 sha1 = SHA1.Create();

View file

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

View file

@ -1,4 +1,6 @@
// <auto-generated />
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

View file

@ -1,4 +1,6 @@
// <auto-generated />
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

View file

@ -1,4 +1,6 @@
// <auto-generated />
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

View file

@ -1,4 +1,6 @@
// <auto-generated />
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;

View file

@ -1,4 +1,6 @@
// <auto-generated />
using LBPUnion.ProjectLighthouse;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

View file

@ -1,11 +1,11 @@
using System;
using System.Diagnostics;
using LBPUnion.ProjectLighthouse.Types.Settings;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using ProjectLighthouse.Types.Settings;
namespace ProjectLighthouse {
namespace LBPUnion.ProjectLighthouse {
public static class Program {
public static void Main(string[] args) {
Stopwatch startupStopwatch = new();

View file

@ -3,6 +3,8 @@
<PropertyGroup>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<AssemblyName>LBPUnion.ProjectLighthouse</AssemblyName>
<RootNamespace>LBPUnion.ProjectLighthouse</RootNamespace>
</PropertyGroup>
<ItemGroup>

View file

@ -2,7 +2,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace 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.

View file

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

View file

@ -1,18 +1,18 @@
using System;
using System.Diagnostics;
using System.IO;
using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse {
namespace LBPUnion.ProjectLighthouse {
public class Startup {
public Startup(IConfiguration configuration) {
Configuration = configuration;
this.Configuration = configuration;
}
public IConfiguration Configuration { get; }

View file

@ -1,6 +1,6 @@
using ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Helpers;
namespace ProjectLighthouse.Types.Files {
namespace LBPUnion.ProjectLighthouse.Types.Files {
public class LbpFile {
public LbpFile(byte[] data) {
this.Data = data;

View file

@ -1,4 +1,4 @@
namespace ProjectLighthouse.Types.Files {
namespace LBPUnion.ProjectLighthouse.Types.Files {
public enum LbpFileType {
Script, // .ff, FSH
Texture, // TEX

View file

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ProjectLighthouse.Types.Levels {
namespace LBPUnion.ProjectLighthouse.Types.Levels {
public class HeartedLevel {
// ReSharper disable once UnusedMember.Global
[Key] public int HeartedLevelId { get; set; }

View file

@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
namespace ProjectLighthouse.Types.Levels {
namespace LBPUnion.ProjectLighthouse.Types.Levels {
/// <summary>
/// A series of tags that can be applied to a level
/// </summary>

View file

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ProjectLighthouse.Types.Levels {
namespace LBPUnion.ProjectLighthouse.Types.Levels {
public class QueuedLevel {
// ReSharper disable once UnusedMember.Global
[Key] public int QueuedLevelId { get; set; }

View file

@ -2,10 +2,10 @@ using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Xml.Serialization;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types.Profiles;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Profiles;
namespace ProjectLighthouse.Types.Levels {
namespace LBPUnion.ProjectLighthouse.Types.Levels {
/// <summary>
/// A LittleBigPlanet level.
/// </summary>

View file

@ -1,8 +1,8 @@
using System.IO;
using System.Text;
using ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Helpers;
namespace ProjectLighthouse.Types {
namespace LBPUnion.ProjectLighthouse.Types {
// This is all the information I can understand for now. More testing is required.
// Example data:
// - LBP2 digital, with the RPCN username `literally1984`

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types {
namespace LBPUnion.ProjectLighthouse.Types {
/// <summary>
/// Response to POST /login
/// </summary>

View file

@ -1,6 +1,6 @@
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.News {
namespace LBPUnion.ProjectLighthouse.Types.News {
/// <summary>
/// Used on the info moon on LBP1. Broken for unknown reasons
/// </summary>

View file

@ -1,6 +1,6 @@
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.News {
namespace LBPUnion.ProjectLighthouse.Types.News {
public class NewsImage {
public string Hash { get; set; }
public string Alignment { get; set; }

View file

@ -1,7 +1,7 @@
using LBPUnion.ProjectLighthouse.Serialization;
using Microsoft.EntityFrameworkCore;
using ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.Profiles {
namespace LBPUnion.ProjectLighthouse.Types.Profiles {
[Keyless]
public class ClientsConnected {
public bool Lbp1 { get; set; }

View file

@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Xml.Serialization;
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.Profiles {
namespace LBPUnion.ProjectLighthouse.Types.Profiles {
[XmlRoot("comment"), XmlType("comment")]
public class Comment {
[Key]

View file

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace ProjectLighthouse.Types.Profiles {
namespace LBPUnion.ProjectLighthouse.Types.Profiles {
public class LastMatch {
[Key] public int UserId { get; set; }
public long Timestamp { get; set; }

View file

@ -1,6 +1,6 @@
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.Profiles {
namespace LBPUnion.ProjectLighthouse.Types.Profiles {
/// <summary>
/// The location of a slot on a planet.
/// </summary>

View file

@ -1,6 +1,6 @@
using System.Xml.Serialization;
namespace ProjectLighthouse.Types {
namespace LBPUnion.ProjectLighthouse.Types {
[XmlRoot("resource"), XmlType("resources")]
public class ResourceList {
[XmlElement("resource")]

View file

@ -1,6 +1,6 @@
using ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
namespace ProjectLighthouse.Types.Settings {
namespace LBPUnion.ProjectLighthouse.Types.Settings {
public class PrivacySettings {
public string LevelVisibility { get; set; }
public string ProfileVisibility { get; set; }

View file

@ -1,7 +1,7 @@
#nullable enable
using System;
namespace ProjectLighthouse.Types.Settings {
namespace LBPUnion.ProjectLighthouse.Types.Settings {
public static class ServerSettings {
/// <summary>
/// The maximum amount of slots allowed on users' earth

View file

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace ProjectLighthouse.Types {
namespace LBPUnion.ProjectLighthouse.Types {
public class Token {
// ReSharper disable once UnusedMember.Global
[Key] public int TokenId { get; set; }

View file

@ -1,9 +1,9 @@
using System.ComponentModel.DataAnnotations.Schema;
using ProjectLighthouse.Serialization;
using ProjectLighthouse.Types.Profiles;
using ProjectLighthouse.Types.Settings;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Profiles;
using LBPUnion.ProjectLighthouse.Types.Settings;
namespace ProjectLighthouse.Types {
namespace LBPUnion.ProjectLighthouse.Types {
public class User {
public int UserId { get; set; }
public string Username { get; set; }