Http w/ dispatch

This commit is contained in:
rafi1212122
2023-05-24 17:18:36 +07:00
parent df32db9a60
commit 8343f08f90
15 changed files with 708 additions and 12 deletions

View File

@@ -0,0 +1,297 @@
using HttpServer.Models;
using Newtonsoft.Json;
using Common;
using System.Text.RegularExpressions;
namespace HttpServer.Controllers
{
public class DispatchController
{
public static void AddHandlers(WebApplication app)
{
app.Map("/query_dispatch", (ctx) =>
{
QueryDispatch rsp = new()
{
Retcode = 0,
RegionList = new Region[] {
new Region() {
Retcode = 0,
DispatchUrl = $"http://{Global.config.Gameserver.Host}/query_gateway",
Name = Global.config.Gameserver.RegionName,
Title = "",
Ext = GetExt(ctx.Request.Query["version"].ToString())
}
}
};
return ctx.Response.WriteAsync(JsonConvert.SerializeObject(rsp));
});
app.Map("/query_gateway", (ctx) =>
{
string Version = ctx.Request.Query["version"].ToString();
Gameserver Gameserver = new()
{
Ip = Global.config.Gameserver.Host,
Port = Global.config.Gameserver.Port
};
QueryGateway rsp = new()
{
Retcode = 0,
Msg = "",
RegionName = Global.config.Gameserver.RegionName,
AccountUrl = $"http://{Global.config.Gameserver.Host}/account",
AccountUrlBackup = $"http://{Global.config.Gameserver.Host}/account",
AssetBundleUrlList = GetAssetBundleUrlList(Version),
ExAudioAndVideoUrlList = GetExAudioAndVideoUrlList(Version),
ExResourceUrlList = GetExResourceUrlList(Version),
Ext = GetExt(Version),
Gameserver = Gameserver,
Gateway = Gameserver,
IsDataReady = true,
OaserverUrl = $"http://{Global.config.Gameserver.Host}/oaserver",
ServerCurTime = Global.GetUnixInSeconds(),
ServerCurTimezone = 8,
ServerExt = new ServerExt()
{
CdkeyUrl = $"http://{Global.config.Gameserver.Host}/common",
MihoyoSdkEnv = "2"
}
};
return ctx.Response.WriteAsync(JsonConvert.SerializeObject(rsp));
});
}
public static Ext GetExt(string version)
{
return new Ext()
{
AiUseAssetBoundle = "1",
ApmLogLevel = "2",
ApmSwitch = "1",
ApmSwitchCrash = "1",
DataUseAssetBoundle = "1",
EnableWatermark = "1",
ExAudioAndVideoUrlList = GetExAudioAndVideoUrlList(version),
ExResPrePublish = "0",
ExResUseHttp = "0",
ExResourceUrlList = GetExResourceUrlList(version),
ForbidRecharge = "1",
IsChecksumOff = "1",
OfflineReportSwitch = "1",
ResUseAssetBoundle = "1",
ShowVersionText = "0",
UpdateStreamingAsb = "1",
UseMultyCdn = "1",
ApmLogDest = "2",
ApmSwitchGameLog = "1",
BlockErrorDialog = "1",
ElevatorModelPath = "GameEntry/EVA/StartLoading_Model",
ExResBuffSize = "10485760",
IsXxxx = "1",
MtpSwitch = "0",
NetworkFeedbackEnable = "0",
ShowBulletinButton = "0",
ShowBulletinEmptyDialogBg = "0"
};
}
public static string[] GetAssetBundleUrlList(string version)
{
Regex regex = new Regex(@"^(.*?)_(os|gf|global)_(.*?)$");
Match matches = regex.Match(version);
if (matches.Success)
{
string type = matches.Groups[2].Value; // get the second group (os or gf)
switch (type)
{
case "os":
return Global.config.UseLocalCache ? new string[]
{
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1",
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1"
} : new string[]
{
"https://hk-bundle-os-mihayo.akamaized.net/asset_bundle/overseas01/1.1",
"https://bundle-aliyun-os.honkaiimpact3.com/asset_bundle/overseas01/1.1"
};
case "gf":
if (version.Contains("beta"))
{
return Global.config.UseLocalCache ? new string[]
{
$"https://{Global.config.Gameserver.Host}/asset_bundle/beta_release/1.0",
$"https://{Global.config.Gameserver.Host}/asset_bundle/beta_release/1.0"
} : new string[]
{
"https://bh3rd-beta-qcloud.bh3.com/asset_bundle/beta_release/1.0",
"https://bh3rd-beta.bh3.com/asset_bundle/beta_release/1.0"
};
}
return Global.config.UseLocalCache ? new string[]
{
$"https://{Global.config.Gameserver.Host}/asset_bundle/android01/1.0",
$"https://{Global.config.Gameserver.Host}/asset_bundle/android01/1.0"
} : new string[]
{
"https://bundle-qcloud.bh3.com/asset_bundle/android01/1.0",
"https://bundle.bh3.com/asset_bundle/android01/1.0"
};
case "global":
return Global.config.UseLocalCache ? new string[]
{
$"https://{Global.config.Gameserver.Host}/asset_bundle/usa01/1.1",
$"https://{Global.config.Gameserver.Host}/asset_bundle/usa01/1.1"
} : new string[]
{
"http://hk-bundle-west-mihayo.akamaized.net/asset_bundle/usa01/1.1",
"http://bundle-aliyun-usa.honkaiimpact3.com/asset_bundle/usa01/1.1"
};
default:
return Global.config.UseLocalCache ? new string[]
{
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1",
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1"
} : new string[]
{
"https://hk-bundle-os-mihayo.akamaized.net/asset_bundle/overseas01/1.1",
"https://bundle-aliyun-os.honkaiimpact3.com/asset_bundle/overseas01/1.1"
};
}
}
else
{
return Global.config.UseLocalCache ? new string[]
{
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1",
$"http://{Global.config.Gameserver.Host}/asset_bundle/overseas01/1.1"
} : new string[]
{
"https://hk-bundle-os-mihayo.akamaized.net/asset_bundle/overseas01/1.1",
"https://bundle-aliyun-os.honkaiimpact3.com/asset_bundle/overseas01/1.1"
};
}
}
public static string[] GetExAudioAndVideoUrlList(string version)
{
Regex regex = new(@"^(.*?)_(os|gf|global)_(.*?)$");
Match matches = regex.Match(version);
if (matches.Success)
{
string type = matches.Groups[2].Value; // get the second group (os or gf)
switch (type)
{
case "os":
return new string[] { };
case "gf":
if (version.Contains("beta"))
{
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/tmp/CGAudio",
$"{Global.config.Gameserver.Host}/tmp/CGAudio"
} : new string[]
{
"bh3rd-beta-qcloud.bh3.com/tmp/CGAudio",
"bh3rd-beta.bh3.com/tmp/CGAudio"
};
}
return new string[] { };
case "global":
return new string[] { };
default:
return new string[] { };
}
}
else
{
return new string[] { };
}
}
public static string[] GetExResourceUrlList(string version)
{
Regex regex = new(@"^(.*?)_(os|gf|global)_(.*?)$");
Match matches = regex.Match(version);
if (matches.Success)
{
string type = matches.Groups[2].Value; // get the second group (os or gf)
switch (type)
{
case "os":
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea",
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea"
} : new string[]
{
"hk-bigfile-os-mihayo.akamaized.net/com.miHoYo.bh3oversea",
"bigfile-aliyun-os.honkaiimpact3.com/com.miHoYo.bh3oversea"
};
case "gf":
if (version.Contains("beta"))
{
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/tmp/beta",
$"{Global.config.Gameserver.Host}/tmp/beta"
} : new string[]
{
"bh3rd-beta-qcloud.bh3.com/tmp/beta",
"bh3rd-beta.bh3.com/tmp/beta"
};
}
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/tmp/Original",
$"{Global.config.Gameserver.Host}/tmp/Original"
} : new string[]
{
"bundle-qcloud.bh3.com/tmp/Original",
"bundle.bh3.com/tmp/Original"
};
case "global":
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/tmp/com.miHoYo.bh3global",
$"{Global.config.Gameserver.Host}/tmp/com.miHoYo.bh3global"
} : new string[]
{
"hk-bundle-west-mihayo.akamaized.net/tmp/com.miHoYo.bh3global",
"bigfile-aliyun-usa.honkaiimpact3.com/tmp/com.miHoYo.bh3global"
};
default:
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea",
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea"
} : new string[]
{
"hk-bigfile-os-mihayo.akamaized.net/com.miHoYo.bh3oversea",
"bigfile-aliyun-os.honkaiimpact3.com/com.miHoYo.bh3oversea"
};
}
}
else
{
return Global.config.UseLocalCache ? new string[]
{
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea",
$"{Global.config.Gameserver.Host}/com.miHoYo.bh3oversea"
} : new string[]
{
"hk-bigfile-os-mihayo.akamaized.net/com.miHoYo.bh3oversea",
"bigfile-aliyun-os.honkaiimpact3.com/com.miHoYo.bh3oversea"
};
}
}
}
}

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,186 @@
using Newtonsoft.Json;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
namespace HttpServer.Models
{
public partial class QueryDispatch
{
[JsonProperty("region_list")]
public Region[] RegionList { get; set; }
[JsonProperty("retcode")]
public int Retcode { get; set; }
}
public partial class QueryGateway
{
[JsonProperty("account_url")]
public string AccountUrl { get; set; }
[JsonProperty("account_url_backup")]
public string AccountUrlBackup { get; set; }
[JsonProperty("asset_bundle_url_list")]
public string[] AssetBundleUrlList { get; set; }
[JsonProperty("ex_audio_and_video_url_list")]
public object[] ExAudioAndVideoUrlList { get; set; }
[JsonProperty("ex_resource_url_list")]
public string[] ExResourceUrlList { get; set; }
[JsonProperty("ext")]
public Ext Ext { get; set; }
[JsonProperty("gameserver")]
public Gameserver Gameserver { get; set; }
[JsonProperty("gateway")]
public Gameserver Gateway { get; set; }
[JsonProperty("is_data_ready")]
public bool IsDataReady { get; set; }
[JsonProperty("msg")]
public string Msg { get; set; }
[JsonProperty("oaserver_url")]
public string OaserverUrl { get; set; }
[JsonProperty("region_name")]
public string RegionName { get; set; }
[JsonProperty("retcode")]
public int Retcode { get; set; }
[JsonProperty("server_cur_time")]
public long ServerCurTime { get; set; }
[JsonProperty("server_cur_timezone")]
public long ServerCurTimezone { get; set; }
[JsonProperty("server_ext")]
public ServerExt ServerExt { get; set; }
}
public partial class Ext
{
[JsonProperty("ai_use_asset_boundle")]
public string AiUseAssetBoundle { get; set; }
[JsonProperty("apm_log_dest")]
public string ApmLogDest { get; set; }
[JsonProperty("apm_log_level")]
public string ApmLogLevel { get; set; }
[JsonProperty("apm_switch")]
public string ApmSwitch { get; set; }
[JsonProperty("apm_switch_crash")]
public string ApmSwitchCrash { get; set; }
[JsonProperty("apm_switch_game_log")]
public string ApmSwitchGameLog { get; set; }
[JsonProperty("block_error_dialog")]
public string BlockErrorDialog { get; set; }
[JsonProperty("data_use_asset_boundle")]
public string DataUseAssetBoundle { get; set; }
[JsonProperty("enable_watermark")]
public string EnableWatermark { get; set; }
[JsonProperty("elevator_model_path")]
public string ElevatorModelPath { get; set; }
[JsonProperty("ex_audio_and_video_url_list")]
public string[] ExAudioAndVideoUrlList { get; set; }
[JsonProperty("ex_res_buff_size")]
public string ExResBuffSize { get; set; }
[JsonProperty("ex_res_pre_publish")]
public string ExResPrePublish { get; set; }
[JsonProperty("ex_res_use_http")]
public string ExResUseHttp { get; set; }
[JsonProperty("ex_resource_url_list")]
public string[] ExResourceUrlList { get; set; }
[JsonProperty("forbid_recharge")]
public string ForbidRecharge { get; set; }
[JsonProperty("is_checksum_off")]
public string IsChecksumOff { get; set; }
[JsonProperty("is_xxxx")]
public string IsXxxx { get; set; }
[JsonProperty("mtp_switch")]
public string MtpSwitch { get; set; }
[JsonProperty("network_feedback_enable")]
public string NetworkFeedbackEnable { get; set; }
[JsonProperty("offline_report_switch")]
public string OfflineReportSwitch { get; set; }
[JsonProperty("res_use_asset_boundle")]
public string ResUseAssetBoundle { get; set; }
[JsonProperty("show_bulletin_button")]
public string ShowBulletinButton { get; set; }
[JsonProperty("show_bulletin_empty_dialog_bg")]
public string ShowBulletinEmptyDialogBg { get; set; }
[JsonProperty("show_version_text")]
public string ShowVersionText { get; set; }
[JsonProperty("update_streaming_asb")]
public string UpdateStreamingAsb { get; set; }
[JsonProperty("use_multy_cdn")]
public string UseMultyCdn { get; set; }
}
public partial class Gameserver
{
[JsonProperty("ip")]
public string Ip { get; set; }
[JsonProperty("port")]
public uint Port { get; set; }
}
public partial class Region
{
[JsonProperty("dispatch_url")]
public string DispatchUrl { get; set; }
[JsonProperty("ext")]
public Ext Ext { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("retcode")]
public int Retcode { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
}
public partial class ServerExt
{
[JsonProperty("cdkey_url")]
public string CdkeyUrl { get; set; }
[JsonProperty("mihoyo_sdk_env")]
public string MihoyoSdkEnv { get; set; }
}
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

24
HttpServer/Program.cs Normal file
View File

@@ -0,0 +1,24 @@
using Common;
using HttpServer.Controllers;
namespace HttpServer
{
public class Program
{
public static void Main()
{
Thread.CurrentThread.IsBackground = true;
var builder = WebApplication.CreateBuilder();
var app = builder.Build();
app.UsePathBase("/");
app.Urls.Add($"http://*:{Global.config.Http.HttpPort}");
app.Urls.Add($"https://*:{Global.config.Http.HttpsPort}");
DispatchController.AddHandlers(app);
app.Run();
}
}
}

View File

@@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64847",
"sslPort": 44333
}
},
"profiles": {
"HttpServer": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7227;http://localhost:5186",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "None"
}
},
"AllowedHosts": "*"
}