Improve protections again and player database (#606)
This commit is contained in:
@ -30,6 +30,7 @@ namespace big
|
||||
NETWORK,
|
||||
SESSION,
|
||||
SPOOFING,
|
||||
PLAYER_DATABASE,
|
||||
|
||||
SETTINGS,
|
||||
CONTEXT_MENU_SETTINGS,
|
||||
@ -78,6 +79,7 @@ namespace big
|
||||
{tabs::NETWORK, { "Network", nullptr, {
|
||||
{ tabs::SPOOFING, { "Spoofing", view::spoofing }},
|
||||
{ tabs::SESSION, { "Session", view::session }},
|
||||
{ tabs::PLAYER_DATABASE, { "Player Database", view::player_database }},
|
||||
}}},
|
||||
{tabs::SETTINGS, { "Settings", view::settings, {
|
||||
{ tabs::CONTEXT_MENU_SETTINGS, { "Context Menu", view::context_menu_settings}},
|
||||
|
@ -19,17 +19,17 @@ namespace big
|
||||
|
||||
void notification_service::push(std::string title, std::string message)
|
||||
{
|
||||
this->push({ NotificationType::INFO, title, message, std::chrono::system_clock::now(), 3000.f , 1.f});
|
||||
this->push({ NotificationType::INFO, title, message, std::chrono::system_clock::now(), 5000.f , 1.f});
|
||||
}
|
||||
|
||||
void notification_service::push_warning(std::string title, std::string message)
|
||||
{
|
||||
this->push({ NotificationType::WARNING, title, message, std::chrono::system_clock::now(), 3000.f , 1.f });
|
||||
this->push({ NotificationType::WARNING, title, message, std::chrono::system_clock::now(), 7000.f , 1.f });
|
||||
}
|
||||
|
||||
void notification_service::push_error(std::string title, std::string message)
|
||||
{
|
||||
this->push({ NotificationType::DANGER, title, message, std::chrono::system_clock::now(), 3000.f , 1.f });
|
||||
this->push({ NotificationType::DANGER, title, message, std::chrono::system_clock::now(), 7000.f , 1.f });
|
||||
}
|
||||
|
||||
std::vector<notification> notification_service::get()
|
||||
|
39
src/services/player_database/persistent_player.hpp
Normal file
39
src/services/player_database/persistent_player.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "core/data/infractions.hpp"
|
||||
#include <unordered_set>
|
||||
#include "json_util.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
struct persistent_player
|
||||
{
|
||||
std::string name;
|
||||
std::uint64_t rockstar_id = 0;
|
||||
bool block_join = false;
|
||||
int block_join_reason = 1;
|
||||
bool is_modder = false;
|
||||
std::unordered_set<int> infractions;
|
||||
};
|
||||
|
||||
static void to_json(nlohmann::json& j, const persistent_player& player)
|
||||
{
|
||||
j = nlohmann::json{
|
||||
{ "name", player.name },
|
||||
{ "rockstar_id", player.rockstar_id },
|
||||
{ "block_join", player.block_join },
|
||||
{ "block_join_reason", player.block_join_reason },
|
||||
{ "is_modder", player.is_modder },
|
||||
{ "infractions", player.infractions },
|
||||
};
|
||||
};
|
||||
|
||||
static void from_json(const nlohmann::json& j, persistent_player& player)
|
||||
{
|
||||
set_from_key_or_default(j, "name", player.name);
|
||||
set_from_key_or_default(j, "rockstar_id", player.rockstar_id);
|
||||
set_from_key_or_default(j, "block_join", player.block_join);
|
||||
set_from_key_or_default(j, "block_join_reason", player.block_join_reason);
|
||||
set_from_key_or_default(j, "is_modder", player.is_modder);
|
||||
set_from_key_or_default(j, "infractions", player.infractions);
|
||||
}
|
||||
};
|
98
src/services/player_database/player_database_service.cpp
Normal file
98
src/services/player_database/player_database_service.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
#include "player_database_service.hpp"
|
||||
#include "file_manager.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
player_database_service::player_database_service() :
|
||||
m_file_path(g_file_manager->get_project_file("./players.json").get_path())
|
||||
{
|
||||
load();
|
||||
g_player_database_service = this;
|
||||
}
|
||||
|
||||
player_database_service::~player_database_service()
|
||||
{
|
||||
g_player_database_service = nullptr;
|
||||
}
|
||||
|
||||
void player_database_service::save()
|
||||
{
|
||||
nlohmann::json json;
|
||||
|
||||
for (auto& [rid, player] : m_players)
|
||||
{
|
||||
json[std::to_string(rid)] = player;
|
||||
}
|
||||
|
||||
std::ofstream file_stream(m_file_path);
|
||||
file_stream << json;
|
||||
}
|
||||
|
||||
void player_database_service::load()
|
||||
{
|
||||
m_selected = nullptr;
|
||||
if (std::filesystem::exists(m_file_path))
|
||||
{
|
||||
std::ifstream file_stream(m_file_path);
|
||||
|
||||
nlohmann::json json;
|
||||
file_stream >> json;
|
||||
file_stream.close();
|
||||
|
||||
for (auto& p : json.items())
|
||||
{
|
||||
m_players[std::stoi(p.key())] = p.value().get<persistent_player>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unordered_map<std::uint64_t, persistent_player>& player_database_service::get_players()
|
||||
{
|
||||
return m_players;
|
||||
}
|
||||
|
||||
persistent_player* player_database_service::get_player_by_rockstar_id(std::uint64_t rockstar_id)
|
||||
{
|
||||
if (m_players.contains(rockstar_id))
|
||||
return &m_players[rockstar_id];
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
persistent_player* player_database_service::get_or_create_player(player_ptr player)
|
||||
{
|
||||
if (m_players.contains(player->get_net_data()->m_gamer_handle_2.m_rockstar_id))
|
||||
return &m_players[player->get_net_data()->m_gamer_handle_2.m_rockstar_id];
|
||||
else
|
||||
{
|
||||
m_players[player->get_net_data()->m_gamer_handle_2.m_rockstar_id] = { player->get_name(), player->get_net_data()->m_gamer_handle_2.m_rockstar_id };
|
||||
save();
|
||||
return &m_players[player->get_net_data()->m_gamer_handle_2.m_rockstar_id];
|
||||
}
|
||||
}
|
||||
|
||||
void player_database_service::update_rockstar_id(std::uint64_t old, std::uint64_t _new)
|
||||
{
|
||||
auto player = m_players.extract(old);
|
||||
player.key() = _new;
|
||||
|
||||
m_players.insert(std::move(player));
|
||||
}
|
||||
|
||||
void player_database_service::remove_rockstar_id(std::uint64_t rockstar_id)
|
||||
{
|
||||
if (m_selected && m_selected->rockstar_id == rockstar_id)
|
||||
m_selected = nullptr;
|
||||
|
||||
m_players.erase(rockstar_id);
|
||||
}
|
||||
|
||||
void player_database_service::set_selected(persistent_player* selected)
|
||||
{
|
||||
m_selected = selected;
|
||||
}
|
||||
|
||||
persistent_player* player_database_service::get_selected()
|
||||
{
|
||||
return m_selected;
|
||||
}
|
||||
}
|
31
src/services/player_database/player_database_service.hpp
Normal file
31
src/services/player_database/player_database_service.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "persistent_player.hpp"
|
||||
#include "services/players/player.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
class player_database_service
|
||||
{
|
||||
std::unordered_map<std::uint64_t, persistent_player> m_players;
|
||||
persistent_player* m_selected = nullptr;
|
||||
|
||||
public:
|
||||
std::filesystem::path m_file_path;
|
||||
player_database_service();
|
||||
~player_database_service();
|
||||
|
||||
void save();
|
||||
void load();
|
||||
|
||||
std::unordered_map<std::uint64_t, persistent_player>& get_players();
|
||||
persistent_player* get_player_by_rockstar_id(std::uint64_t rockstar_id);
|
||||
persistent_player* get_or_create_player(player_ptr player);
|
||||
void update_rockstar_id(std::uint64_t old, std::uint64_t _new);
|
||||
void remove_rockstar_id(std::uint64_t rockstar_id);
|
||||
|
||||
void set_selected(persistent_player* selected);
|
||||
persistent_player* get_selected();
|
||||
};
|
||||
|
||||
inline player_database_service* g_player_database_service;
|
||||
}
|
@ -45,6 +45,10 @@ namespace big
|
||||
std::chrono::system_clock::time_point m_last_transition_msg_sent{};
|
||||
int m_num_failed_transition_attempts = 0;
|
||||
|
||||
bool is_modder = false;
|
||||
bool block_join = false;
|
||||
int block_join_reason = 0;
|
||||
|
||||
protected:
|
||||
bool equals(const CNetGamePlayer* net_game_player) const;
|
||||
|
||||
|
47
src/services/vehicle/model_attachment.hpp
Normal file
47
src/services/vehicle/model_attachment.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include "natives.hpp"
|
||||
#include "json_util.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
struct model_attachment
|
||||
{
|
||||
Hash model_hash;
|
||||
Vector3 position;
|
||||
Vector3 rotation;
|
||||
bool has_collision;
|
||||
bool is_visible;
|
||||
bool is_invincible;
|
||||
|
||||
};
|
||||
|
||||
static void to_json(nlohmann::json& j, const model_attachment& attachment)
|
||||
{
|
||||
|
||||
j = nlohmann::json{ {"model_hash", attachment.model_hash},
|
||||
{"position_x", attachment.position.x}, {"position_y", attachment.position.y}, {"position_z", attachment.position.z},
|
||||
{"rotation_x", attachment.rotation.x}, {"rotation_y", attachment.rotation.y}, {"rotation_z", attachment.rotation.z},
|
||||
{"has_collision", attachment.has_collision},
|
||||
{"is_visible", attachment.is_visible},
|
||||
{"is_invincible", attachment.is_invincible}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
static void from_json(const nlohmann::json& j, model_attachment& attachment)
|
||||
{
|
||||
set_from_key_or_default(j, "model_hash", attachment.model_hash);
|
||||
|
||||
set_from_key_or_default(j, "position_x", attachment.position.x);
|
||||
set_from_key_or_default(j, "position_y", attachment.position.y);
|
||||
set_from_key_or_default(j, "position_z", attachment.position.z);
|
||||
|
||||
set_from_key_or_default(j, "rotation_x", attachment.rotation.x);
|
||||
set_from_key_or_default(j, "rotation_y", attachment.rotation.y);
|
||||
set_from_key_or_default(j, "rotation_z", attachment.rotation.z);
|
||||
|
||||
set_from_key_or_default(j, "has_collision", attachment.has_collision);
|
||||
set_from_key_or_default(j, "is_visible", attachment.is_visible, true);
|
||||
set_from_key_or_default(j, "is_invincible", attachment.is_invincible);
|
||||
}
|
||||
};
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "natives.hpp"
|
||||
#include "core/data/model_attachment.hpp"
|
||||
#include "model_attachment.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
|
Reference in New Issue
Block a user