mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 08:28:39 +00:00
Censor filter logging improvements (#804)
* Move censor/msg logging to MessageController & separate LogAreas/config * Correct LBP character limit to 95 * Log filtered comments as well * Remove two unnecessary variables from CensorHelper * Add censor logging to SlotPage/UserPage controllers and improve logging slightly * Remove accidental dollar sign in log * Grammatical nitpick in CommentController.cs * Contextual nitpick in MessageController.cs * Add escaped quotes in CommentController log to match the rest * Increase limit to account for descriptions, magic mouth, etc. * Consolidate LogChatMessages logging into Filter log area to prevent confusion * Apply code review suggestions
This commit is contained in:
parent
8b1121a4f8
commit
e5cfeb1e39
6 changed files with 39 additions and 22 deletions
|
@ -1,11 +1,14 @@
|
|||
#nullable enable
|
||||
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;
|
||||
|
@ -119,6 +122,10 @@ public class CommentController : ControllerBase
|
|||
|
||||
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);
|
||||
|
||||
bool success = await this.database.PostComment(token.UserId, targetId, type, filteredText);
|
||||
if (success) return this.Ok();
|
||||
|
||||
|
|
|
@ -86,6 +86,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
|
|||
|
||||
string message = await this.ReadBodyAsync();
|
||||
|
||||
const int lbpCharLimit = 512;
|
||||
if (message.Length > lbpCharLimit) return this.BadRequest();
|
||||
|
||||
if (message.StartsWith("/setemail ") && ServerConfiguration.Instance.Mail.MailEnabled)
|
||||
{
|
||||
string email = message[(message.IndexOf(" ", StringComparison.Ordinal)+1)..];
|
||||
|
@ -102,12 +105,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.";
|
|||
return this.Ok();
|
||||
}
|
||||
|
||||
string filteredText = CensorHelper.FilterMessage(message);
|
||||
|
||||
string username = await this.database.UsernameFromGameToken(token);
|
||||
|
||||
if (ServerConfiguration.Instance.LogChatFiltering)
|
||||
Logger.Info($"{username}: {message} / {filteredText}", LogArea.Filter);
|
||||
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);
|
||||
|
||||
return this.Ok(filteredText);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -68,16 +69,21 @@ public class SlotPageController : ControllerBase
|
|||
return this.Redirect("~/slot/" + id);
|
||||
}
|
||||
|
||||
msg = CensorHelper.FilterMessage(msg);
|
||||
string username = await this.database.UsernameFromWebToken(token);
|
||||
string filteredText = CensorHelper.FilterMessage(msg);
|
||||
|
||||
bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, msg);
|
||||
if (ServerConfiguration.Instance.LogChatFiltering && filteredText != msg)
|
||||
Logger.Info($"Censored profane word(s) from slot comment sent by {username}: \"{msg}\" => \"{filteredText}\"",
|
||||
LogArea.Filter);
|
||||
|
||||
bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, filteredText);
|
||||
if (success)
|
||||
{
|
||||
Logger.Success($"Posted comment from {token.UserId}: \"{msg}\" on level {id}", LogArea.Comments);
|
||||
Logger.Success($"Posted comment from {username}: \"{filteredText}\" on level {id}", LogArea.Comments);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"Failed to post comment from {token.UserId}: \"{msg}\" on level {id}", LogArea.Comments);
|
||||
Logger.Error($"Failed to post comment from {username}: \"{filteredText}\" on level {id}", LogArea.Comments);
|
||||
}
|
||||
|
||||
return this.Redirect("~/slot/" + id);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
|
@ -44,16 +45,21 @@ public class UserPageController : ControllerBase
|
|||
return this.Redirect("~/user/" + id);
|
||||
}
|
||||
|
||||
msg = CensorHelper.FilterMessage(msg);
|
||||
string username = await this.database.UsernameFromWebToken(token);
|
||||
string filteredText = CensorHelper.FilterMessage(msg);
|
||||
|
||||
bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, msg);
|
||||
if (ServerConfiguration.Instance.LogChatFiltering && filteredText != msg)
|
||||
Logger.Info($"Censored profane word(s) from user comment sent by {username}: \"{msg}\" => \"{filteredText}\"",
|
||||
LogArea.Filter);
|
||||
|
||||
bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, filteredText);
|
||||
if (success)
|
||||
{
|
||||
Logger.Success($"Posted comment from {token.UserId}: \"{msg}\" on user {id}", LogArea.Comments);
|
||||
Logger.Success($"Posted comment from {username}: \"{filteredText}\" on user {id}", LogArea.Comments);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"Failed to post comment from {token.UserId}: \"{msg}\" on user {id}", LogArea.Comments);
|
||||
Logger.Error($"Failed to post comment from {username}: \"{filteredText}\" on user {id}", LogArea.Comments);
|
||||
}
|
||||
|
||||
return this.Redirect("~/user/" + id);
|
||||
|
|
|
@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
|
|||
// This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly.
|
||||
// If you are modifying anything here, this value MUST be incremented.
|
||||
// Thanks for listening~
|
||||
public override int ConfigVersion { get; set; } = 20;
|
||||
public override int ConfigVersion { get; set; } = 21;
|
||||
|
||||
public override string ConfigName { get; set; } = "lighthouse.yml";
|
||||
public string WebsiteListenUrl { get; set; } = "http://localhost:10060";
|
||||
|
@ -30,6 +30,7 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
|
|||
#endif
|
||||
public bool CheckForUnsafeFiles { get; set; } = true;
|
||||
public bool LogChatFiltering { get; set; } = false;
|
||||
public bool LogChatMessages { get; set; } = false;
|
||||
|
||||
public AuthenticationConfiguration Authentication { get; set; } = new();
|
||||
public CaptchaConfiguration Captcha { get; set; } = new();
|
||||
|
|
|
@ -2,8 +2,6 @@ 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;
|
||||
|
||||
|
@ -24,10 +22,6 @@ public static class CensorHelper
|
|||
if (CensorConfiguration.Instance.UserInputFilterMode == FilterMode.None) return message;
|
||||
StringBuilder stringBuilder = new(message);
|
||||
|
||||
const int lbpCharLimit = 94;
|
||||
|
||||
int profaneCount = 0;
|
||||
|
||||
foreach (string profanity in CensorConfiguration.Instance.FilteredWordList)
|
||||
{
|
||||
int lastFoundProfanity = 0;
|
||||
|
@ -47,13 +41,9 @@ public static class CensorHelper
|
|||
for (int i = censorIndices.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Censor(censorIndices[i], profanity.Length, stringBuilder);
|
||||
profaneCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ServerConfiguration.Instance.LogChatFiltering && profaneCount > 0 && message.Length <= lbpCharLimit)
|
||||
Logger.Info($"Censored {profaneCount} profane words from message \"{message}\"", LogArea.Filter);
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue