mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 23:29:26 +08:00
179 lines
6.7 KiB
C++
179 lines
6.7 KiB
C++
|
|
#include "server.hpp"
|
||
|
|
|
||
|
|
#include <thread>
|
||
|
|
#include <json/json.h>
|
||
|
|
#include <spdlog/spdlog.h>
|
||
|
|
#include <vector>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
#include "cracker.hpp"
|
||
|
|
|
||
|
|
CrackerServer::CrackerServer() {
|
||
|
|
Post("/disable_all", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_all();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_global_ship_properties_crack", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_global_ship_properties_crack();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_global_ship_properties_crack", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_global_ship_properties_crack();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/update_global_ship_properties", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Json::Reader reader;
|
||
|
|
Json::Value j;
|
||
|
|
reader.parse(req.body, j);
|
||
|
|
Cracker::ShipProperties properties = {
|
||
|
|
.armor = j["armor"].asDouble(),
|
||
|
|
.speed = j["speed"].asDouble(),
|
||
|
|
.antiaircraft = j["antiaircraft"].asDouble(),
|
||
|
|
.oxy_recovery_bench = j["oxy_recovery_bench"].asDouble(),
|
||
|
|
.torpedo = j["torpedo"].asDouble(),
|
||
|
|
.hit = j["hit"].asDouble(),
|
||
|
|
.sonarRange = j["sonarRange"].asDouble(),
|
||
|
|
.attack_duration = j["attack_duration"].asDouble(),
|
||
|
|
.raid_distance = j["raid_distance"].asDouble(),
|
||
|
|
.oxy_recovery_surface = j["oxy_recovery_surface"].asDouble(),
|
||
|
|
.oxy_recovery = j["oxy_recovery"].asDouble(),
|
||
|
|
.dodge = j["dodge"].asDouble(),
|
||
|
|
.luck = j["luck"].asDouble(),
|
||
|
|
.reload = j["reload"].asDouble(),
|
||
|
|
.oxy_cost = j["oxy_cost"].asDouble(),
|
||
|
|
.durability = j["durability"].asDouble(),
|
||
|
|
.air = j["air"].asDouble(),
|
||
|
|
.oxy_max = j["oxy_max"].asDouble(),
|
||
|
|
.cannon = j["cannon"].asDouble(),
|
||
|
|
.antisub = j["antisub"].asDouble(),
|
||
|
|
};
|
||
|
|
Cracker::Instance().update_global_ship_properties(properties);
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_fast_stage_move", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_fast_stage_move();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_fast_stage_move", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_fast_stage_move();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_remove_hard_mode_ship_properties_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_remove_hard_mode_ship_properties_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_remove_hard_mode_ship_properties_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_remove_hard_mode_ship_properties_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_remove_hard_mode_ship_type_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_remove_hard_mode_ship_type_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_remove_hard_mode_ship_type_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_remove_hard_mode_ship_type_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_remove_hard_mode_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
auto& cracker = Cracker::Instance();
|
||
|
|
cracker.enable_remove_hard_mode_ship_type_limit();
|
||
|
|
cracker.enable_remove_hard_mode_ship_properties_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_remove_hard_mode_limit", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
auto& cracker = Cracker::Instance();
|
||
|
|
cracker.disable_remove_hard_mode_ship_type_limit();
|
||
|
|
cracker.disable_remove_hard_mode_ship_properties_limit();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_no_bb_animation", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_no_bb_animation();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_no_bb_animation", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_no_bb_animation();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/print_table_field", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Json::Reader reader;
|
||
|
|
Json::Value j;
|
||
|
|
reader.parse(req.body, j);
|
||
|
|
std::vector<std::string> path;
|
||
|
|
for (auto& key : j["path"]) {
|
||
|
|
path.push_back(key.asString());
|
||
|
|
}
|
||
|
|
Cracker::Instance().print_table_field(path);
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_fake_player", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_fake_player();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_fake_player", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_fake_player();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/update_fake_player_info", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Json::Reader reader;
|
||
|
|
Json::Value j;
|
||
|
|
reader.parse(req.body, j);
|
||
|
|
Cracker::FakePlayerInfo info = {
|
||
|
|
.name = j["name"].asString(),
|
||
|
|
.id = j["id"].asString(),
|
||
|
|
.level = j["level"].asString(),
|
||
|
|
};
|
||
|
|
Cracker::Instance().update_fake_player_info(info);
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_no_emotion_warning", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_no_emotion_warning();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_no_emotion_warning", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_no_emotion_warning();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/enable_opsi_fast_move", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().enable_opsi_fast_move();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/disable_opsi_fast_move", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
Cracker::Instance().disable_opsi_fast_move();
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
Post("/is_alive", [](const httplib::Request& req, httplib::Response& res) {
|
||
|
|
res.status = 200;
|
||
|
|
});
|
||
|
|
|
||
|
|
std::thread([this] {
|
||
|
|
SPDLOG_INFO("Start server on port 7540");
|
||
|
|
listen("0.0.0.0", 7540);
|
||
|
|
}).detach();
|
||
|
|
}
|
||
|
|
|
||
|
|
void CrackerServer::Start() {
|
||
|
|
new CrackerServer;
|
||
|
|
}
|