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