Format code [skip actions]

This commit is contained in:
github-actions
2023-05-11 02:23:43 +00:00
parent f51fd55cb5
commit f9906c4492
730 changed files with 29212 additions and 29159 deletions

View File

@@ -1,121 +1,121 @@
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.config.Configuration.*;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.HttpJsonResponse;
import emu.grasscutter.utils.FileUtils;
import io.javalin.Javalin;
import io.javalin.http.ContentType;
import io.javalin.http.Context;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.StringJoiner;
/** Handles requests related to the announcements page. */
public final class AnnouncementsHandler implements Router {
private static void getAnnouncement(Context ctx) {
String data = "";
if (Objects.equals(
ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnContent")) {
try {
data = FileUtils.readToString(DataLoader.load("GameAnnouncement.json"));
} catch (Exception e) {
if (e.getClass() == IOException.class) {
Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e);
}
}
} else if (Objects.equals(
ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnList")) {
try {
data = FileUtils.readToString(DataLoader.load("GameAnnouncementList.json"));
} catch (Exception e) {
if (e.getClass() == IOException.class) {
Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e);
}
}
} else {
ctx.result("{\"retcode\":404,\"message\":\"Unknown request path\"}");
}
if (data.isEmpty()) {
ctx.result("{\"retcode\":500,\"message\":\"Unable to fetch requsted content\"}");
return;
}
String dispatchDomain =
"http"
+ (HTTP_ENCRYPTION.useInRouting ? "s" : "")
+ "://"
+ lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress)
+ ":"
+ lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort);
data =
data.replace("{{DISPATCH_PUBLIC}}", dispatchDomain)
.replace("{{SYSTEM_TIME}}", String.valueOf(System.currentTimeMillis()));
ctx.result("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}");
}
private static void getPageResources(Context ctx) {
// Re-process the path - remove the first slash and prevent directory traversal
// (the first slash will act as root path when resolving local path)
String[] path = ctx.path().split("/");
StringJoiner stringJoiner = new StringJoiner("/");
for (String pathName : path) {
// Filter the illegal payload to prevent directory traversal
if (!pathName.isEmpty() && !pathName.equals("..") && !pathName.contains("\\")) {
stringJoiner.add(pathName);
}
}
try (InputStream filestream = DataLoader.load(stringJoiner.toString())) {
String possibleFilename = ctx.path();
ContentType fromExtension =
ContentType.getContentTypeByExtension(
possibleFilename.substring(possibleFilename.lastIndexOf(".") + 1));
ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM);
ctx.result(filestream.readAllBytes());
} catch (Exception e) {
Grasscutter.getLogger().warn("File does not exist: " + ctx.path());
ctx.status(404);
}
}
@Override
public void applyRoutes(Javalin javalin) {
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAlertPic",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}"));
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAlertAnn",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}"));
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAnnList",
AnnouncementsHandler::getAnnouncement);
// hk4e-api-os-static.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAnnContent",
AnnouncementsHandler::getAnnouncement);
// hk4e-sdk-os.hoyoverse.com
this.allRoutes(
javalin,
"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}"));
javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources);
}
}
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.config.Configuration.*;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.HttpJsonResponse;
import emu.grasscutter.utils.FileUtils;
import io.javalin.Javalin;
import io.javalin.http.ContentType;
import io.javalin.http.Context;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.StringJoiner;
/** Handles requests related to the announcements page. */
public final class AnnouncementsHandler implements Router {
private static void getAnnouncement(Context ctx) {
String data = "";
if (Objects.equals(
ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnContent")) {
try {
data = FileUtils.readToString(DataLoader.load("GameAnnouncement.json"));
} catch (Exception e) {
if (e.getClass() == IOException.class) {
Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e);
}
}
} else if (Objects.equals(
ctx.endpointHandlerPath(), "/common/hk4e_global/announcement/api/getAnnList")) {
try {
data = FileUtils.readToString(DataLoader.load("GameAnnouncementList.json"));
} catch (Exception e) {
if (e.getClass() == IOException.class) {
Grasscutter.getLogger().info("Unable to read file 'GameAnnouncementList.json'. \n" + e);
}
}
} else {
ctx.result("{\"retcode\":404,\"message\":\"Unknown request path\"}");
}
if (data.isEmpty()) {
ctx.result("{\"retcode\":500,\"message\":\"Unable to fetch requsted content\"}");
return;
}
String dispatchDomain =
"http"
+ (HTTP_ENCRYPTION.useInRouting ? "s" : "")
+ "://"
+ lr(HTTP_INFO.accessAddress, HTTP_INFO.bindAddress)
+ ":"
+ lr(HTTP_INFO.accessPort, HTTP_INFO.bindPort);
data =
data.replace("{{DISPATCH_PUBLIC}}", dispatchDomain)
.replace("{{SYSTEM_TIME}}", String.valueOf(System.currentTimeMillis()));
ctx.result("{\"retcode\":0,\"message\":\"OK\",\"data\": " + data + "}");
}
private static void getPageResources(Context ctx) {
// Re-process the path - remove the first slash and prevent directory traversal
// (the first slash will act as root path when resolving local path)
String[] path = ctx.path().split("/");
StringJoiner stringJoiner = new StringJoiner("/");
for (String pathName : path) {
// Filter the illegal payload to prevent directory traversal
if (!pathName.isEmpty() && !pathName.equals("..") && !pathName.contains("\\")) {
stringJoiner.add(pathName);
}
}
try (InputStream filestream = DataLoader.load(stringJoiner.toString())) {
String possibleFilename = ctx.path();
ContentType fromExtension =
ContentType.getContentTypeByExtension(
possibleFilename.substring(possibleFilename.lastIndexOf(".") + 1));
ctx.contentType(fromExtension != null ? fromExtension : ContentType.APPLICATION_OCTET_STREAM);
ctx.result(filestream.readAllBytes());
} catch (Exception e) {
Grasscutter.getLogger().warn("File does not exist: " + ctx.path());
ctx.status(404);
}
}
@Override
public void applyRoutes(Javalin javalin) {
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAlertPic",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"total\":0,\"list\":[]}}"));
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAlertAnn",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"alert\":false,\"alert_id\":0,\"remind\":true}}"));
// hk4e-api-os.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAnnList",
AnnouncementsHandler::getAnnouncement);
// hk4e-api-os-static.hoyoverse.com
this.allRoutes(
javalin,
"/common/hk4e_global/announcement/api/getAnnContent",
AnnouncementsHandler::getAnnouncement);
// hk4e-sdk-os.hoyoverse.com
this.allRoutes(
javalin,
"/hk4e_global/mdk/shopwindow/shopwindow/listPriceTier",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"suggest_currency\":\"USD\",\"tiers\":[]}}"));
javalin.get("/hk4e/announcement/*", AnnouncementsHandler::getPageResources);
}
}

