forked from Raphael/SCHALE.GameServer
162 lines
5.8 KiB
C#
162 lines
5.8 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
|
using MX.Core.Crypto;
|
|
using Newtonsoft.Json.Linq;
|
|
using SCHALE.Common.Crypto;
|
|
using SCHALE.Common.Crypto.XXHash;
|
|
using SCHALE.Common.FlatData;
|
|
using SCHALE.Common.NetworkProtocol;
|
|
using SCHALE.GameServer.Utils;
|
|
using Serilog;
|
|
using System.Net.Http.Headers;
|
|
using System.Text.Json;
|
|
|
|
namespace SCHALE.GameServer.Services
|
|
{
|
|
public class PrivateClientService : BackgroundService
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public static readonly string PS_URL = "http://10.0.0.149/api/gateway";
|
|
public static readonly string MITM_URL = "http://10.0.0.149:8080";
|
|
public static readonly string OFFICIAL_API_URL = "http://prod-gateway.bluearchiveyostar.com:5100/api/";
|
|
|
|
private readonly long AccountServerId = -1;
|
|
private readonly string MxToken = "";
|
|
private readonly long Hash = 0;
|
|
|
|
public PrivateClientService(HttpClient httpClient)
|
|
{
|
|
_httpClient = httpClient;
|
|
}
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
//await SendPostRequestAsync(OFFICIAL_API_URL, new AcademyGetInfoRequest(){ });
|
|
|
|
await SendPostRequestAsync(OFFICIAL_API_URL, new ShopBuyGacha3Request()
|
|
{
|
|
FreeRecruitId = 0,
|
|
Cost = new()
|
|
{
|
|
ParcelInfos = [
|
|
new()
|
|
{
|
|
Key = new()
|
|
{
|
|
Type = ParcelType.Currency,
|
|
Id = 4,
|
|
},
|
|
Amount = 120,
|
|
Multiplier = new(10000),
|
|
Probability = new(10000)
|
|
}
|
|
],
|
|
|
|
Currency = new()
|
|
{
|
|
currencyValue = new()
|
|
{
|
|
Values = new()
|
|
{
|
|
{ CurrencyTypes.Gem, 120 }
|
|
},
|
|
Tickets = new() { },
|
|
Property = new() { },
|
|
Gem = 120,
|
|
IsEmpty = false
|
|
},
|
|
|
|
Gold = 0,
|
|
Gem = 120,
|
|
|
|
},
|
|
EquipmentDBs = [],
|
|
ItemDBs = [],
|
|
FurnitureDBs = [],
|
|
ConsumeCondition = 0,
|
|
},
|
|
GoodsId = 35840,
|
|
ShopUniqueId = 50668,
|
|
});
|
|
}
|
|
|
|
public async Task SendPostRequestAsync<T>(string url, T requestPacket) where T : RequestPacket
|
|
{
|
|
requestPacket.SessionKey = new()
|
|
{
|
|
MxToken = this.MxToken,
|
|
AccountServerId = this.AccountServerId,
|
|
};
|
|
|
|
requestPacket.Hash = this.Hash;
|
|
requestPacket.Resendable = true;
|
|
requestPacket.ClientUpTime = 0;
|
|
requestPacket.IsTest = false;
|
|
|
|
string packetJsonStr = JsonSerializer.Serialize((T)requestPacket);
|
|
|
|
Log.Information("Sending Post Request to " + url);
|
|
Log.Information($"Payload: {packetJsonStr}");
|
|
|
|
byte[] payload = PacketCryptManager.Instance.RequestToBinary(requestPacket.Protocol, packetJsonStr);
|
|
|
|
File.WriteAllBytes("./mx.dat", payload);
|
|
Log.Information("Writeen All Bytes");
|
|
|
|
return;
|
|
|
|
using var fileStream = new FileStream("./mx.dat", FileMode.Create, FileAccess.Write);
|
|
using var binaryWriterFile = new BinaryWriter(fileStream);
|
|
|
|
binaryWriterFile.Write(payload);
|
|
|
|
var mxFile = new StreamContent(binaryWriterFile.BaseStream);
|
|
|
|
mxFile.Headers.ContentType = MediaTypeHeaderValue.Parse("application/octet-stream");
|
|
|
|
// Add the in-memory content as a file with a name
|
|
var boundary = "BestHTTP_HTTPMultiPartForm_328B5160";
|
|
using var content = new MultipartFormDataContent(boundary);
|
|
|
|
content.Add(mxFile, "mx", "1");
|
|
|
|
content.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
|
|
content.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("boundary", boundary));
|
|
|
|
// Set up custom headers to match the request shown
|
|
_httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
|
|
_httpClient.DefaultRequestHeaders.Add("Bundle-Version", "li3pmyogha");
|
|
_httpClient.DefaultRequestHeaders.Connection.Add("Keep-Alive");
|
|
_httpClient.DefaultRequestHeaders.Connection.Add("TE");
|
|
_httpClient.DefaultRequestHeaders.Add("Keep-Alive", "timeout=21");
|
|
//_httpClient.DefaultRequestHeaders.Add("TE", "identity");
|
|
_httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("BestHTTP/2 v2.4.0");
|
|
|
|
|
|
// Send the POST request
|
|
HttpResponseMessage response = await _httpClient.PostAsync(url, content);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string responseData = await response.Content.ReadAsStringAsync();
|
|
Log.Information("Success: " + responseData);
|
|
}
|
|
|
|
else
|
|
{
|
|
Log.Information($"Error: {response.StatusCode}");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
internal static class PrivateClientServiceExtensions
|
|
{
|
|
public static void AddPrivateClientService(this IServiceCollection services)
|
|
{
|
|
services.AddHostedService<PrivateClientService>();
|
|
}
|
|
}
|
|
}
|