Cleanup code

This commit is contained in:
jvyden 2021-12-11 14:33:28 -05:00
parent 1ec7bdf1f6
commit b0b9ad2172
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
58 changed files with 310 additions and 424 deletions

View file

@ -70,10 +70,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (user == null) return this.StatusCode(403, "");
Comment? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId);
if (comment == null)
{
return this.NotFound();
}
if (comment == null) return this.NotFound();
if (comment.TargetUserId != user.UserId && comment.PosterUserId != user.UserId) return this.StatusCode(403, "");

View file

@ -63,10 +63,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
v = await visited.FirstOrDefaultAsync();
}
if (v == null)
{
return this.NotFound();
}
if (v == null) return this.NotFound();
switch (gameVersion)
{
@ -119,10 +116,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
v = await visited.FirstOrDefaultAsync();
}
if (v == null)
{
return this.NotFound();
}
if (v == null) return this.NotFound();
slot.PlaysLBP1++;
v.PlaysLBP1++;

View file

@ -78,9 +78,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
GameToken gameToken = userAndToken.Value.Item2;
if (!FriendHelper.FriendIdsByUserId.TryGetValue(user.UserId, out int[]? friendIds) || friendIds == null)
{
return this.Ok(LbpSerializer.BlankElement("myFriends"));
}
string friends = "";
foreach (int friendId in friendIds)

View file

@ -57,7 +57,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (ServerSettings.Instance.UseExternalAuth)
{
string ipAddressAndName = $"{token.UserLocation}|{user.Username}";
if (DeniedAuthenticationHelper.RecentlyDenied(ipAddressAndName) || (DeniedAuthenticationHelper.GetAttempts(ipAddressAndName) > 3))
if (DeniedAuthenticationHelper.RecentlyDenied(ipAddressAndName) || DeniedAuthenticationHelper.GetAttempts(ipAddressAndName) > 3)
{
this.database.AuthenticationAttempts.RemoveRange
(this.database.AuthenticationAttempts.Include(a => a.GameToken).Where(a => a.GameToken.UserId == user.UserId));
@ -89,10 +89,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client ({titleId})", LoggerLevelLogin.Instance);
// Create a new room on LBP2+/Vita
if (token.GameVersion != GameVersion.LittleBigPlanet1)
{
RoomHelper.CreateRoom(user);
}
if (token.GameVersion != GameVersion.LittleBigPlanet1) RoomHelper.CreateRoom(user);
return this.Ok
(

View file

@ -80,9 +80,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
Room? room = RoomHelper.FindRoomByUser(user, true);
if (playerData.RoomState != null)
{
if (room != null && Equals(room.Host, user)) room.State = (RoomState)playerData.RoomState;
}
if (room != null && Equals(room.Host, user))
room.State = (RoomState)playerData.RoomState;
}
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
@ -92,10 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (response == null) return this.NotFound();
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
foreach (Player player in response.Players)
{
MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
}
foreach (Player player in response.Players) MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
return this.Ok($"[{{\"StatusCode\":200}},{serialized}]");
}
@ -107,10 +103,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
User? player = await this.database.Users.FirstOrDefaultAsync(u => u.Username == playerUsername);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (player != null)
{
users.Add(player);
}
if (player != null) users.Add(player);
else return this.BadRequest();
}

View file

@ -31,16 +31,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (user == null) return this.StatusCode(403, "");
if (ServerSettings.Instance.UseExternalAuth)
{
return this.Ok
(
$"Please stay on this screen.\n" +
"Please stay on this screen.\n" +
$"Before continuing, you must approve this session at {ServerSettings.Instance.ExternalUrl}.\n" +
$"Please keep in mind that if the session is denied you may have to wait up to 5-10 minutes to try logging in again.\n" +
$"Once approved, you may press X and continue.\n\n" +
"Please keep in mind that if the session is denied you may have to wait up to 5-10 minutes to try logging in again.\n" +
"Once approved, you may press X and continue.\n\n" +
ServerSettings.Instance.EulaText
);
}
return this.Ok($"You are now logged in as {user.Username} (id: {user.UserId}).\n\n" + ServerSettings.Instance.EulaText);
}

View file

@ -114,10 +114,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (userFromQuery == null) return this.NotFound();
List<Photo> photos = new();
foreach (Photo photo in this.database.Photos.Include(p => p.Creator))
{
photos.AddRange(photo.Subjects.Where(subject => subject.User.UserId == userFromQuery.UserId).Select(_ => photo));
}
foreach (Photo photo in this.database.Photos.Include
(p => p.Creator)) photos.AddRange(photo.Subjects.Where(subject => subject.User.UserId == userFromQuery.UserId).Select(_ => photo));
string response = photos.OrderByDescending
(s => s.Timestamp)

View file

