From dca82a40600d0c17bb6aec409ebeeb1f205d8eea Mon Sep 17 00:00:00 2001 From: DayibBaba <79384354+DayibBaba@users.noreply.github.com> Date: Sat, 17 Jun 2023 15:49:48 +0200 Subject: [PATCH] fix: Made breakup conditional (being host) (#1436) Closes #1448 --- .../commands/player/kick/breakup_kick.cpp | 3 ++ .../commands/player/kick/host_kick.cpp | 28 +++++++++++++++++++ src/backend/looped/session/auto_kick_host.cpp | 4 ++- src/backend/reactions/reaction.cpp | 8 ++++-- .../assign_physical_index.cpp | 24 ++++++++++++---- src/hooks/protections/receive_net_message.cpp | 7 ++++- src/views/network/view_session.cpp | 5 ++++ src/views/players/player/player_kick.cpp | 13 +++++++-- 8 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 src/backend/commands/player/kick/host_kick.cpp diff --git a/src/backend/commands/player/kick/breakup_kick.cpp b/src/backend/commands/player/kick/breakup_kick.cpp index 261b9111..f0281a52 100644 --- a/src/backend/commands/player/kick/breakup_kick.cpp +++ b/src/backend/commands/player/kick/breakup_kick.cpp @@ -20,6 +20,9 @@ namespace big virtual void execute(player_ptr player, const std::vector& _args, const std::shared_ptr ctx) { + if (!g_player_service->get_self()->is_host()) + return; + rage::snMsgRemoveGamersFromSessionCmd cmd{}; cmd.m_session_id = gta_util::get_network()->m_game_session_ptr->m_rline_session.m_session_id; cmd.m_num_peers = 1; diff --git a/src/backend/commands/player/kick/host_kick.cpp b/src/backend/commands/player/kick/host_kick.cpp new file mode 100644 index 00000000..344d5902 --- /dev/null +++ b/src/backend/commands/player/kick/host_kick.cpp @@ -0,0 +1,28 @@ +#include "backend/player_command.hpp" +#include "natives.hpp" + +namespace big +{ + class host_kick : player_command + { + using player_command::player_command; + + virtual CommandAccessLevel get_access_level() + { + return CommandAccessLevel::TOXIC; + } + + virtual void execute(player_ptr player, const std::vector& _args, const std::shared_ptr ctx) + { + if (!g_player_service->get_self()->is_host()) + { + g_notification_service->push_error("Host kick", "Host kick failed"); + return; + } + + NETWORK::NETWORK_SESSION_KICK_PLAYER(player->id()); + } + }; + + host_kick g_host_kick("hostkick", "Host Kick", "Host kick that only works when host", 0, false); +} \ No newline at end of file diff --git a/src/backend/looped/session/auto_kick_host.cpp b/src/backend/looped/session/auto_kick_host.cpp index 2e7f3096..8911077f 100644 --- a/src/backend/looped/session/auto_kick_host.cpp +++ b/src/backend/looped/session/auto_kick_host.cpp @@ -14,7 +14,9 @@ namespace big g_player_service->iterate([](auto& plyr) { if (plyr.second->is_host()) { - dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(plyr.second, {}); + dynamic_cast(command::get(RAGE_JOAAT("bailkick")))->call(plyr.second, {}); + dynamic_cast(command::get(RAGE_JOAAT("nfkick")))->call(plyr.second, {}); + //dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(plyr.second, {}); } }); } diff --git a/src/backend/reactions/reaction.cpp b/src/backend/reactions/reaction.cpp index 51eba918..a8f6d60c 100644 --- a/src/backend/reactions/reaction.cpp +++ b/src/backend/reactions/reaction.cpp @@ -36,17 +36,21 @@ namespace big } } - if (kick) + if (kick) { g_fiber_pool->queue_job([player] { + dynamic_cast(command::get(RAGE_JOAAT("bailkick")))->call(player, {}); dynamic_cast(command::get(RAGE_JOAAT("nfkick")))->call(player, {}); script::get_current()->yield(700ms); - dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(player, {}); + if(g_player_service->get_self()->is_host()) + dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(player, {}), + NETWORK::NETWORK_SESSION_KICK_PLAYER(player->id()); }); } } + void reaction::process(player_ptr player) { if (!player->is_valid()) diff --git a/src/hooks/player_management/assign_physical_index.cpp b/src/hooks/player_management/assign_physical_index.cpp index 2c7c3524..c410dc5e 100644 --- a/src/hooks/player_management/assign_physical_index.cpp +++ b/src/hooks/player_management/assign_physical_index.cpp @@ -109,13 +109,25 @@ namespace big } if (plyr->block_join) { - dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(plyr, {}); - g_notification_service->push_warning("Block Join", - std::format("Block Join method failed for {}, sending breakup kick instead...", - plyr->get_net_data()->m_name)); - LOG(WARNING) << "Sending Breakup Kick due to block join failure... "; + if (g_player_service->get_self()->is_host()) + { + dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(plyr, {}); + g_notification_service->push_warning("Block Join", + std::format("Block Join method failed for {}, sending breakup kick instead...", + plyr->get_net_data()->m_name)); + LOG(WARNING) << "Sending Breakup Kick due to block join failure... "; + } + else + { + g_notification_service->push_warning("Block Join", + std::format("Block Join method failed for {}, can't send breakup without host...\n trying Desync", + plyr->get_net_data()->m_name)); + LOG(WARNING) << "Failed blocking join due to not being host... trying Desync "; + + dynamic_cast(command::get(RAGE_JOAAT("desync")))->call(plyr, {}); + } } - if (lock_session) + if (lock_session && g_player_service->get_self()->is_host()) { dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(plyr, {}); g_notification_service->push_warning("Lock Session", diff --git a/src/hooks/protections/receive_net_message.cpp b/src/hooks/protections/receive_net_message.cpp index 5da75777..d7fe7229 100644 --- a/src/hooks/protections/receive_net_message.cpp +++ b/src/hooks/protections/receive_net_message.cpp @@ -117,7 +117,12 @@ namespace big player->is_spammer = true; if (g.session.kick_chat_spammers) { - dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(player, {}); + if(g_player_service->get_self()->is_host()) + dynamic_cast(command::get(RAGE_JOAAT("breakup")))->call(player, {}), + dynamic_cast(command::get(RAGE_JOAAT("hostkick")))->call(player, {}); + + dynamic_cast(command::get(RAGE_JOAAT("bailkick")))->call(player, {}); + dynamic_cast(command::get(RAGE_JOAAT("nfkick")))->call(player, {}); } return true; } diff --git a/src/views/network/view_session.cpp b/src/views/network/view_session.cpp index be4ad821..a203db48 100644 --- a/src/views/network/view_session.cpp +++ b/src/views/network/view_session.cpp @@ -126,9 +126,14 @@ namespace big } components::sub_title("Lobby Lock"); + ImGui::BeginDisabled(!g_player_service->get_self()->is_host()); + ImGui::Checkbox("Lock", &g.session.lock_session); if (ImGui::IsItemHovered()) ImGui::SetTooltip("Blocks all players from joining. May not work on some modders."); + + ImGui::EndDisabled(); + components::sub_title("DECLOAK"_T); components::script_patch_checkbox("REVEAL_OTR_PLAYERS"_T, &g.session.decloak_players); diff --git a/src/views/players/player/player_kick.cpp b/src/views/players/player/player_kick.cpp index a2659b5c..2322a4b8 100644 --- a/src/views/players/player/player_kick.cpp +++ b/src/views/players/player/player_kick.cpp @@ -12,9 +12,16 @@ namespace big return gta_util::get_network()->m_game_session_ptr->is_host(); }; - //components::player_command_button<"breakup">(g_player_service->get_selected()); - //ImGui::SameLine(); - //components::command_checkbox<"breakupcheating">(); + ImGui::Text("Host/breakup kick require Host"); + ImGui::BeginDisabled(!g_player_service->get_self()->is_host()); + + components::player_command_button<"hostkick">(g_player_service->get_selected()); + components::player_command_button<"breakup">(g_player_service->get_selected()); + + ImGui::EndDisabled(); + + ImGui::SameLine(); + components::command_checkbox<"breakupcheating">(); components::player_command_button<"bailkick">(g_player_service->get_selected()); ImGui::SameLine();