Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing filtering, filter inconsistencies, and filter logging #1082

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Serialization;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -24,7 +22,7 @@
public class CommentController : ControllerBase
{
private readonly DatabaseContext database;
public CommentController(DatabaseContext database)

Check notice on line 25 in ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -144,11 +142,7 @@
targetId = await this.database.UserIdFromUsername(username!);
}

string filteredText = CensorHelper.FilterMessage(comment.Message);

if (ServerConfiguration.Instance.LogChatFiltering && filteredText != comment.Message)
Logger.Info($"Censored profane word(s) from in-game comment sent by {username}: \"{comment.Message}\" => \"{filteredText}\"",
LogArea.Filter);
string filteredText = CensorHelper.FilterMessage(comment.Message, FilterLocation.ChatMessage, username);

bool success = await this.database.PostComment(token.UserId, targetId, type, filteredText);
if (success) return this.Ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using LBPUnion.ProjectLighthouse.Types.Entities.Notifications;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Mail;
using LBPUnion.ProjectLighthouse.Types.Serialization;
Expand Down Expand Up @@ -41,7 +42,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.";

public MessageController(DatabaseContext database)

Check notice on line 45 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -71,7 +72,7 @@
$"user.UserId: {token.UserId}\n" +
$"token.GameVersion: {token.GameVersion}\n" +
$"token.TicketHash: {token.TicketHash}\n" +
$"token.ExpiresAt: {token.ExpiresAt.ToString()}\n" +

Check warning on line 75 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Specify string culture explicitly

Specify string culture explicitly
"---DEBUG INFO---");
#endif

Expand Down Expand Up @@ -127,7 +128,7 @@

if (message.StartsWith("/setemail ") && ServerConfiguration.Instance.Mail.MailEnabled)
{
string email = message[(message.IndexOf(" ", StringComparison.Ordinal)+1)..];

Check notice on line 131 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Use char overload

Use 'string.IndexOf(char)' instead of 'string.IndexOf(string)' when you have a string with a single char
if (!SanitizationHelper.IsValidEmail(email)) return this.Ok();

if (await this.database.Users.AnyAsync(u => u.EmailAddress == email)) return this.Ok();
Expand All @@ -143,15 +144,10 @@

string username = await this.database.UsernameFromGameToken(token);

string filteredText = CensorHelper.FilterMessage(message);

if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter);

if (ServerConfiguration.Instance.LogChatFiltering && filteredText != message)
Logger.Info(
$"Censored profane word(s) from in-game text sent by {username}: \"{message}\" => \"{filteredText}\"",
LogArea.Filter);
message = CensorHelper.FilterMessage(message, FilterLocation.ChatMessage, username);

