TmpMenu/BigBaseV2/src/services/gta_data/gta_data_service.hpp
aa15032261 00a19d9290 Improved error handling of gta_data_service. (#412)
* Bug fix for #403

* Fixed Issue #403

* Minor fixes.

* Improved error handling of gta_data_service.

Fixed an issue where the game crashes when throwing invalid json format exception.

* Minor fixes.

* Minor fixes.

* Improved error handling of gta_data_service.

Also extended the timeout to 30s.

* Improved error handling of gta_data_service.

- Fixed an issue where http_request doesn't handle HEAD requests and socket.recv error correctly.

- Limited gta_data_service to have only 1 active http request.

* Minor fixes.

* Minor fixes.
2022-08-13 17:17:59 +02:00

55 lines
1.6 KiB
C++

#pragma once
#include "file_manager/file.hpp"
#include "vehicle_item.hpp"
#include "ped_item.hpp"
#include "weapon_item.hpp"
#include "gta/joaat.hpp"
namespace big
{
class gta_data_service
{
std::vector<std::string> m_vehicle_class_arr;
std::map<Hash, int> m_vehicle_hash_idx_map;
std::vector<vehicle_item> m_vehicle_item_arr;
const vehicle_item empty_vehicle_item = vehicle_item();
std::vector<std::string> m_ped_type_arr;
std::map<Hash, int> m_ped_hash_idx_map;
std::vector<ped_item> m_ped_item_arr;
const ped_item empty_ped_item = ped_item();
std::vector<std::string> m_weapon_type_arr;
std::map<Hash, int> m_weapon_hash_idx_map;
std::vector<weapon_item> m_weapon_item_arr;
const weapon_item empty_weapon_item = weapon_item();
public:
gta_data_service();
~gta_data_service();
const vehicle_item& find_vehicle_by_hash(Hash hash);
const std::vector<std::string>& get_vehicle_class_arr();
const std::vector<vehicle_item>& get_vehicle_arr();
const ped_item& find_ped_by_hash(Hash hash);
const std::vector<std::string>& get_ped_type_arr();
const std::vector<ped_item>& get_ped_arr();
const weapon_item& find_weapon_by_hash(Hash hash);
const std::vector<std::string>& get_weapon_type_arr();
const std::vector<weapon_item>& get_weapon_arr();
private:
void load_from_file(
std::string file_path, std::string etag_path, std::string url,
bool(gta_data_service::* load_func)(std::filesystem::path), std::string data_name
);
bool load_vehicles(std::filesystem::path path);
bool load_peds(std::filesystem::path path);
bool load_weapons(std::filesystem::path path);
};
inline gta_data_service* g_gta_data_service{};
}