View File

@@ -1,153 +1,153 @@
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.utils.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.gacha.GachaBanner;
import emu.grasscutter.game.gacha.GachaSystem;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import io.javalin.Javalin;
import io.javalin.http.ContentType;
import io.javalin.http.Context;
import io.javalin.http.staticfiles.Location;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import lombok.Getter;
/** Handles all gacha-related HTTP requests. */
public final class GachaHandler implements Router {
@Getter
private static final Path gachaMappingsPath = FileUtils.getDataUserPath("gacha/mappings.js");
@Deprecated(forRemoval = true)
public static final String gachaMappings = gachaMappingsPath.toString();
private static void gachaRecords(Context ctx) {
String sessionKey = ctx.queryParam("s");
Account account = DatabaseHelper.getAccountBySessionKey(sessionKey);
if (account == null) {
ctx.status(403).result("Requested account was not found");
return;
}
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
if (player == null) {
ctx.status(403).result("No player associated with requested account");
return;
}
int page = 0, gachaType = 0;
if (ctx.queryParam("p") != null) page = Integer.parseInt(ctx.queryParam("p"));
if (ctx.queryParam("gachaType") != null)
gachaType = Integer.parseInt(ctx.queryParam("gachaType"));
String records = DatabaseHelper.getGachaRecords(player.getUid(), page, gachaType).toString();
long maxPage = DatabaseHelper.getGachaRecordsMaxPage(player.getUid(), page, gachaType);
String template =
new String(
FileUtils.read(FileUtils.getDataPath("gacha/records.html")), StandardCharsets.UTF_8)
.replace("{{REPLACE_RECORDS}}", records)
.replace("{{REPLACE_MAXPAGE}}", String.valueOf(maxPage))
.replace("{{TITLE}}", translate(player, "gacha.records.title"))
.replace("{{DATE}}", translate(player, "gacha.records.date"))
.replace("{{ITEM}}", translate(player, "gacha.records.item"))
.replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale()));
ctx.contentType(ContentType.TEXT_HTML);
ctx.result(template);
}
private static void gachaDetails(Context ctx) {
Path detailsTemplate = FileUtils.getDataPath("gacha/details.html");
String sessionKey = ctx.queryParam("s");
Account account = DatabaseHelper.getAccountBySessionKey(sessionKey);
if (account == null) {
ctx.status(403).result("Requested account was not found");
return;
}
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
if (player == null) {
ctx.status(403).result("No player associated with requested account");
return;
}
String template;
try {
template = Files.readString(detailsTemplate);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to read data/gacha/details.html");
ctx.status(500);
return;
}
// Add translated title etc. to the page.
template =
template
.replace("{{TITLE}}", translate(player, "gacha.details.title"))
.replace(
"{{AVAILABLE_FIVE_STARS}}", translate(player, "gacha.details.available_five_stars"))
.replace(
"{{AVAILABLE_FOUR_STARS}}", translate(player, "gacha.details.available_four_stars"))
.replace(
"{{AVAILABLE_THREE_STARS}}",
translate(player, "gacha.details.available_three_stars"))
.replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale()));
// Get the banner info for the banner we want.
int scheduleId = Integer.parseInt(ctx.queryParam("scheduleId"));
GachaSystem manager = Grasscutter.getGameServer().getGachaSystem();
GachaBanner banner = manager.getGachaBanners().get(scheduleId);
// Add 5-star items.
Set<String> fiveStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getRateUpItems5()).forEach(i -> fiveStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems5Pool1())
.forEach(i -> fiveStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems5Pool2())
.forEach(i -> fiveStarItems.add(Integer.toString(i)));
template = template.replace("{{FIVE_STARS}}", "[" + String.join(",", fiveStarItems) + "]");
// Add 4-star items.
Set<String> fourStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getRateUpItems4()).forEach(i -> fourStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems4Pool1())
.forEach(i -> fourStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems4Pool2())
.forEach(i -> fourStarItems.add(Integer.toString(i)));
template = template.replace("{{FOUR_STARS}}", "[" + String.join(",", fourStarItems) + "]");
// Add 3-star items.
Set<String> threeStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getFallbackItems3()).forEach(i -> threeStarItems.add(Integer.toString(i)));
template = template.replace("{{THREE_STARS}}", "[" + String.join(",", threeStarItems) + "]");
// Done.
ctx.contentType(ContentType.TEXT_HTML);
ctx.result(template);
}
@Override
public void applyRoutes(Javalin javalin) {
javalin.get("/gacha", GachaHandler::gachaRecords);
javalin.get("/gacha/details", GachaHandler::gachaDetails);
javalin._conf.addSinglePageRoot(
"/gacha/mappings",
gachaMappingsPath.toString(),
Location.EXTERNAL); // TODO: This ***must*** be changed to take the Path not a String. This
// might involve upgrading Javalin.
}
}
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.utils.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.gacha.GachaBanner;
import emu.grasscutter.game.gacha.GachaSystem;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.Utils;
import io.javalin.Javalin;
import io.javalin.http.ContentType;
import io.javalin.http.Context;
import io.javalin.http.staticfiles.Location;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import lombok.Getter;
/** Handles all gacha-related HTTP requests. */
public final class GachaHandler implements Router {
@Getter
private static final Path gachaMappingsPath = FileUtils.getDataUserPath("gacha/mappings.js");
@Deprecated(forRemoval = true)
public static final String gachaMappings = gachaMappingsPath.toString();
private static void gachaRecords(Context ctx) {
String sessionKey = ctx.queryParam("s");
Account account = DatabaseHelper.getAccountBySessionKey(sessionKey);
if (account == null) {
ctx.status(403).result("Requested account was not found");
return;
}
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
if (player == null) {
ctx.status(403).result("No player associated with requested account");
return;
}
int page = 0, gachaType = 0;
if (ctx.queryParam("p") != null) page = Integer.parseInt(ctx.queryParam("p"));
if (ctx.queryParam("gachaType") != null)
gachaType = Integer.parseInt(ctx.queryParam("gachaType"));
String records = DatabaseHelper.getGachaRecords(player.getUid(), page, gachaType).toString();
long maxPage = DatabaseHelper.getGachaRecordsMaxPage(player.getUid(), page, gachaType);
String template =
new String(
FileUtils.read(FileUtils.getDataPath("gacha/records.html")), StandardCharsets.UTF_8)
.replace("{{REPLACE_RECORDS}}", records)
.replace("{{REPLACE_MAXPAGE}}", String.valueOf(maxPage))
.replace("{{TITLE}}", translate(player, "gacha.records.title"))
.replace("{{DATE}}", translate(player, "gacha.records.date"))
.replace("{{ITEM}}", translate(player, "gacha.records.item"))
.replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale()));
ctx.contentType(ContentType.TEXT_HTML);
ctx.result(template);
}
private static void gachaDetails(Context ctx) {
Path detailsTemplate = FileUtils.getDataPath("gacha/details.html");
String sessionKey = ctx.queryParam("s");
Account account = DatabaseHelper.getAccountBySessionKey(sessionKey);
if (account == null) {
ctx.status(403).result("Requested account was not found");
return;
}
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
if (player == null) {
ctx.status(403).result("No player associated with requested account");
return;
}
String template;
try {
template = Files.readString(detailsTemplate);
} catch (IOException e) {
Grasscutter.getLogger().warn("Failed to read data/gacha/details.html");
ctx.status(500);
return;
}
// Add translated title etc. to the page.
template =
template
.replace("{{TITLE}}", translate(player, "gacha.details.title"))
.replace(
"{{AVAILABLE_FIVE_STARS}}", translate(player, "gacha.details.available_five_stars"))
.replace(
"{{AVAILABLE_FOUR_STARS}}", translate(player, "gacha.details.available_four_stars"))
.replace(
"{{AVAILABLE_THREE_STARS}}",
translate(player, "gacha.details.available_three_stars"))
.replace("{{LANGUAGE}}", Utils.getLanguageCode(account.getLocale()));
// Get the banner info for the banner we want.
int scheduleId = Integer.parseInt(ctx.queryParam("scheduleId"));
GachaSystem manager = Grasscutter.getGameServer().getGachaSystem();
GachaBanner banner = manager.getGachaBanners().get(scheduleId);
// Add 5-star items.
Set<String> fiveStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getRateUpItems5()).forEach(i -> fiveStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems5Pool1())
.forEach(i -> fiveStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems5Pool2())
.forEach(i -> fiveStarItems.add(Integer.toString(i)));
template = template.replace("{{FIVE_STARS}}", "[" + String.join(",", fiveStarItems) + "]");
// Add 4-star items.
Set<String> fourStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getRateUpItems4()).forEach(i -> fourStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems4Pool1())
.forEach(i -> fourStarItems.add(Integer.toString(i)));
Arrays.stream(banner.getFallbackItems4Pool2())
.forEach(i -> fourStarItems.add(Integer.toString(i)));
template = template.replace("{{FOUR_STARS}}", "[" + String.join(",", fourStarItems) + "]");
// Add 3-star items.
Set<String> threeStarItems = new LinkedHashSet<>();
Arrays.stream(banner.getFallbackItems3()).forEach(i -> threeStarItems.add(Integer.toString(i)));
template = template.replace("{{THREE_STARS}}", "[" + String.join(",", threeStarItems) + "]");
// Done.
ctx.contentType(ContentType.TEXT_HTML);
ctx.result(template);
}
@Override
public void applyRoutes(Javalin javalin) {
javalin.get("/gacha", GachaHandler::gachaRecords);
javalin.get("/gacha/details", GachaHandler::gachaDetails);
javalin._conf.addSinglePageRoot(
"/gacha/mappings",
gachaMappingsPath.toString(),
Location.EXTERNAL); // TODO: This ***must*** be changed to take the Path not a String. This
// might involve upgrading Javalin.
}
}