return this.Ok(filteredText);
return this.Ok(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Resources;
using LBPUnion.ProjectLighthouse.Types.Serialization;
using LBPUnion.ProjectLighthouse.Types.Users;
Expand All @@ -27,7 +28,7 @@
{
private readonly DatabaseContext database;

public PublishController(DatabaseContext database)

Check notice on line 31 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -63,7 +64,7 @@
return this.BadRequest();
}

if (slot.Resources?.Length == 0) slot.Resources = new[]{slot.RootLevel,};

Check notice on line 67 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression

if (slot.Resources == null)
{
Expand Down Expand Up @@ -99,7 +100,7 @@
return this.Forbid();
}

HashSet<string> resources = new(slot.Resources)

Check notice on line 103 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
{
slot.IconHash,
};
Expand Down Expand Up @@ -142,7 +143,7 @@
// Yes Rider, this isn't null
Debug.Assert(slot.Resources != null, "slot.ResourceList != null");

slot.Name = CensorHelper.FilterMessage(slot.Name);
slot.Name = CensorHelper.FilterMessage(slot.Name, FilterLocation.SlotName, user.Username);

if (slot.Name.Length > 64)
{
Expand All @@ -153,7 +154,7 @@
return this.BadRequest();
}

slot.Description = CensorHelper.FilterMessage(slot.Description);
slot.Description = CensorHelper.FilterMessage(slot.Description, FilterLocation.SlotDescription, user.Username);

if (slot.Description.Length > 512)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
Expand All @@ -22,7 +22,7 @@
{
private readonly DatabaseContext database;

public ReviewController(DatabaseContext database)

Check notice on line 25 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -99,7 +99,9 @@
GameReview? newReview = await this.DeserializeBody<GameReview>();
if (newReview == null) return this.BadRequest();

newReview.Text = CensorHelper.FilterMessage(newReview.Text);
// Temporary fix until this can be refactored to use a UserEntity properly
string username = await this.database.UsernameFromGameToken(token);
newReview.Text = CensorHelper.FilterMessage(newReview.Text, FilterLocation.SlotReview, username);

if (newReview.Text.Length > 512) return this.BadRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
Expand All @@ -11,6 +12,7 @@
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Serialization;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -27,7 +29,7 @@
{
private readonly DatabaseContext database;

public UserController(DatabaseContext database)

Check notice on line 32 in ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand All @@ -44,7 +46,7 @@
[HttpGet("users")]
public async Task<IActionResult> GetUserAlt([FromQuery(Name = "u")] string[] userList)
{
List<MinimalUserProfile> minimalUserList = new();

Check notice on line 49 in ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
foreach (string username in userList)
{
MinimalUserProfile? profile = await this.database.Users.Where(u => u.Username == username)
Expand Down Expand Up @@ -79,7 +81,9 @@

if (update.Biography.Length > 512) return this.BadRequest();

user.Biography = update.Biography;
string filteredBio = CensorHelper.FilterMessage(update.Biography, FilterLocation.UserBiography, user.Username);

user.Biography = filteredBio;
}

if (update.Location != null) user.Location = update.Location;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
Expand All @@ -6,6 +6,7 @@
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Logging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -23,7 +24,7 @@
{
private readonly DatabaseContext database;

public SlotPageController(DatabaseContext database)

Check notice on line 27 in ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -73,11 +74,7 @@
}

string username = await this.database.UsernameFromWebToken(token);
string filteredText = CensorHelper.FilterMessage(msg);

if (ServerConfiguration.Instance.LogChatFiltering && filteredText != msg)
Logger.Info($"Censored profane word(s) from slot comment sent by {username}: \"{msg}\" => \"{filteredText}\"",
LogArea.Filter);
string filteredText = CensorHelper.FilterMessage(msg, FilterLocation.SlotReview, username);

bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, filteredText);
if (success)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Logging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
Expand All @@ -17,7 +18,7 @@
{
private readonly DatabaseContext database;

public UserPageController(DatabaseContext database)

Check notice on line 21 in ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand Down Expand Up @@ -49,11 +50,7 @@
}

string username = await this.database.UsernameFromWebToken(token);
string filteredText = CensorHelper.FilterMessage(msg);

if (ServerConfiguration.Instance.LogChatFiltering && filteredText != msg)
Logger.Info($"Censored profane word(s) from user comment sent by {username}: \"{msg}\" => \"{filteredText}\"",
LogArea.Filter);
string filteredText = CensorHelper.FilterMessage(msg, FilterLocation.UserComment, username);

bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, filteredText);
if (success)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
#if DEBUG
using LBPUnion.ProjectLighthouse.Helpers;
#endif
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -10,7 +11,7 @@

public class FilterTestPage : BaseLayout
{
public FilterTestPage(DatabaseContext database) : base(database)

Check notice on line 14 in ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{}

public string? FilteredText;
Expand All @@ -19,7 +20,7 @@
public IActionResult OnGet(string? text = null)
{
#if DEBUG
if (text != null) this.FilteredText = CensorHelper.FilterMessage(text);
if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, FilterLocation.Test);
this.Text = text;

return this.Page();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Filter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

Expand All @@ -14,17 +15,17 @@
{

public SlotEntity? Slot;
public SlotSettingsPage(DatabaseContext database) : base(database)

Check notice on line 18 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{}

public async Task<IActionResult> OnPost([FromRoute] int slotId, [FromForm] string? avatar, [FromForm] string? name, [FromForm] string? description, string? labels)
{
this.Slot = await this.Database.Slots.FirstOrDefaultAsync(u => u.SlotId == slotId);

Check notice on line 23 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Query can return incomplete data for related entities

Query can return incomplete data for related entities
if (this.Slot == null) return this.NotFound();

if (this.User == null) return this.Redirect("~/slot/" + slotId);

if (!this.User.IsModerator && this.User != this.Slot.Creator) return this.Redirect("~/slot/" + slotId);

Check warning on line 28 in ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Usage of navigational property can return incomplete data

Usage of navigational property can return incomplete data

// Deny request if in read-only mode
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode)
Expand All @@ -36,15 +37,15 @@

if (name != null)
{
name = CensorHelper.FilterMessage(name);
if (this.Slot.Name != name && name.Length <= 64)
name = CensorHelper.FilterMessage(name, FilterLocation.SlotName, this.User.Username);
if (this.Slot.Name != name && name.Length <= 64)
this.Slot.Name = name;
}

if (description != null)
{
description = CensorHelper.FilterMessage(description);
if (this.Slot.Description != description && description?.Length <= 512)
description = CensorHelper.FilterMessage(description, FilterLocation.SlotDescription, this.User.Username);
if (this.Slot.Description != description && description.Length <= 512)
this.Slot.Description = description;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using System.Diagnostics.CodeAnalysis;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
Expand All @@ -7,6 +7,7 @@
using LBPUnion.ProjectLighthouse.Localization;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Filter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

Expand All @@ -16,7 +17,7 @@
{

public UserEntity? ProfileUser;
public UserSettingsPage(DatabaseContext database) : base(database)

Check notice on line 20 in ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{}

[SuppressMessage("ReSharper", "SpecifyStringComparison")]
Expand Down Expand Up @@ -55,9 +56,12 @@
if (ServerConfiguration.Instance.UserGeneratedContentLimits.ReadOnlyMode)
return this.Redirect($"~/user/{userId}");

biography = CensorHelper.FilterMessage(biography);
if (this.ProfileUser.Biography != biography && biography.Length <= 512)
this.ProfileUser.Biography = biography;
{
string filteredBio = CensorHelper.FilterMessage(biography, FilterLocation.UserBiography, this.ProfileUser.Username);

this.ProfileUser.Biography = filteredBio;
}
}

if (ServerConfiguration.Instance.Mail.MailEnabled &&
Expand All @@ -65,7 +69,7 @@
(this.User == this.ProfileUser || this.User.IsAdmin))
{
// if email hasn't already been used
if (!await this.Database.Users.AnyAsync(u => u.EmailAddress != null && u.EmailAddress.ToLower() == email!.ToLower()))

Check notice on line 72 in ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Use the 'StringComparison' method overloads to perform case-insensitive string comparisons

Prefer using 'string.Equals(string, StringComparison)' to perform a case-insensitive comparison, but keep in mind that this might cause subtle changes in behavior, so make sure to conduct thorough testing after applying the suggestion, or if culturally sensitive comparison is not required, consider using 'StringComparison.OrdinalIgnoreCase'
{
if (this.ProfileUser.EmailAddress != email)
{
Expand Down
14 changes: 12 additions & 2 deletions ProjectLighthouse/Helpers/CensorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
using System.Collections.Generic;
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Filter;
using LBPUnion.ProjectLighthouse.Types.Logging;

namespace LBPUnion.ProjectLighthouse.Helpers;

public static class CensorHelper
{
private static readonly char[] randomCharacters =
{

Check notice on line 14 in ProjectLighthouse/Helpers/CensorHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
'!', '@', '#', '$', '&', '%', '-', '_',
};

private static readonly string[] randomFurry =
{

Check notice on line 19 in ProjectLighthouse/Helpers/CensorHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
"UwU", "OwO", "uwu", "owo", "o3o", ">.>", "*pounces on you*", "*boops*", "*baps*", ":P", "x3", "O_O", "xD", ":3", ";3", "^w^",
};

public static string FilterMessage(string message)
public static string FilterMessage(string message, FilterLocation filterLocation = FilterLocation.None, string username = null)
{
if (CensorConfiguration.Instance.UserInputFilterMode == FilterMode.None) return message;
StringBuilder stringBuilder = new(message);
Expand All @@ -26,7 +29,7 @@
{
int lastFoundProfanity = 0;
int profaneIndex;
List<int> censorIndices = new();

Check notice on line 32 in ProjectLighthouse/Helpers/CensorHelper.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
do
{
profaneIndex = message.IndexOf(profanity, lastFoundProfanity, StringComparison.OrdinalIgnoreCase);
Expand All @@ -44,7 +47,14 @@
}
}

return stringBuilder.ToString();
string filteredMessage = stringBuilder.ToString();

if (ServerConfiguration.Instance.LogChatFiltering && filteredMessage != message)
Logger.Info(
$"Comment sent {(username != null ? $"by {username} " : "")}" + $"from {filterLocation}" +
$"\"{message}\" => \"{filteredMessage}\"", LogArea.Filter);

return filteredMessage;
}

private static void Censor(int profanityIndex, int profanityLength, StringBuilder message)
Expand Down
13 changes: 13 additions & 0 deletions ProjectLighthouse/Types/Filter/FilterLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace LBPUnion.ProjectLighthouse.Types.Filter;

public enum FilterLocation
{
SlotName = 0,
SlotDescription = 1,
SlotReview = 2,
UserBiography = 3,
UserComment = 4,
ChatMessage = 5,
Test = 6,
None = 7,
}
Loading