Skip to content

Commit

Permalink
nu med basic http listner
Browse files Browse the repository at this point in the history
  • Loading branch information
brianholmgreen committed Oct 16, 2021
1 parent 427d588 commit 3359c75
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Binary file modified .vs/csgo-network-log-parser/v16/.suo
Binary file not shown.
1 change: 1 addition & 0 deletions src/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
51 changes: 51 additions & 0 deletions src/controllers/LogController.cs
Original file line number Diff line number Diff line change
@@ -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<LogController> 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<string> StreamToStringAsync(HttpRequest request)
{
using (var sr = new StreamReader(request.Body))
{
return await sr.ReadToEndAsync();
}
}
}
}

0 comments on commit 3359c75

Please sign in to comment.