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
This commit is contained in:
HCR-750F
2023-11-04 21:54:32 +08:00
committed by GitHub
parent b5c7a70e7b
commit 5cd260d198
19 changed files with 135 additions and 62 deletions

View File

@ -20,6 +20,14 @@ namespace big
{
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)
{
@ -34,8 +42,8 @@ namespace big
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,
false))
notify::draw_chat(chat, g_player_service->get_self()->get_name(), false);
is_team_only))
notify::draw_chat(chat, g_player_service->get_self()->get_name(), is_team_only);
});
}

View File

@ -14,7 +14,7 @@ namespace big
bool m_blockable;
bool m_karmaable;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(interloper_reaction, announce_in_chat, notify, log, add_to_player_db, block_joins, kick, block, karma, timeout)// json doesn't serialize parent fields automatically
NLOHMANN_DEFINE_TYPE_INTRUSIVE(interloper_reaction, announce_in_chat, is_team_only, notify, log, add_to_player_db, block_joins, kick, block, karma, timeout) // json doesn't serialize parent fields automatically
virtual void process(player_ptr attacker, player_ptr victim);
};

View File

@ -19,12 +19,6 @@ namespace big
void reaction::process_common(player_ptr player)
{
if (log)
{
uint64_t rockstar_id = player->get_net_data() == nullptr ? 0 : player->get_net_data()->m_gamer_handle.m_rockstar_id;
LOG(WARNING) << std::format("Received {} from {} ({})", m_event_name, player->get_name(), rockstar_id);
}
if (add_to_player_db)
{
auto entry = g_player_database_service->get_or_create_player(player);
@ -49,7 +43,7 @@ namespace big
player->block_net_events = true;
player->block_clone_sync = true;
player->block_clone_create = true;
LOG(WARNING) << std::format("{} has been timed out", player->get_name());
LOGF(WARNING, "{} has been timed out", player->get_name());
}
}
@ -58,6 +52,14 @@ namespace big
{
if (!player->is_valid())
return;
if ((player->is_friend() && g.session.trust_friends) || player->is_trusted || g.session.trust_session)
return;
if (log)
{
uint64_t rockstar_id = player->get_net_data() == nullptr ? 0 : player->get_net_data()->m_gamer_handle.m_rockstar_id;
LOGF(WARNING, "Received {} from {} ({})", m_event_name, player->get_name(), rockstar_id);
}
if (announce_in_chat)
{
@ -71,8 +73,8 @@ namespace big
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,
false))
notify::draw_chat(chat, g_player_service->get_self()->get_name(), false);
is_team_only))
notify::draw_chat(chat, g_player_service->get_self()->get_name(), is_team_only);
});
}

View File

@ -9,6 +9,7 @@ namespace big
{
public:
bool announce_in_chat = false;
bool is_team_only = false;
bool notify = true;
bool log = true;
bool add_to_player_db = false;
@ -20,7 +21,7 @@ namespace big
const char* m_notify_message;
const char* m_announce_message;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(reaction, announce_in_chat, notify, log, add_to_player_db, block_joins, kick, timeout)
NLOHMANN_DEFINE_TYPE_INTRUSIVE(reaction, announce_in_chat, is_team_only, notify, log, add_to_player_db, block_joins, kick, timeout)
reaction(const char* event_name, const char* notify_message, const char* announce_message);
virtual void process(player_ptr player);