From 27f0a81dc59d30d73eb19c5a159c69f27ec3ea72 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Wed, 13 Nov 2024 21:12:55 -0500 Subject: [PATCH 1/7] Fix missing filtering, filter inconsistencies, and filter logging --- .../.idea/projectSettingsUpdater.xml | 3 ++- .../Controllers/CommentController.cs | 8 +------- .../Controllers/MessageController.cs | 11 ++--------- .../Controllers/Slots/PublishController.cs | 4 ++-- .../Controllers/Slots/ReviewController.cs | 5 ++++- .../Controllers/UserController.cs | 5 ++++- .../Controllers/SlotPageController.cs | 6 +----- .../Controllers/UserPageController.cs | 6 +----- .../Pages/Debug/FilterTestPage.cshtml.cs | 2 +- .../Pages/SlotSettingsPage.cshtml.cs | 8 ++++---- .../Pages/UserSettingsPage.cshtml.cs | 7 +++++-- ProjectLighthouse/Helpers/CensorHelper.cs | 15 +++++++++++++-- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.idea/.idea.ProjectLighthouse/.idea/projectSettingsUpdater.xml b/.idea/.idea.ProjectLighthouse/.idea/projectSettingsUpdater.xml index 4bb9f4d2a..64af657f5 100644 --- a/.idea/.idea.ProjectLighthouse/.idea/projectSettingsUpdater.xml +++ b/.idea/.idea.ProjectLighthouse/.idea/projectSettingsUpdater.xml @@ -1,6 +1,7 @@ - \ No newline at end of file diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index a906b170b..a2415c140 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -3,12 +3,10 @@ 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 async Task PostComment(string? username, string? slotType, 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(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 26ae10acf..a5f6a039e 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -143,15 +143,8 @@ public async Task Filter(IMailService mailService) 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); } } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs index 7bedc01dc..0c1d2b9f9 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs @@ -142,7 +142,7 @@ await this.database.SendNotification(user.UserId, // 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 @@ await this.database.SendNotification(user.UserId, return this.BadRequest(); } - slot.Description = CensorHelper.FilterMessage(slot.Description); + slot.Description = CensorHelper.FilterMessage(slot.Description, "slot description", user.Username); if (slot.Description.Length > 512) { diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs index 0dd54c078..062f0b57d 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs @@ -5,6 +5,7 @@ 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 async Task PostReview(int slotId) GameReview? newReview = await this.DeserializeBody(); 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(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index 7019cdd76..d346780a3 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -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; @@ -79,7 +80,9 @@ public async Task UpdateUser() 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; diff --git a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs index 7f22b0b6b..62c3cb9f5 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs @@ -73,11 +73,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } 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) diff --git a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs index afd23458d..e1cf09543 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs @@ -49,11 +49,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } 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) diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs index fe61d7e87..ac88acac8 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs @@ -19,7 +19,7 @@ public FilterTestPage(DatabaseContext database) : base(database) 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(); diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs index b461d9825..9066cacae 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs @@ -36,15 +36,15 @@ public async Task OnPost([FromRoute] int slotId, [FromForm] strin 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; } diff --git a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs index 85b0c242f..2b4e4d4b0 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs @@ -55,9 +55,12 @@ [FromForm] string? language 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 && diff --git a/ProjectLighthouse/Helpers/CensorHelper.cs b/ProjectLighthouse/Helpers/CensorHelper.cs index e5ff79539..e73d17799 100644 --- a/ProjectLighthouse/Helpers/CensorHelper.cs +++ b/ProjectLighthouse/Helpers/CensorHelper.cs @@ -2,6 +2,8 @@ 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 string FilterMessage(string message) } } - 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) From 78b0f587aebaec2bbd438540af8000c483ca020c Mon Sep 17 00:00:00 2001 From: FeTetra Date: Wed, 13 Nov 2024 21:20:54 -0500 Subject: [PATCH 2/7] Remove unused import and replace removed logger --- .../Controllers/MessageController.cs | 2 ++ .../Controllers/Slots/ReviewController.cs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index a5f6a039e..12d37d3d2 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -143,6 +143,8 @@ public async Task Filter(IMailService mailService) string username = await this.database.UsernameFromGameToken(token); + if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter); + message = CensorHelper.FilterMessage(message,"in-game message", username); return this.Ok(message); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs index 062f0b57d..e9e9fefdc 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs @@ -5,7 +5,6 @@ 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; From 0415299b31e176bbc9116fcc3416628196064dd3 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Thu, 14 Nov 2024 16:48:14 -0500 Subject: [PATCH 3/7] Make filter log arguments optional --- ProjectLighthouse/Helpers/CensorHelper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ProjectLighthouse/Helpers/CensorHelper.cs b/ProjectLighthouse/Helpers/CensorHelper.cs index e73d17799..2a9e879e9 100644 --- a/ProjectLighthouse/Helpers/CensorHelper.cs +++ b/ProjectLighthouse/Helpers/CensorHelper.cs @@ -19,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, string filterLocation, string username) + public static string FilterMessage(string message, string filterLocation = null, string username = null) { if (CensorConfiguration.Instance.UserInputFilterMode == FilterMode.None) return message; StringBuilder stringBuilder = new(message); @@ -50,9 +50,9 @@ public static string FilterMessage(string message, string filterLocation, string if (ServerConfiguration.Instance.LogChatFiltering && filteredMessage != message) Logger.Info( - $"Censored profane word(s) from {filterLocation} " - + $"sent by {username}" - + $": \"{message}\" => \"{filteredMessage}\"", + $"Comment sent {(username != null ? $"by {username} " : "")}" + + $"{(filterLocation != null ? $"from {filterLocation}" : "")}" + + $"\"{message}\" => \"{filteredMessage}\"", LogArea.Filter); return filteredMessage; From d4a56a96175fd1e10686ce4a2d935b904a786a88 Mon Sep 17 00:00:00 2001 From: FeTetra <166051662+FeTetra@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:03:43 -0500 Subject: [PATCH 4/7] Update ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs Co-authored-by: sudokoko --- .../Controllers/MessageController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 12d37d3d2..414a4b2c4 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -145,7 +145,7 @@ public async Task Filter(IMailService mailService) if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter); - message = CensorHelper.FilterMessage(message,"in-game message", username); + message = CensorHelper.FilterMessage(message, "in-game message", username); return this.Ok(message); } From 967231603dfd8bd2160559761d286406e2ad6761 Mon Sep 17 00:00:00 2001 From: FeTetra <166051662+FeTetra@users.noreply.github.com> Date: Fri, 15 Nov 2024 00:04:39 -0500 Subject: [PATCH 5/7] Update ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs Co-authored-by: sudokoko --- .../Pages/Debug/FilterTestPage.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs index ac88acac8..53e17c996 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs @@ -19,7 +19,7 @@ public FilterTestPage(DatabaseContext database) : base(database) public IActionResult OnGet(string? text = null) { #if DEBUG - if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, "test filter", null); + if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, "test filter"); this.Text = text; return this.Page(); From 3c7a3c7bf594accd9ea4b1cb6e4d69c243da7d03 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Tue, 10 Dec 2024 09:48:37 -0500 Subject: [PATCH 6/7] Replace filter location strings with enum --- .../Controllers/CommentController.cs | 2 +- .../Controllers/MessageController.cs | 3 ++- .../Controllers/Slots/PublishController.cs | 5 +++-- .../Controllers/Slots/ReviewController.cs | 2 +- .../Controllers/UserController.cs | 3 ++- .../Controllers/SlotPageController.cs | 3 ++- .../Controllers/UserPageController.cs | 3 ++- .../Pages/Debug/FilterTestPage.cshtml.cs | 3 ++- .../Pages/SlotSettingsPage.cshtml.cs | 5 +++-- .../Pages/UserSettingsPage.cshtml.cs | 3 ++- ProjectLighthouse/Helpers/CensorHelper.cs | 9 ++++----- ProjectLighthouse/Types/Filter/FilterLocation.cs | 13 +++++++++++++ 12 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 ProjectLighthouse/Types/Filter/FilterLocation.cs diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index a2415c140..3e0498767 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -142,7 +142,7 @@ public async Task PostComment(string? username, string? slotType, targetId = await this.database.UserIdFromUsername(username!); } - string filteredText = CensorHelper.FilterMessage(comment.Message, "in-game comment", username); + string filteredText = CensorHelper.FilterMessage(comment.Message, Location.ChatMessage, username); bool success = await this.database.PostComment(token.UserId, targetId, type, filteredText); if (success) return this.Ok(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 414a4b2c4..2c2af4e1c 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -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; @@ -145,7 +146,7 @@ public async Task Filter(IMailService mailService) if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter); - message = CensorHelper.FilterMessage(message, "in-game message", username); + message = CensorHelper.FilterMessage(message, Location.ChatMessage, username); return this.Ok(message); } diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs index 0c1d2b9f9..284333e6c 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs @@ -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; @@ -142,7 +143,7 @@ await this.database.SendNotification(user.UserId, // Yes Rider, this isn't null Debug.Assert(slot.Resources != null, "slot.ResourceList != null"); - slot.Name = CensorHelper.FilterMessage(slot.Name, "slot name", user.Username); + slot.Name = CensorHelper.FilterMessage(slot.Name, Location.SlotName, user.Username); if (slot.Name.Length > 64) { @@ -153,7 +154,7 @@ await this.database.SendNotification(user.UserId, return this.BadRequest(); } - slot.Description = CensorHelper.FilterMessage(slot.Description, "slot description", user.Username); + slot.Description = CensorHelper.FilterMessage(slot.Description, Location.SlotDescription, user.Username); if (slot.Description.Length > 512) { diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs index e9e9fefdc..4991d9063 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs @@ -101,7 +101,7 @@ public async Task PostReview(int slotId) // 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); + newReview.Text = CensorHelper.FilterMessage(newReview.Text, Location.SlotReview, username); if (newReview.Text.Length > 512) return this.BadRequest(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index d346780a3..f51ac8f23 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -12,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; @@ -80,7 +81,7 @@ public async Task UpdateUser() if (update.Biography.Length > 512) return this.BadRequest(); - string filteredBio = CensorHelper.FilterMessage(update.Biography, "user biography", user.Username); + string filteredBio = CensorHelper.FilterMessage(update.Biography, Location.UserBiography, user.Username); user.Biography = filteredBio; } diff --git a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs index 62c3cb9f5..a76ba4cb3 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs @@ -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; @@ -73,7 +74,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } string username = await this.database.UsernameFromWebToken(token); - string filteredText = CensorHelper.FilterMessage(msg, "slot comment", username); + string filteredText = CensorHelper.FilterMessage(msg, Location.SlotReview, username); bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, filteredText); if (success) diff --git a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs index e1cf09543..3783b7cd4 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs @@ -5,6 +5,7 @@ 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; @@ -49,7 +50,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } string username = await this.database.UsernameFromWebToken(token); - string filteredText = CensorHelper.FilterMessage(msg, "user comment", username); + string filteredText = CensorHelper.FilterMessage(msg, Location.UserComment, username); bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, filteredText); if (success) diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs index 53e17c996..55c73094e 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs @@ -3,6 +3,7 @@ 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; @@ -19,7 +20,7 @@ public FilterTestPage(DatabaseContext database) : base(database) public IActionResult OnGet(string? text = null) { #if DEBUG - if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, "test filter"); + if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, Location.Test); this.Text = text; return this.Page(); diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs index 9066cacae..db17a1c1c 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs @@ -5,6 +5,7 @@ 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; @@ -36,14 +37,14 @@ public async Task OnPost([FromRoute] int slotId, [FromForm] strin if (name != null) { - name = CensorHelper.FilterMessage(name, "slot name", this.User.Username); + name = CensorHelper.FilterMessage(name, Location.SlotName, this.User.Username); if (this.Slot.Name != name && name.Length <= 64) this.Slot.Name = name; } if (description != null) { - description = CensorHelper.FilterMessage(description, "slot description", this.User.Username); + description = CensorHelper.FilterMessage(description, Location.SlotDescription, this.User.Username); if (this.Slot.Description != description && description.Length <= 512) this.Slot.Description = description; } diff --git a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs index 2b4e4d4b0..1ab7395d6 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs @@ -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; @@ -57,7 +58,7 @@ [FromForm] string? language if (this.ProfileUser.Biography != biography && biography.Length <= 512) { - string filteredBio = CensorHelper.FilterMessage(biography, "user biography", this.ProfileUser.Username); + string filteredBio = CensorHelper.FilterMessage(biography, Location.UserBiography, this.ProfileUser.Username); this.ProfileUser.Biography = filteredBio; } diff --git a/ProjectLighthouse/Helpers/CensorHelper.cs b/ProjectLighthouse/Helpers/CensorHelper.cs index 2a9e879e9..327d8a43f 100644 --- a/ProjectLighthouse/Helpers/CensorHelper.cs +++ b/ProjectLighthouse/Helpers/CensorHelper.cs @@ -3,6 +3,7 @@ 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; @@ -19,7 +20,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, string filterLocation = null, string username = null) + public static string FilterMessage(string message, Location filterLocation = Location.None, string username = null) { if (CensorConfiguration.Instance.UserInputFilterMode == FilterMode.None) return message; StringBuilder stringBuilder = new(message); @@ -50,10 +51,8 @@ public static string FilterMessage(string message, string filterLocation = null, if (ServerConfiguration.Instance.LogChatFiltering && filteredMessage != message) Logger.Info( - $"Comment sent {(username != null ? $"by {username} " : "")}" + - $"{(filterLocation != null ? $"from {filterLocation}" : "")}" + - $"\"{message}\" => \"{filteredMessage}\"", - LogArea.Filter); + $"Comment sent {(username != null ? $"by {username} " : "")}" + $"from {filterLocation}" + + $"\"{message}\" => \"{filteredMessage}\"", LogArea.Filter); return filteredMessage; } diff --git a/ProjectLighthouse/Types/Filter/FilterLocation.cs b/ProjectLighthouse/Types/Filter/FilterLocation.cs new file mode 100644 index 000000000..1951db261 --- /dev/null +++ b/ProjectLighthouse/Types/Filter/FilterLocation.cs @@ -0,0 +1,13 @@ +namespace LBPUnion.ProjectLighthouse.Types.Filter; + +public enum Location +{ + SlotName = 0, + SlotDescription = 1, + SlotReview = 2, + UserBiography = 3, + UserComment = 4, + ChatMessage = 5, + Test = 6, + None = 7, +} \ No newline at end of file From bffd53cdc009947063303c04c33944fa667e8a32 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Tue, 10 Dec 2024 13:08:49 -0500 Subject: [PATCH 7/7] Rename enum to FilterLocation for readability --- .../Controllers/CommentController.cs | 2 +- .../Controllers/MessageController.cs | 2 +- .../Controllers/Slots/PublishController.cs | 4 ++-- .../Controllers/Slots/ReviewController.cs | 2 +- .../Controllers/UserController.cs | 2 +- .../Controllers/SlotPageController.cs | 2 +- .../Controllers/UserPageController.cs | 2 +- .../Pages/Debug/FilterTestPage.cshtml.cs | 2 +- .../Pages/SlotSettingsPage.cshtml.cs | 4 ++-- .../Pages/UserSettingsPage.cshtml.cs | 2 +- ProjectLighthouse/Helpers/CensorHelper.cs | 2 +- ProjectLighthouse/Types/Filter/FilterLocation.cs | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index 3e0498767..7e3baeb9e 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -142,7 +142,7 @@ public async Task PostComment(string? username, string? slotType, targetId = await this.database.UserIdFromUsername(username!); } - string filteredText = CensorHelper.FilterMessage(comment.Message, Location.ChatMessage, username); + 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(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 2c2af4e1c..42b1d1b7b 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -146,7 +146,7 @@ public async Task Filter(IMailService mailService) if (ServerConfiguration.Instance.LogChatMessages) Logger.Info($"{username}: \"{message}\"", LogArea.Filter); - message = CensorHelper.FilterMessage(message, Location.ChatMessage, username); + message = CensorHelper.FilterMessage(message, FilterLocation.ChatMessage, username); return this.Ok(message); } diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs index 284333e6c..dfb42c710 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/PublishController.cs @@ -143,7 +143,7 @@ await this.database.SendNotification(user.UserId, // Yes Rider, this isn't null Debug.Assert(slot.Resources != null, "slot.ResourceList != null"); - slot.Name = CensorHelper.FilterMessage(slot.Name, Location.SlotName, user.Username); + slot.Name = CensorHelper.FilterMessage(slot.Name, FilterLocation.SlotName, user.Username); if (slot.Name.Length > 64) { @@ -154,7 +154,7 @@ await this.database.SendNotification(user.UserId, return this.BadRequest(); } - slot.Description = CensorHelper.FilterMessage(slot.Description, Location.SlotDescription, user.Username); + slot.Description = CensorHelper.FilterMessage(slot.Description, FilterLocation.SlotDescription, user.Username); if (slot.Description.Length > 512) { diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs index 4991d9063..3b2a7fbbf 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs @@ -101,7 +101,7 @@ public async Task PostReview(int slotId) // 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, Location.SlotReview, username); + newReview.Text = CensorHelper.FilterMessage(newReview.Text, FilterLocation.SlotReview, username); if (newReview.Text.Length > 512) return this.BadRequest(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index f51ac8f23..7301bc52c 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -81,7 +81,7 @@ public async Task UpdateUser() if (update.Biography.Length > 512) return this.BadRequest(); - string filteredBio = CensorHelper.FilterMessage(update.Biography, Location.UserBiography, user.Username); + string filteredBio = CensorHelper.FilterMessage(update.Biography, FilterLocation.UserBiography, user.Username); user.Biography = filteredBio; } diff --git a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs index a76ba4cb3..1b4381c1a 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/SlotPageController.cs @@ -74,7 +74,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } string username = await this.database.UsernameFromWebToken(token); - string filteredText = CensorHelper.FilterMessage(msg, Location.SlotReview, username); + string filteredText = CensorHelper.FilterMessage(msg, FilterLocation.SlotReview, username); bool success = await this.database.PostComment(token.UserId, id, CommentType.Level, filteredText); if (success) diff --git a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs index 3783b7cd4..9c1883529 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/UserPageController.cs @@ -50,7 +50,7 @@ public async Task PostComment([FromRoute] int id, [FromForm] stri } string username = await this.database.UsernameFromWebToken(token); - string filteredText = CensorHelper.FilterMessage(msg, Location.UserComment, username); + string filteredText = CensorHelper.FilterMessage(msg, FilterLocation.UserComment, username); bool success = await this.database.PostComment(token.UserId, id, CommentType.Profile, filteredText); if (success) diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs index 55c73094e..e8e613ec0 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/FilterTestPage.cshtml.cs @@ -20,7 +20,7 @@ public FilterTestPage(DatabaseContext database) : base(database) public IActionResult OnGet(string? text = null) { #if DEBUG - if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, Location.Test); + if (text != null) this.FilteredText = CensorHelper.FilterMessage(text, FilterLocation.Test); this.Text = text; return this.Page(); diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs index db17a1c1c..2c44a87cb 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotSettingsPage.cshtml.cs @@ -37,14 +37,14 @@ public async Task OnPost([FromRoute] int slotId, [FromForm] strin if (name != null) { - name = CensorHelper.FilterMessage(name, Location.SlotName, this.User.Username); + 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, Location.SlotDescription, this.User.Username); + description = CensorHelper.FilterMessage(description, FilterLocation.SlotDescription, this.User.Username); if (this.Slot.Description != description && description.Length <= 512) this.Slot.Description = description; } diff --git a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs index 1ab7395d6..55375a425 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/UserSettingsPage.cshtml.cs @@ -58,7 +58,7 @@ [FromForm] string? language if (this.ProfileUser.Biography != biography && biography.Length <= 512) { - string filteredBio = CensorHelper.FilterMessage(biography, Location.UserBiography, this.ProfileUser.Username); + string filteredBio = CensorHelper.FilterMessage(biography, FilterLocation.UserBiography, this.ProfileUser.Username); this.ProfileUser.Biography = filteredBio; } diff --git a/ProjectLighthouse/Helpers/CensorHelper.cs b/ProjectLighthouse/Helpers/CensorHelper.cs index 327d8a43f..494d3ce06 100644 --- a/ProjectLighthouse/Helpers/CensorHelper.cs +++ b/ProjectLighthouse/Helpers/CensorHelper.cs @@ -20,7 +20,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, Location filterLocation = Location.None, string username = null) + 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); diff --git a/ProjectLighthouse/Types/Filter/FilterLocation.cs b/ProjectLighthouse/Types/Filter/FilterLocation.cs index 1951db261..5f439872b 100644 --- a/ProjectLighthouse/Types/Filter/FilterLocation.cs +++ b/ProjectLighthouse/Types/Filter/FilterLocation.cs @@ -1,6 +1,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Filter; -public enum Location +public enum FilterLocation { SlotName = 0, SlotDescription = 1,