From f36106cc86d4ed6e669561e26218d2e34459d5d1 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 27 Oct 2021 21:29:22 -0400 Subject: [PATCH] Log filter requests --- ProjectLighthouse/Controllers/MessageController.cs | 11 ++++++++++- ProjectLighthouse/Logging/LoggerLevels.cs | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Controllers/MessageController.cs b/ProjectLighthouse/Controllers/MessageController.cs index ff6b8112..b060c88f 100644 --- a/ProjectLighthouse/Controllers/MessageController.cs +++ b/ProjectLighthouse/Controllers/MessageController.cs @@ -1,5 +1,7 @@ using System.IO; using System.Threading.Tasks; +using Kettu; +using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; @@ -32,10 +34,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers { } /// /// Filters chat messages sent by a user. + /// The reponse sent is the text that will appear in-game. /// [HttpPost("filter")] public async Task Filter() { - return this.Ok(await new StreamReader(this.Request.Body).ReadToEndAsync()); + User user = await this.database.UserFromRequest(this.Request); + if(user == null) return this.StatusCode(403, ""); + + string loggedText = await new StreamReader(this.Request.Body).ReadToEndAsync(); + + Logger.Log($"{user.Username}: {loggedText}", LoggerLevelFilter.Instance); + return this.Ok(loggedText); } } } \ No newline at end of file diff --git a/ProjectLighthouse/Logging/LoggerLevels.cs b/ProjectLighthouse/Logging/LoggerLevels.cs index 72831dd3..7ddb690c 100644 --- a/ProjectLighthouse/Logging/LoggerLevels.cs +++ b/ProjectLighthouse/Logging/LoggerLevels.cs @@ -16,6 +16,11 @@ namespace LBPUnion.ProjectLighthouse.Logging { public override string Name => "HTTP"; public static readonly LoggerLevelHttp Instance = new(); } + + public class LoggerLevelFilter : LoggerLevel { + public override string Name => "Filter"; + public static readonly LoggerLevelFilter Instance = new(); + } public class LoggerLevelAspNet : LoggerLevel { public override string Name => "AspNet";