diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 4303c910..235e8186 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -355,41 +355,38 @@ namespace party bool download_files(const game::netadr_s& target, const utils::info_string& info, bool allow_download); - int user_download_response(game::hks::lua_State* state) + void user_download_response(bool response) { - const auto response = state->m_apistack.base[0].v.boolean; if (!response) { - return 0; + return; } nlohmann::json obj = get_whitelist_json_object(); if (obj == nullptr) { - return 0; + obj = {}; } - obj.insert(obj.end(), target_ip_to_string(saved_info_response.host)); - utils::io::write_file_json(get_whitelist_json_path(), obj); + obj.push_back(target_ip_to_string(saved_info_response.host)); + + utils::io::write_file(get_whitelist_json_path(), obj.dump(4)); download_files(saved_info_response.host, saved_info_response.info_string, true); - return 1; } bool should_user_confirm(const game::netadr_s& target, const utils::info_string& info) { nlohmann::json obj = get_whitelist_json_object(); - if (obj == nullptr) + if (obj != nullptr) { - return false; - } - - const auto target_ip = target_ip_to_string(target); - for (const auto& [key, value] : obj.items()) - { - if (value.is_string() && value.get() == target_ip) + const auto target_ip = target_ip_to_string(target); + for (const auto& [key, value] : obj.items()) { - return false; + if (value.is_string() && value.get() == target_ip) + { + return false; + } } } diff --git a/src/common/utils/io.cpp b/src/common/utils/io.cpp index b05ee816..5d898cc9 100644 --- a/src/common/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -19,27 +19,6 @@ namespace utils::io return std::ifstream(file).good(); } - bool write_file_json(const std::string& file, const nlohmann::json& object) - { - const auto pos = file.find_last_of("/\\"); - if (pos != std::string::npos) - { - create_directory(file.substr(0, pos)); - } - - std::ofstream stream( - file, std::ios::binary | std::ofstream::out); - - if (stream.is_open()) - { - stream << object; - stream.close(); - return true; - } - - return false; - } - bool write_file(const std::string& file, const std::string& data, const bool append) { const auto pos = file.find_last_of("/\\"); diff --git a/src/common/utils/io.hpp b/src/common/utils/io.hpp index 553930d8..ee5998db 100644 --- a/src/common/utils/io.hpp +++ b/src/common/utils/io.hpp @@ -10,7 +10,6 @@ namespace utils::io bool remove_file(const std::string& file); bool move_file(const std::string& src, const std::string& target); bool file_exists(const std::string& file); - bool write_file_json(const std::string& file, const nlohmann::json& object); bool write_file(const std::string& file, const std::string& data, bool append = false); bool read_file(const std::string& file, std::string* data); std::string read_file(const std::string& file);