mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-15 14:12:27 +00:00
Cleanup code
This commit is contained in:
parent
1ec7bdf1f6
commit
b0b9ad2172
58 changed files with 310 additions and 424 deletions
|
@ -70,10 +70,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (user == null) return this.StatusCode(403, "");
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
Comment? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId);
|
Comment? comment = await this.database.Comments.FirstOrDefaultAsync(c => c.CommentId == commentId);
|
||||||
if (comment == null)
|
if (comment == null) return this.NotFound();
|
||||||
{
|
|
||||||
return this.NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment.TargetUserId != user.UserId && comment.PosterUserId != user.UserId) return this.StatusCode(403, "");
|
if (comment.TargetUserId != user.UserId && comment.PosterUserId != user.UserId) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
|
|
@ -63,10 +63,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
v = await visited.FirstOrDefaultAsync();
|
v = await visited.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v == null)
|
if (v == null) return this.NotFound();
|
||||||
{
|
|
||||||
return this.NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (gameVersion)
|
switch (gameVersion)
|
||||||
{
|
{
|
||||||
|
@ -119,10 +116,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
v = await visited.FirstOrDefaultAsync();
|
v = await visited.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v == null)
|
if (v == null) return this.NotFound();
|
||||||
{
|
|
||||||
return this.NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
slot.PlaysLBP1++;
|
slot.PlaysLBP1++;
|
||||||
v.PlaysLBP1++;
|
v.PlaysLBP1++;
|
||||||
|
|
|
@ -78,9 +78,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
GameToken gameToken = userAndToken.Value.Item2;
|
GameToken gameToken = userAndToken.Value.Item2;
|
||||||
|
|
||||||
if (!FriendHelper.FriendIdsByUserId.TryGetValue(user.UserId, out int[]? friendIds) || friendIds == null)
|
if (!FriendHelper.FriendIdsByUserId.TryGetValue(user.UserId, out int[]? friendIds) || friendIds == null)
|
||||||
{
|
|
||||||
return this.Ok(LbpSerializer.BlankElement("myFriends"));
|
return this.Ok(LbpSerializer.BlankElement("myFriends"));
|
||||||
}
|
|
||||||
|
|
||||||
string friends = "";
|
string friends = "";
|
||||||
foreach (int friendId in friendIds)
|
foreach (int friendId in friendIds)
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (ServerSettings.Instance.UseExternalAuth)
|
if (ServerSettings.Instance.UseExternalAuth)
|
||||||
{
|
{
|
||||||
string ipAddressAndName = $"{token.UserLocation}|{user.Username}";
|
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.RemoveRange
|
||||||
(this.database.AuthenticationAttempts.Include(a => a.GameToken).Where(a => a.GameToken.UserId == user.UserId));
|
(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);
|
Logger.Log($"Successfully logged in user {user.Username} as {token.GameVersion} client ({titleId})", LoggerLevelLogin.Instance);
|
||||||
|
|
||||||
// Create a new room on LBP2+/Vita
|
// Create a new room on LBP2+/Vita
|
||||||
if (token.GameVersion != GameVersion.LittleBigPlanet1)
|
if (token.GameVersion != GameVersion.LittleBigPlanet1) RoomHelper.CreateRoom(user);
|
||||||
{
|
|
||||||
RoomHelper.CreateRoom(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Ok
|
return this.Ok
|
||||||
(
|
(
|
||||||
|
|
|
@ -80,9 +80,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
Room? room = RoomHelper.FindRoomByUser(user, true);
|
Room? room = RoomHelper.FindRoomByUser(user, true);
|
||||||
|
|
||||||
if (playerData.RoomState != null)
|
if (playerData.RoomState != null)
|
||||||
{
|
if (room != null && Equals(room.Host, user))
|
||||||
if (room != null && Equals(room.Host, user)) room.State = (RoomState)playerData.RoomState;
|
room.State = (RoomState)playerData.RoomState;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
|
if (matchData is FindBestRoom && MatchHelper.UserLocations.Count > 1)
|
||||||
|
@ -92,10 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (response == null) return this.NotFound();
|
if (response == null) return this.NotFound();
|
||||||
|
|
||||||
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
|
string serialized = JsonSerializer.Serialize(response, typeof(FindBestRoomResponse));
|
||||||
foreach (Player player in response.Players)
|
foreach (Player player in response.Players) MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
|
||||||
{
|
|
||||||
MatchHelper.AddUserRecentlyDivedIn(user.UserId, player.User.UserId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Ok($"[{{\"StatusCode\":200}},{serialized}]");
|
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);
|
User? player = await this.database.Users.FirstOrDefaultAsync(u => u.Username == playerUsername);
|
||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
if (player != null)
|
if (player != null) users.Add(player);
|
||||||
{
|
|
||||||
users.Add(player);
|
|
||||||
}
|
|
||||||
else return this.BadRequest();
|
else return this.BadRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,16 +31,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (user == null) return this.StatusCode(403, "");
|
if (user == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
if (ServerSettings.Instance.UseExternalAuth)
|
if (ServerSettings.Instance.UseExternalAuth)
|
||||||
{
|
|
||||||
return this.Ok
|
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" +
|
$"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" +
|
"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" +
|
"Once approved, you may press X and continue.\n\n" +
|
||||||
ServerSettings.Instance.EulaText
|
ServerSettings.Instance.EulaText
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return this.Ok($"You are now logged in as {user.Username} (id: {user.UserId}).\n\n" + ServerSettings.Instance.EulaText);
|
return this.Ok($"You are now logged in as {user.Username} (id: {user.UserId}).\n\n" + ServerSettings.Instance.EulaText);
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,10 +114,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (userFromQuery == null) return this.NotFound();
|
if (userFromQuery == null) return this.NotFound();
|
||||||
|
|
||||||
List<Photo> photos = new();
|
List<Photo> photos = new();
|
||||||
foreach (Photo photo in this.database.Photos.Include(p => p.Creator))
|
foreach (Photo photo in this.database.Photos.Include
|
||||||
{
|
(p => p.Creator)) photos.AddRange(photo.Subjects.Where(subject => subject.User.UserId == userFromQuery.UserId).Select(_ => photo));
|
||||||
photos.AddRange(photo.Subjects.Where(subject => subject.User.UserId == userFromQuery.UserId).Select(_ => photo));
|
|
||||||
}
|
|
||||||
|
|
||||||
string response = photos.OrderByDescending
|
string response = photos.OrderByDescending
|
||||||
(s => s.Timestamp)
|
(s => s.Timestamp)
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Controllers
|
namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
{
|
{
|
||||||
|
@ -77,10 +77,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
ratedLevel.Rating = Math.Max(Math.Min(1, rating), -1);
|
ratedLevel.Rating = Math.Max(Math.Min(1, rating), -1);
|
||||||
|
|
||||||
Review? review = await this.database.Reviews.FirstOrDefaultAsync(r => r.SlotId == slotId && r.ReviewerId == user.UserId);
|
Review? review = await this.database.Reviews.FirstOrDefaultAsync(r => r.SlotId == slotId && r.ReviewerId == user.UserId);
|
||||||
if (review != null)
|
if (review != null) review.Thumb = ratedLevel.Rating;
|
||||||
{
|
|
||||||
review.Thumb = ratedLevel.Rating;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
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? review = await this.database.Reviews.FirstOrDefaultAsync(r => r.SlotId == slotId && r.ReviewerId == user.UserId);
|
||||||
Review? newReview = await this.GetReviewFromBody();
|
Review? newReview = await this.GetReviewFromBody();
|
||||||
if (newReview == null) return this.BadRequest();
|
if (newReview == null) return this.BadRequest();
|
||||||
|
|
||||||
if (review == null)
|
if (review == null)
|
||||||
{
|
{
|
||||||
review = new();
|
review = new Review();
|
||||||
review.SlotId = slotId;
|
review.SlotId = slotId;
|
||||||
review.ReviewerId = user.UserId;
|
review.ReviewerId = user.UserId;
|
||||||
review.DeletedBy = DeletedBy.None;
|
review.DeletedBy = DeletedBy.None;
|
||||||
|
@ -145,19 +143,22 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
Random rand = new();
|
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);
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slotId);
|
||||||
if (slot == null) return this.BadRequest();
|
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)
|
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.ReviewerId = user.UserId;
|
||||||
yourReview.Reviewer = user;
|
yourReview.Reviewer = user;
|
||||||
yourReview.Thumb = ratedLevel?.Rating == null ? 0 : ratedLevel.Rating;
|
yourReview.Thumb = ratedLevel?.Rating == null ? 0 : ratedLevel.Rating;
|
||||||
|
@ -180,30 +181,35 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
IEnumerable<Review?> prependedReviews;
|
IEnumerable<Review?> prependedReviews;
|
||||||
if (canNowReviewLevel) // this can only be true if you have not posted a review but have visited the level
|
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
|
// prepend the fake review to the top of the list to be easily edited
|
||||||
prependedReviews = reviews.ToList().Prepend(yourReview);
|
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
|
||||||
{
|
(
|
||||||
if (review == null) return current;
|
string.Empty,
|
||||||
return current + review.Serialize();
|
(current, review) =>
|
||||||
});
|
{
|
||||||
|
if (review == null) return current;
|
||||||
|
|
||||||
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
|
||||||
"hint_start", pageStart + pageSize
|
},
|
||||||
},
|
{
|
||||||
{
|
"hint", pageStart // not sure
|
||||||
"hint", pageStart // not sure
|
},
|
||||||
},
|
}
|
||||||
});
|
);
|
||||||
return this.Ok(response);
|
return this.Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,22 +233,31 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
.Skip(pageStart - 1)
|
.Skip(pageStart - 1)
|
||||||
.Take(pageSize);
|
.Take(pageSize);
|
||||||
|
|
||||||
string inner = Enumerable.Aggregate(reviews, string.Empty, (current, review) =>
|
string inner = reviews.Aggregate
|
||||||
{
|
(
|
||||||
//RatedLevel? ratedLevel = this.database.RatedLevels.FirstOrDefault(r => r.SlotId == review.SlotId && r.UserId == user.UserId);
|
string.Empty,
|
||||||
//RatedReview? ratedReview = this.database.RatedReviews.FirstOrDefault(r => r.ReviewId == review.ReviewId && r.UserId == user.UserId);
|
(current, review) =>
|
||||||
return current + review.Serialize(/*, ratedReview*/);
|
{
|
||||||
});
|
//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
|
||||||
"hint_start", pageStart
|
},
|
||||||
},
|
{
|
||||||
{
|
"hint", reviews.Last().Timestamp // Seems to be the timestamp of oldest
|
||||||
"hint", reviews.Last().Timestamp // Seems to be the timestamp of oldest
|
},
|
||||||
},
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
return this.Ok(response);
|
return this.Ok(response);
|
||||||
}
|
}
|
||||||
|
@ -312,6 +327,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
return review;
|
return review;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -80,7 +80,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
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);
|
return this.Ok(myRanking);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
if (user == null) return this.StatusCode(403, "");
|
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")]
|
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
||||||
|
@ -139,17 +139,13 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
);
|
);
|
||||||
|
|
||||||
string res;
|
string res;
|
||||||
if (myScore == null)
|
if (myScore == null) res = LbpSerializer.StringElement("scores", serializedScores);
|
||||||
{
|
|
||||||
res = LbpSerializer.StringElement("scores", serializedScores);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
res = LbpSerializer.TaggedStringElement
|
res = LbpSerializer.TaggedStringElement
|
||||||
(
|
(
|
||||||
"scores",
|
"scores",
|
||||||
serializedScores,
|
serializedScores,
|
||||||
new Dictionary<string, object>()
|
new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
"yourScore", myScore.Score.Points
|
"yourScore", myScore.Score.Points
|
||||||
|
@ -162,7 +158,6 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}, // This is the denominator of your position globally in the side menu.
|
}, // This is the denominator of your position globally in the side menu.
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -44,14 +44,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
s.SlotId.ToString().Equals(keyword)
|
s.SlotId.ToString().Equals(keyword)
|
||||||
);
|
);
|
||||||
|
|
||||||
List<Slot> slots = await dbQuery
|
List<Slot> slots = await dbQuery.Skip(pageStart - 1).Take(Math.Min(pageSize, 30)).ToListAsync();
|
||||||
.Skip(pageStart - 1)
|
|
||||||
.Take(Math.Min(pageSize, 30))
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize());
|
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize());
|
||||||
|
|
||||||
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
|
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,8 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
@ -91,7 +91,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
|
|
||||||
[HttpGet("slots/lbp2cool")]
|
[HttpGet("slots/lbp2cool")]
|
||||||
[HttpGet("slots/cool")]
|
[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")]
|
[HttpGet("slots")]
|
||||||
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
public async Task<IActionResult> NewestSlots([FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
|
@ -198,6 +198,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,10 +51,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
if (token == null) return this.StatusCode(403, "");
|
if (token == null) return this.StatusCode(403, "");
|
||||||
|
|
||||||
List<string?> serializedUsers = new();
|
List<string?> serializedUsers = new();
|
||||||
foreach (string userId in u)
|
foreach (string userId in u) serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
|
||||||
{
|
|
||||||
serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
string serialized = serializedUsers.Aggregate(string.Empty, (current, user) => user == null ? current : current + user);
|
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
|
Location? l = await this.database.Locations.FirstOrDefaultAsync(l => l.Id == user.LocationId); // find the location in the database again
|
||||||
|
|
||||||
if (l == null)
|
if (l == null) throw new Exception("this shouldn't happen ever but we handle this");
|
||||||
{
|
|
||||||
throw new Exception("this shouldn't happen ever but we handle this");
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the location in the database to the one we modified above
|
// set the location in the database to the one we modified above
|
||||||
l.X = user.Location.X;
|
l.X = user.Location.X;
|
||||||
|
|
|
@ -26,10 +26,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
[HttpGet("heart")]
|
[HttpGet("heart")]
|
||||||
public async Task<IActionResult> HeartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
public async Task<IActionResult> HeartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(callbackUrl))
|
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
|
||||||
{
|
|
||||||
callbackUrl = "~/slot/" + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
@ -45,10 +42,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
[HttpGet("unheart")]
|
[HttpGet("unheart")]
|
||||||
public async Task<IActionResult> UnheartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
public async Task<IActionResult> UnheartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(callbackUrl))
|
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
|
||||||
{
|
|
||||||
callbackUrl = "~/slot/" + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
@ -64,10 +58,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
[HttpGet("queue")]
|
[HttpGet("queue")]
|
||||||
public async Task<IActionResult> QueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
public async Task<IActionResult> QueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(callbackUrl))
|
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
|
||||||
{
|
|
||||||
callbackUrl = "~/slot/" + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
@ -83,10 +74,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
[HttpGet("unqueue")]
|
[HttpGet("unqueue")]
|
||||||
public async Task<IActionResult> UnqueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
public async Task<IActionResult> UnqueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(callbackUrl))
|
if (string.IsNullOrEmpty(callbackUrl)) callbackUrl = "~/slot/" + id;
|
||||||
{
|
|
||||||
callbackUrl = "~/slot/" + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
|
@ -6,8 +6,8 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
{
|
{
|
||||||
public class FakeRemoteIPAddressMiddleware
|
public class FakeRemoteIPAddressMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate next;
|
|
||||||
private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1");
|
private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1");
|
||||||
|
private readonly RequestDelegate next;
|
||||||
|
|
||||||
public FakeRemoteIPAddressMiddleware(RequestDelegate next)
|
public FakeRemoteIPAddressMiddleware(RequestDelegate next)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,12 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
{
|
{
|
||||||
public static class MaintenanceHelper
|
public static class MaintenanceHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static MaintenanceHelper()
|
||||||
|
{
|
||||||
|
Commands = getListOfInterfaceObjects<ICommand>();
|
||||||
|
MaintenanceJobs = getListOfInterfaceObjects<IMaintenanceJob>();
|
||||||
|
}
|
||||||
public static List<ICommand> Commands { get; }
|
public static List<ICommand> Commands { get; }
|
||||||
|
|
||||||
public static List<IMaintenanceJob> MaintenanceJobs { get; }
|
public static List<IMaintenanceJob> MaintenanceJobs { get; }
|
||||||
|
@ -23,22 +29,14 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
.ToList()!;
|
.ToList()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
static MaintenanceHelper()
|
|
||||||
{
|
|
||||||
Commands = getListOfInterfaceObjects<ICommand>();
|
|
||||||
MaintenanceJobs = getListOfInterfaceObjects<IMaintenanceJob>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task RunCommand(string[] args)
|
public static async Task RunCommand(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length < 1)
|
if (args.Length < 1)
|
||||||
{
|
|
||||||
throw new Exception
|
throw new Exception
|
||||||
(
|
(
|
||||||
"This should never happen. " +
|
"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."
|
"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();
|
||||||
|
|
|
@ -22,10 +22,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
|
|
||||||
public static void AddUserRecentlyDivedIn(int userId, int otherUserId)
|
public static void AddUserRecentlyDivedIn(int userId, int otherUserId)
|
||||||
{
|
{
|
||||||
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn))
|
if (!UserRecentlyDivedIn.TryGetValue(userId, out List<int>? recentlyDivedIn)) UserRecentlyDivedIn.Add(userId, recentlyDivedIn = new List<int>());
|
||||||
{
|
|
||||||
UserRecentlyDivedIn.Add(userId, recentlyDivedIn = new List<int>());
|
|
||||||
}
|
|
||||||
|
|
||||||
Debug.Assert(recentlyDivedIn != null, nameof(recentlyDivedIn) + " is null, somehow.");
|
Debug.Assert(recentlyDivedIn != null, nameof(recentlyDivedIn) + " is null, somehow.");
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
{
|
{
|
||||||
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value);
|
bool gotValue = MatchHelper.UserLocations.TryGetValue(p.UserId, out string? value);
|
||||||
|
|
||||||
if (gotValue && value != null)
|
if (gotValue && value != null) relevantUserLocations.Add(p.UserId, value);
|
||||||
{
|
|
||||||
relevantUserLocations.Add(p.UserId, value);
|
|
||||||
}
|
|
||||||
return gotValue;
|
return gotValue;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -138,7 +135,6 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
{
|
{
|
||||||
// Delete old rooms based on host
|
// Delete old rooms based on host
|
||||||
if (host != null)
|
if (host != null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Rooms.RemoveAll(r => r.Host == host);
|
Rooms.RemoveAll(r => r.Host == host);
|
||||||
|
@ -147,18 +143,15 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
{
|
{
|
||||||
// TODO: detect the room that failed and remove it
|
// TODO: detect the room that failed and remove it
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Remove players in this new room from other rooms
|
// Remove players in this new room from other rooms
|
||||||
if (newRoom != null)
|
if (newRoom != null)
|
||||||
{
|
|
||||||
foreach (Room room in Rooms)
|
foreach (Room room in Rooms)
|
||||||
{
|
{
|
||||||
if (room == newRoom) continue;
|
if (room == newRoom) continue;
|
||||||
|
|
||||||
foreach (User newRoomPlayer in newRoom.Players) room.Players.RemoveAll(p => p == newRoomPlayer);
|
foreach (User newRoomPlayer in newRoom.Players) room.Players.RemoveAll(p => p == newRoomPlayer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ namespace LBPUnion.ProjectLighthouse.Logging
|
||||||
{
|
{
|
||||||
public class InfluxLogger : LoggerBase
|
public class InfluxLogger : LoggerBase
|
||||||
{
|
{
|
||||||
|
public override bool AllowMultiple => false;
|
||||||
|
|
||||||
public override void Send(LoggerLine line)
|
public override void Send(LoggerLine line)
|
||||||
{
|
{
|
||||||
|
@ -22,6 +23,5 @@ namespace LBPUnion.ProjectLighthouse.Logging
|
||||||
|
|
||||||
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
||||||
}
|
}
|
||||||
public override bool AllowMultiple => false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,7 @@ namespace LBPUnion.ProjectLighthouse.Logging
|
||||||
File.AppendAllText(Path.Combine(logsDirectory, line.LoggerLevel.Name.ToFileName() + ".log"), contentFile);
|
File.AppendAllText(Path.Combine(logsDirectory, line.LoggerLevel.Name.ToFileName() + ".log"), contentFile);
|
||||||
File.AppendAllText(Path.Combine(logsDirectory, "all.log"), contentAll);
|
File.AppendAllText(Path.Combine(logsDirectory, "all.log"), contentAll);
|
||||||
}
|
}
|
||||||
catch (IOException) { } // windows, ya goofed
|
catch(IOException) {} // windows, ya goofed
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ using JetBrains.Annotations;
|
||||||
using Kettu;
|
using Kettu;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
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);
|
User? user = await this._database.Users.FirstOrDefaultAsync(u => u.Username == onlineId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
user = await this._database.CreateUser(onlineId,
|
user = await this._database.CreateUser(onlineId, HashHelper.BCryptHash(password));
|
||||||
HashHelper.BCryptHash(password));
|
Logger.Log($"Created user {user.UserId} with online ID (username) {user.Username} and the specified password.", LoggerLevelLogin.Instance);
|
||||||
Logger.Log(
|
|
||||||
$"Created user {user.UserId} with online ID (username) {user.Username} and the specified password.", LoggerLevelLogin.Instance);
|
|
||||||
|
|
||||||
user.PasswordResetRequired = true;
|
user.PasswordResetRequired = true;
|
||||||
Logger.Log("This user will need to reset their password when they log in.",
|
Logger.Log("This user will need to reset their password when they log in.", LoggerLevelLogin.Instance);
|
||||||
LoggerLevelLogin.Instance);
|
|
||||||
|
|
||||||
await this._database.SaveChangesAsync();
|
await this._database.SaveChangesAsync();
|
||||||
Logger.Log("Database changes saved.",
|
Logger.Log("Database changes saved.", LoggerLevelDatabase.Instance);
|
||||||
LoggerLevelDatabase.Instance);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Log("A user with this username already exists.",
|
Logger.Log("A user with this username already exists.", LoggerLevelLogin.Instance);
|
||||||
LoggerLevelLogin.Instance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name() => "Create New User";
|
public string Name() => "Create New User";
|
||||||
|
|
||||||
public string[] Aliases() =>
|
public string[] Aliases()
|
||||||
new[]
|
=> new[]
|
||||||
{
|
{
|
||||||
"useradd", "adduser", "newuser", "createUser"
|
"useradd", "adduser", "newuser", "createUser",
|
||||||
};
|
};
|
||||||
|
|
||||||
public string Arguments() => "<OnlineID> <Password>";
|
public string Arguments() => "<OnlineID> <Password>";
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
||||||
{
|
{
|
||||||
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
|
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]}'");
|
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await this.database.RemoveUser(user);
|
await this.database.RemoveUser(user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
||||||
{
|
{
|
||||||
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
|
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]}'");
|
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
user.IsAdmin = true;
|
user.IsAdmin = true;
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
||||||
{
|
{
|
||||||
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
|
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]}'");
|
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
string password = args[1];
|
string password = args[1];
|
||||||
if (password.Length != 64) password = HashHelper.Sha256Hash(password);
|
if (password.Length != 64) password = HashHelper.Sha256Hash(password);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.Commands
|
||||||
{
|
{
|
||||||
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
User? user = await this.database.Users.FirstOrDefaultAsync(u => u.Username == args[0]);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
user = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == Convert.ToInt32(args[0]));
|
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]}'");
|
Console.WriteLine($"Could not find user by parameter '{args[0]}'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.database.GameTokens.RemoveRange(this.database.GameTokens.Where(t => t.UserId == user.UserId));
|
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));
|
this.database.WebTokens.RemoveRange(this.database.WebTokens.Where(t => t.UserId == user.UserId));
|
||||||
|
|
|
@ -4,14 +4,14 @@ namespace LBPUnion.ProjectLighthouse.Maintenance
|
||||||
{
|
{
|
||||||
public interface ICommand
|
public interface ICommand
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public string FirstAlias => this.Aliases()[0];
|
||||||
public Task Run(string[] args);
|
public Task Run(string[] args);
|
||||||
|
|
||||||
public string Name();
|
public string Name();
|
||||||
|
|
||||||
public string[] Aliases();
|
public string[] Aliases();
|
||||||
|
|
||||||
public string FirstAlias => this.Aliases()[0];
|
|
||||||
|
|
||||||
public string Arguments();
|
public string Arguments();
|
||||||
|
|
||||||
public int RequiredArgs();
|
public int RequiredArgs();
|
||||||
|
|
|
@ -14,7 +14,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
await foreach (Slot slot in this.database.Slots)
|
await foreach (Slot slot in this.database.Slots)
|
||||||
{
|
|
||||||
if (slot.MinimumPlayers == 0 || slot.MaximumPlayers == 0)
|
if (slot.MinimumPlayers == 0 || slot.MaximumPlayers == 0)
|
||||||
{
|
{
|
||||||
slot.MinimumPlayers = 1;
|
slot.MinimumPlayers = 1;
|
||||||
|
@ -23,7 +22,6 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
Console.WriteLine($"Fixed slotId {slot.SlotId}");
|
Console.WriteLine($"Fixed slotId {slot.SlotId}");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,10 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class AdminPanelPage : BaseLayout
|
public class AdminPanelPage : BaseLayout
|
||||||
{
|
{
|
||||||
public AdminPanelPage(Database database) : base(database)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public List<ICommand> Commands = MaintenanceHelper.Commands;
|
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)
|
public async Task<IActionResult> OnGet([FromQuery] string? args, [FromQuery] string? command, [FromQuery] string? maintenanceJob)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,10 +11,10 @@ namespace LBPUnion.ProjectLighthouse.Pages.ExternalAuth
|
||||||
{
|
{
|
||||||
public class AuthenticationPage : BaseLayout
|
public class AuthenticationPage : BaseLayout
|
||||||
{
|
{
|
||||||
public AuthenticationPage(Database database) : base(database)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
public List<AuthenticationAttempt> AuthenticationAttempts;
|
public List<AuthenticationAttempt> AuthenticationAttempts;
|
||||||
|
public AuthenticationPage(Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet()
|
public async Task<IActionResult> OnGet()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,11 +13,11 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class LandingPage : BaseLayout
|
public class LandingPage : BaseLayout
|
||||||
{
|
{
|
||||||
public LandingPage(Database database) : base(database)
|
public List<User> PlayersOnline;
|
||||||
{}
|
|
||||||
|
|
||||||
public int PlayersOnlineCount;
|
public int PlayersOnlineCount;
|
||||||
public List<User> PlayersOnline;
|
public LandingPage(Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public async Task<IActionResult> OnGet()
|
public async Task<IActionResult> OnGet()
|
||||||
|
|
|
@ -9,25 +9,6 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
|
||||||
{
|
{
|
||||||
public readonly Database Database;
|
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()
|
public readonly List<PageNavigationItem> NavigationItems = new()
|
||||||
{
|
{
|
||||||
new PageNavigationItem("Home", "/", "home"),
|
new PageNavigationItem("Home", "/", "home"),
|
||||||
|
@ -35,8 +16,26 @@ namespace LBPUnion.ProjectLighthouse.Pages.Layouts
|
||||||
new PageNavigationItem("Levels", "/slots/0", "certificate"),
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,14 +16,14 @@
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@if (!string.IsNullOrWhiteSpace(Model.Error))
|
@if (!string.IsNullOrWhiteSpace(Model.Error))
|
||||||
{
|
{
|
||||||
<div class="ui negative message">
|
<div class="ui negative message">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
Uh oh!
|
Uh oh!
|
||||||
</div>
|
</div>
|
||||||
<p>@Model.Error</p>
|
<p>@Model.Error</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
public class LoginForm : BaseLayout
|
public class LoginForm : BaseLayout
|
||||||
{
|
{
|
||||||
public LoginForm(Database database) : base(database)
|
public LoginForm(Database database) : base(database)
|
||||||
{ }
|
{}
|
||||||
|
|
||||||
public string Error { get; private set; }
|
public string Error { get; private set; }
|
||||||
|
|
||||||
|
@ -40,8 +40,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!BCrypt.Net.BCrypt.Verify(password,
|
if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
|
||||||
user.Password))
|
|
||||||
{
|
{
|
||||||
this.Error = "The username or password you entered is invalid.";
|
this.Error = "The username or password you entered is invalid.";
|
||||||
return this.Page();
|
return this.Page();
|
||||||
|
@ -56,19 +55,17 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
this.Database.WebTokens.Add(webToken);
|
this.Database.WebTokens.Add(webToken);
|
||||||
await this.Database.SaveChangesAsync();
|
await this.Database.SaveChangesAsync();
|
||||||
|
|
||||||
this.Response.Cookies.Append("LighthouseToken",
|
this.Response.Cookies.Append("LighthouseToken", webToken.UserToken);
|
||||||
webToken.UserToken);
|
|
||||||
|
|
||||||
if (user.PasswordResetRequired) return this.Redirect("~/passwordResetRequired");
|
if (user.PasswordResetRequired) return this.Redirect("~/passwordResetRequired");
|
||||||
|
|
||||||
return this.RedirectToPage(nameof(LandingPage));
|
return this.RedirectToPage(nameof(LandingPage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public async Task<IActionResult> OnGet()
|
public async Task<IActionResult> OnGet()
|
||||||
{
|
{
|
||||||
Error = string.Empty;
|
this.Error = string.Empty;
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@if (!string.IsNullOrWhiteSpace(Model.Error))
|
@if (!string.IsNullOrWhiteSpace(Model.Error))
|
||||||
{
|
{
|
||||||
<div class="ui negative message">
|
<div class="ui negative message">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
Uh oh!
|
Uh oh!
|
||||||
</div>
|
</div>
|
||||||
<p>@Model.Error</p>
|
<p>@Model.Error</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
public PasswordResetPage(Database database) : base(database)
|
public PasswordResetPage(Database database) : base(database)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
public string Error { get; private set; }
|
public string Error { get; private set; }
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
|
@ -47,6 +46,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class PhotosPage : BaseLayout
|
public class PhotosPage : BaseLayout
|
||||||
{
|
{
|
||||||
public PhotosPage([NotNull] Database database) : base(database)
|
|
||||||
{}
|
public int PageNumber;
|
||||||
|
|
||||||
public int PhotoCount;
|
public int PhotoCount;
|
||||||
|
|
||||||
public List<Photo> Photos;
|
public List<Photo> Photos;
|
||||||
|
public PhotosPage([NotNull] Database database) : base(database)
|
||||||
public int PageNumber;
|
{}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<div class="ui negative message">
|
<div class="ui negative message">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
Uh oh!
|
Uh oh!
|
||||||
</div>
|
</div>
|
||||||
<p>@Model.Error</p>
|
<p>@Model.Error</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,12 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public RegisterForm(Database database) : base(database)
|
public RegisterForm(Database database) : base(database)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public string Error { get; private set; }
|
public string Error { get; private set; }
|
||||||
public bool WasRegisterRequest { get; private set; }
|
public bool WasRegisterRequest { get; private set; }
|
||||||
|
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
[SuppressMessage("ReSharper",
|
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
|
||||||
"SpecifyStringComparison")]
|
|
||||||
public async Task<IActionResult> OnPost(string username, string password, string confirmPassword)
|
public async Task<IActionResult> OnPost(string username, string password, string confirmPassword)
|
||||||
{
|
{
|
||||||
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
|
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
|
||||||
|
@ -43,16 +42,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool userExists =
|
bool userExists = await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null;
|
||||||
await this.Database.Users.FirstOrDefaultAsync(u => u.Username.ToLower() == username.ToLower()) != null;
|
|
||||||
if (userExists)
|
if (userExists)
|
||||||
{
|
{
|
||||||
this.Error = "The username you've chosen is already taken.";
|
this.Error = "The username you've chosen is already taken.";
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = await this.Database.CreateUser(username,
|
User user = await this.Database.CreateUser(username, HashHelper.BCryptHash(password));
|
||||||
HashHelper.BCryptHash(password));
|
|
||||||
|
|
||||||
WebToken webToken = new()
|
WebToken webToken = new()
|
||||||
{
|
{
|
||||||
|
@ -63,8 +60,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
this.Database.WebTokens.Add(webToken);
|
this.Database.WebTokens.Add(webToken);
|
||||||
await this.Database.SaveChangesAsync();
|
await this.Database.SaveChangesAsync();
|
||||||
|
|
||||||
this.Response.Cookies.Append("LighthouseToken",
|
this.Response.Cookies.Append("LighthouseToken", webToken.UserToken);
|
||||||
webToken.UserToken);
|
|
||||||
|
|
||||||
return this.RedirectToPage(nameof(LandingPage));
|
return this.RedirectToPage(nameof(LandingPage));
|
||||||
}
|
}
|
||||||
|
@ -73,7 +69,7 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
|
[SuppressMessage("ReSharper", "SpecifyStringComparison")]
|
||||||
public IActionResult OnGet()
|
public IActionResult OnGet()
|
||||||
{
|
{
|
||||||
Error = string.Empty;
|
this.Error = string.Empty;
|
||||||
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
|
if (!ServerSettings.Instance.RegistrationEnabled) return this.NotFound();
|
||||||
|
|
||||||
return this.Page();
|
return this.Page();
|
||||||
|
|
|
@ -10,10 +10,10 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class SlotPage : BaseLayout
|
public class SlotPage : BaseLayout
|
||||||
{
|
{
|
||||||
public SlotPage([NotNull] Database database) : base(database)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public Slot Slot;
|
public Slot Slot;
|
||||||
|
public SlotPage([NotNull] Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int id)
|
public async Task<IActionResult> OnGet([FromRoute] int id)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,14 +13,14 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class SlotsPage : BaseLayout
|
public class SlotsPage : BaseLayout
|
||||||
{
|
{
|
||||||
public SlotsPage([NotNull] Database database) : base(database)
|
|
||||||
{}
|
public int PageNumber;
|
||||||
|
|
||||||
public int SlotCount;
|
public int SlotCount;
|
||||||
|
|
||||||
public List<Slot> Slots;
|
public List<Slot> Slots;
|
||||||
|
public SlotsPage([NotNull] Database database) : base(database)
|
||||||
public int PageNumber;
|
{}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
public async Task<IActionResult> OnGet([FromRoute] int pageNumber)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,16 +12,16 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
{
|
{
|
||||||
public class UserPage : BaseLayout
|
public class UserPage : BaseLayout
|
||||||
{
|
{
|
||||||
public UserPage(Database database) : base(database)
|
|
||||||
{}
|
|
||||||
|
|
||||||
public User? ProfileUser;
|
|
||||||
|
|
||||||
public List<Photo>? Photos;
|
|
||||||
public List<Comment>? Comments;
|
public List<Comment>? Comments;
|
||||||
|
|
||||||
public bool IsProfileUserHearted;
|
public bool IsProfileUserHearted;
|
||||||
|
|
||||||
|
public List<Photo>? Photos;
|
||||||
|
|
||||||
|
public User? ProfileUser;
|
||||||
|
public UserPage(Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int userId)
|
public async Task<IActionResult> OnGet([FromRoute] int userId)
|
||||||
{
|
{
|
||||||
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
|
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
|
||||||
|
@ -37,12 +37,9 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if (this.User != null)
|
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;
|
null;
|
||||||
}
|
|
||||||
|
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,7 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
if (args.Length != 0 && args[0] == "--wait-for-debugger")
|
if (args.Length != 0 && args[0] == "--wait-for-debugger")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Waiting for a debugger to be attached...");
|
Console.WriteLine("Waiting for a debugger to be attached...");
|
||||||
while (!Debugger.IsAttached)
|
while (!Debugger.IsAttached) Thread.Sleep(100);
|
||||||
{
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
Console.WriteLine("Debugger attached.");
|
Console.WriteLine("Debugger attached.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,38 +8,38 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2"/>
|
||||||
<PackageReference Include="InfluxDB.Client" Version="3.2.0" />
|
<PackageReference Include="InfluxDB.Client" Version="3.2.0"/>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
|
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0"/>
|
||||||
<PackageReference Include="Kettu" Version="1.2.1" />
|
<PackageReference Include="Kettu" Version="1.2.1"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="gitVersion.txt" />
|
<None Remove="gitVersion.txt"/>
|
||||||
<EmbeddedResource Include="gitVersion.txt">
|
<EmbeddedResource Include="gitVersion.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<None Remove="gitBranch.txt" />
|
<None Remove="gitBranch.txt"/>
|
||||||
<EmbeddedResource Include="gitBranch.txt">
|
<EmbeddedResource Include="gitBranch.txt">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<_ContentIncludedByDefault Remove="Pages\Admin\Index.cshtml" />
|
<_ContentIncludedByDefault Remove="Pages\Admin\Index.cshtml"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt"" />
|
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
||||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt"" />
|
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -148,10 +148,8 @@ namespace LBPUnion.ProjectLighthouse
|
||||||
GameToken? gameToken = await database.GameTokenFromRequest(context.Request);
|
GameToken? gameToken = await database.GameTokenFromRequest(context.Request);
|
||||||
|
|
||||||
if (gameToken != null && gameToken.GameVersion == GameVersion.LittleBigPlanet1)
|
if (gameToken != null && gameToken.GameVersion == GameVersion.LittleBigPlanet1)
|
||||||
{
|
|
||||||
// Ignore UserFromGameToken null because user must exist for a token to exist
|
// Ignore UserFromGameToken null because user must exist for a token to exist
|
||||||
await LastContactHelper.SetLastContact((await database.UserFromGameToken(gameToken))!, GameVersion.LittleBigPlanet1);
|
await LastContactHelper.SetLastContact((await database.UserFromGameToken(gameToken))!, GameVersion.LittleBigPlanet1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,12 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
{
|
{
|
||||||
[XmlEnum(Name = "none")]
|
[XmlEnum(Name = "none")]
|
||||||
None,
|
None,
|
||||||
|
|
||||||
[XmlEnum(Name = "moderator")]
|
[XmlEnum(Name = "moderator")]
|
||||||
Moderator,
|
Moderator,
|
||||||
|
|
||||||
[XmlEnum(Name = "level_author")]
|
[XmlEnum(Name = "level_author")]
|
||||||
LevelAuthor
|
LevelAuthor,
|
||||||
// TODO: deletion types for comments (profile etc)
|
// TODO: deletion types for comments (profile etc)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,8 +41,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlElement("resource")]
|
[XmlElement("resource")]
|
||||||
public string[] Resources
|
public string[] Resources {
|
||||||
{
|
|
||||||
get => this.ResourceCollection.Split(",");
|
get => this.ResourceCollection.Split(",");
|
||||||
set => this.ResourceCollection = string.Join(',', value);
|
set => this.ResourceCollection = string.Join(',', value);
|
||||||
}
|
}
|
||||||
|
@ -104,10 +103,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int Hearts
|
public int Hearts {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.HeartedLevels.Count(s => s.SlotId == this.SlotId);
|
return database.HeartedLevels.Count(s => s.SlotId == this.SlotId);
|
||||||
|
@ -164,10 +161,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlElement("thumbsup")]
|
[XmlElement("thumbsup")]
|
||||||
public int Thumbsup
|
public int Thumbsup {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1);
|
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == 1);
|
||||||
|
@ -176,10 +171,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlElement("thumbsdown")]
|
[XmlElement("thumbsdown")]
|
||||||
public int Thumbsdown
|
public int Thumbsdown {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1);
|
return database.RatedLevels.Count(r => r.SlotId == this.SlotId && r.Rating == -1);
|
||||||
|
@ -188,10 +181,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlElement("averageRating")]
|
[XmlElement("averageRating")]
|
||||||
public double RatingLBP1
|
public double RatingLBP1 {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
IQueryable<RatedLevel> ratedLevels = database.RatedLevels.Where(r => r.SlotId == this.SlotId && r.RatingLBP1 > 0);
|
IQueryable<RatedLevel> ratedLevels = database.RatedLevels.Where(r => r.SlotId == this.SlotId && r.RatingLBP1 > 0);
|
||||||
|
@ -203,10 +194,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlElement("reviewCount")]
|
[XmlElement("reviewCount")]
|
||||||
public int ReviewCount
|
public int ReviewCount {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.Reviews.Count(r => r.SlotId == this.SlotId);
|
return database.Reviews.Count(r => r.SlotId == this.SlotId);
|
||||||
|
|
|
@ -8,6 +8,17 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
||||||
public class CreateRoom : IMatchData
|
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":""]]
|
//[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; }
|
public List<string> Players { get; set; }
|
||||||
|
|
||||||
|
@ -25,17 +36,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
public RoomSlot RoomSlot
|
public RoomSlot RoomSlot
|
||||||
=> new()
|
=> new()
|
||||||
{
|
{
|
||||||
SlotType = (SlotType)Slots[0][0],
|
SlotType = (SlotType)this.Slots[0][0],
|
||||||
SlotId = Slots[0][1],
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -8,6 +8,15 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
|
||||||
public class FindBestRoom : IMatchData
|
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> Players { get; set; }
|
||||||
|
|
||||||
public List<string> Reservations { get; set; }
|
public List<string> Reservations { get; set; }
|
||||||
|
@ -15,14 +24,5 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IEnumerable<int> FirstSlot => this.Slots[0];
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
public string PlayerId => User.Username;
|
public string PlayerId => this.User.Username;
|
||||||
|
|
||||||
[JsonPropertyName("matching_res")]
|
[JsonPropertyName("matching_res")]
|
||||||
public int MatchingRes { get; set; }
|
public int MatchingRes { get; set; }
|
||||||
|
|
|
@ -6,13 +6,13 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public class Room
|
public class Room
|
||||||
{
|
{
|
||||||
public int RoomId;
|
|
||||||
|
|
||||||
public List<User> Players;
|
public List<User> Players;
|
||||||
public RoomState State;
|
public int RoomId;
|
||||||
public RoomSlot Slot;
|
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 bool IsLookingForPlayers => this.State == RoomState.DivingIntoLevel || this.State == RoomState.DivingInWaiting;
|
||||||
|
|
||||||
public User Host => this.Players[0];
|
public User Host => this.Players[0];
|
||||||
|
@ -20,7 +20,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
#nullable enable
|
#nullable enable
|
||||||
public override bool Equals(object? obj)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
{
|
{
|
||||||
public class RoomSlot
|
public class RoomSlot
|
||||||
{
|
{
|
||||||
public SlotType SlotType;
|
|
||||||
public int SlotId;
|
public int SlotId;
|
||||||
|
public SlotType SlotType;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,27 +6,27 @@ namespace LBPUnion.ProjectLighthouse.Types.Match
|
||||||
public enum RoomState
|
public enum RoomState
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The room isn't doing anything in particular.
|
/// The room isn't doing anything in particular.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Idle = 0,
|
Idle = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The room is looking to join an existing room playing a specific slot.
|
/// The room is looking to join an existing room playing a specific slot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DivingIntoLevel = 1,
|
DivingIntoLevel = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ???
|
/// ???
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Unknown = 2,
|
Unknown = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The room is looking for other rooms to join.
|
/// The room is looking for other rooms to join.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DivingIn = 3,
|
DivingIn = 3,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The room is waiting for players to join their room.
|
/// The room is waiting for players to join their room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DivingInWaiting = 4,
|
DivingInWaiting = 4,
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,15 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
[XmlType("photo")]
|
[XmlType("photo")]
|
||||||
public class Photo
|
public class Photo
|
||||||
{
|
{
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
private List<PhotoSubject>? _subjects;
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
[XmlArray("subjects")]
|
||||||
|
[XmlArrayItem("subject")]
|
||||||
|
public List<PhotoSubject>? SubjectsXmlDontUseLiterallyEver;
|
||||||
|
|
||||||
[Key]
|
[Key]
|
||||||
public int PhotoId { get; set; }
|
public int PhotoId { get; set; }
|
||||||
|
|
||||||
|
@ -33,14 +42,6 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
[XmlElement("plan")]
|
[XmlElement("plan")]
|
||||||
public string PlanHash { get; set; } = "";
|
public string PlanHash { get; set; } = "";
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
private List<PhotoSubject>? _subjects;
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
[XmlArray("subjects")]
|
|
||||||
[XmlArrayItem("subject")]
|
|
||||||
public List<PhotoSubject>? SubjectsXmlDontUseLiterallyEver;
|
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public List<PhotoSubject> Subjects {
|
public List<PhotoSubject> Subjects {
|
||||||
get {
|
get {
|
||||||
|
@ -94,7 +95,7 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
LbpSerializer.StringElement("subjects", subjectsAggregate) +
|
LbpSerializer.StringElement("subjects", subjectsAggregate) +
|
||||||
slot;
|
slot;
|
||||||
|
|
||||||
return LbpSerializer.TaggedStringElement("photo", photo, "timestamp", Timestamp * 1000);
|
return LbpSerializer.TaggedStringElement("photo", photo, "timestamp", this.Timestamp * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,9 +31,9 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
|
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
string response = LbpSerializer.StringElement("npHandle", User.Username) +
|
string response = LbpSerializer.StringElement("npHandle", this.User.Username) +
|
||||||
LbpSerializer.StringElement("displayName", User.Username) +
|
LbpSerializer.StringElement("displayName", this.User.Username) +
|
||||||
LbpSerializer.StringElement("bounds", Bounds);
|
LbpSerializer.StringElement("bounds", this.Bounds);
|
||||||
|
|
||||||
return LbpSerializer.StringElement("subject", response);
|
return LbpSerializer.StringElement("subject", response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using System.IO;
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Reviews
|
namespace LBPUnion.ProjectLighthouse.Types.Reviews
|
||||||
{
|
{
|
||||||
|
@ -38,14 +37,13 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public string[] Labels
|
public string[] Labels {
|
||||||
{
|
|
||||||
get => this.LabelCollection.Split(",");
|
get => this.LabelCollection.Split(",");
|
||||||
set => this.LabelCollection = string.Join(',', value);
|
set => this.LabelCollection = string.Join(',', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[XmlElement("deleted")]
|
[XmlElement("deleted")]
|
||||||
public Boolean Deleted { get; set; }
|
public bool Deleted { get; set; }
|
||||||
|
|
||||||
[XmlElement("deleted_by")]
|
[XmlElement("deleted_by")]
|
||||||
public DeletedBy DeletedBy { get; set; }
|
public DeletedBy DeletedBy { get; set; }
|
||||||
|
@ -58,26 +56,23 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
|
||||||
|
|
||||||
[XmlElement("thumbsup")]
|
[XmlElement("thumbsup")]
|
||||||
public int ThumbsUp { get; set; }
|
public int ThumbsUp { get; set; }
|
||||||
|
|
||||||
[XmlElement("thumbsdown")]
|
[XmlElement("thumbsdown")]
|
||||||
public int ThumbsDown { get; set; }
|
public int ThumbsDown { get; set; }
|
||||||
|
|
||||||
public string Serialize(RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
|
public string Serialize
|
||||||
{
|
(RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
|
||||||
return this.Serialize("review", yourLevelRating, yourRatingStats);
|
=> this.Serialize("review", yourLevelRating, yourRatingStats);
|
||||||
}
|
|
||||||
|
|
||||||
public string Serialize(string elementOverride, RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
|
public string Serialize(string elementOverride, RatedLevel? yourLevelRating = null, RatedReview? yourRatingStats = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
XmlWriterSettings settings = new XmlWriterSettings();
|
XmlWriterSettings settings = new();
|
||||||
settings.OmitXmlDeclaration = true;
|
settings.OmitXmlDeclaration = true;
|
||||||
|
|
||||||
XmlSerializer serializer = new(typeof(DeletedBy));
|
XmlSerializer serializer = new(typeof(DeletedBy));
|
||||||
StringWriter stringWriter = new StringWriter();
|
StringWriter stringWriter = new();
|
||||||
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
|
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings)) serializer.Serialize(xmlWriter, this.DeletedBy);
|
||||||
{
|
|
||||||
serializer.Serialize(xmlWriter, this.DeletedBy);
|
|
||||||
}
|
|
||||||
string deletedBy = stringWriter.ToString();
|
string deletedBy = stringWriter.ToString();
|
||||||
|
|
||||||
string reviewData = LbpSerializer.TaggedStringElement("slot_id", this.SlotId, "type", this.Slot.Type) +
|
string reviewData = LbpSerializer.TaggedStringElement("slot_id", this.SlotId, "type", this.Slot.Type) +
|
||||||
|
@ -96,5 +91,4 @@ namespace LBPUnion.ProjectLighthouse.Types.Reviews
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,6 +11,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ServerSettings
|
public class ServerSettings
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public const int CurrentConfigVersion = 12; // MUST BE INCREMENTED FOR EVERY CONFIG CHANGE!
|
||||||
static ServerSettings()
|
static ServerSettings()
|
||||||
{
|
{
|
||||||
if (ServerStatics.IsUnitTesting) return; // Unit testing, we don't want to read configurations here since the tests will provide their own
|
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 InfluxEnabled { get; set; }
|
||||||
public bool InfluxLoggingEnabled { get; set; }
|
public bool InfluxLoggingEnabled { get; set; }
|
||||||
public string InfluxOrg { get; set; } = "lighthouse";
|
public string InfluxOrg { get; set; } = "lighthouse";
|
||||||
|
@ -105,8 +93,21 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
|
|
||||||
public int PhotosQuota { get; set; } = 500;
|
public int PhotosQuota { get; set; } = 500;
|
||||||
|
|
||||||
public bool GoogleAnalyticsEnabled { get; set; } = false;
|
public bool GoogleAnalyticsEnabled { get; set; }
|
||||||
|
|
||||||
public string GoogleAnalyticsId { 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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,15 +10,15 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
{
|
{
|
||||||
public const string ServerName = "ProjectLighthouse";
|
public const string ServerName = "ProjectLighthouse";
|
||||||
|
|
||||||
public static bool DbConnected
|
public const int PageSize = 20;
|
||||||
{
|
|
||||||
get
|
public static bool DbConnected {
|
||||||
{
|
get {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new Database().Database.CanConnect();
|
return new Database().Database.CanConnect();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
Logger.Log(e.ToString(), LoggerLevelDatabase.Instance);
|
Logger.Log(e.ToString(), LoggerLevelDatabase.Instance);
|
||||||
return false;
|
return false;
|
||||||
|
@ -27,7 +27,5 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit"));
|
public static bool IsUnitTesting => AppDomain.CurrentDomain.GetAssemblies().Any(assembly => assembly.FullName.StartsWith("xunit"));
|
||||||
|
|
||||||
public const int PageSize = 20;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,40 +26,32 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
public string Biography { get; set; }
|
public string Biography { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int Reviews
|
public int Reviews {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.Reviews.Count(r => r.ReviewerId == this.UserId);
|
return database.Reviews.Count(r => r.ReviewerId == this.UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int Comments
|
public int Comments {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.Comments.Count(c => c.TargetUserId == this.UserId);
|
return database.Comments.Count(c => c.TargetUserId == this.UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int PhotosByMe
|
public int PhotosByMe {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.Photos.Count(p => p.CreatorId == this.UserId);
|
return database.Photos.Count(p => p.CreatorId == this.UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int PhotosWithMe
|
public int PhotosWithMe {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return Enumerable.Sum(database.Photos, photo => photo.Subjects.Count(subject => subject.User.UserId == this.UserId));
|
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; }
|
public Location Location { get; set; }
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int HeartedLevels
|
public int HeartedLevels {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.HeartedLevels.Count(p => p.UserId == this.UserId);
|
return database.HeartedLevels.Count(p => p.UserId == this.UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int HeartedUsers
|
public int HeartedUsers {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.HeartedProfiles.Count(p => p.UserId == this.UserId);
|
return database.HeartedProfiles.Count(p => p.UserId == this.UserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int QueuedLevels
|
public int QueuedLevels {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.QueuedLevels.Count(p => p.UserId == this.UserId);
|
return database.QueuedLevels.Count(p => p.UserId == this.UserId);
|
||||||
}
|
}
|
||||||
|
@ -107,10 +93,8 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
|
|
||||||
public string PlanetHash { get; set; } = "";
|
public string PlanetHash { get; set; } = "";
|
||||||
|
|
||||||
public int Hearts
|
public int Hearts {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
|
|
||||||
return database.HeartedProfiles.Count(s => s.HeartedUserId == this.UserId);
|
return database.HeartedProfiles.Count(s => s.HeartedUserId == this.UserId);
|
||||||
|
@ -125,12 +109,10 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
public string BooHash { get; set; } = "";
|
public string BooHash { get; set; } = "";
|
||||||
public string MehHash { get; set; } = "";
|
public string MehHash { get; set; } = "";
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public string Status
|
public string Status {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
LastContact? lastMatch = database.LastContacts.Where
|
LastContact? lastMatch = database.LastContacts.Where
|
||||||
(l => l.UserId == this.UserId)
|
(l => l.UserId == this.UserId)
|
||||||
|
@ -141,7 +123,7 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
return "Currently online on " + lastMatch.GameVersion.ToPrettyString();
|
return "Currently online on " + lastMatch.GameVersion.ToPrettyString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
||||||
{
|
{
|
||||||
|
@ -165,9 +147,9 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
LbpSerializer.StringElement("planets", this.PlanetHash) +
|
LbpSerializer.StringElement("planets", this.PlanetHash) +
|
||||||
LbpSerializer.BlankElement("photos") +
|
LbpSerializer.BlankElement("photos") +
|
||||||
LbpSerializer.StringElement("heartCount", this.Hearts) +
|
LbpSerializer.StringElement("heartCount", this.Hearts) +
|
||||||
LbpSerializer.StringElement("yay2", YayHash) +
|
LbpSerializer.StringElement("yay2", this.YayHash) +
|
||||||
LbpSerializer.StringElement("boo2", YayHash) +
|
LbpSerializer.StringElement("boo2", this.YayHash) +
|
||||||
LbpSerializer.StringElement("meh2", YayHash);
|
LbpSerializer.StringElement("meh2", this.YayHash);
|
||||||
this.ClientsConnected.Serialize();
|
this.ClientsConnected.Serialize();
|
||||||
|
|
||||||
return LbpSerializer.TaggedStringElement("user", user, "type", "user");
|
return LbpSerializer.TaggedStringElement("user", user, "type", "user");
|
||||||
|
@ -179,10 +161,8 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
/// The number of used slots on the earth
|
/// The number of used slots on the earth
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public int UsedSlots
|
public int UsedSlots {
|
||||||
{
|
get {
|
||||||
get
|
|
||||||
{
|
|
||||||
using Database database = new();
|
using Database database = new();
|
||||||
return database.Slots.Count(s => s.CreatorId == this.UserId);
|
return database.Slots.Count(s => s.CreatorId == this.UserId);
|
||||||
}
|
}
|
||||||
|
@ -243,10 +223,10 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
|
|
||||||
#endregion Slots
|
#endregion Slots
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
public override bool Equals(object? obj)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -263,6 +243,6 @@ namespace LBPUnion.ProjectLighthouse.Types
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
|
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
|
||||||
public override int GetHashCode() => this.UserId;
|
public override int GetHashCode() => this.UserId;
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 Vita | Compatible | Incompatible, marked as "bootable" on Vita3k | N/A |
|
||||||
| LBP PSP | Potentially compatible | Incompatible, PSN not supported on PPSSPP | Potentially Compatible |
|
| 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.
|
While LBP Vita and LBP PSP can be supported, they are not properly seperated from the mainline games at this time. We
|
||||||
We recommend you run seperate instances for these games to avoid problems.
|
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.
|
Project Lighthouse is still a heavy work in progress, so this chart is subject to change at any point.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue