Fix missing filtering, filter inconsistencies, and filter logging

This commit is contained in:
FeTetra 2024-11-13 21:12:55 -05:00
parent a3022ff5b4
commit 27f0a81dc5
12 changed files with 40 additions and 40 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
<option name="singleClickDiffPreview" value="1" />
<option name="vcsConfiguration" value="3" />
</component>
</project>

View file

@ -3,12 +3,10 @@ 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;
@ -144,11 +142,7 @@ public class CommentController : ControllerBase
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, "in-game comment", username);
bool success = await this.database.PostComment(token.UserId, targetId, type, filteredText);
if (success) return this.Ok();

View file

@ -143,15 +143,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
string username = await this.database.UsernameFromGameToken(token);
string filteredText = CensorHelper.FilterMessage(message);
message = CensorHelper.FilterMessage(message,"in-game message", username);
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);
return this.Ok(filteredText);
return this.Ok(message);
}
}

View file

@ -142,7 +142,7 @@ public class PublishController : ControllerBase
// 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, "slot name", user.Username);
if (slot.Name.Length > 64)
{
@ -153,7 +153,7 @@ public class PublishController : ControllerBase
return this.BadRequest();
}
slot.Description = CensorHelper.FilterMessage(slot.Description);
slot.Description = CensorHelper.FilterMessage(slot.Description, "slot description", user.Username);
if (slot.Description.Length > 512)
{

View file

@ -5,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
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.Serialization;
@ -99,7 +100,9 @@ public class ReviewController : ControllerBase
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, "slot review", username);
if (newReview.Text.Length > 512) return this.BadRequest();

View file

@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Configuration;
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;
@ -79,7 +80,9 @@ public class UserController : ControllerBase
if (update.Biography.Length > 512) return this.BadRequest();
user.Biography = update.Biography;
string filteredBio = CensorHelper.FilterMessage(update.Biography, "user biography", user.Username);
user.Biography = filteredBio;
}
if (update.Location != null) user.Location = update.Location;

View file

@ -73,11 +73,7 @@ public class SlotPageController : ControllerBase
}
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, "slot comment", username);
bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, filteredText);
if (success)

View file

@ -49,11 +49,7 @@ public class UserPageController : ControllerBase
}
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, "user comment", username);
bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, filteredText);
if (success)

View file

@ -19,7 +19,7 @@ public class FilterTestPage : BaseLayout
public IActionResult OnGet(string? text = null)
{
#if DEBUG
if (text != null) this.FilteredText = CensorHelper.FilterMessage(text);
if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, "test filter", null);
this.Text = text;
return this.Page();

View file

@ -36,15 +36,15 @@ public class SlotSettingsPage : BaseLayout
if (name != null)
{
name = CensorHelper.FilterMessage(name);
if (this.Slot.Name != name && name.Length <= 64)
name = CensorHelper.FilterMessage(name, "slot name", 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, "slot description", this.User.Username);
if (this.Slot.Description != description && description.Length <= 512)
this.Slot.Description = description;
}

View file

@ -55,9 +55,12 @@ public class UserSettingsPage : BaseLayout
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, "user biography", this.ProfileUser.Username);
this.ProfileUser.Biography = filteredBio;
}
}
if (ServerConfiguration.Instance.Mail.MailEnabled &&

View file

@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Logging;
namespace LBPUnion.ProjectLighthouse.Helpers;
@ -17,7 +19,7 @@ public static class CensorHelper
"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, string filterLocation, string username)
{
if (CensorConfiguration.Instance.UserInputFilterMode == FilterMode.None) return message;
StringBuilder stringBuilder = new(message);
@ -44,7 +46,16 @@ public static class CensorHelper
}
}
return stringBuilder.ToString();
string filteredMessage = stringBuilder.ToString();
if (ServerConfiguration.Instance.LogChatFiltering && filteredMessage != message)
Logger.Info(
$"Censored profane word(s) from {filterLocation} "
+ $"sent by {username}"
+ $": \"{message}\" => \"{filteredMessage}\"",
LogArea.Filter);
return filteredMessage;
}
private static void Censor(int profanityIndex, int profanityLength, StringBuilder message)