Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support IOS #89

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions src/main/java/emu/lunarcore/server/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class HttpServer {
private boolean started;

private long nextRegionUpdate;
private Object2ObjectMap<String, RegionInfo> regions;
private final Object2ObjectMap<String, RegionInfo> regions;
private String regionList;

public HttpServer(ServerType type) {
Expand Down Expand Up @@ -71,37 +71,42 @@ private SslContextFactory.Server getSSLContextFactory() {
sslContextFactory.setRenegotiationAllowed(false);
return sslContextFactory;
}

public void forceRegionListRefresh() {
this.nextRegionUpdate = 0;
}

public String getRegionList() {
synchronized (this.regions) {
// Check if region list needs to be cached
if (System.currentTimeMillis() > this.nextRegionUpdate || this.regionList == null) {
// Clear regions first
this.regions.clear();

// Pull region infos from database
LunarCore.getAccountDatabase().getObjects(RegionInfo.class)
.forEach(region -> {
this.regions.put(region.getId(), region);
});


// Serialize to proto
DispatchRegionData regionData = DispatchRegionData.newInstance();
regions.values().stream().map(RegionInfo::toProto).forEach(regionData::addRegionList);

// Set region list cache
this.regionList = Utils.base64Encode(regionData.toByteArray());
this.nextRegionUpdate = System.currentTimeMillis() + getServerConfig().regionListRefresh;
}
}

return regionList;
}






public void start() {
if (this.started) return;
this.started = true;
Expand Down Expand Up @@ -135,7 +140,6 @@ private void addRoutes() {

// Fallback handler
getApp().error(404, this::notFoundHandler);
getApp().get("/status/server", new StatusServerHandler()::handle);
}

private void addDispatchRoutes() {
Expand All @@ -147,36 +151,41 @@ private void addDispatchRoutes() {

// === AUTHENTICATION === hkrpg-sdk-os-static.hoyoverse.com

// Username & Password login (from client). Returns a session key to the client.
getApp().post("/hkrpg_global/mdk/shield/api/login", new UsernameLoginHandler());
getApp().post("/hkrpg_{region}/mdk/shield/api/login", new UsernameLoginHandler());
// Cached session key verify (from registry). Returns a session key to the client.
getApp().post("/hkrpg_global/mdk/shield/api/verify", new TokenLoginHandler());
getApp().post("/hkrpg_{region}/mdk/shield/api/verify", new TokenLoginHandler());

// Exchange session key for login token (combo token)
getApp().post("/hkrpg_global/combo/granter/login/v2/login", new ComboTokenGranterHandler());
getApp().post("/hkrpg_{region}/combo/granter/login/v2/login", new ComboTokenGranterHandler());

// Config
getApp().get("/hkrpg_global/combo/granter/api/getConfig", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"\",\"push_alias_type\":0,\"disable_ysdk_guard\":true,\"enable_announce_pic_popup\":false,\"app_name\":\"崩�??RPG\",\"qr_enabled_apps\":{\"bbs\":false,\"cloud\":false},\"qr_app_icons\":{\"app\":\"\",\"bbs\":\"\",\"cloud\":\"\"},\"qr_cloud_display_name\":\"\",\"enable_user_center\":true,\"functional_switch_configs\":{}}}"));
getApp().get("/hkrpg_global/mdk/shield/api/loadConfig", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":24,\"game_key\":\"hkrpg_global\",\"client\":\"PC\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"崩�??RPG\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[\"fb\",\"tw\",\"gl\",\"ap\"],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{\"tw\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":2592000},\"ap\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800},\"fb\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":2592000},\"gl\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800}},\"initialize_firebase\":false,\"bbs_auth_login\":false,\"bbs_auth_login_ignore\":[],\"fetch_instance_id\":false,\"enable_flash_login\":false}}"));
getApp().get("/hkrpg_{region}/combo/granter/api/getConfig", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"\",\"push_alias_type\":0,\"disable_ysdk_guard\":true,\"enable_announce_pic_popup\":false,\"app_name\":\"崩�??RPG\",\"qr_enabled_apps\":{\"bbs\":false,\"cloud\":false},\"qr_app_icons\":{\"app\":\"\",\"bbs\":\"\",\"cloud\":\"\"},\"qr_cloud_display_name\":\"\",\"enable_user_center\":true,\"functional_switch_configs\":{}}}"));
getApp().get("/hkrpg_cn/combo/granter/api/getConfig", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":false,\"qr_enabled\":true,\"log_level\":\"INFO\",\"announce_url\":\"https://webstatic.mihoyo.com/hkrpg/announcement/index.html?sdk_presentation_style=fullscreen\\u0026game=hkrpg\\u0026game_biz=hkrpg_cn\\u0026sdk_screen_transparent=true\\u0026auth_appid=announcement\\u0026authkey_ver=1\\u0026version=1.44\\u0026sign_type=2#/\",\"push_alias_type\":1,\"disable_ysdk_guard\":false,\"enable_announce_pic_popup\":false,\"app_name\":\"崩坏:星穹铁道\",\"qr_enabled_apps\":null,\"qr_app_icons\":null,\"qr_cloud_display_name\":\"\",\"enable_user_center\":true,\"functional_switch_configs\":{\"jpush\":true}}}"));

