mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-07 19:22:26 +00:00
Combine a bunch of helpers together, shuffle some things around
This commit is contained in:
parent
71a97894ad
commit
330c01317d
61 changed files with 327 additions and 371 deletions
|
@ -1,4 +1,4 @@
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Middlewares;
|
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Servers.API.Startup;
|
namespace LBPUnion.ProjectLighthouse.Servers.API.Startup;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
namespace LBPUnion.ProjectLighthouse.Servers.API;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>
|
/// <para>
|
|
@ -89,7 +89,7 @@ public class LoginController : ControllerBase
|
||||||
{
|
{
|
||||||
GameToken = token,
|
GameToken = token,
|
||||||
GameTokenId = token.TokenId,
|
GameTokenId = token.TokenId,
|
||||||
Timestamp = TimestampHelper.Timestamp,
|
Timestamp = TimeHelper.Timestamp,
|
||||||
IPAddress = ipAddress,
|
IPAddress = ipAddress,
|
||||||
Platform = npTicket.Platform,
|
Platform = npTicket.Platform,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Match;
|
using LBPUnion.ProjectLighthouse.Types.Match;
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class PhotosController : ControllerBase
|
||||||
|
|
||||||
if (photo.Subjects.Count > 4) return this.BadRequest();
|
if (photo.Subjects.Count > 4) return this.BadRequest();
|
||||||
|
|
||||||
if (photo.Timestamp > TimestampHelper.Timestamp) photo.Timestamp = TimestampHelper.Timestamp;
|
if (photo.Timestamp > TimeHelper.Timestamp) photo.Timestamp = TimeHelper.Timestamp;
|
||||||
|
|
||||||
foreach (PhotoSubject subject in photo.Subjects)
|
foreach (PhotoSubject subject in photo.Subjects)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
using System.Buffers;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
@ -75,7 +77,7 @@ public class ResourcesController : ControllerBase
|
||||||
if (FileHelper.ResourceExists(hash)) this.Conflict();
|
if (FileHelper.ResourceExists(hash)) this.Conflict();
|
||||||
|
|
||||||
Logger.LogInfo($"Processing resource upload (hash: {hash})", LogArea.Resources);
|
Logger.LogInfo($"Processing resource upload (hash: {hash})", LogArea.Resources);
|
||||||
LbpFile file = new(await BinaryHelper.ReadFromPipeReader(this.Request.BodyReader));
|
LbpFile file = new(await readFromPipeReader(this.Request.BodyReader));
|
||||||
|
|
||||||
if (!FileHelper.IsFileSafe(file))
|
if (!FileHelper.IsFileSafe(file))
|
||||||
{
|
{
|
||||||
|
@ -95,4 +97,25 @@ public class ResourcesController : ControllerBase
|
||||||
await IOFile.WriteAllBytesAsync(path, file.Data);
|
await IOFile.WriteAllBytesAsync(path, file.Data);
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Written with reference from
|
||||||
|
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/request-response?view=aspnetcore-5.0
|
||||||
|
// Surprisingly doesn't take seconds. (67ms for a 100kb file)
|
||||||
|
private static async Task<byte[]> readFromPipeReader(PipeReader reader)
|
||||||
|
{
|
||||||
|
List<byte> data = new();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
ReadResult readResult = await reader.ReadAsync();
|
||||||
|
ReadOnlySequence<byte> buffer = readResult.Buffer;
|
||||||
|
|
||||||
|
if (readResult.IsCompleted && buffer.Length > 0) data.AddRange(buffer.ToArray());
|
||||||
|
|
||||||
|
reader.AdvanceTo(buffer.Start, buffer.End);
|
||||||
|
|
||||||
|
if (readResult.IsCompleted) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Serialization;
|
using LBPUnion.ProjectLighthouse.Serialization;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Middlewares;
|
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
|
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class ResourcesController : ControllerBase
|
||||||
}
|
}
|
||||||
|
|
||||||
LbpFile? file = LbpFile.FromHash(hash);
|
LbpFile? file = LbpFile.FromHash(hash);
|
||||||
if (file != null && ImageHelper.LbpFileToPNG(file))
|
if (file != null && FileHelper.LbpFileToPNG(file))
|
||||||
{
|
{
|
||||||
return this.File(IOFile.OpenRead(path), "image/png");
|
return this.File(IOFile.OpenRead(path), "image/png");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@page "/admin"
|
@page "/admin"
|
||||||
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers
|
@using LBPUnion.ProjectLighthouse.Helpers
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
|
||||||
@using LBPUnion.ProjectLighthouse.Maintenance
|
@using LBPUnion.ProjectLighthouse.Maintenance
|
||||||
@using LBPUnion.ProjectLighthouse.Types
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.AdminPanelPage
|
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.AdminPanelPage
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class LandingPage : BaseLayout
|
||||||
(a => a.GameToken)
|
(a => a.GameToken)
|
||||||
.CountAsync(a => a.GameToken.UserId == user.UserId);
|
.CountAsync(a => a.GameToken.UserId == user.UserId);
|
||||||
|
|
||||||
List<int> userIds = await this.Database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync();
|
List<int> userIds = await this.Database.LastContacts.Where(l => TimeHelper.Timestamp - l.Timestamp < 300).Select(l => l.UserId).ToListAsync();
|
||||||
|
|
||||||
this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync();
|
this.PlayersOnline = await this.Database.Users.Where(u => userIds.Contains(u.UserId)).ToListAsync();
|
||||||
return this.Page();
|
return this.Page();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers
|
@using LBPUnion.ProjectLighthouse.Helpers
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
|
||||||
@using LBPUnion.ProjectLighthouse.Types
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
@using LBPUnion.ProjectLighthouse.Types.Settings
|
@using LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts.BaseLayout
|
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts.BaseLayout
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
Model.IsMobile = Model.Request.IsMobile();
|
Model.IsMobile = Model.Request.IsMobile();
|
||||||
long timeStarted = TimestampHelper.TimestampMillis;
|
long timeStarted = TimeHelper.TimestampMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -179,7 +179,7 @@
|
||||||
<p>Model.Title: @Model.Title</p>
|
<p>Model.Title: @Model.Title</p>
|
||||||
<p>Model.Description: @Model.Description</p>
|
<p>Model.Description: @Model.Description</p>
|
||||||
<p>Model.User.UserId: @(Model.User?.UserId.ToString() ?? "(not logged in)")</p>
|
<p>Model.User.UserId: @(Model.User?.UserId.ToString() ?? "(not logged in)")</p>
|
||||||
<p>Render time: ~@(TimestampHelper.TimestampMillis - timeStarted)ms</p>
|
<p>Render time: ~@(TimeHelper.TimestampMillis - timeStarted)ms</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@page "/slot/{id:int}"
|
@page "/slot/{id:int}"
|
||||||
@using System.Web
|
@using System.Web
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Types
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
@using LBPUnion.ProjectLighthouse.Types.Reviews
|
@using LBPUnion.ProjectLighthouse.Types.Reviews
|
||||||
@using LBPUnion.ProjectLighthouse.Types.Settings
|
@using LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@page "/slots/{pageNumber:int}"
|
@page "/slots/{pageNumber:int}"
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Types.Levels
|
@using LBPUnion.ProjectLighthouse.Types.Levels
|
||||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.SlotsPage
|
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.SlotsPage
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@page "/user/{userId:int}"
|
@page "/user/{userId:int}"
|
||||||
@using System.Web
|
@using System.Web
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Types
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.UserPage
|
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.UserPage
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@page "/users/{pageNumber:int}"
|
@page "/users/{pageNumber:int}"
|
||||||
@using LBPUnion.ProjectLighthouse.Helpers.Extensions
|
@using LBPUnion.ProjectLighthouse.Extensions
|
||||||
@using LBPUnion.ProjectLighthouse.Types
|
@using LBPUnion.ProjectLighthouse.Types
|
||||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.UsersPage
|
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.UsersPage
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Middlewares;
|
using LBPUnion.ProjectLighthouse.Middlewares;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Startup;
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Startup;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class AuthenticationTests : LighthouseWebTest
|
||||||
await using Database database = new();
|
await using Database database = new();
|
||||||
Random random = new();
|
Random random = new();
|
||||||
|
|
||||||
string password = CryptoHelper.Sha256Hash(RandomHelper.GenerateRandomBytes(64).ToArray());
|
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
|
||||||
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash(CryptoHelper.Sha256Hash(password)));
|
User user = await database.CreateUser($"unitTestUser{random.Next()}", CryptoHelper.BCryptHash(CryptoHelper.Sha256Hash(password)));
|
||||||
|
|
||||||
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/login");
|
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/login");
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class RegisterTests : LighthouseWebTest
|
||||||
await using Database database = new();
|
await using Database database = new();
|
||||||
|
|
||||||
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
||||||
string password = CryptoHelper.Sha256Hash(RandomHelper.GenerateRandomBytes(64).ToArray());
|
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
|
||||||
|
|
||||||
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/register");
|
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/register");
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class RegisterTests : LighthouseWebTest
|
||||||
await using Database database = new();
|
await using Database database = new();
|
||||||
|
|
||||||
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
||||||
string password = CryptoHelper.Sha256Hash(RandomHelper.GenerateRandomBytes(64).ToArray());
|
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
|
||||||
|
|
||||||
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/register");
|
this.Driver.Navigate().GoToUrl(this.BaseAddress + "/register");
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class RegisterTests : LighthouseWebTest
|
||||||
await using Database database = new();
|
await using Database database = new();
|
||||||
|
|
||||||
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
string username = ("unitTestUser" + new Random().Next()).Substring(0, 16);
|
||||||
string password = CryptoHelper.Sha256Hash(RandomHelper.GenerateRandomBytes(64).ToArray());
|
string password = CryptoHelper.Sha256Hash(CryptoHelper.GenerateRandomBytes(64).ToArray());
|
||||||
|
|
||||||
await database.CreateUser(username, CryptoHelper.BCryptHash(password));
|
await database.CreateUser(username, CryptoHelper.BCryptHash(password));
|
||||||
User? user = await database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
User? user = await database.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||||
|
|
|
@ -107,6 +107,8 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCET/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCET/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCJB/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCJB/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCJS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCJS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCKS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=BCUS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Braaains/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Braaains/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=brun/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=brun/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=deflater/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=deflater/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
@ -127,7 +129,14 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mmpicks/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mmpicks/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=npdata/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=npdata/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPEA/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPEA/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPEG/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHA/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHG/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHG/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPHO/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPJA/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPJG/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPUA/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPUG/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPWR/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=NPWR/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCAS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCAS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCJS/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=PCJS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
@ -147,5 +156,8 @@
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unheart/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unheart/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpublish/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpushed/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpushed/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=VCAS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=VCJS/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=VCKS/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourlbp/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourlbp/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=yourthumb/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -1,7 +1,7 @@
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using AspLogLevel = Microsoft.Extensions.Logging.LogLevel;
|
using AspLogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
public static class AspLogLevelExtensions
|
public static class AspLogLevelExtensions
|
||||||
{
|
{
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
public static class BinaryReaderExtensions
|
public static class BinaryReaderExtensions
|
||||||
{
|
{
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
internal static class ConsoleColorExtensions
|
internal static class ConsoleColorExtensions
|
||||||
{
|
{
|
|
@ -4,7 +4,7 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
using LBPUnion.ProjectLighthouse.Types.Reviews;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
public static class DatabaseExtensions
|
public static class DatabaseExtensions
|
||||||
{
|
{
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
// https://stackoverflow.com/a/8039737
|
// https://stackoverflow.com/a/8039737
|
||||||
public static class ExceptionExtensions
|
public static class ExceptionExtensions
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
public static class LogLevelExtensions
|
public static class LogLevelExtensions
|
||||||
{
|
{
|
76
ProjectLighthouse/Extensions/RequestExtensions.cs
Normal file
76
ProjectLighthouse/Extensions/RequestExtensions.cs
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
#nullable enable
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
|
public static class RequestExtensions
|
||||||
|
{
|
||||||
|
// yoinked and adapted from https://stackoverflow.com/a/68641796
|
||||||
|
|
||||||
|
#region Mobile Checking
|
||||||
|
|
||||||
|
private static readonly Regex mobileCheck = new
|
||||||
|
(
|
||||||
|
"Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|PlayStation Vita",
|
||||||
|
RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled
|
||||||
|
);
|
||||||
|
|
||||||
|
public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString());
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Captcha
|
||||||
|
|
||||||
|
private static readonly HttpClient client = new()
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri("https://hcaptcha.com"),
|
||||||
|
};
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")]
|
||||||
|
private static async Task<bool> verifyCaptcha(string token)
|
||||||
|
{
|
||||||
|
if (!ServerConfiguration.Instance.Captcha.CaptchaEnabled) return true;
|
||||||
|
|
||||||
|
List<KeyValuePair<string, string>> payload = new()
|
||||||
|
{
|
||||||
|
new("secret", ServerConfiguration.Instance.Captcha.Secret),
|
||||||
|
new("response", token),
|
||||||
|
};
|
||||||
|
|
||||||
|
HttpResponseMessage response = await client.PostAsync("/siteverify", new FormUrlEncodedContent(payload));
|
||||||
|
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
// We only really care about the success result, nothing else that hcaptcha sends us, so lets only parse that.
|
||||||
|
bool success = bool.Parse(JObject.Parse(responseBody)["success"]?.ToString() ?? "false");
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> CheckCaptchaValidity(this HttpRequest request)
|
||||||
|
{
|
||||||
|
if (ServerConfiguration.Instance.Captcha.CaptchaEnabled)
|
||||||
|
{
|
||||||
|
bool gotCaptcha = request.Form.TryGetValue("h-captcha-response", out StringValues values);
|
||||||
|
if (!gotCaptcha) return false;
|
||||||
|
|
||||||
|
if (!await verifyCaptcha(values[0])) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
namespace LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
public static class StringExtensions
|
public static class StringExtensions
|
||||||
{
|
{
|
|
@ -1,66 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Buffers;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Pipelines;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class BinaryHelper
|
|
||||||
{
|
|
||||||
public static string ReadString(BinaryReader reader)
|
|
||||||
{
|
|
||||||
List<byte> readBytes = new();
|
|
||||||
|
|
||||||
byte readByte;
|
|
||||||
do readBytes.Add(readByte = reader.ReadByte());
|
|
||||||
while (readByte != 0x00);
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString(readBytes.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ReadUntilByte(BinaryReader reader, byte byteToReadTo)
|
|
||||||
{
|
|
||||||
byte readByte;
|
|
||||||
do readByte = reader.ReadByte();
|
|
||||||
while (readByte != byteToReadTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] ReadToEnd(BinaryReader reader) => reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position));
|
|
||||||
|
|
||||||
public static byte[] ReadLastBytes(BinaryReader reader, int count, bool restoreOldPosition = true)
|
|
||||||
{
|
|
||||||
long oldPosition = reader.BaseStream.Position;
|
|
||||||
|
|
||||||
if (reader.BaseStream.Length < count) return Array.Empty<byte>();
|
|
||||||
|
|
||||||
reader.BaseStream.Position = reader.BaseStream.Length - count;
|
|
||||||
byte[] data = reader.ReadBytes(count);
|
|
||||||
|
|
||||||
if (restoreOldPosition) reader.BaseStream.Position = oldPosition;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Written with reference from
|
|
||||||
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/request-response?view=aspnetcore-5.0
|
|
||||||
// Surprisingly doesn't take seconds. (67ms for a 100kb file)
|
|
||||||
public static async Task<byte[]> ReadFromPipeReader(PipeReader reader)
|
|
||||||
{
|
|
||||||
List<byte> data = new();
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
ReadResult readResult = await reader.ReadAsync();
|
|
||||||
ReadOnlySequence<byte> buffer = readResult.Buffer;
|
|
||||||
|
|
||||||
if (readResult.IsCompleted && buffer.Length > 0) data.AddRange(buffer.ToArray());
|
|
||||||
|
|
||||||
reader.AdvanceTo(buffer.Start, buffer.End);
|
|
||||||
|
|
||||||
if (readResult.IsCompleted) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class CaptchaHelper
|
|
||||||
{
|
|
||||||
private static readonly HttpClient client = new()
|
|
||||||
{
|
|
||||||
BaseAddress = new Uri("https://hcaptcha.com"),
|
|
||||||
};
|
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "ArrangeObjectCreationWhenTypeNotEvident")]
|
|
||||||
public static async Task<bool> Verify(string token)
|
|
||||||
{
|
|
||||||
if (!ServerConfiguration.Instance.Captcha.CaptchaEnabled) return true;
|
|
||||||
|
|
||||||
List<KeyValuePair<string, string>> payload = new()
|
|
||||||
{
|
|
||||||
new("secret", ServerConfiguration.Instance.Captcha.Secret),
|
|
||||||
new("response", token),
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpResponseMessage response = await client.PostAsync("/siteverify", new FormUrlEncodedContent(payload));
|
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
|
|
||||||
string responseBody = await response.Content.ReadAsStringAsync();
|
|
||||||
|
|
||||||
// We only really care about the success result, nothing else that hcaptcha sends us, so lets only parse that.
|
|
||||||
bool success = bool.Parse(JObject.Parse(responseBody)["success"]?.ToString() ?? "false");
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ public static class CensorHelper
|
||||||
"UwU", "OwO", "uwu", "owo", "o3o", ">.>", "*pounces on you*", "*boops*", "*baps*", ":P", "x3", "O_O", "xD", ":3", ";3", "^w^",
|
"UwU", "OwO", "uwu", "owo", "o3o", ">.>", "*pounces on you*", "*boops*", "*baps*", ":P", "x3", "O_O", "xD", ":3", ";3", "^w^",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly string[] censorList = ResourceHelper.readManifestFile("chatCensoredList.txt").Replace("\r", "").Split("\n");
|
private static readonly string[] censorList = ResourceHelper.ReadManifestFile("chatCensoredList.txt").Replace("\r", "").Split("\n");
|
||||||
|
|
||||||
public static string ScanMessage(string message)
|
public static string ScanMessage(string message)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ public static class CensorHelper
|
||||||
{
|
{
|
||||||
case FilterMode.Random:
|
case FilterMode.Random:
|
||||||
for(int i = 0; i < profanityLength; i++)
|
for(int i = 0; i < profanityLength; i++)
|
||||||
lock(RandomHelper.Random)
|
lock(CryptoHelper.Random)
|
||||||
{
|
{
|
||||||
if (message[i] == ' ')
|
if (message[i] == ' ')
|
||||||
{
|
{
|
||||||
|
@ -56,8 +56,8 @@ public static class CensorHelper
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char randomChar = randomCharacters[RandomHelper.Random.Next(0, randomCharacters.Length - 1)];
|
char randomChar = randomCharacters[CryptoHelper.Random.Next(0, randomCharacters.Length - 1)];
|
||||||
if (randomChar == prevRandomChar) randomChar = randomCharacters[RandomHelper.Random.Next(0, randomCharacters.Length - 1)];
|
if (randomChar == prevRandomChar) randomChar = randomCharacters[CryptoHelper.Random.Next(0, randomCharacters.Length - 1)];
|
||||||
|
|
||||||
prevRandomChar = randomChar;
|
prevRandomChar = randomChar;
|
||||||
|
|
||||||
|
@ -81,9 +81,9 @@ public static class CensorHelper
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case FilterMode.Furry:
|
case FilterMode.Furry:
|
||||||
lock(RandomHelper.Random)
|
lock(CryptoHelper.Random)
|
||||||
{
|
{
|
||||||
string randomWord = randomFurry[RandomHelper.Random.Next(0, randomFurry.Length - 1)];
|
string randomWord = randomFurry[CryptoHelper.Random.Next(0, randomFurry.Length - 1)];
|
||||||
sb.Append(randomWord);
|
sb.Append(randomWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
@ -10,6 +11,11 @@ namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||||
public static class CryptoHelper
|
public static class CryptoHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// An instance of Random. Must be locked when in use.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly Random Random = new();
|
||||||
|
|
||||||
// private static readonly SHA1 sha1 = SHA1.Create();
|
// private static readonly SHA1 sha1 = SHA1.Create();
|
||||||
private static readonly SHA256 sha256 = SHA256.Create();
|
private static readonly SHA256 sha256 = SHA256.Create();
|
||||||
|
|
||||||
|
@ -19,7 +25,7 @@ public static class CryptoHelper
|
||||||
/// <returns>The token as a string.</returns>
|
/// <returns>The token as a string.</returns>
|
||||||
public static string GenerateAuthToken()
|
public static string GenerateAuthToken()
|
||||||
{
|
{
|
||||||
byte[] bytes = (byte[])RandomHelper.GenerateRandomBytes(256);
|
byte[] bytes = (byte[])GenerateRandomBytes(256);
|
||||||
|
|
||||||
return BCryptHash(Sha256Hash(bytes));
|
return BCryptHash(Sha256Hash(bytes));
|
||||||
}
|
}
|
||||||
|
@ -48,6 +54,23 @@ public static class CryptoHelper
|
||||||
return digestString;
|
return digestString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates a specified amount of random bytes in an array.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count">The amount of bytes to generate.</param>
|
||||||
|
/// <returns>The bytes generated</returns>
|
||||||
|
public static IEnumerable<byte> GenerateRandomBytes(int count)
|
||||||
|
{
|
||||||
|
byte[] b = new byte[count];
|
||||||
|
|
||||||
|
lock(Random)
|
||||||
|
{
|
||||||
|
Random.NextBytes(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
#region Hash Functions
|
#region Hash Functions
|
||||||
|
|
||||||
public static string Sha256Hash(string str) => Sha256Hash(Encoding.UTF8.GetBytes(str));
|
public static string Sha256Hash(string str) => Sha256Hash(Encoding.UTF8.GetBytes(str));
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
#nullable enable
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.Extensions.Primitives;
|
|
||||||
using Microsoft.Net.Http.Headers;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
|
|
||||||
public static class RequestExtensions
|
|
||||||
{
|
|
||||||
// yoinked and adapted from https://stackoverflow.com/a/68641796
|
|
||||||
|
|
||||||
#region Mobile Checking
|
|
||||||
|
|
||||||
private static readonly Regex mobileCheck = new
|
|
||||||
(
|
|
||||||
"Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|PlayStation Vita",
|
|
||||||
RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled
|
|
||||||
);
|
|
||||||
|
|
||||||
public static bool IsMobile(this HttpRequest request) => mobileCheck.IsMatch(request.Headers[HeaderNames.UserAgent].ToString());
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public static async Task<bool> CheckCaptchaValidity(this HttpRequest request)
|
|
||||||
{
|
|
||||||
if (ServerConfiguration.Instance.Captcha.CaptchaEnabled)
|
|
||||||
{
|
|
||||||
bool gotCaptcha = request.Form.TryGetValue("h-captcha-response", out StringValues values);
|
|
||||||
if (!gotCaptcha) return false;
|
|
||||||
|
|
||||||
if (!await CaptchaHelper.Verify(values[0])) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,9 +6,14 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using DDSReader;
|
||||||
|
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Files;
|
using LBPUnion.ProjectLighthouse.Types.Files;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ public static class FileHelper
|
||||||
// Determine if file is a FARC (File Archive).
|
// Determine if file is a FARC (File Archive).
|
||||||
// Needs to be done before anything else that determines the type by the header
|
// Needs to be done before anything else that determines the type by the header
|
||||||
// because this determines the type by the footer.
|
// because this determines the type by the footer.
|
||||||
string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4));
|
string footer = Encoding.ASCII.GetString(readLastBytes(reader, 4));
|
||||||
if (footer == "FARC") return LbpFileType.FileArchive;
|
if (footer == "FARC") return LbpFileType.FileArchive;
|
||||||
|
|
||||||
byte[] header = reader.ReadBytes(3);
|
byte[] header = reader.ReadBytes(3);
|
||||||
|
@ -75,6 +80,19 @@ public static class FileHelper
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] readLastBytes(BinaryReader reader, int count, bool restoreOldPosition = true)
|
||||||
|
{
|
||||||
|
long oldPosition = reader.BaseStream.Position;
|
||||||
|
|
||||||
|
if (reader.BaseStream.Length < count) return Array.Empty<byte>();
|
||||||
|
|
||||||
|
reader.BaseStream.Position = reader.BaseStream.Length - count;
|
||||||
|
byte[] data = reader.ReadBytes(count);
|
||||||
|
|
||||||
|
if (restoreOldPosition) reader.BaseStream.Position = oldPosition;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
private static LbpFileType readAlternateHeader(BinaryReader reader)
|
private static LbpFileType readAlternateHeader(BinaryReader reader)
|
||||||
{
|
{
|
||||||
reader.BaseStream.Position = 0;
|
reader.BaseStream.Position = 0;
|
||||||
|
@ -133,7 +151,7 @@ public static class FileHelper
|
||||||
|
|
||||||
if (file.FileType == LbpFileType.Jpeg || file.FileType == LbpFileType.Png || file.FileType == LbpFileType.Texture)
|
if (file.FileType == LbpFileType.Jpeg || file.FileType == LbpFileType.Png || file.FileType == LbpFileType.Texture)
|
||||||
{
|
{
|
||||||
ImageHelper.LbpFileToPNG(file);
|
LbpFileToPNG(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,4 +165,111 @@ public static class FileHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Images
|
||||||
|
|
||||||
|
public static bool LbpFileToPNG(LbpFile file) => LbpFileToPNG(file.Data, file.Hash, file.FileType);
|
||||||
|
|
||||||
|
public static bool LbpFileToPNG(byte[] data, string hash, LbpFileType type)
|
||||||
|
{
|
||||||
|
if (type != LbpFileType.Jpeg && type != LbpFileType.Png && type != LbpFileType.Texture) return false;
|
||||||
|
|
||||||
|
if (File.Exists(Path.Combine("png", $"{hash}.png"))) return true;
|
||||||
|
|
||||||
|
using MemoryStream ms = new(data);
|
||||||
|
using BinaryReader reader = new(ms);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
LbpFileType.Texture => TextureToPNG(hash, reader),
|
||||||
|
LbpFileType.Png => PNGToPNG(hash, data),
|
||||||
|
LbpFileType.Jpeg => JPGToPNG(hash, data),
|
||||||
|
// ReSharper disable once UnreachableSwitchArmDueToIntegerAnalysis
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error while converting {hash}:");
|
||||||
|
Console.WriteLine(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TextureToPNG(string hash, BinaryReader reader)
|
||||||
|
{
|
||||||
|
// Skip the magic (3 bytes), we already know its a texture
|
||||||
|
for(int i = 0; i < 3; i++) reader.ReadByte();
|
||||||
|
|
||||||
|
// This below is shamelessly stolen from ennuo's Toolkit: https://github.com/ennuo/toolkit/blob/d996ee4134740db0ee94e2cbf1e4edbd1b5ec798/src/main/java/ennuo/craftworld/utilities/Compressor.java#L40
|
||||||
|
|
||||||
|
// This byte determines the method of reading. We can only read a texture (' ') so if it's not ' ' it must be invalid.
|
||||||
|
if ((char)reader.ReadByte() != ' ') return false;
|
||||||
|
|
||||||
|
reader.ReadInt16(); // ?
|
||||||
|
short chunks = reader.ReadInt16BE();
|
||||||
|
|
||||||
|
int[] compressed = new int[chunks];
|
||||||
|
int[] decompressed = new int[chunks];
|
||||||
|
|
||||||
|
for(int i = 0; i < chunks; ++i)
|
||||||
|
{
|
||||||
|
compressed[i] = reader.ReadUInt16BE();
|
||||||
|
decompressed[i] = reader.ReadUInt16BE();
|
||||||
|
}
|
||||||
|
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
using BinaryWriter writer = new(ms);
|
||||||
|
for(int i = 0; i < chunks; ++i)
|
||||||
|
{
|
||||||
|
byte[] deflatedData = reader.ReadBytes(compressed[i]);
|
||||||
|
if (compressed[i] == decompressed[i])
|
||||||
|
{
|
||||||
|
writer.Write(deflatedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
Inflater inflater = new();
|
||||||
|
inflater.SetInput(deflatedData);
|
||||||
|
byte[] inflatedData = new byte[decompressed[i]];
|
||||||
|
inflater.Inflate(inflatedData);
|
||||||
|
|
||||||
|
writer.Write(inflatedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DDSToPNG(hash, ms.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool DDSToPNG(string hash, byte[] data)
|
||||||
|
{
|
||||||
|
using MemoryStream stream = new();
|
||||||
|
DDSImage image = new(data);
|
||||||
|
|
||||||
|
image.SaveAsPng(stream);
|
||||||
|
|
||||||
|
Directory.CreateDirectory("png");
|
||||||
|
File.WriteAllBytes($"png/{hash}.png", stream.ToArray());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool JPGToPNG(string hash, byte[] data)
|
||||||
|
{
|
||||||
|
using Image<Rgba32> image = Image.Load(data);
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
image.SaveAsPng(ms);
|
||||||
|
|
||||||
|
File.WriteAllBytes($"png/{hash}.png", ms.ToArray());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// it sounds dumb i know but hear me out:
|
||||||
|
// you're completely correct
|
||||||
|
private static bool PNGToPNG(string hash, byte[] data)
|
||||||
|
{
|
||||||
|
File.WriteAllBytes($"png/{hash}.png", data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,117 +0,0 @@
|
||||||
#nullable enable
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using DDSReader;
|
|
||||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Types.Files;
|
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class ImageHelper
|
|
||||||
{
|
|
||||||
public static bool LbpFileToPNG(LbpFile file) => LbpFileToPNG(file.Data, file.Hash, file.FileType);
|
|
||||||
|
|
||||||
public static bool LbpFileToPNG(byte[] data, string hash, LbpFileType type)
|
|
||||||
{
|
|
||||||
if (type != LbpFileType.Jpeg && type != LbpFileType.Png && type != LbpFileType.Texture) return false;
|
|
||||||
|
|
||||||
if (File.Exists(Path.Combine("png", $"{hash}.png"))) return true;
|
|
||||||
|
|
||||||
using MemoryStream ms = new(data);
|
|
||||||
using BinaryReader reader = new(ms);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return type switch
|
|
||||||
{
|
|
||||||
LbpFileType.Texture => TextureToPNG(hash, reader),
|
|
||||||
LbpFileType.Png => PNGToPNG(hash, data),
|
|
||||||
LbpFileType.Jpeg => JPGToPNG(hash, data),
|
|
||||||
// ReSharper disable once UnreachableSwitchArmDueToIntegerAnalysis
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Error while converting {hash}:");
|
|
||||||
Console.WriteLine(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TextureToPNG(string hash, BinaryReader reader)
|
|
||||||
{
|
|
||||||
// Skip the magic (3 bytes), we already know its a texture
|
|
||||||
for(int i = 0; i < 3; i++) reader.ReadByte();
|
|
||||||
|
|
||||||
// This below is shamelessly stolen from ennuo's Toolkit: https://github.com/ennuo/toolkit/blob/d996ee4134740db0ee94e2cbf1e4edbd1b5ec798/src/main/java/ennuo/craftworld/utilities/Compressor.java#L40
|
|
||||||
|
|
||||||
// This byte determines the method of reading. We can only read a texture (' ') so if it's not ' ' it must be invalid.
|
|
||||||
if ((char)reader.ReadByte() != ' ') return false;
|
|
||||||
|
|
||||||
reader.ReadInt16(); // ?
|
|
||||||
short chunks = reader.ReadInt16BE();
|
|
||||||
|
|
||||||
int[] compressed = new int[chunks];
|
|
||||||
int[] decompressed = new int[chunks];
|
|
||||||
|
|
||||||
for(int i = 0; i < chunks; ++i)
|
|
||||||
{
|
|
||||||
compressed[i] = reader.ReadUInt16BE();
|
|
||||||
decompressed[i] = reader.ReadUInt16BE();
|
|
||||||
}
|
|
||||||
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
using BinaryWriter writer = new(ms);
|
|
||||||
for(int i = 0; i < chunks; ++i)
|
|
||||||
{
|
|
||||||
byte[] deflatedData = reader.ReadBytes(compressed[i]);
|
|
||||||
if (compressed[i] == decompressed[i])
|
|
||||||
{
|
|
||||||
writer.Write(deflatedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
Inflater inflater = new();
|
|
||||||
inflater.SetInput(deflatedData);
|
|
||||||
byte[] inflatedData = new byte[decompressed[i]];
|
|
||||||
inflater.Inflate(inflatedData);
|
|
||||||
|
|
||||||
writer.Write(inflatedData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DDSToPNG(hash, ms.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool DDSToPNG(string hash, byte[] data)
|
|
||||||
{
|
|
||||||
using MemoryStream stream = new();
|
|
||||||
DDSImage image = new(data);
|
|
||||||
|
|
||||||
image.SaveAsPng(stream);
|
|
||||||
|
|
||||||
Directory.CreateDirectory("png");
|
|
||||||
File.WriteAllBytes($"png/{hash}.png", stream.ToArray());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool JPGToPNG(string hash, byte[] data)
|
|
||||||
{
|
|
||||||
using Image<Rgba32> image = Image.Load(data);
|
|
||||||
using MemoryStream ms = new();
|
|
||||||
image.SaveAsPng(ms);
|
|
||||||
|
|
||||||
File.WriteAllBytes($"png/{hash}.png", ms.ToArray());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// it sounds dumb i know but hear me out:
|
|
||||||
// you're completely correct
|
|
||||||
private static bool PNGToPNG(string hash, byte[] data)
|
|
||||||
{
|
|
||||||
File.WriteAllBytes($"png/{hash}.png", data);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InfluxDB.Client;
|
using InfluxDB.Client;
|
||||||
using InfluxDB.Client.Writes;
|
using InfluxDB.Client.Writes;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
|
|
@ -26,7 +26,7 @@ public static class LastContactHelper
|
||||||
database.LastContacts.Add(lastContact);
|
database.LastContacts.Add(lastContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastContact.Timestamp = TimestampHelper.Timestamp;
|
lastContact.Timestamp = TimeHelper.Timestamp;
|
||||||
lastContact.GameVersion = gameVersion;
|
lastContact.GameVersion = gameVersion;
|
||||||
lastContact.Platform = platform;
|
lastContact.Platform = platform;
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class RandomHelper
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// An instance of Random. Must be locked when in use.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly Random Random = new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates a specified amount of random bytes in an array.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count">The amount of bytes to generate.</param>
|
|
||||||
/// <returns>The bytes generated</returns>
|
|
||||||
public static IEnumerable<byte> GenerateRandomBytes(int count)
|
|
||||||
{
|
|
||||||
byte[] b = new byte[count];
|
|
||||||
|
|
||||||
lock(Random)
|
|
||||||
{
|
|
||||||
Random.NextBytes(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
|
||||||
public static class ResourceHelper
|
public static class ResourceHelper
|
||||||
{
|
{
|
||||||
public static string readManifestFile(string fileName)
|
public static string ReadManifestFile(string fileName)
|
||||||
{
|
{
|
||||||
using Stream stream = typeof(Database).Assembly.GetManifestResourceStream($"{typeof(Database).Namespace}.{fileName}");
|
using Stream stream = typeof(Database).Assembly.GetManifestResourceStream($"{typeof(Database).Namespace}.{fileName}");
|
||||||
using StreamReader reader = new(stream ?? throw new Exception("The assembly or manifest resource is null."));
|
using StreamReader reader = new(stream ?? throw new Exception("The assembly or manifest resource is null."));
|
||||||
|
|
|
@ -9,11 +9,11 @@ public static class StatisticsHelper
|
||||||
{
|
{
|
||||||
private static readonly Database database = new();
|
private static readonly Database database = new();
|
||||||
|
|
||||||
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync();
|
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimeHelper.Timestamp - l.Timestamp < 300).CountAsync();
|
||||||
|
|
||||||
public static async Task<int> RecentMatchesForGame
|
public static async Task<int> RecentMatchesForGame
|
||||||
(GameVersion gameVersion)
|
(GameVersion gameVersion)
|
||||||
=> await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300 && l.GameVersion == gameVersion).CountAsync();
|
=> await database.LastContacts.Where(l => TimeHelper.Timestamp - l.Timestamp < 300 && l.GameVersion == gameVersion).CountAsync();
|
||||||
|
|
||||||
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,10 @@ public static class TimeHelper
|
||||||
{
|
{
|
||||||
public static long UnixTimeMilliseconds() => DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
public static long UnixTimeMilliseconds() => DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
public static long UnixTimeSeconds() => DateTimeOffset.Now.ToUnixTimeSeconds();
|
public static long UnixTimeSeconds() => DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||||
|
|
||||||
|
public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||||
|
|
||||||
|
public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1397109686193
|
// 1397109686193
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
|
|
||||||
public static class TimestampHelper
|
|
||||||
{
|
|
||||||
public static long Timestamp => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
|
||||||
|
|
||||||
public static long TimestampMillis => (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
|
||||||
}
|
|
|
@ -10,10 +10,10 @@ public static class VersionHelper
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CommitHash = ResourceHelper.readManifestFile("gitVersion.txt");
|
CommitHash = ResourceHelper.ReadManifestFile("gitVersion.txt");
|
||||||
Branch = ResourceHelper.readManifestFile("gitBranch.txt");
|
Branch = ResourceHelper.ReadManifestFile("gitBranch.txt");
|
||||||
|
|
||||||
string remotesFile = ResourceHelper.readManifestFile("gitRemotes.txt");
|
string remotesFile = ResourceHelper.ReadManifestFile("gitRemotes.txt");
|
||||||
|
|
||||||
string[] lines = remotesFile.Split('\n');
|
string[] lines = remotesFile.Split('\n');
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public static class VersionHelper
|
||||||
// linq is a serious and painful catastrophe but its useful so i'm gonna keep using it
|
// linq is a serious and painful catastrophe but its useful so i'm gonna keep using it
|
||||||
Remotes = lines.Select(line => line.Split("\t")[1]).ToArray();
|
Remotes = lines.Select(line => line.Split("\t")[1]).ToArray();
|
||||||
|
|
||||||
CommitsOutOfDate = ResourceHelper.readManifestFile("gitUnpushed.txt").Split('\n').Length;
|
CommitsOutOfDate = ResourceHelper.ReadManifestFile("gitUnpushed.txt").Split('\n').Length;
|
||||||
|
|
||||||
CanCheckForUpdates = true;
|
CanCheckForUpdates = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using AspLogLevel = Microsoft.Extensions.Logging.LogLevel;
|
using AspLogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Logging.Loggers;
|
namespace LBPUnion.ProjectLighthouse.Logging.Loggers;
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class CleanupBrokenPhotosMaintenanceJob : IMaintenanceJob
|
||||||
goto removePhoto;
|
goto removePhoto;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (photo.Timestamp > TimestampHelper.Timestamp)
|
if (photo.Timestamp > TimeHelper.Timestamp)
|
||||||
{
|
{
|
||||||
takenInTheFuture = true;
|
takenInTheFuture = true;
|
||||||
goto removePhoto;
|
goto removePhoto;
|
||||||
|
|
|
@ -2,7 +2,7 @@ using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers.Middlewares;
|
namespace LBPUnion.ProjectLighthouse.Middlewares;
|
||||||
|
|
||||||
public class FakeRemoteIPAddressMiddleware
|
public class FakeRemoteIPAddressMiddleware
|
||||||
{
|
{
|
|
@ -48,10 +48,6 @@
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Extensions"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="Extensions\SerializationExtensions.cs"/>
|
<Compile Remove="Extensions\SerializationExtensions.cs"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -2,7 +2,7 @@ using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
namespace LBPUnion.ProjectLighthouse.Types.Categories;
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class UserStatus
|
||||||
|
|
||||||
public UserStatus(Database database, int userId)
|
public UserStatus(Database database, int userId)
|
||||||
{
|
{
|
||||||
LastContact? lastContact = database.LastContacts.Where(l => l.UserId == userId).FirstOrDefault(l => TimestampHelper.Timestamp - l.Timestamp < 300);
|
LastContact? lastContact = database.LastContacts.Where(l => l.UserId == userId).FirstOrDefault(l => TimeHelper.Timestamp - l.Timestamp < 300);
|
||||||
|
|
||||||
if (lastContact == null)
|
if (lastContact == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -152,7 +152,6 @@ internal class LegacyServerSettings
|
||||||
configuration.Authentication = new AuthenticationConfiguration
|
configuration.Authentication = new AuthenticationConfiguration
|
||||||
{
|
{
|
||||||
RegistrationEnabled = this.RegistrationEnabled,
|
RegistrationEnabled = this.RegistrationEnabled,
|
||||||
BlockDeniedUsers = this.BlockDeniedUsers,
|
|
||||||
UseExternalAuth = this.UseExternalAuth,
|
UseExternalAuth = this.UseExternalAuth,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Types.Tickets;
|
namespace LBPUnion.ProjectLighthouse.Types.Tickets;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue