diff --git a/src/hooks/player_management/assign_physical_index.cpp b/src/hooks/player_management/assign_physical_index.cpp index 82f1c496..8187164b 100644 --- a/src/hooks/player_management/assign_physical_index.cpp +++ b/src/hooks/player_management/assign_physical_index.cpp @@ -115,32 +115,7 @@ namespace big } if (plyr->block_join && *g_pointers->m_gta.m_is_session_started) - { - if (g_player_service->get_self()->is_host()) - { - dynamic_cast(command::get("breakup"_J))->call(plyr, {}); - } - else - { - dynamic_cast(command::get("desync"_J))->call(plyr, {}); - } - } - - if (g.session.lock_session && g_player_service->get_self()->is_host() && *g_pointers->m_gta.m_is_session_started) - { - if ((plyr->is_friend() && g.session.allow_friends_into_locked_session) || plyr->is_trusted) - { - g_notification_service.push_success("LOBBY_LOCK"_T.data(), - std::vformat("LOBBY_LOCK_ALLOWED"_T.data(), - std::make_format_args(plyr->get_net_data()->m_name))); - } - else - { - dynamic_cast(command::get("smartkick"_J))->call(plyr, {}); - g_notification_service.push_warning("LOBBY_LOCK"_T.data(), - std::vformat("LOBBY_LOCK_DENIED"_T.data(), std::make_format_args(plyr->get_net_data()->m_name))); - } - } + dynamic_cast(command::get("smartkick"_J))->call(plyr, {}); if (is_spoofed_host_token(plyr->get_net_data()->m_host_token)) { diff --git a/src/hooks/protections/handle_join_request.cpp b/src/hooks/protections/handle_join_request.cpp index 15ea1bd6..2910e4b6 100644 --- a/src/hooks/protections/handle_join_request.cpp +++ b/src/hooks/protections/handle_join_request.cpp @@ -1,5 +1,7 @@ #include "hooking/hooking.hpp" #include "pointers.hpp" +#include "services/friends/friends_service.hpp" +#include "services/notifications/notification.hpp" #include "services/player_database/player_database_service.hpp" #include @@ -10,19 +12,39 @@ namespace big { bool hooks::handle_join_request(Network* network, rage::snSession* session, rage::rlGamerInfo* player_info, CJoinRequestContext* ctx, BOOL is_transition_session) { - if (auto player = g_player_database_service->get_player_by_rockstar_id(player_info->m_gamer_handle.m_rockstar_id); - player && player->block_join) [[unlikely]] - { + auto rockstar_id = player_info->m_gamer_handle.m_rockstar_id; + auto is_friend = friends_service::is_friend(rockstar_id); + auto db_player = g_player_database_service->get_player_by_rockstar_id(rockstar_id); + auto block_join = db_player && db_player->block_join; + auto is_trusted = db_player && db_player->is_trusted; + auto player_name = player_info->m_name; + + auto send_response = [ctx](int block_join_reason = 1) { CMsgJoinResponse response{}; - response.m_status_code = player->block_join_reason; + response.m_status_code = block_join_reason; g_pointers->m_gta.m_write_join_response_data(&response, ctx->m_join_response_data, 512, &ctx->m_join_response_size); - g_notification_service.push("BLOCK_JOIN"_T.data(), - std::vformat("BLOCK_JOIN_INFO"_T, std::make_format_args(player->name))); + }; + + if (block_join) + { + send_response(db_player->block_join_reason); + g_notification_service.push("BLOCK_JOIN"_T.data(), std::vformat("BLOCK_JOIN_INFO"_T, std::make_format_args(player_name))); return false; } - else [[likely]] + else if (g.session.lock_session) { - return g_hooking->get_original()(network, session, player_info, ctx, is_transition_session); + if ((is_friend && g.session.allow_friends_into_locked_session) || is_trusted) + { + g_notification_service.push_success("LOBBY_LOCK"_T.data(), std::vformat("LOBBY_LOCK_ALLOWED"_T.data(), std::make_format_args(player_name))); + } + else + { + send_response(); + g_notification_service.push_warning("LOBBY_LOCK"_T.data(), std::vformat("LOBBY_LOCK_DENIED"_T.data(), std::make_format_args(player_name))); + return false; + } } + + return g_hooking->get_original()(network, session, player_info, ctx, is_transition_session); } } diff --git a/src/services/friends/friends_service.cpp b/src/services/friends/friends_service.cpp index b78a5b29..55829e32 100644 --- a/src/services/friends/friends_service.cpp +++ b/src/services/friends/friends_service.cpp @@ -17,6 +17,15 @@ namespace big g_friends_service = nullptr; } + bool friends_service::is_friend(int64_t rockstar_id) + { + for (uint32_t i = 0; i < g_pointers->m_gta.m_friend_registry->m_friend_count; i++) + if (rockstar_id == g_pointers->m_gta.m_friend_registry->get(i)->m_rockstar_id) + return true; + + return false; + } + bool friends_service::is_friend(CNetGamePlayer* net_player) { if (net_player == nullptr) @@ -25,9 +34,7 @@ namespace big if (auto net_data = net_player->get_net_data()) { const auto rockstar_id = net_data->m_gamer_handle.m_rockstar_id; - for (uint32_t i = 0; i < g_pointers->m_gta.m_friend_registry->m_friend_count; i++) - if (rockstar_id == g_pointers->m_gta.m_friend_registry->get(i)->m_rockstar_id) - return true; + return is_friend(rockstar_id); } return false; } diff --git a/src/services/friends/friends_service.hpp b/src/services/friends/friends_service.hpp index 79bd2f9f..9b34293f 100644 --- a/src/services/friends/friends_service.hpp +++ b/src/services/friends/friends_service.hpp @@ -13,6 +13,7 @@ namespace big friends_service& operator=(const friends_service&) = delete; friends_service& operator=(friends_service&&) noexcept = delete; + [[nodiscard]] static bool is_friend(int64_t rockstar_id); [[nodiscard]] static bool is_friend(CNetGamePlayer* net_player); };