@ -1,17 +1,17 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Generic;
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.Reviews;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using LBPUnion.ProjectLighthouse.Serialization;
namespace LBPUnion.ProjectLighthouse.Controllers
{
@ -77,10 +77,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
ratedLevel.Rating = Math.Max(Math.Min(1, rating), -1);
Review? review = await this.database.Reviews.FirstOrDefaultAsync(r => r.SlotId == slotId && r.ReviewerId == user.UserId);
if (review != null)
{
review.Thumb = ratedLevel.Rating;
}
if (review != null) review.Thumb = ratedLevel.Rating;
await this.database.SaveChangesAsync();
@ -96,9 +93,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers
Review? review = await this.database.Reviews.FirstOrDefaultAsync(r => r.SlotId == slotId && r.ReviewerId == user.UserId);
Review? newReview = await this.GetReviewFromBody();
if (newReview == null) return this.BadRequest();
if (review == null)
{
review = new();
review = new Review();
review.SlotId = slotId;
review.ReviewerId = user.UserId;
review.DeletedBy = DeletedBy.None;
@ -145,19 +143,22 @@ namespace LBPUnion.ProjectLighthouse.Controllers
Random rand = new();
Review? yourReview = await this.database.Reviews.FirstOrDefaultAsync(r => r.ReviewerId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
Review? yourReview = await this.database.Reviews.FirstOrDefaultAsync
(r => r.ReviewerId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
VisitedLevel? visitedLevel = await this.database.VisitedLevels.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SlotId == slotId && v.Slot.GameVersion <= gameVersion);
VisitedLevel? visitedLevel = await this.database.VisitedLevels.FirstOrDefaultAsync
(v => v.UserId == user.UserId && v.SlotId == slotId && v.Slot.GameVersion <= gameVersion);
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
if (slot == null) return this.BadRequest();
Boolean canNowReviewLevel = slot.CreatorId != user.UserId && visitedLevel != null && yourReview == null;
bool canNowReviewLevel = slot.CreatorId != user.UserId && visitedLevel != null && yourReview == null;
if (canNowReviewLevel)
{
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync(r => r.UserId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
RatedLevel? ratedLevel = await this.database.RatedLevels.FirstOrDefaultAsync
(r => r.UserId == user.UserId && r.SlotId == slotId && r.Slot.GameVersion <= gameVersion);
yourReview = new();
yourReview = new Review();
yourReview.ReviewerId = user.UserId;
yourReview.Reviewer = user;
yourReview.Thumb = ratedLevel?.Rating == null ? 0 : ratedLevel.Rating;
@ -180,22 +181,26 @@ namespace LBPUnion.ProjectLighthouse.Controllers
IEnumerable<Review?> prependedReviews;
if (canNowReviewLevel) // this can only be true if you have not posted a review but have visited the level
{
// prepend the fake review to the top of the list to be easily edited
prependedReviews = reviews.ToList().Prepend(yourReview);
}
else
{
prependedReviews = reviews.ToList();
}
else prependedReviews = reviews.ToList();
string inner = Enumerable.Aggregate(prependedReviews, string.Empty, (current, review) =>
string inner = prependedReviews.Aggregate
(
string.Empty,
(current, review) =>
{
if (review == null) return current;
return current + review.Serialize();
});
string response = LbpSerializer.TaggedStringElement("reviews", inner, new Dictionary<string, object>
return current + review.Serialize();
}
);
string response = LbpSerializer.TaggedStringElement
(
"reviews",
inner,
new Dictionary<string, object>
{
{
"hint_start", pageStart + pageSize
@ -203,7 +208,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
"hint", pageStart // not sure
},
});
}
);
return this.Ok(response);
}
@ -227,14 +233,22 @@ namespace LBPUnion.ProjectLighthouse.Controllers
.Skip(pageStart - 1)
.Take(pageSize);
string inner = Enumerable.Aggregate(reviews, string.Empty, (current, review) =>
string inner = reviews.Aggregate
(
string.Empty,
(current, review) =>
{
//RatedLevel? ratedLevel = this.database.RatedLevels.FirstOrDefault(r => r.SlotId == review.SlotId && r.UserId == user.UserId);
//RatedReview? ratedReview = this.database.RatedReviews.FirstOrDefault(r => r.ReviewId == review.ReviewId && r.UserId == user.UserId);
return current + review.Serialize( /*, ratedReview*/);
});
}
);
string response = LbpSerializer.TaggedStringElement("reviews", inner, new Dictionary<string, object>
string response = LbpSerializer.TaggedStringElement
(
"reviews",
inner,
new Dictionary<string, object>
{
{
"hint_start", pageStart
@ -242,7 +256,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
"hint", reviews.Last().Timestamp // Seems to be the timestamp of oldest
},
});
}
);
return this.Ok(response);
}
@ -312,6 +327,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers
return review;
}
}
}

View file

