This repository has been archived on 2025-01-22. You can view files and clone it, but cannot push or open issues or pull requests.
SCHALE.GameServer/SCHALE.GameClient/GameClient.cs

167 lines
79 KiB
C#
Raw Normal View History

2024-11-16 11:55:27 +00:00
using Microsoft.AspNetCore.Http;
using Microsoft.IdentityModel.Tokens;
using MX.Core.Crypto;
using SCHALE.Common.NetworkProtocol;
2024-11-16 11:55:27 +00:00
using SCHALE.GameServer.Utils;
using Serilog;
2024-11-16 11:55:27 +00:00
using System.Text.Json;
2024-11-16 11:55:27 +00:00
namespace SCHALE.GameServer.Services
{
2024-11-16 11:55:27 +00:00
public class GameClient
{
2024-11-16 11:55:27 +00:00
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)
{
2024-11-16 11:55:27 +00:00
GameClient gameClient = new GameClient();
2024-11-16 11:55:27 +00:00
if (args.Length < 2 && (gameClient.AccountServerId == -1 || gameClient.MxToken == ""))
{
2024-11-16 11:55:27 +00:00
Log.Information("Please input the nessary data.");
return;
}
2024-11-16 11:55:27 +00:00
if (gameClient.AccountServerId == -1)
{
gameClient.AccountServerId = int.Parse(args[0]);
}
2024-11-16 11:55:27 +00:00
if (gameClient.MxToken.IsNullOrEmpty())
{
2024-11-16 11:55:27 +00:00
gameClient.MxToken = args[1];
}
await gameClient.SendPostRequestAsync(OFFICIAL_API_URL, new AccountLoginSyncRequest()
{
SyncProtocols = [Protocol.Item_List],
});
//var EliminateRaid_CreateBattlePcap = PcapUtils.GetPacketFromPcap<EliminateRaidCreateBattleRequest>(Protocol.EliminateRaid_CreateBattle, PacketType.Request);
//var EliminateRaid_EndBattlePcap = PcapUtils.GetPacketFromPcap<EliminateRaidEndBattleRequest>(Protocol.EliminateRaid_EndBattle, PacketType.Request);
//EliminateRaid_CreateBattlePcap.IsPractice = false;
//EliminateRaid_EndBattlePcap.IsPractice = false;
//await gameClient.SendPostRequestAsync(OFFICIAL_API_URL, EliminateRaid_CreateBattlePcap);
//await gameClient.SendPostRequestAsync(OFFICIAL_API_URL, EliminateRaid_EndBattlePcap);
//EliminateRaid_EndBattlePcap.RaidServerId = 2;
//await gameClient.SendPostRequestAsync(OFFICIAL_API_URL, new AcademyGetInfoRequest(){ });
/*
2024-11-16 11:55:27 +00:00
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)
}
],
2024-11-16 11:55:27 +00:00
Currency = new()
{
currencyValue = new()
{
Values = new()
{
{ CurrencyTypes.Gem, 120 }
},
Tickets = new() { },
Property = new() { },
Gem = 120,
IsEmpty = false
},
2024-11-16 11:55:27 +00:00
Gold = 0,
Gem = 120,
2024-11-16 11:55:27 +00:00
},
EquipmentDBs = [],
ItemDBs = [],
FurnitureDBs = [],
ConsumeCondition = 0,
},
GoodsId = 35840,
ShopUniqueId = 50668,
});
*/
}
public async Task<string> SendPostRequestAsync<T>(string url, T requestPacket) where T : RequestPacket
2024-11-16 11:55:27 +00:00
{
requestPacket.SessionKey = new()
{
MxToken = this.MxToken,
AccountServerId = this.AccountServerId,
};
2024-11-16 11:55:27 +00:00
requestPacket.Hash = this.Hash;
requestPacket.Resendable = true;
requestPacket.ClientUpTime = 0;
requestPacket.IsTest = false;
string packetJsonStr = JsonSerializer.Serialize((T)requestPacket);
//packetJsonStr = "{{\"Protocol\":45006,\"EchelonId\":1,\"RaidServerId\":0,\"IsPractice\":true,\"Summary\":{\"IsAbort\":false,\"IsDefeatBattle\":false,\"HashKey\":0,\"IsBossBattle\":true,\"BattleType\":16384,\"StageId\":2032301,\"GroundId\":6022301,\"Winner\":\"Group01\",\"EndType\":4,\"EndFrame\":4983,\"Group01Summary\":{\"TeamId\":1,\"LeaderEntityId\":{\"uniqueId\":16777217},\"Heroes\":[{\"ServerId\":278143883,\"OwnerAccountId\":50868960,\"BattleEntityId\":{\"uniqueId\":16777217},\"CharacterId\":10036,\"CostumeId\":0,\"Grade\":5,\"Level\":52,\"PotentialStatLevel\":{\"MaxHP\":0,\"AttackPower\":0,\"HealPower\":0},\"ExSkillLevel\":1,\"PublicSkillLevel\":3,\"PassiveSkillLevel\":1,\"ExtraPassiveSkillLevel\":3,\"FavorRank\":7,\"StatSnapshotCollection\":[{\"Stat\":1,\"Start\":21369,\"End\":21369},{\"Stat\":2,\"Start\":2354,\"End\":2354},{\"Stat\":3,\"Start\":100,\"End\":100},{\"Stat\":4,\"Start\":4641,\"End\":4641},{\"Stat\":5,\"Start\":101,\"End\":101},{\"Stat\":7,\"Start\":1086,\"End\":1086},{\"Stat\":9,\"Start\":282,\"End\":282},{\"Stat\":12,\"Start\":20000,\"End\":24624},{\"Stat\":30,\"Start\":10000,\"End\":10000},{\"Stat\":34,\"Start\":10000,\"End\":10000},{\"Stat\":42,\"Start\":700,\"End\":775},{\"Stat\":44,\"Start\":0,\"End\":0}],\"HPRateBefore\":10000,\"HPRateAfter\":9922,\"CrowdControlCount\":0,\"CrowdControlDuration\":0,\"EvadeCount\":14,\"DamageImmuneCount\":0,\"CrowdControlImmuneCount\":0,\"MaxAttackPower\":3505,\"AverageCriticalRate\":2307,\"AverageStabilityRate\":8517,\"AverageAccuracyRate\":8188,\"DeadFrame\":-1,\"DamageGivenAbsorbedSum\":0,\"TacticEntityType\":1,\"GivenNumericLogs\":[{\"EntityType\":\"Character\",\"Category\":1,\"Source\":1,\"CalculatedSum\":99250,\"AppliedSum\":40481,\"Count\":18,\"CriticalMultiplierMax\":19624,\"CriticalCount\":4,\"CalculatedMin\":4010,\"CalculatedMax\":8400,\"AppliedMin\":378,\"AppliedMax\":8448},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":5,\"CalculatedSum\":49467,\"AppliedSum\":0,\"Count\":38,\"CriticalMultiplierMax\":19624,\"CriticalCount\":9,\"CalculatedMin\":955,\"CalculatedMax\":2006,\"AppliedMin\":0,\"AppliedMax\":0},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":3,\"CalculatedSum\":229367,\"AppliedSum\":12546,\"Count\":16,\"CriticalMultiplierMax\":19624,\"CriticalCount\":6,\"CalculatedMin\":9808,\"CalculatedMax\":20496,\"AppliedMin\":0,\"AppliedMax\":3711},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":2,\"CalculatedSum\":450638,\"AppliedSum\":67764,\"Count\":32,\"CriticalMultiplierMax\":19624,\"CriticalCount\":5,\"CalculatedMin\":9926,\"CalculatedMax\":20251,\"AppliedMin\":825,\"AppliedMax\":3711}],\"TakenNumericLogs\":[{\"EntityType\":\"Character\",\"Category\":1,\"Source\":1,\"CalculatedSum\":264,\"AppliedSum\":167,\"Count\":6,\"CriticalMultiplierMax\":10000,\"CriticalCount\":0,\"CalculatedMin\":22,\"CalculatedMax\":86,\"AppliedMin\":13,\"AppliedMax\":81}],\"Equipments\":[{\"ServerId\":1592147985,\"UniqueId\":1001,\"Level\":20,\"Tier\":2},{\"ServerId\":1592251648,\"UniqueId\":6001,\"Level\":20,\"Tier\":2},{\"ServerId\":1694587612,\"UniqueId\":8000,\"Level\":10,\"Tier\":1}],\"CharacterWeapon\":{\"UniqueId\":10036,\"StarGrade\":1,\"Level\":1},\"SkillCount\":{\"PublicSkill01\":7,\"ExSkill01\":4},\"KillLog\":{\"16777224\":311,\"16777226\":537,\"16777227\":602,\"16777231\":682,\"16777236\":1051,\"16777237\":1051,\"16777239\":1041,\"16777240\":1187,\"16777243\":1058,\"16777245\":1066,\"16777247\":1041,\"16777248\":1041,\"16777249\":1066,\"16777250\":1066,\"16777256\":1599,\"16777259\":1970,\"16777260\":1970,\"16777262\":1970,\"16777264\":1970,\"16777268\":1834,\"16777271\":2550,\"16777275\":2365,\"16777279\":2430,\"16777290\":3127,\"16777291\":3152,\"16777292\":3137,\"16777293\":3152,\"16777296\":3127,\"16777297\":3039,\"16777298\":3152,\"16777299\":3127,\"16777300\":3152,\"16777307\":3398,\"16777310\":3718,\"16777312\":3924,\"16777314\":4191,\"16777317\":4071,\"16777319\":3846,\"16777322\":4479,\"16777324\":4485,\"16777325\":4494,\"16777326\":4499,\"16777328\":4469,\"16777329\":4469,\"16777330\":4870,\"16777331\":4740,\"16777
//packetJsonStr = "{\"Protocol\":45006,\"EchelonId\":1,\"RaidServerId\":2,\"IsPractice\":true,\"Summary\":{\"IsAbort\":false,\"IsDefeatBattle\":false,\"HashKey\":0,\"IsBossBattle\":true,\"BattleType\":16384,\"StageId\":2032301,\"GroundId\":6022301,\"Winner\":\"Group01\",\"EndType\":4,\"EndFrame\":5325,\"Group01Summary\":{\"TeamId\":1,\"LeaderEntityId\":{\"uniqueId\":16777217},\"Heroes\":[{\"ServerId\":278143883,\"OwnerAccountId\":50868960,\"BattleEntityId\":{\"uniqueId\":16777217},\"CharacterId\":10036,\"CostumeId\":0,\"Grade\":5,\"Level\":52,\"PotentialStatLevel\":{\"MaxHP\":0,\"AttackPower\":0,\"HealPower\":0},\"ExSkillLevel\":1,\"PublicSkillLevel\":3,\"PassiveSkillLevel\":1,\"ExtraPassiveSkillLevel\":3,\"FavorRank\":7,\"StatSnapshotCollection\":[{\"Stat\":1,\"Start\":21369,\"End\":21369},{\"Stat\":2,\"Start\":2354,\"End\":2354},{\"Stat\":3,\"Start\":100,\"End\":100},{\"Stat\":4,\"Start\":4641,\"End\":4641},{\"Stat\":5,\"Start\":101,\"End\":101},{\"Stat\":7,\"Start\":1086,\"End\":1086},{\"Stat\":9,\"Start\":282,\"End\":282},{\"Stat\":12,\"Start\":20000,\"End\":24624},{\"Stat\":30,\"Start\":10000,\"End\":10000},{\"Stat\":34,\"Start\":10000,\"End\":10000},{\"Stat\":42,\"Start\":700,\"End\":775},{\"Stat\":44,\"Start\":0,\"End\":0}],\"HPRateBefore\":10000,\"HPRateAfter\":9858,\"CrowdControlCount\":0,\"CrowdControlDuration\":0,\"EvadeCount\":14,\"DamageImmuneCount\":0,\"CrowdControlImmuneCount\":0,\"MaxAttackPower\":3505,\"AverageCriticalRate\":3097,\"AverageStabilityRate\":8602,\"AverageAccuracyRate\":7902,\"DeadFrame\":-1,\"DamageGivenAbsorbedSum\":0,\"TacticEntityType\":1,\"GivenNumericLogs\":[{\"EntityType\":\"Character\",\"Category\":1,\"Source\":1,\"CalculatedSum\":109804,\"AppliedSum\":36801,\"Count\":20,\"CriticalMultiplierMax\":19624,\"CriticalCount\":4,\"CalculatedMin\":3936,\"CalculatedMax\":8083,\"AppliedMin\":0,\"AppliedMax\":5109},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":5,\"CalculatedSum\":58493,\"AppliedSum\":0,\"Count\":45,\"CriticalMultiplierMax\":19624,\"CriticalCount\":13,\"CalculatedMin\":960,\"CalculatedMax\":2018,\"AppliedMin\":0,\"AppliedMax\":0},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":3,\"CalculatedSum\":229937,\"AppliedSum\":18046,\"Count\":16,\"CriticalMultiplierMax\":19624,\"CriticalCount\":6,\"CalculatedMin\":10149,\"CalculatedMax\":19756,\"AppliedMin\":0,\"AppliedMax\":3711},{\"EntityType\":\"Character\",\"Category\":1,\"Source\":2,\"CalculatedSum\":387477,\"AppliedSum\":72120,\"Count\":32,\"CriticalMultiplierMax\":19624,\"CriticalCount\":12,\"CalculatedMin\":10252,\"CalculatedMax\":14162,\"AppliedMin\":929,\"AppliedMax\":3711}],\"TakenNumericLogs\":[{\"EntityType\":\"Character\",\"Category\":1,\"Source\":1,\"CalculatedSum\":544,\"AppliedSum\":305,\"Count\":13,\"CriticalMultiplierMax\":15000,\"CriticalCount\":5,\"CalculatedMin\":33,\"CalculatedMax\":87,\"AppliedMin\":7,\"AppliedMax\":123}],\"Equipments\":[{\"ServerId\":1592147985,\"UniqueId\":1001,\"Level\":20,\"Tier\":2},{\"ServerId\":1592251648,\"UniqueId\":6001,\"Level\":20,\"Tier\":2},{\"ServerId\":1694587612,\"UniqueId\":8000,\"Level\":10,\"Tier\":1}],\"CharacterWeapon\":{\"UniqueId\":10036,\"StarGrade\":1,\"Level\":1},\"SkillCount\":{\"PublicSkill01\":8,\"ExSkill01\":4},\"KillLog\":{\"16777222\":311,\"16777224\":246,\"16777226\":540,\"16777231\":605,\"16777232\":686,\"16777239\":949,\"16777246\":938,\"16777247\":938,\"16777248\":949,\"16777249\":964,\"16777250\":964,\"16777256\":1914,\"16777259\":1924,\"16777260\":1832,\"16777262\":1924,\"16777263\":1939,\"16777264\":1914,\"16777265\":1939,\"16777268\":2079,\"16777271\":2353,\"16777274\":2763,\"16777275\":2416,\"16777277\":2494,\"16777279\":2660,\"16777290\":3475,\"16777291\":3449,\"16777294\":3475,\"16777298\":3460,\"16777299\":3460,\"16777301\":3475,\"16777303\":3460,\"16777304\":3449,\"16777308\":3911,\"16777309\":3846,\"16777313\":4023,\"16777316\":4387,\"16777318\":4406,\"16777319\":4406,\"16777320\":4406,\"16777321\":4376,\"16777322\":4387,\"16777323\":4376,\"16777327\":4810,\"16777329\":4745,\"16777331\":5115,\"16777333\":4983,\"16777335\
2024-11-16 11:55:27 +00:00
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");
2024-11-16 11:55:27 +00:00
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);
return responseBody;
}
}
}