mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-15 14:12:27 +00:00
Add basic checks to grief reporting
This commit is contained in:
parent
cf1adbe640
commit
a796cb9185
2 changed files with 12 additions and 3 deletions
|
@ -3,6 +3,7 @@ using System.Text.Json;
|
||||||
using LBPUnion.ProjectLighthouse.Configuration;
|
using LBPUnion.ProjectLighthouse.Configuration;
|
||||||
using LBPUnion.ProjectLighthouse.Database;
|
using LBPUnion.ProjectLighthouse.Database;
|
||||||
using LBPUnion.ProjectLighthouse.Extensions;
|
using LBPUnion.ProjectLighthouse.Extensions;
|
||||||
|
using LBPUnion.ProjectLighthouse.Files;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
|
||||||
|
@ -37,6 +38,14 @@ public class ReportController : ControllerBase
|
||||||
|
|
||||||
SanitizationHelper.SanitizeStringsInClass(report);
|
SanitizationHelper.SanitizeStringsInClass(report);
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(report.JpegHash)) return this.BadRequest();
|
||||||
|
|
||||||
|
if (!FileHelper.ResourceExists(report.JpegHash)) return this.BadRequest();
|
||||||
|
|
||||||
|
if (report.XmlPlayers.Length > 4) return this.BadRequest();
|
||||||
|
|
||||||
|
if (report.XmlPlayers.Any(p => !this.database.IsUsernameValid(p.Name))) return this.BadRequest();
|
||||||
|
|
||||||
report.Bounds = JsonSerializer.Serialize(report.XmlBounds.Rect, typeof(Rectangle));
|
report.Bounds = JsonSerializer.Serialize(report.XmlBounds.Rect, typeof(Rectangle));
|
||||||
report.Players = JsonSerializer.Serialize(report.XmlPlayers, typeof(ReportPlayer[]));
|
report.Players = JsonSerializer.Serialize(report.XmlPlayers, typeof(ReportPlayer[]));
|
||||||
report.Timestamp = TimeHelper.TimestampMillis;
|
report.Timestamp = TimeHelper.TimestampMillis;
|
||||||
|
|
|
@ -21,6 +21,8 @@ public partial class DatabaseContext
|
||||||
[GeneratedRegex("^[a-zA-Z0-9_.-]{3,16}$")]
|
[GeneratedRegex("^[a-zA-Z0-9_.-]{3,16}$")]
|
||||||
private static partial Regex UsernameRegex();
|
private static partial Regex UsernameRegex();
|
||||||
|
|
||||||
|
public bool IsUsernameValid(string username) => UsernameRegex().IsMatch(username);
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
public async Task<User> CreateUser(string username, string password, string? emailAddress = null)
|
public async Task<User> CreateUser(string username, string password, string? emailAddress = null)
|
||||||
{
|
{
|
||||||
|
@ -31,9 +33,7 @@ public partial class DatabaseContext
|
||||||
{
|
{
|
||||||
if (username.Length is > 16 or < 3) throw new ArgumentException(nameof(username) + " is either too long or too short");
|
if (username.Length is > 16 or < 3) throw new ArgumentException(nameof(username) + " is either too long or too short");
|
||||||
|
|
||||||
Regex regex = UsernameRegex();
|
if (!this.IsUsernameValid(username)) throw new ArgumentException(nameof(username) + " does not match the username regex");
|
||||||
|
|
||||||
if (!regex.IsMatch(username)) throw new ArgumentException(nameof(username) + " does not match the username regex");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
User? user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync();
|
User? user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue