1
0
mirror of https://github.com/0O0o0oOoO00/Alas.git synced 2026-05-14 22:19:26 +08:00

add: webui of luahook

This commit is contained in:
0O0o0oOoO00
2025-05-26 20:29:41 +08:00
parent 959bc3a1f3
commit bbbd155401
20 changed files with 3658 additions and 2 deletions

View File

@@ -657,6 +657,101 @@ CrackerServer::CrackerServer() {
CRACK_OK();
});
Get("/get_config", [](const httplib::Request& req, httplib::Response& res) {
try {
auto j = Cracker::Instance().get_config_json();
Json::FastWriter writer;
res.body = writer.write(j);
res.status = 200;
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Headers", "*");
res.set_header("Access-Control-Allow-Methods", "*");
return;
} catch (std::exception& e) {
SPDLOG_ERROR("Get config failed: {}", e.what());
res.status = 500;
return;
}
res.status = 500;
return;
});
Options("/get_config", [](const httplib::Request& req, httplib::Response& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Headers", "*");
res.set_header("Access-Control-Allow-Methods", "*");
res.status = 200;
});
Post("/apply", [](const httplib::Request& req, httplib::Response& res) {
try {
Json::Reader reader;
Json::Value j;
reader.parse(req.body, j);
Cracker::Config config = {
.flag = {
.GLOBAL_SHIP_PROPERTIES_CRACK = j["globalShipProperties"]["enabled"].asBool(),
.FAST_STAGE_MOVE_CRACK = j["chapterFastMove"]["enabled"].asBool(),
.REMOVE_HARD_MODE_SHIP_PROPERTIES_LIMIT = j["removeHardModeShipPropertiesLimit"]["enabled"].asBool(),
.REMOVE_HARD_MODE_SHIP_TYPE_LIMIT = j["removeHardModeShipTypeLimit"]["enabled"].asBool(),
.NO_BB_ANIMATION = j["noBBAnimation"]["enabled"].asBool(),
.NO_EMOTION_WARNING = j["noEmotionWarning"]["enabled"].asBool(),
.OPSI_FAST_MOVE = j["opsiFastMove"]["enabled"].asBool(),
.GG_FACTOR = j["ggFactor"]["enabled"].asBool(),
.GLOBAL_SPEEDUP = j["globalSpeedup"]["enabled"].asBool(),
},
.globle_ship_properties = {
.armor = j["globalShipProperties"]["value"]["armor"]["value"].asDouble(),
.speed = j["globalShipProperties"]["value"]["speed"]["value"].asDouble(),
.antiaircraft = j["globalShipProperties"]["value"]["antiaircraft"]["value"].asDouble(),
.oxy_recovery_bench = j["globalShipProperties"]["value"]["oxy_recovery_bench"]["value"].asDouble(),
.torpedo = j["globalShipProperties"]["value"]["torpedo"]["value"].asDouble(),
.hit = j["globalShipProperties"]["value"]["hit"]["value"].asDouble(),
.sonarRange = j["globalShipProperties"]["value"]["sonarRange"]["value"].asDouble(),
.attack_duration = j["globalShipProperties"]["value"]["attack_duration"]["value"].asDouble(),
.raid_distance = j["globalShipProperties"]["value"]["raid_distance"]["value"].asDouble(),
.oxy_recovery_surface = j["globalShipProperties"]["value"]["oxy_recovery_surface"]["value"].asDouble(),
.oxy_recovery = j["globalShipProperties"]["value"]["oxy_recovery"]["value"].asDouble(),
.dodge = j["globalShipProperties"]["value"]["dodge"]["value"].asDouble(),
.luck = j["globalShipProperties"]["value"]["luck"]["value"].asDouble(),
.reload = j["globalShipProperties"]["value"]["reload"]["value"].asDouble(),
.oxy_cost = j["globalShipProperties"]["value"]["oxy_cost"]["value"].asDouble(),
.durability = j["globalShipProperties"]["value"]["durability"]["value"].asDouble(),
.air = j["globalShipProperties"]["value"]["air"]["value"].asDouble(),
.oxy_max = j["globalShipProperties"]["value"]["oxy_max"]["value"].asDouble(),
.cannon = j["globalShipProperties"]["value"]["cannon"]["value"].asDouble(),
.antisub = j["globalShipProperties"]["value"]["antisub"]["value"].asDouble(),
},
.global_speedup_rate = j["globalSpeedup"]["value"].asFloat(),
.gg_factor = j["ggFactor"]["value"].asDouble(),
};
Cracker::Instance().apply_config(config);
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Headers", "*");
res.set_header("Access-Control-Allow-Methods", "*");
CRACK_OK();
return;
} catch (std::exception& e) {
SPDLOG_ERROR("Apply config failed: {}", e.what());
res.status = 500;
return;
}
res.status = 500;
return;
});
Options("/apply", [](const httplib::Request& req, httplib::Response& res) {
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Headers", "*");
res.set_header("Access-Control-Allow-Methods", "*");
res.status = 200;
});
set_web_page();
std::thread([this] {
SPDLOG_INFO("Start server on port 23897");
listen("0.0.0.0", 23897);
@@ -666,3 +761,20 @@ CrackerServer::CrackerServer() {
void CrackerServer::Start() {
new CrackerServer;
}
void CrackerServer::set_web_page() {
if (WebRes.contains("/index.html")) {
Get("/", WebPageResponder(WebRes["/index.html"]));
}
for (auto& item: WebRes) {
Get(item.first, WebPageResponder(item.second));
}
}
CrackerServer::WebPageResponder::WebPageResponder(WebPage& page)
: m_page(page) {}
void CrackerServer::WebPageResponder::operator()(const httplib::Request& req, httplib::Response& res) const {
res.set_content(reinterpret_cast<const char *>(m_page.content.data()), m_page.content.size(), m_page.type);
res.status = 200;
}