Stuff works

This commit is contained in:
gamer147
2024-09-08 10:27:12 -04:00
parent 7e4bce9ac5
commit ac3b002d74
14 changed files with 157 additions and 87 deletions

View File

@@ -4,7 +4,10 @@ using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using SVSim.Database.Models;
using SVSim.EmulatedEntrypoint.Constants;
using SVSim.EmulatedEntrypoint.Extensions;
using SVSim.EmulatedEntrypoint.Models.Dtos;
using SVSim.EmulatedEntrypoint.Security;
using SVSim.EmulatedEntrypoint.Services;
@@ -61,8 +64,10 @@ public class ShadowverseTranslationMiddleware : IMiddleware
context.Request.Headers.ContentType = new StringValues("application/json");
await next.Invoke(context);
Viewer? viewer = context.GetViewer();
// Convert the response into a messagepack, encrypt it
// Grab the response object
var responseType = ((ControllerActionDescriptor)endpointDescriptor).MethodInfo.ReturnType;
if (responseType.IsGenericType && responseType.GetGenericTypeDefinition() == typeof(Task<>))
{
@@ -73,7 +78,25 @@ public class ShadowverseTranslationMiddleware : IMiddleware
await context.Response.Body.CopyToAsync(responseBytesStream);
var responseBytes = responseBytesStream.ToArray();
var responseData = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(responseBytes), responseType);
var packedData = MessagePackSerializer.Serialize(responseType, responseData);
// Wrap the response in a datawrapper
DataWrapper wrappedResponseData = new DataWrapper
{
Data = responseData,
DataHeaders = new DataHeaders
{
Servertime = DateTime.UtcNow.Ticks,
Sid =
context.Request.Headers[NetworkConstants.SessionIdHeaderName].FirstOrDefault(),
// TODO error handling
ResultCode = 1,
ShortUdid = viewer.ShortUdid,
ViewerId = viewer.Id
}
};
// Convert the response into a messagepack, encrypt it
var packedData = MessagePackSerializer.Serialize<DataWrapper>(wrappedResponseData);
packedData = Encryption.Encrypt(packedData, udid);
await originalResponsebody.WriteAsync(Encoding.UTF8.GetBytes(Convert.ToBase64String(packedData)));
context.Response.Body = originalResponsebody;