move session lock logic to handle_join_request (#3136)
This commit is contained in:
parent
860a466f82
commit
a568dea653
@ -115,32 +115,7 @@ namespace big
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (plyr->block_join && *g_pointers->m_gta.m_is_session_started)
|
if (plyr->block_join && *g_pointers->m_gta.m_is_session_started)
|
||||||
{
|
dynamic_cast<player_command*>(command::get("smartkick"_J))->call(plyr, {});
|
||||||
if (g_player_service->get_self()->is_host())
|
|
||||||
{
|
|
||||||
dynamic_cast<player_command*>(command::get("breakup"_J))->call(plyr, {});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dynamic_cast<player_command*>(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<player_command*>(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)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_spoofed_host_token(plyr->get_net_data()->m_host_token))
|
if (is_spoofed_host_token(plyr->get_net_data()->m_host_token))
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "hooking/hooking.hpp"
|
#include "hooking/hooking.hpp"
|
||||||
#include "pointers.hpp"
|
#include "pointers.hpp"
|
||||||
|
#include "services/friends/friends_service.hpp"
|
||||||
|
#include "services/notifications/notification.hpp"
|
||||||
#include "services/player_database/player_database_service.hpp"
|
#include "services/player_database/player_database_service.hpp"
|
||||||
|
|
||||||
#include <network/CJoinRequestContext.hpp>
|
#include <network/CJoinRequestContext.hpp>
|
||||||
@ -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)
|
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);
|
auto rockstar_id = player_info->m_gamer_handle.m_rockstar_id;
|
||||||
player && player->block_join) [[unlikely]]
|
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{};
|
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_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;
|
return false;
|
||||||
}
|
}
|
||||||
else [[likely]]
|
else if (g.session.lock_session)
|
||||||
{
|
{
|
||||||
return g_hooking->get_original<hooks::handle_join_request>()(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<hooks::handle_join_request>()(network, session, player_info, ctx, is_transition_session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,15 @@ namespace big
|
|||||||
g_friends_service = nullptr;
|
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)
|
bool friends_service::is_friend(CNetGamePlayer* net_player)
|
||||||
{
|
{
|
||||||
if (net_player == nullptr)
|
if (net_player == nullptr)
|
||||||
@ -25,9 +34,7 @@ namespace big
|
|||||||
if (auto net_data = net_player->get_net_data())
|
if (auto net_data = net_player->get_net_data())
|
||||||
{
|
{
|
||||||
const auto rockstar_id = net_data->m_gamer_handle.m_rockstar_id;
|
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++)
|
return is_friend(rockstar_id);
|
||||||
if (rockstar_id == g_pointers->m_gta.m_friend_registry->get(i)->m_rockstar_id)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace big
|
|||||||
friends_service& operator=(const friends_service&) = delete;
|
friends_service& operator=(const friends_service&) = delete;
|
||||||
friends_service& operator=(friends_service&&) noexcept = 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);
|
[[nodiscard]] static bool is_friend(CNetGamePlayer* net_player);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user