@ -80,7 +80,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
await this.database.SaveChangesAsync();
string myRanking = GetScores(score.SlotId, score.Type, user);
string myRanking = this.GetScores(score.SlotId, score.Type, user);
return this.Ok(myRanking);
}
@ -99,7 +99,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (user == null) return this.StatusCode(403, "");
return this.Ok(GetScores(slotId, type, user, pageStart, pageSize));
return this.Ok(this.GetScores(slotId, type, user, pageStart, pageSize));
}
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
@ -139,17 +139,13 @@ namespace LBPUnion.ProjectLighthouse.Controllers
);
string res;
if (myScore == null)
{
res = LbpSerializer.StringElement("scores", serializedScores);
}
if (myScore == null) res = LbpSerializer.StringElement("scores", serializedScores);
else
{
res = LbpSerializer.TaggedStringElement
(
"scores",
serializedScores,
new Dictionary<string, object>()
new Dictionary<string, object>
{
{
"yourScore", myScore.Score.Points
@ -162,7 +158,6 @@ namespace LBPUnion.ProjectLighthouse.Controllers
}, // This is the denominator of your position globally in the side menu.
}
);
}
return res;
}

View file

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc;
@ -44,10 +44,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
s.SlotId.ToString().Equals(keyword)
);
List<Slot> slots = await dbQuery
.Skip(pageStart - 1)
.Take(Math.Min(pageSize, 30))
.ToListAsync();
List<Slot> slots = await dbQuery.Skip(pageStart - 1).Take(Math.Min(pageSize, 30)).ToListAsync();
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize());

View file

@ -3,8 +3,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Settings;
@ -91,7 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpGet("slots/lbp2cool")]
[HttpGet("slots/cool")]
public async Task<IActionResult> CoolSlots([FromQuery] int page) => await LuckyDipSlots(30 * page, 30, 69);
public async Task<IActionResult> CoolSlots([FromQuery] int page) => await this.LuckyDipSlots(30 * page, 30, 69);
[HttpGet("slots")]
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
@ -198,6 +198,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers
)
);
}
}
}

View file

@ -51,10 +51,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (token == null) return this.StatusCode(403, "");
List<string?> serializedUsers = new();
foreach (string userId in u)
{
serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
}
foreach (string userId in u) serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
string serialized = serializedUsers.Aggregate(string.Empty, (current, user) => user == null ? current : current + user);
@ -159,10 +156,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
Location? l = await this.database.Locations.FirstOrDefaultAsync(l => l.Id == user.LocationId); // find the location in the database again
if (l == null)
{
throw new Exception("this shouldn't happen ever but we handle this");
}
if (l == null) throw new Exception("this shouldn't happen ever but we handle this");
// set the location in the database to the one we modified above
l.X = user.Location.X;

View file

