SCHALE.GameServer/SCHALE.GameClient/GameClient.cs

157 lines
5.2 KiB
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.IdentityModel.Tokens;
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.Collections;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Text.Json;
namespace SCHALE.GameServer.Services
{
public class GameClient
{
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 = "https://prod-game.bluearchiveyostar.com:5000/api/gateway";
private long AccountServerId = -1;
private string MxToken = "";
private long Hash = 0;
public GameClient()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Log.Information("Application starting up...");
httpClient = new HttpClient();
}
public static async Task Main(string[] args)
{
GameClient gameClient = new GameClient();
if (args.Length < 2 && (gameClient.AccountServerId == -1 || gameClient.MxToken == ""))
{
Log.Information("Please input the nessary data.");
return;
}
if (gameClient.AccountServerId == -1)
{
gameClient.AccountServerId = int.Parse(args[0]);
}
if (gameClient.MxToken.IsNullOrEmpty())
{
gameClient.MxToken = args[1];
}
await gameClient.SendPostRequestAsync(OFFICIAL_API_URL, new AcademyGetInfoRequest(){ });
/*
await gameClient.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("Written All Bytes");
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("mx", "1");
request.Headers.Add("Bundle-Version", "li3pmyogha");
var content = new MultipartFormDataContent();
content.Add(new StreamContent(new MemoryStream(payload)), "mx", ".mx.dat");
request.Content = content;
Log.Information("Sending POST Request!");
var response = await httpClient.SendAsync(request);
// Response
Log.Information("Response Details:");
Log.Information($"Status Code: {response.StatusCode}");
string responseBody = await response.Content.ReadAsStringAsync();
Log.Information("Response Body:");
Log.Information(responseBody);
}
}
}