diff --git a/.vs/csgo-network-log-parser/v16/.suo b/.vs/csgo-network-log-parser/v16/.suo index 3f49ba5..01a834f 100644 Binary files a/.vs/csgo-network-log-parser/v16/.suo and b/.vs/csgo-network-log-parser/v16/.suo differ diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json index e6074fd..6f9a4a1 100644 --- a/src/Properties/launchSettings.json +++ b/src/Properties/launchSettings.json @@ -22,6 +22,7 @@ "CSGO_ServersToReactTo": "", "CSGO_ApiEndpointsToCall": "http://127.0.0.1/webhook?action=%%ServerAction%%&Token=123;http://127.0.0.1/wow?action=%%ServerAction%%&Token=123", "CSGO_UDP_PORT": "9000", + "ASPNETCORE_URLS": "http://+:5000", "CSGO_DebugMode": "true", "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/src/controllers/LogController.cs b/src/controllers/LogController.cs new file mode 100644 index 0000000..39c4664 --- /dev/null +++ b/src/controllers/LogController.cs @@ -0,0 +1,51 @@ +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace CSGO_DataLogger.controllers +{ + [ApiController] + [Route("Log")] + public class LogController : ControllerBase + { + private readonly ILogger _logger; + private readonly ConfigCache _configCache; + private readonly LogManager _logManager; + + public LogController(ILogger logger,ConfigCache configCache, LogManager logManager) + { + _logger = logger; + _configCache = configCache; + _logManager = logManager; + } + + [HttpPost] + [Route("Log")] + //[ReadableBodyStream] + public async Task Log(CancellationToken cancellationToken) + { + string lines = await StreamToStringAsync(Request); + foreach (string line in lines.Split('\n')) + { + if (_configCache.Debug) + { + _logger.LogInformation($"Recieved: {line}"); + Task.Run(() => _logManager.ParseLog(Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "Unknown", line, cancellationToken)); + } + } + } + + private async Task StreamToStringAsync(HttpRequest request) + { + using (var sr = new StreamReader(request.Body)) + { + return await sr.ReadToEndAsync(); + } + } + } +} \ No newline at end of file