@ -26,10 +26,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
[HttpGet("heart")]
public async Task<IActionResult> HeartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
{
if (string.IsNullOrEmpty(callbackUrl))
{
callbackUrl = "~/slot/" + id;
}
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
@ -45,10 +42,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
[HttpGet("unheart")]
public async Task<IActionResult> UnheartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
{
if (string.IsNullOrEmpty(callbackUrl))
{
callbackUrl = "~/slot/" + id;
}
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
@ -64,10 +58,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
[HttpGet("queue")]
public async Task<IActionResult> QueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
{
if (string.IsNullOrEmpty(callbackUrl))
{
callbackUrl = "~/slot/" + id;
}
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
@ -83,10 +74,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
[HttpGet("unqueue")]
public async Task<IActionResult> UnqueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
{
if (string.IsNullOrEmpty(callbackUrl))
{
callbackUrl = "~/slot/" + id;
}
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
User? user = this.database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");

View file

@ -6,8 +6,8 @@ namespace LBPUnion.ProjectLighthouse
{
public class FakeRemoteIPAddressMiddleware
{
private readonly RequestDelegate next;
private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1");
private readonly RequestDelegate next;
public FakeRemoteIPAddressMiddleware(RequestDelegate next)
{

View file

@ -10,6 +10,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{
public static class MaintenanceHelper
{
static MaintenanceHelper()
{
Commands = getListOfInterfaceObjects<ICommand>();
MaintenanceJobs = getListOfInterfaceObjects<IMaintenanceJob>();
}
public static List<ICommand> Commands { get; }
public static List<IMaintenanceJob> MaintenanceJobs { get; }
@ -23,22 +29,14 @@ namespace LBPUnion.ProjectLighthouse.Helpers
.ToList()!;
}
static MaintenanceHelper()
{
Commands = getListOfInterfaceObjects<ICommand>();
MaintenanceJobs = getListOfInterfaceObjects<IMaintenanceJob>();
}
public static async Task RunCommand(string[] args)
{
if (args.Length < 1)
{
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."
);
}
string baseCmd = args[0];
args = args.Skip(1).ToArray();

View file

@ -22,10 +22,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static void AddUserRecentlyDivedIn(int userId, int otherUserId)
{
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn))
{
UserRecentlyDivedIn.Add(userId, recentlyDivedIn = new List<int>());
}
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn)) UserRecentlyDivedIn.Add(userId, recentlyDivedIn = new List<int>());
Debug.Assert(recentlyDivedIn != null, nameof(recentlyDivedIn) + " is null, somehow.");

View file

@ -43,10 +43,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value);
if (gotValue && value != null)
{
relevantUserLocations.Add(p.UserId, value);
}
if (gotValue && value != null) relevantUserLocations.Add(p.UserId, value);
return gotValue;
}
);
@ -138,7 +135,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{
// Delete old rooms based on host
if (host != null)
{
try
{
Rooms.RemoveAll(r => r.Host == host);
@ -147,11 +143,9 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{
// TODO: detect the room that failed and remove it
}
}
// Remove players in this new room from other rooms
if (newRoom != null)
{
foreach (Room room in Rooms)
{
if (room == newRoom) continue;
@ -161,4 +155,3 @@ namespace LBPUnion.ProjectLighthouse.Helpers
}
}
}
}

View file

@ -8,6 +8,7 @@ namespace LBPUnion.ProjectLighthouse.Logging
{
public class InfluxLogger : LoggerBase
{
public override bool AllowMultiple => false;
public override void Send(LoggerLine line)
{
@ -22,6 +23,5 @@ namespace LBPUnion.ProjectLighthouse.Logging
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
}
public override bool AllowMultiple => false;
}
}

View file

@ -4,8 +4,8 @@ using JetBrains.Annotations;
using Kettu;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using Microsoft.EntityFrameworkCore;
using LBPUnion.ProjectLighthouse.Types;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
{
@ -24,32 +24,27 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
User? user = await this._database.Users.FirstOrDefaultAsync(u => u.Username == onlineId);
if (user == null)
{
user = await this._database.CreateUser(onlineId,
HashHelper.BCryptHash(password));
Logger.Log(
$"Created user {user.UserId} with online ID (username) {user.Username} and the specified password.", LoggerLevelLogin.Instance);
user = await this._database.CreateUser(onlineId, HashHelper.BCryptHash(password));
Logger.Log($"Created user {user.UserId} with online ID (username) {user.Username} and the specified password.", LoggerLevelLogin.Instance);
user.PasswordResetRequired = true;
Logger.Log("This user will need to reset their password when they log in.",
LoggerLevelLogin.Instance);
Logger.Log("This user will need to reset their password when they log in.", LoggerLevelLogin.Instance);
await this._database.SaveChangesAsync();
Logger.Log("Database changes saved.",
LoggerLevelDatabase.Instance);
Logger.Log("Database changes saved.", LoggerLevelDatabase.Instance);
}
else
{
Logger.Log("A user with this username already exists.",
LoggerLevelLogin.Instance);
Logger.Log("A user with this username already exists.", LoggerLevelLogin.Instance);
}
}
public string Name() => "Create New User";
public string[] Aliases() =>
new[]
public string[] Aliases()
=> new[]
{
"useradd", "adduser", "newuser", "createUser"
"useradd", "adduser", "newuser", "createUser",
};
public string Arguments() => "<OnlineID> <Password>";

View file

@ -23,7 +23,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
if (user == null)
{
try
{
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
@ -34,7 +33,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
return;
}
}
await this.database.RemoveUser(user);
}

View file

@ -25,7 +25,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
if (user == null)
{
try
{
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
@ -36,7 +35,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
return;
}
}
user.IsAdmin = true;
await this.database.SaveChangesAsync();

View file

@ -25,7 +25,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
if (user == null)
{
try
{
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
@ -36,7 +35,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
return;
}
}
string password = args[1];
if (password.Length != 64) password = HashHelper.Sha256Hash(password);

View file

@ -23,7 +23,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
{
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
if (user == null)
{
try
{
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
@ -34,7 +33,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
return;
}
}
this.database.GameTokens.RemoveRange(this.database.GameTokens.Where(t => t.UserId == user.UserId));
this.database.WebTokens.RemoveRange(this.database.WebTokens.Where(t => t.UserId == user.UserId));

View file

@ -4,14 +4,14 @@ namespace LBPUnion.ProjectLighthouse.Maintenance
{
public interface ICommand
{
public string FirstAlias => this.Aliases()[0];
public Task Run(string[] args);
public string Name();
public string[] Aliases();
public string FirstAlias => this.Aliases()[0];
public string Arguments();
public int RequiredArgs();

View file

@ -14,7 +14,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
{
int count = 0;
await foreach (Slot slot in this.database.Slots)
{
if (slot.MinimumPlayers == 0 || slot.MaximumPlayers == 0)
{
slot.MinimumPlayers = 1;
@ -23,7 +22,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
Console.WriteLine($"Fixed slotId {slot.SlotId}");
count++;
}
}
await this.database.SaveChangesAsync();

View file

@ -11,10 +11,10 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
public class AdminPanelPage : BaseLayout
{
public AdminPanelPage(Database database) : base(database)
{}
public List<ICommand> Commands = MaintenanceHelper.Commands;
public AdminPanelPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob)
{

View file

@ -11,10 +11,10 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
{
public class AuthenticationPage : BaseLayout
{
public AuthenticationPage(Database database) : base(database)
{ }
public List<AuthenticationAttempt> AuthenticationAttempts;
public AuthenticationPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet()
{

View file

@ -13,11 +13,11 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
public class LandingPage : BaseLayout
{
public LandingPage(Database database) : base(database)
{}
public List<User> PlayersOnline;
public int PlayersOnlineCount;
public List<User> PlayersOnline;
public LandingPage(Database database) : base(database)
{}
[UsedImplicitly]
public async Task<IActionResult> OnGet()

View file

@ -9,25 +9,6 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
{
public readonly Database Database;
public string Title = string.Empty;
public bool ShowTitleInPage = true;
private User? user;
public new User? User {
get {
if (this.user != null) return this.user;
return user = Database.UserFromWebRequest(this.Request);
}
set => this.user = value;
}
public BaseLayout(Database database)
{
this.Database = database;
}
public readonly List<PageNavigationItem> NavigationItems = new()
{
new PageNavigationItem("Home", "/", "home"),
@ -35,8 +16,26 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
new PageNavigationItem("Levels", "/slots/0", "certificate"),
};
public readonly List<PageNavigationItem> NavigationItemsRight = new()
{};
public readonly List<PageNavigationItem> NavigationItemsRight = new();
public bool ShowTitleInPage = true;
public string Title = string.Empty;
private User? user;
public BaseLayout(Database database)
{
this.Database = database;
}
public new User? User {
get {
if (this.user != null) return this.user;
return this.user = this.Database.UserFromWebRequest(this.Request);
}
set => this.user = value;
}
}
}

View file

@ -40,8 +40,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page();
}
if (!BCrypt.Net.BCrypt.Verify(password,
user.Password))
if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
{
this.Error = "The username or password you entered is invalid.";
return this.Page();
@ -56,19 +55,17 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.Database.WebTokens.Add(webToken);
await this.Database.SaveChangesAsync();
this.Response.Cookies.Append("LighthouseToken",
webToken.UserToken);
this.Response.Cookies.Append("LighthouseToken", webToken.UserToken);
if (user.PasswordResetRequired) return this.Redirect("~/passwordResetRequired");
return this.RedirectToPage(nameof(LandingPage));
}
[UsedImplicitly]
public async Task<IActionResult> OnGet()
{
Error = string.Empty;
this.Error = string.Empty;
return this.Page();
}
}

View file

@ -13,7 +13,6 @@ namespace LBPUnion.ProjectLighthouse.Pages
public PasswordResetPage(Database database) : base(database)
{}
public string Error { get; private set; }
[UsedImplicitly]
@ -47,6 +46,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.Redirect("~/login");
return this.Page();
}
}

View file

@ -13,14 +13,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
public class PhotosPage : BaseLayout
{
public PhotosPage([NotNull] Database database) : base(database)
{}
public int PageNumber;
public int PhotoCount;
public List<Photo> Photos;
public int PageNumber;
public PhotosPage([NotNull] Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
{

View file

@ -19,8 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
public bool WasRegisterRequest { get; private set; }
[UsedImplicitly]
[SuppressMessage("ReSharper",
"SpecifyStringComparison")]
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
public async Task<IActionResult> OnPost(string username, string password, string confirmPassword)
{
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
@ -43,16 +42,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
return this.Page();
}
bool userExists =
await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null;
bool userExists = await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null;
if (userExists)
{
this.Error = "The username you've chosen is already taken.";
return this.Page();
}
User user = await this.Database.CreateUser(username,
HashHelper.BCryptHash(password));
User user = await this.Database.CreateUser(username, HashHelper.BCryptHash(password));
WebToken webToken = new()
{
@ -63,8 +60,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
this.Database.WebTokens.Add(webToken);
await this.Database.SaveChangesAsync();
this.Response.Cookies.Append("LighthouseToken",
webToken.UserToken);
this.Response.Cookies.Append("LighthouseToken", webToken.UserToken);
return this.RedirectToPage(nameof(LandingPage));
}
@ -73,7 +69,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
public IActionResult OnGet()
{
Error = string.Empty;
this.Error = string.Empty;
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
return this.Page();

View file

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

View file

@ -13,14 +13,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
public class SlotsPage : BaseLayout
{
public SlotsPage([NotNull] Database database) : base(database)
{}
public int PageNumber;
public int SlotCount;
public List<Slot> Slots;
public int PageNumber;
public SlotsPage([NotNull] Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
{

View file

@ -12,16 +12,16 @@ namespace LBPUnion.ProjectLighthouse.Pages
{
public class UserPage : BaseLayout
{
public UserPage(Database database) : base(database)
{}
public User? ProfileUser;
public List<Photo>? Photos;
public List<Comment>? Comments;
public bool IsProfileUserHearted;
public List<Photo>? Photos;
public User? ProfileUser;
public UserPage(Database database) : base(database)
{}
public async Task<IActionResult> OnGet([FromRoute] int userId)
{
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
@ -37,12 +37,9 @@ namespace LBPUnion.ProjectLighthouse.Pages
.ToListAsync();
if (this.User != null)
{
this.IsProfileUserHearted = (await this.Database.HeartedProfiles.FirstOrDefaultAsync
(u => u.UserId == this.User.UserId && u.HeartedUserId == this.ProfileUser.UserId)) !=
this.IsProfileUserHearted = await this.Database.HeartedProfiles.FirstOrDefaultAsync
(u => u.UserId == this.User.UserId && u.HeartedUserId == this.ProfileUser.UserId) !=
null;
}
return this.Page();
}

View file

@ -21,10 +21,7 @@ namespace LBPUnion.ProjectLighthouse
if (args.Length != 0 && args[0] == "--wait-for-debugger")
{
Console.WriteLine("Waiting for a debugger to be attached...");
while (!Debugger.IsAttached)
{
Thread.Sleep(100);
}
while (!Debugger.IsAttached) Thread.Sleep(100);
Console.WriteLine("Debugger attached.");
}

View file

@ -148,11 +148,9 @@ namespace LBPUnion.ProjectLighthouse
GameToken? gameToken = await database.GameTokenFromRequest(context.Request);
if (gameToken != null && gameToken.GameVersion == GameVersion.LittleBigPlanet1)
{
// Ignore UserFromGameToken null because user must exist for a token to exist
await LastContactHelper.SetLastContact((await database.UserFromGameToken(gameToken))!, GameVersion.LittleBigPlanet1);
}
}
#nullable disable
requestStopwatch.Stop();

View file

@ -7,10 +7,12 @@ namespace LBPUnion.ProjectLighthouse.Types
{
[XmlEnum(Name = "none")]
None,
[XmlEnum(Name = "moderator")]
Moderator,
[XmlEnum(Name = "level_author")]
LevelAuthor
LevelAuthor,
// TODO: deletion types for comments (profile etc)
}
}

View file

@ -41,8 +41,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[NotMapped]
[XmlElement("resource")]
public string[] Resources
{
public string[] Resources {
get => this.ResourceCollection.Split(",");
set => this.ResourceCollection = string.Join(',', value);
}
@ -104,10 +103,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[XmlIgnore]
[NotMapped]
public int Hearts
{
get
{
public int Hearts {
get {
using Database database = new();
return database.HeartedLevels.Count(s => s.SlotId == this.SlotId);
@ -164,10 +161,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[NotMapped]
[XmlElement("thumbsup")]
public int Thumbsup
{
get
{
public int Thumbsup {
get {
using Database database = new();
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1);
@ -176,10 +171,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[NotMapped]
[XmlElement("thumbsdown")]
public int Thumbsdown
{
get
{
public int Thumbsdown {
get {
using Database database = new();
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1);
@ -188,10 +181,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[NotMapped]
[XmlElement("averageRating")]
public double RatingLBP1
{
get
{
public double RatingLBP1 {
get {
using Database database = new();
IQueryable<RatedLevel> ratedLevels = database.RatedLevels.Where(r => r.SlotId == this.SlotId && r.RatingLBP1 > 0);
@ -203,10 +194,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
[NotMapped]
[XmlElement("reviewCount")]
public int ReviewCount
{
get
{
public int ReviewCount {
get {
using Database database = new();
return database.Reviews.Count(r => r.SlotId == this.SlotId);

View file

@ -8,6 +8,17 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
public class CreateRoom : IMatchData
{
public int BuildVersion;
public int HostMood;
public int Language;
public List<int> Location;
public List<int> NAT;
public int PassedNoJoinPoint;
public RoomState RoomState;
public string Search;
//[CreateRoom,["Players":["LumaLivy"],"Reservations":["0"],"NAT":[2],"Slots":[[1,3]],"RoomState":0,"HostMood":1,"PassedNoJoinPoint":0,"Location":[0x7f000001],"Language":1,"BuildVersion":289,"Search":""]]
public List<string> Players { get; set; }
@ -25,17 +36,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
public RoomSlot RoomSlot
=> new()
{
SlotType = (SlotType)Slots[0][0],
SlotId = Slots[0][1],
SlotType = (SlotType)this.Slots[0][0],
SlotId = this.Slots[0][1],
};
public List<int> NAT;
public RoomState RoomState;
public int HostMood;
public int PassedNoJoinPoint;
public List<int> Location;
public int Language;
public int BuildVersion;
public string Search;
}
}

View file

@ -8,6 +8,15 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
public class FindBestRoom : IMatchData
{
public int BuildVersion;
public int HostMood;
public int Language;
public List<int> Location;
public List<int> NAT;
public int PassedNoJoinPoint;
public RoomState RoomState;
public string Search;
public List<string> Players { get; set; }
public List<string> Reservations { get; set; }
@ -15,14 +24,5 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
[JsonIgnore]
public IEnumerable<int> FirstSlot => this.Slots[0];
public List<int> NAT;
public RoomState RoomState;
public int HostMood;
public int PassedNoJoinPoint;
public List<int> Location;
public int Language;
public int BuildVersion;
public string Search;
}
}

View file

@ -11,7 +11,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
public User User { get; set; }
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public string PlayerId => User.Username;
public string PlayerId => this.User.Username;
[JsonPropertyName("matching_res")]
public int MatchingRes { get; set; }

View file

@ -6,13 +6,13 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
{
public class Room
{
public int RoomId;
public List<User> Players;
public RoomState State;
public int RoomId;
public RoomSlot Slot;
public RoomState State;
public bool IsInPod => Slot.SlotType == SlotType.Pod;
public bool IsInPod => this.Slot.SlotType == SlotType.Pod;
public bool IsLookingForPlayers => this.State == RoomState.DivingIntoLevel || this.State == RoomState.DivingInWaiting;
public User Host => this.Players[0];
@ -20,7 +20,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
#nullable enable
public override bool Equals(object? obj)
{
if (obj is Room room) return room.RoomId == RoomId;
if (obj is Room room) return room.RoomId == this.RoomId;
return false;
}

View file

@ -4,7 +4,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
{
public class RoomSlot
{
public SlotType SlotType;
public int SlotId;
public SlotType SlotType;
}
}

View file

@ -14,6 +14,15 @@ namespace LBPUnion.ProjectLighthouse.Types
[XmlType("photo")]
public class Photo
{
[NotMapped]
private List<PhotoSubject>? _subjects;
[NotMapped]
[XmlArray("subjects")]
[XmlArrayItem("subject")]
public List<PhotoSubject>? SubjectsXmlDontUseLiterallyEver;
[Key]
public int PhotoId { get; set; }
@ -33,14 +42,6 @@ namespace LBPUnion.ProjectLighthouse.Types
[XmlElement("plan")]
public string PlanHash { get; set; } = "";
[NotMapped]
private List<PhotoSubject>? _subjects;
[NotMapped]
[XmlArray("subjects")]
[XmlArrayItem("subject")]
public List<PhotoSubject>? SubjectsXmlDontUseLiterallyEver;
[NotMapped]
public List<PhotoSubject> Subjects {
get {
@ -94,7 +95,7 @@ namespace LBPUnion.ProjectLighthouse.Types
LbpSerializer.StringElement("subjects", subjectsAggregate) +
slot;
return LbpSerializer.TaggedStringElement("photo", photo, "timestamp", Timestamp * 1000);
return LbpSerializer.TaggedStringElement("photo", photo, "timestamp", this.Timestamp * 1000);
}
}
}

View file

@ -31,9 +31,9 @@ namespace LBPUnion.ProjectLighthouse.Types
public string Serialize()
{
string response = LbpSerializer.StringElement("npHandle", User.Username) +
LbpSerializer.StringElement("displayName", User.Username) +
LbpSerializer.StringElement("bounds", Bounds);
string response = LbpSerializer.StringElement("npHandle", this.User.Username) +
LbpSerializer.StringElement("displayName", this.User.Username) +
LbpSerializer.StringElement("bounds", this.Bounds);
return LbpSerializer.StringElement("subject", response);
}

View file

@ -1,12 +1,11 @@
#nullable enable
using System;
using System.IO;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Serialization;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
namespace LBPUnion.ProjectLighthouse.Types.Reviews
{
@ -38,14 +37,13 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
[NotMapped]
[XmlIgnore]
public string[] Labels
{
public string[] Labels {
get => this.LabelCollection.Split(",");
set => this.LabelCollection = string.Join(',', value);
}
[XmlElement("deleted")]
public Boolean Deleted { get; set; }
public bool Deleted { get; set; }
[XmlElement("deleted_by")]
public DeletedBy DeletedBy { get; set; }
@ -58,26 +56,23 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
[XmlElement("thumbsup")]
public int ThumbsUp { get; set; }
[XmlElement("thumbsdown")]
public int ThumbsDown { get; set; }
public string Serialize(RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
{
return this.Serialize("review", yourLevelRating, yourRatingStats);
}
public string Serialize
(RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
=> this.Serialize("review", yourLevelRating, yourRatingStats);
public string Serialize(string elementOverride, RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
{
XmlWriterSettings settings = new XmlWriterSettings();
XmlWriterSettings settings = new();
settings.OmitXmlDeclaration = true;
XmlSerializer serializer = new(typeof(DeletedBy));
StringWriter stringWriter = new StringWriter();
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
{
serializer.Serialize(xmlWriter, this.DeletedBy);
}
StringWriter stringWriter = new();
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings)) serializer.Serialize(xmlWriter, this.DeletedBy);
string deletedBy = stringWriter.ToString();
string reviewData = LbpSerializer.TaggedStringElement("slot_id", this.SlotId, "type", this.Slot.Type) +
@ -96,5 +91,4 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
}
}
}

View file

@ -11,6 +11,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
[Serializable]
public class ServerSettings
{
public const int CurrentConfigVersion = 12; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE!
static ServerSettings()
{
if (ServerStatics.IsUnitTesting) return; // Unit testing, we don't want to read configurations here since the tests will provide their own
@ -63,20 +65,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
}
}
public const int CurrentConfigVersion = 12; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE!
#region Meta
[NotNull]
public static ServerSettings Instance;
[JsonPropertyName("ConfigVersionDoNotModifyOrYouWillBeSlapped")]
public int ConfigVersion { get; set; } = CurrentConfigVersion;
public const string ConfigFileName = "lighthouse.config.json";
#endregion Meta
public bool InfluxEnabled { get; set; }
public bool InfluxLoggingEnabled { get; set; }
public string InfluxOrg { get; set; } = "lighthouse";
@ -105,8 +93,21 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
public int PhotosQuota { get; set; } = 500;
public bool GoogleAnalyticsEnabled { get; set; } = false;
public bool GoogleAnalyticsEnabled { get; set; }
public string GoogleAnalyticsId { get; set; } = "";
#region Meta
[NotNull]
public static ServerSettings Instance;
[JsonPropertyName("ConfigVersionDoNotModifyOrYouWillBeSlapped")]
public int ConfigVersion { get; set; } = CurrentConfigVersion;
public const string ConfigFileName = "lighthouse.config.json";
#endregion Meta
}
}

View file

@ -10,10 +10,10 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
{
public const string ServerName = "ProjectLighthouse";
public static bool DbConnected
{
get
{
public const int PageSize = 20;
public static bool DbConnected {
get {
try
{
return new Database().Database.CanConnect();
@ -27,7 +27,5 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
}
public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit"));
public const int PageSize = 20;
}
}

View file

@ -26,40 +26,32 @@ namespace LBPUnion.ProjectLighthouse.Types
public string Biography { get; set; }
[NotMapped]
public int Reviews
{
get
{
public int Reviews {
get {
using Database database = new();
return database.Reviews.Count(r => r.ReviewerId == this.UserId);
}
}
[NotMapped]
public int Comments
{
get
{
public int Comments {
get {
using Database database = new();
return database.Comments.Count(c => c.TargetUserId == this.UserId);
}
}
[NotMapped]
public int PhotosByMe
{
get
{
public int PhotosByMe {
get {
using Database database = new();
return database.Photos.Count(p => p.CreatorId == this.UserId);
}
}
[NotMapped]
public int PhotosWithMe
{
get
{
public int PhotosWithMe {
get {
using Database database = new();
return Enumerable.Sum(database.Photos, photo => photo.Subjects.Count(subject => subject.User.UserId == this.UserId));
}
@ -74,30 +66,24 @@ namespace LBPUnion.ProjectLighthouse.Types
public Location Location { get; set; }
[NotMapped]
public int HeartedLevels
{
get
{
public int HeartedLevels {
get {
using Database database = new();
return database.HeartedLevels.Count(p => p.UserId == this.UserId);
}
}
[NotMapped]
public int HeartedUsers
{
get
{
public int HeartedUsers {
get {
using Database database = new();
return database.HeartedProfiles.Count(p => p.UserId == this.UserId);
}
}
[NotMapped]
public int QueuedLevels
{
get
{
public int QueuedLevels {
get {
using Database database = new();
return database.QueuedLevels.Count(p => p.UserId == this.UserId);
}
@ -107,10 +93,8 @@ namespace LBPUnion.ProjectLighthouse.Types
public string PlanetHash { get; set; } = "";
public int Hearts
{
get
{
public int Hearts {
get {
using Database database = new();
return database.HeartedProfiles.Count(s => s.HeartedUserId == this.UserId);
@ -127,10 +111,8 @@ namespace LBPUnion.ProjectLighthouse.Types
#nullable enable
[NotMapped]
public string Status
{
get
{
public string Status {
get {
using Database database = new();
LastContact? lastMatch = database.LastContacts.Where
(l => l.UserId == this.UserId)
@ -165,9 +147,9 @@ namespace LBPUnion.ProjectLighthouse.Types
LbpSerializer.StringElement("planets", this.PlanetHash) +
LbpSerializer.BlankElement("photos") +
LbpSerializer.StringElement("heartCount", this.Hearts) +
LbpSerializer.StringElement("yay2", YayHash) +
LbpSerializer.StringElement("boo2", YayHash) +
LbpSerializer.StringElement("meh2", YayHash);
LbpSerializer.StringElement("yay2", this.YayHash) +
LbpSerializer.StringElement("boo2", this.YayHash) +
LbpSerializer.StringElement("meh2", this.YayHash);
this.ClientsConnected.Serialize();
return LbpSerializer.TaggedStringElement("user", user, "type", "user");
@ -179,10 +161,8 @@ namespace LBPUnion.ProjectLighthouse.Types
/// The number of used slots on the earth
/// </summary>
[NotMapped]
public int UsedSlots
{
get
{
public int UsedSlots {
get {
using Database database = new();
return database.Slots.Count(s => s.CreatorId == this.UserId);
}
@ -246,7 +226,7 @@ namespace LBPUnion.ProjectLighthouse.Types
#nullable enable
public override bool Equals(object? obj)
{
if (obj is User user) return user.UserId == UserId;
if (obj is User user) return user.UserId == this.UserId;
return false;
}

View file

@ -88,7 +88,7 @@ Keep in mind while running database tests you need to have `LIGHTHOUSE_DB_CONNEC
| LBP Vita | Compatible | Incompatible, marked as "bootable" on Vita3k | N/A |
| LBP PSP | Potentially compatible | Incompatible, PSN not supported on PPSSPP | Potentially Compatible |
While LBP Vita and LBP PSP can be supported, they are not properly seperated from the mainline games at this time.
We recommend you run seperate instances for these games to avoid problems.
While LBP Vita and LBP PSP can be supported, they are not properly seperated from the mainline games at this time. We
recommend you run seperate instances for these games to avoid problems.
Project Lighthouse is still a heavy work in progress, so this chart is subject to change at any point.