getApp().get("/hkrpg_{region}/mdk/shield/api/loadConfig", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":19,\"game_key\":\"hkrpg_cn\",\"client\":\"IOS\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"崩坏RPG\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{\"ap\":\"0.90.0\"},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{},\"initialize_firebase\":false,\"bbs_auth_login\":true,\"bbs_auth_login_ignore\":[],\"fetch_instance_id\":false,\"enable_flash_login\":true,\"enable_logo_18\":false,\"logo_height\":\"0\",\"logo_width\":\"0\"}}"));

// === EXTRA ===

// hkrpg-sdk-os.hoyoverse.com
getApp().post("/hkrpg_global/combo/granter/api/compareProtocolVersion", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":false,\"protocol\":null}}"));
getApp().get("/hkrpg_global/mdk/agreement/api/getAgreementInfos", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));
getApp().post("/hkrpg_{region}/combo/granter/api/compareProtocolVersion", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":false,\"protocol\":null}}"));
getApp().get("/hkrpg_{region}/mdk/agreement/api/getAgreementInfos", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));

// sdk-os-static.hoyoverse.com
getApp().get("/combo/box/api/config/sdk/combo", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"kibana_pc_config\":\"{ \\\"enable\\\": 0, \\\"level\\\": \\\"Info\\\",\\\"modules\\\": [\\\"download\\\"] }\\n\",\"network_report_config\":\"{ \\\"enable\\\": 0, \\\"status_codes\\\": [206], \\\"url_paths\\\": [\\\"dataUpload\\\", \\\"red_dot\\\"] }\\n\",\"list_price_tierv2_enable\":\"false\\n\",\"pay_payco_centered_host\":\"bill.payco.com\",\"telemetry_config\":\"{\\n \\\"dataupload_enable\\\": 0,\\n}\",\"enable_web_dpi\":\"true\"}}}"));
getApp().get("/combo/box/api/config/sw/precache", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"url\":\"\",\"enable\":\"false\"}}}"));

// sg-public-data-api.hoyoverse.com
getApp().get("/device-fp/api/getFp", new FingerprintHandler());
getApp().get("/device-fp/api/getExtList", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"code\":200,\"msg\":\"ok\",\"ext_list\":[],\"pkg_list\":[],\"pkg_str\":\"/vK5WTh5SS3SAj8Zm0qPWg==\"}}"));
getApp().post("/device-fp/api/getFp", new FingerprintHandler());
getApp().get("/device-fp/api/getExtList", new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"code\":200,\"msg\":\"ok\",\"ext_list\":[\"IDFV\",\"model\",\"osVersion\",\"screenSize\",\"vendor\",\"cpuType\",\"cpuCores\",\"isJailBreak\",\"networkType\",\"proxyStatus\",\"batteryStatus\",\"chargeStatus\",\"romCapacity\",\"romRemain\",\"ramCapacity\",\"ramRemain\",\"appMemory\",\"accelerometer\",\"gyroscope\",\"magnetometer\",\"deviceName\",\"screenBrightness\",\"isSimInserted\",\"isPushEnabled\",\"buildTime\",\"appInstallTimeDiff\",\"appUpdateTimeDiff\",\"hasVpn\",\"packageName\",\"packageVersion\"],\"pkg_list\":[],\"pkg_str\":\"\"}}"));

// abtest-api-data-sg.hoyoverse.com
getApp().post("/data_abtest_api/config/experiment/list", new HttpJsonResponse("{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6125_197\",\"version\":\"1\",\"configs\":{\"cardType\":\"direct\"}}]}"));

