This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/backend/reactions/interloper_reaction.cpp
HCR-750F 7aad4c5860
refactor(reaction): rework reaction code (#2331)
1. Allow interloper_reaction to use timeout.
2. Fix crash reaction(except TSE) cannot use announce in chat.
3. Allow all friends to bypass auto kick spammers, modder flag and  reactions.
Provides an alternative for users who experience this weird bug https://github.com/YimMenu/YimMenu/issues/2266 . They can just trust their friends until someone provides valuable information for developers to fix.
4. Allow trusting specific players (bypass auto kick spammers, modder flag and reactions).
5. Trust the whole session temporarily (Avoid team members being kicked when in mission).
6. Remove duplicate logs when blocking crash (except for TSE crash)
7. remove unused gamer_instruction_kick in reaction list
8. Allow announce in team only chat
2023-11-04 14:54:32 +01:00

59 lines
1.9 KiB
C++

#include "interloper_reaction.hpp"
#include "backend/player_command.hpp"
#include "fiber_pool.hpp"
#include "hooking.hpp"
#include "pointers.hpp"
#include "script.hpp"
#include "util/notify.hpp"
namespace big
{
interloper_reaction::interloper_reaction(const char* event_name, const char* notify_message, const char* announce_message, bool blockable, bool karmaable) :
reaction(event_name, notify_message, announce_message),
m_blockable(blockable),
m_karmaable(karmaable)
{
}
void interloper_reaction::process(player_ptr attacker, player_ptr victim)
{
if (!attacker->is_valid() || !victim->is_valid())
return;
if ((attacker->is_friend() && g.session.trust_friends) || attacker->is_trusted || g.session.trust_session)
return;
if (log)
{
uint64_t rockstar_id = attacker->get_net_data() == nullptr ? 0 : attacker->get_net_data()->m_gamer_handle.m_rockstar_id;
LOGF(WARNING, "Received {} from {} ({}), victim is {}", m_event_name, attacker->get_name(), rockstar_id, victim->get_name());
}
if (announce_in_chat)
{
g_fiber_pool->queue_job([attacker, victim, this] {
char chat[255];
snprintf(chat,
sizeof(chat),
std::format("{} {}", g.session.chat_output_prefix, m_announce_message).data(),
attacker->get_name(),
victim->get_name());
if (g_hooking->get_original<hooks::send_chat_message>()(*g_pointers->m_gta.m_send_chat_ptr,
g_player_service->get_self()->get_net_data(),
chat,
is_team_only))
notify::draw_chat(chat, g_player_service->get_self()->get_name(), is_team_only);
});
}
if (notify)
{
char notification[500]{};// I don't like using sprintf but there isn't an alternative afaik
snprintf(notification, sizeof(notification), m_notify_message, attacker->get_name(), victim->get_name());
g_notification_service->push_warning("PROTECTIONS"_T.data(), notification);
}
process_common(attacker);
}
}