View File

@@ -1,85 +1,85 @@
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.config.Configuration.ACCOUNT;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.HttpJsonResponse;
import emu.grasscutter.server.http.objects.WebStaticVersionResponse;
import io.javalin.Javalin;
import io.javalin.http.Context;
/** Handles all generic, hard-coded responses. */
public final class GenericHandler implements Router {
private static void serverStatus(Context ctx) {
int playerCount = Grasscutter.getGameServer().getPlayers().size();
int maxPlayer = ACCOUNT.maxPlayer;
String version = GameConstants.VERSION;
ctx.result(
"{\"retcode\":0,\"status\":{\"playerCount\":"
+ playerCount
+ ",\"maxPlayer\":"
+ maxPlayer
+ ",\"version\":\""
+ version
+ "\"}}");
}
@Override
public void applyRoutes(Javalin javalin) {
// hk4e-sdk-os.hoyoverse.com
javalin.get(
"/hk4e_global/mdk/agreement/api/getAgreementInfos",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));
// hk4e-sdk-os.hoyoverse.com (this could be either GET or POST based on the observation of
// different clients)
this.allRoutes(
javalin,
"/hk4e_global/combo/granter/api/compareProtocolVersion",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}"));
// api-account-os.hoyoverse.com
javalin.post(
"/account/risky/api/check",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}"));
// sdk-os-static.hoyoverse.com
javalin.get(
"/combo/box/api/config/sdk/combo",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"disable_email_bind_skip\":\"false\",\"email_bind_remind_interval\":\"7\",\"email_bind_remind\":\"true\"}}}"));
// hk4e-sdk-os-static.hoyoverse.com
javalin.get(
"/hk4e_global/combo/granter/api/getConfig",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"https://webstatic-sea.hoyoverse.com/hk4e/announcement/index.html?sdk_presentation_style=fullscreen\\u0026sdk_screen_transparent=true\\u0026game_biz=hk4e_global\\u0026auth_appid=announcement\\u0026game=hk4e#/\",\"push_alias_type\":2,\"disable_ysdk_guard\":false,\"enable_announce_pic_popup\":true}}"));
// hk4e-sdk-os-static.hoyoverse.com
javalin.get(
"/hk4e_global/mdk/shield/api/loadConfig",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":6,\"game_key\":\"hk4e_global\",\"client\":\"PC\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"原神海外\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[\"fb\",\"tw\"],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{\"tw\":\"\",\"fb\":\"\"},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{\"tw\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800},\"fb\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800}}}}"));
// Test api?
// abtest-api-data-sg.hoyoverse.com
javalin.post(
"/data_abtest_api/config/experiment/list",
new HttpJsonResponse(
"{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}"));
// log-upload-os.mihoyo.com
this.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
this.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}"));
// /perf/config/verify?device_id=xxx&platform=x&name=xxx
this.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}"));
// webstatic-sea.hoyoverse.com
javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse());
javalin.get("/status/server", GenericHandler::serverStatus);
}
}
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.config.Configuration.ACCOUNT;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.HttpJsonResponse;
import emu.grasscutter.server.http.objects.WebStaticVersionResponse;
import io.javalin.Javalin;
import io.javalin.http.Context;
/** Handles all generic, hard-coded responses. */
public final class GenericHandler implements Router {
private static void serverStatus(Context ctx) {
int playerCount = Grasscutter.getGameServer().getPlayers().size();
int maxPlayer = ACCOUNT.maxPlayer;
String version = GameConstants.VERSION;
ctx.result(
"{\"retcode\":0,\"status\":{\"playerCount\":"
+ playerCount
+ ",\"maxPlayer\":"
+ maxPlayer
+ ",\"version\":\""
+ version
+ "\"}}");
}
@Override
public void applyRoutes(Javalin javalin) {
// hk4e-sdk-os.hoyoverse.com
javalin.get(
"/hk4e_global/mdk/agreement/api/getAgreementInfos",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"marketing_agreements\":[]}}"));
// hk4e-sdk-os.hoyoverse.com (this could be either GET or POST based on the observation of
// different clients)
this.allRoutes(
javalin,
"/hk4e_global/combo/granter/api/compareProtocolVersion",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"modified\":true,\"protocol\":{\"id\":0,\"app_id\":4,\"language\":\"en\",\"user_proto\":\"\",\"priv_proto\":\"\",\"major\":7,\"minimum\":0,\"create_time\":\"0\",\"teenager_proto\":\"\",\"third_proto\":\"\"}}}"));
// api-account-os.hoyoverse.com
javalin.post(
"/account/risky/api/check",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":\"none\",\"action\":\"ACTION_NONE\",\"geetest\":null}}"));
// sdk-os-static.hoyoverse.com
javalin.get(
"/combo/box/api/config/sdk/combo",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"vals\":{\"disable_email_bind_skip\":\"false\",\"email_bind_remind_interval\":\"7\",\"email_bind_remind\":\"true\"}}}"));
// hk4e-sdk-os-static.hoyoverse.com
javalin.get(
"/hk4e_global/combo/granter/api/getConfig",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"protocol\":true,\"qr_enabled\":false,\"log_level\":\"INFO\",\"announce_url\":\"https://webstatic-sea.hoyoverse.com/hk4e/announcement/index.html?sdk_presentation_style=fullscreen\\u0026sdk_screen_transparent=true\\u0026game_biz=hk4e_global\\u0026auth_appid=announcement\\u0026game=hk4e#/\",\"push_alias_type\":2,\"disable_ysdk_guard\":false,\"enable_announce_pic_popup\":true}}"));
// hk4e-sdk-os-static.hoyoverse.com
javalin.get(
"/hk4e_global/mdk/shield/api/loadConfig",
new HttpJsonResponse(
"{\"retcode\":0,\"message\":\"OK\",\"data\":{\"id\":6,\"game_key\":\"hk4e_global\",\"client\":\"PC\",\"identity\":\"I_IDENTITY\",\"guest\":false,\"ignore_versions\":\"\",\"scene\":\"S_NORMAL\",\"name\":\"原神海外\",\"disable_regist\":false,\"enable_email_captcha\":false,\"thirdparty\":[\"fb\",\"tw\"],\"disable_mmt\":false,\"server_guest\":false,\"thirdparty_ignore\":{\"tw\":\"\",\"fb\":\"\"},\"enable_ps_bind_account\":false,\"thirdparty_login_configs\":{\"tw\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800},\"fb\":{\"token_type\":\"TK_GAME_TOKEN\",\"game_token_expires_in\":604800}}}}"));
// Test api?
// abtest-api-data-sg.hoyoverse.com
javalin.post(
"/data_abtest_api/config/experiment/list",
new HttpJsonResponse(
"{\"retcode\":0,\"success\":true,\"message\":\"\",\"data\":[{\"code\":1000,\"type\":2,\"config_id\":\"14\",\"period_id\":\"6036_99\",\"version\":\"1\",\"configs\":{\"cardType\":\"old\"}}]}"));
// log-upload-os.mihoyo.com
this.allRoutes(javalin, "/log/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
this.allRoutes(javalin, "/sdk/upload", new HttpJsonResponse("{\"code\":0}"));
javalin.post("/sdk/dataUpload", new HttpJsonResponse("{\"code\":0}"));
// /perf/config/verify?device_id=xxx&platform=x&name=xxx
this.allRoutes(javalin, "/perf/config/verify", new HttpJsonResponse("{\"code\":0}"));
// webstatic-sea.hoyoverse.com
javalin.get("/admin/mi18n/plat_oversea/*", new WebStaticVersionResponse());
javalin.get("/status/server", GenericHandler::serverStatus);
}
}

View File

@@ -1,21 +1,21 @@
package emu.grasscutter.server.http.handlers;
import emu.grasscutter.server.http.Router;
import io.javalin.Javalin;
import io.javalin.http.Context;
/** Handles logging requests made to the server. */
public final class LogHandler implements Router {
private static void log(Context ctx) {
// TODO: Figure out how to dump request body and log to file.
ctx.result("{\"code\":0}");
}
@Override
public void applyRoutes(Javalin javalin) {
// overseauspider.yuanshen.com
javalin.post("/log", LogHandler::log);
// log-upload-os.mihoyo.com
javalin.post("/crash/dataUpload", LogHandler::log);
}
}
package emu.grasscutter.server.http.handlers;
import emu.grasscutter.server.http.Router;
import io.javalin.Javalin;
import io.javalin.http.Context;
/** Handles logging requests made to the server. */
public final class LogHandler implements Router {
private static void log(Context ctx) {
// TODO: Figure out how to dump request body and log to file.
ctx.result("{\"code\":0}");
}
@Override
public void applyRoutes(Javalin javalin) {
// overseauspider.yuanshen.com
javalin.post("/log", LogHandler::log);
// log-upload-os.mihoyo.com
javalin.post("/crash/dataUpload", LogHandler::log);
}
}