// Add mode
getApp().post("/data_abtest_api/config/experiment/list", new HttpJsonResponse("{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"296\",\"period_id\":\"5306_534\",\"version\":\"2\",\"configs\":{\"loginType\":\"porte\"}}]}"));
//cn https://passport-api.mihoyo.com
getApp().post("/account/ma-cn-session/app/verify",new HttpJsonResponse("{\"retcode\":0,\"message\":\"OK\",\"data\":{\"user_info\":{\"aid\":\"888888888\",\"mid\":\"0zuobmxgmz_mhy\",\"account_name\":\"\",\"email\":\"\",\"is_email_verify\":0,\"area_code\":\"+86\",\"mobile\":\"188******88\",\"safe_area_code\":\"\",\"safe_mobile\":\"\",\"realname\":\"**游\",\"identity_code\":\"488************888\",\"rebind_area_code\":\"\",\"rebind_mobile\":\"\",\"rebind_mobile_time\":\"0\",\"links\":[],\"country\":\"\",\"unmasked_email\":\"\",\"unmasked_email_type\":0},\"realname_info\":{\"required\":false,\"action_type\":\"\",\"action_ticket\":\"\"},\"need_realperson\":false}}"));
getApp().get("_ts", new HttpJsonResponse(
"{\"code\":0,\"message\":\"app running\",\"milliTs\":\"" + System.currentTimeMillis() + "\"}"
));
getApp().get("/sdk_global/apphub/api/getAttributionReportConfig",new HttpJsonResponse("{\"data\":{\"device_blacklist\":\"\",\"enabled\":true,\"report_detail\":\"{\\n \\\"allowed_fields\\\": [\\n \\\"app_version\\\",\\n \\\"manufacturer\\\",\\n \\\"model\\\",\\n \\\"os\\\",\\n \\\"osversion\\\",\\n \\\"network_type\\\",\\n \\\"mac\\\",\\n \\\"deviceid\\\",\\n \\\"resolution\\\",\\n \\\"idfa\\\",\\n \\\"pkgname\\\",\\n \\\"idfv\\\",\\n \\\"lat\\\",\\n \\\"tz\\\",\\n \\\"devicetype\\\",\\n \\\"screen_brightness\\\",\\n \\\"audio_volume\\\",\\n \\\"lib_version\\\",\\n \\\"gyrodata\\\",\\n \\\"ua\\\",\\n \\\"boot_time\\\",\\n \\\"update_time\\\",\\n \\\"att_status\\\",\\n \\\"language\\\",\\n \\\"attribution_token\\\",\\n \\\"country_code\\\",\\n \\\"device_name\\\",\\n \\\"carrier_info\\\",\\n \\\"memory\\\",\\n \\\"disk\\\",\\n \\\"device_model\\\",\\n \\\"caid\\\",\\n\\t\\\"mnt_id\\\",\\n\\t\\\"file_init_time\\\"\\n ]\\n}\",\"report_interval_seconds\":3},\"message\":\"OK\",\"retcode\":0}"));// Add mode
this.modes.add("DISPATCH");
}

Expand All @@ -200,9 +209,9 @@ private void addGateServerRoutes() {
this.modes.add("GATESERVER");
}

private void notFoundHandler(Context ctx) {
private void notFoundHandler(Context ctx) {
ctx.status(404);
ctx.contentType(ContentType.TEXT_PLAIN);
ctx.result("not found");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ public void handle(@NotNull Context ctx) throws Exception {

FingerprintReqJson req = JsonUtils.decode(ctx.body(), FingerprintReqJson.class);

// 检查请求体是否成功解析
if (req == null) {
res.retcode = -202;
res.retcode = -202; // 或其他适当的错误代码
res.message = "Error";
} else {
// 设置成功响应
res.retcode = 0; // 成功的 retcode
res.message = "OK";
res.data = new FingerprintResJson.FingerprintDataJson(req.device_fp);
}

res.message = "OK";
res.data = new FingerprintDataJson(req.device_fp);

// Result
// 设置响应类型并返回结果
ctx.contentType(ContentType.APPLICATION_JSON);
ctx.result(JsonUtils.encode(res));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public QueryGatewayHandler() {
@Override
public void handle(@NotNull Context ctx) throws Exception {
// Get streaming data from config
var data = LunarCore.getHotfixData();
var data = LunarCore.getConfig().getDownloadData();

// Build gateserver proto
Gateserver gateserver = Gateserver.newInstance()
Expand All @@ -31,30 +31,25 @@ public void handle(@NotNull Context ctx) throws Exception {
.setUnk4(true)
.setUnk5(true);

// Set hotfix urls
if (data.assetBundleUrl != null && !data.assetBundleUrl.isBlank()) {
if (data.assetBundleUrl != null) {
gateserver.setAssetBundleUrl(data.assetBundleUrl);
}
if (data.exResourceUrl != null && !data.exResourceUrl.isBlank()) {
if (data.exResourceUrl != null) {
gateserver.setExResourceUrl(data.exResourceUrl);
}
if (data.luaUrl != null && !data.luaUrl.isBlank()) {
if (data.luaUrl != null) {
gateserver.setLuaUrl(data.luaUrl);
gateserver.setMdkResVersion(
data.luaUrl.split("/")[data.luaUrl.split("/").length - 1].split("_")[1]
);
}
if (data.ifixUrl != null && !data.ifixUrl.isBlank()) {
if (data.ifixUrl != null) {
gateserver.setIfixUrl(data.ifixUrl);
gateserver.setIfixVersion(
data.ifixUrl.split("/")[data.ifixUrl.split("/").length - 1].split("_")[1]
);
}

// Set hotfix versions
String mdkResVersion = data.getMdkResVersion();
String ifixVersion = data.getIfixVersion();
if (mdkResVersion != null) {
gateserver.setMdkResVersion(mdkResVersion);
}
if (ifixVersion != null) {
gateserver.setIfixVersion(ifixVersion);
}


// Log
if (LunarCore.getConfig().getLogOptions().connections) {
LunarCore.getLogger().info("Client request: query_gateway");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class FingerprintResJson {

public static class FingerprintDataJson {
public String device_fp;
public String message;
public String msg; // 修改字段名为 msg
public int code;

public FingerprintDataJson(String fp) {
this.code = 200;
this.message = "OK";
this.msg = "ok"; // 修改字段名为 msg
this.device_fp = fp;
}
}
Expand Down
Loading