mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-17 12:29:29 +08:00
add: add the function of obtaining player resources and scanning warehouses
This commit is contained in:
@@ -167,6 +167,154 @@ CrackerServer::CrackerServer() {
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_coin", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto coin = Cracker::Instance().get_coin();
|
||||
res.body = std::to_string(coin);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_oil", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto oil = Cracker::Instance().get_oil();
|
||||
res.body = std::to_string(oil);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_gems", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto gems = Cracker::Instance().get_gems();
|
||||
res.body = std::to_string(gems);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_level", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto level = Cracker::Instance().get_level();
|
||||
res.body = std::to_string(level);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_exp", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto exp = Cracker::Instance().get_exp();
|
||||
res.body = std::to_string(exp);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_merit", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto merit = Cracker::Instance().get_merit();
|
||||
res.body = std::to_string(merit);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_guild_coin", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto guild_coin = Cracker::Instance().get_guild_coin();
|
||||
res.body = std::to_string(guild_coin);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_design_prt", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto design_prt = Cracker::Instance().get_design_prt();
|
||||
res.body = std::to_string(design_prt);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_core_data", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto core_data = Cracker::Instance().get_core_data();
|
||||
res.body = std::to_string(core_data);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_medal", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto medal = Cracker::Instance().get_medal();
|
||||
res.body = std::to_string(medal);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_pt", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto pt = Cracker::Instance().get_pt();
|
||||
res.body = std::to_string(pt);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_specialized_core", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto specialized_core = Cracker::Instance().get_specialized_core();
|
||||
res.body = std::to_string(specialized_core);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_curr_action_point", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto curr_action_point = Cracker::Instance().get_curr_action_point();
|
||||
res.body = std::to_string(curr_action_point);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/scan_dock", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto dock = Cracker::Instance().scan_dock();
|
||||
Json::Value j;
|
||||
for (auto& ship : dock) {
|
||||
Json::Value ship_info_j;
|
||||
ship_info_j["config_id"] = ship.second.config_id;
|
||||
ship_info_j["emotion"] = ship.second.emotion;
|
||||
ship_info_j["rarity"] = ship.second.rarity;
|
||||
ship_info_j["level"] = ship.second.level;
|
||||
ship_info_j["exp"] = ship.second.exp;
|
||||
ship_info_j["curr_star"] = ship.second.curr_star;
|
||||
j[std::to_string(ship.first)] = ship_info_j;
|
||||
}
|
||||
Json::FastWriter writer;
|
||||
res.body = writer.write(j);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/scan_storage", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto storage = Cracker::Instance().scan_storage();
|
||||
Json::Value j;
|
||||
for (auto& item : storage) {
|
||||
j[std::to_string(item.first)] = item.second;
|
||||
}
|
||||
Json::FastWriter writer;
|
||||
res.body = writer.write(j);
|
||||
res.status = 200;
|
||||
});
|
||||
|
||||
Get("/get_ship_info", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto id = req.get_param_value("id");
|
||||
if (id.empty()) {
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
auto ship_info = Cracker::Instance().get_ship_info(std::stoi(id));
|
||||
if (ship_info.has_value()) {
|
||||
Cracker::ShipInfo& info = ship_info.value();
|
||||
Json::Value j;
|
||||
j["config_id"] = info.config_id;
|
||||
j["emotion"] = info.emotion;
|
||||
j["rarity"] = info.rarity;
|
||||
j["level"] = info.level;
|
||||
j["exp"] = info.exp;
|
||||
j["curr_star"] = info.curr_star;
|
||||
Json::FastWriter writer;
|
||||
res.body = writer.write(j);
|
||||
res.status = 200;
|
||||
} else {
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
Get("/get_storage_item_count", [](const httplib::Request& req, httplib::Response& res) {
|
||||
auto item_id = req.get_param_value("item_id");
|
||||
if (item_id.empty()) {
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
auto count = Cracker::Instance().get_storage_item_count(std::stoi(item_id));
|
||||
if (count.has_value()) {
|
||||
res.body = std::to_string(count.value());
|
||||
res.status = 200;
|
||||
} else {
|
||||
res.status = 400;
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
std::thread([this] {
|
||||
SPDLOG_INFO("Start server on port 23897");
|
||||
listen("0.0.0.0", 23897);
|
||||
|
||||
Reference in New Issue
Block a user