mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-12-24 16:27:23 +01:00
Add basic crash report uploader/processor.
This commit is contained in:
parent
624084421e
commit
4877479528
12
GPatch/CopyBinaries.bat
Normal file
12
GPatch/CopyBinaries.bat
Normal file
@ -0,0 +1,12 @@
|
||||
xcopy "%GIANTS_PATH%\gg_dx7r.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\gg_dx9r.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\Giants.exe" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\GiantsMain.exe" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\GiantsDedicated.exe" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\gs_ds.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\Giants.WebApi.Clients.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\fmt.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\BugTrap.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\cpprest_2_10.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\Newtonsoft.Json.dll" "Files\" /Y
|
||||
xcopy "%GIANTS_PATH%\zlib1.dll" "Files\" /Y
|
@ -42,7 +42,7 @@ SetCompressor /SOLID lzma
|
||||
; MUI end ------
|
||||
|
||||
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
|
||||
OutFile "Output\GPatch1_498_201_0.exe"
|
||||
OutFile "Output\GPatch1_498_204_0.exe"
|
||||
InstallDir "$PROGRAMFILES\Giants\"
|
||||
InstallDirRegKey HKCU "SOFTWARE\PlanetMoon\Giants" "DestDir"
|
||||
ShowInstDetails hide
|
||||
|
@ -18,6 +18,7 @@
|
||||
services.AddSingleton<IUpdaterStore, CosmosDbUpdaterStore>();
|
||||
services.AddSingleton<IUpdaterService, UpdaterService>();
|
||||
services.AddSingleton<ICommunityService, CommunityService>();
|
||||
services.AddSingleton<ICrashReportService, CrashReportService>();
|
||||
|
||||
services.AddHostedService<InitializerService>();
|
||||
services.AddHostedService<ServerRegistryCleanupService>();
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
||||
<PackageReference Include="Azure.Storage.Blobs" Version="12.5.1" />
|
||||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.12.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.6" />
|
||||
|
48
Giants.Services/Services/CrashReportService.cs
Normal file
48
Giants.Services/Services/CrashReportService.cs
Normal file
@ -0,0 +1,48 @@
|
||||
namespace Giants.Services.Services
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Azure.Storage.Blobs;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public class CrashReportService : ICrashReportService
|
||||
{
|
||||
private readonly BlobServiceClient blobServiceClient;
|
||||
private readonly IConfiguration configuration;
|
||||
private readonly ILogger<CrashReportService> logger;
|
||||
|
||||
public CrashReportService(
|
||||
IConfiguration configuration,
|
||||
ILogger<CrashReportService> logger)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
this.logger = logger;
|
||||
|
||||
string blobConnectionString = configuration["BlobConnectionString"];
|
||||
this.blobServiceClient = new BlobServiceClient(blobConnectionString);
|
||||
}
|
||||
|
||||
public async Task ProcessReport(string fileName, string senderIpAddress, Stream stream)
|
||||
{
|
||||
this.logger.LogInformation("Processing crash report file {FileName} from {IP}", fileName, senderIpAddress);
|
||||
|
||||
var containerClient = this.blobServiceClient.GetBlobContainerClient(
|
||||
this.configuration["CrashBlobContainerName"]);
|
||||
|
||||
string blobPath = this.GetBlobPath(fileName);
|
||||
var blobClient = containerClient.GetBlobClient(blobPath);
|
||||
|
||||
this.logger.LogInformation("Saving {FileName} to path: {Path}", fileName, blobPath);
|
||||
|
||||
await blobClient.UploadAsync(stream).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private string GetBlobPath(string fileName)
|
||||
{
|
||||
DateTime dateTime = DateTime.Now;
|
||||
return $"{dateTime.Year}/{dateTime.Month}/{dateTime.Day}/{fileName}";
|
||||
}
|
||||
}
|
||||
}
|
10
Giants.Services/Services/ICrashReportService.cs
Normal file
10
Giants.Services/Services/ICrashReportService.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Giants.Services.Services
|
||||
{
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface ICrashReportService
|
||||
{
|
||||
Task ProcessReport(string fileName, string senderIpAddress, Stream stream);
|
||||
}
|
||||
}
|
67
Giants.WebApi/Controllers/CrashReportsController.cs
Normal file
67
Giants.WebApi/Controllers/CrashReportsController.cs
Normal file
@ -0,0 +1,67 @@
|
||||
namespace Giants.WebApi.Controllers
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Giants.Services.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CrashReportsController : ControllerBase
|
||||
{
|
||||
private readonly ICrashReportService crashReportService;
|
||||
private readonly IHttpContextAccessor httpContextAccessor;
|
||||
|
||||
private const long MaximumSizeInBytes = 5242880; // 5MB
|
||||
|
||||
public CrashReportsController(
|
||||
ICrashReportService crashReportService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
this.crashReportService = crashReportService;
|
||||
this.httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task Upload()
|
||||
{
|
||||
this.ValidateFiles(this.Request.Form.Files);
|
||||
|
||||
var file = this.Request.Form.Files.First();
|
||||
using (var stream = file.OpenReadStream())
|
||||
{
|
||||
await this.crashReportService.ProcessReport(file.FileName, this.GetRequestIpAddress(), stream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateFiles(IEnumerable<IFormFile> formFiles)
|
||||
{
|
||||
if (formFiles.Count() != 1)
|
||||
{
|
||||
// We only expect one .zip file
|
||||
throw new ArgumentException("Only one file is accepted.", nameof(formFiles));
|
||||
}
|
||||
|
||||
var file = this.Request.Form.Files.First();
|
||||
if (file.Length > MaximumSizeInBytes)
|
||||
{
|
||||
throw new ArgumentException("File too large.", nameof(formFiles));
|
||||
}
|
||||
|
||||
string fileName = Path.GetFileNameWithoutExtension(file.FileName);
|
||||
if (!Guid.TryParse(fileName, out Guid _) || file.Name != "crashrpt")
|
||||
{
|
||||
throw new ArgumentException("Unexpected file name.", nameof(formFiles));
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRequestIpAddress()
|
||||
{
|
||||
return this.httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,5 +12,7 @@
|
||||
"ServerTimeoutPeriodInMinutes": "7",
|
||||
"ServerCleanupIntervalInMinutes": "1",
|
||||
"MaxServerCount": 1000,
|
||||
"DiscordUri": "https://discord.gg/Avj4azU"
|
||||
"DiscordUri": "https://discord.gg/Avj4azU",
|
||||
"BlobConnectionString": "",
|
||||
"CrashBlobContainerName": "crashes"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user