Reactions, remote kick and better protections (#807)
* feat(Scripts): Complete GlobalPlayerBD * feat(Scripts): add GPBD_Kicking * feat(Scripts): start work on GPBD_FM_3 * feat(Scripts): add more to GPBD_FM_3 * feat(Scripts): complete GPBD_FM_3 * feat(Scripts): start work on GPBD_FM * feat(Scripts): improve GPBD_FM * feat(Scripts): complete GPBD_FM * feat(Reactions): Add reactions * feat(Protections): Improve protections * feat(RemoteKick): Add remote kick * feat(Stats): add KillsOnPlayers and DeathsByPlayers * fix(Classes): Fix compiler warnings
This commit is contained in:
37
src/backend/reactions/interloper_reaction.cpp
Normal file
37
src/backend/reactions/interloper_reaction.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "interloper_reaction.hpp"
|
||||
#include "backend/player_command.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "script.hpp"
|
||||
#include "hooking.hpp"
|
||||
#include "pointers.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 (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_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);
|
||||
});
|
||||
}
|
||||
|
||||
process_common(attacker);
|
||||
}
|
||||
}
|
21
src/backend/reactions/interloper_reaction.hpp
Normal file
21
src/backend/reactions/interloper_reaction.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "reaction.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
class interloper_reaction : public reaction
|
||||
{
|
||||
public:
|
||||
interloper_reaction(const char* event_name, const char* notify_message, const char* announce_message, bool blockable, bool karmaable);
|
||||
|
||||
bool block = true;
|
||||
bool karma = false;
|
||||
|
||||
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) // json doesn't serialize parent fields automatically
|
||||
|
||||
virtual void process(player_ptr attacker, player_ptr victim);
|
||||
};
|
||||
}
|
76
src/backend/reactions/reaction.cpp
Normal file
76
src/backend/reactions/reaction.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
#include "reaction.hpp"
|
||||
#include "backend/player_command.hpp"
|
||||
#include "services/player_database/player_database_service.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "script.hpp"
|
||||
#include "hooking.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "util/notify.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
reaction::reaction(const char* event_name, const char* notify_message, const char* announce_message) :
|
||||
m_event_name(event_name),
|
||||
m_notify_message(notify_message),
|
||||
m_announce_message(announce_message)
|
||||
{
|
||||
}
|
||||
|
||||
void reaction::process_common(player_ptr player)
|
||||
{
|
||||
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, player->get_name());
|
||||
g_notification_service->push_warning("Protections", notification);
|
||||
}
|
||||
|
||||
if (log)
|
||||
{
|
||||
uint64_t rockstar_id = player->get_net_data() == nullptr ? 0 : player->get_net_data()->m_gamer_handle_2.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);
|
||||
|
||||
if (block_joins)
|
||||
{
|
||||
entry->block_join = true;
|
||||
g_player_database_service->save();
|
||||
}
|
||||
}
|
||||
|
||||
if (kick)
|
||||
{
|
||||
g_fiber_pool->queue_job([player]
|
||||
{
|
||||
((player_command*)command::get(RAGE_JOAAT("bailkick")))->call(player, {});
|
||||
((player_command*)command::get(RAGE_JOAAT("nfkick")))->call(player, {});
|
||||
script::get_current()->yield(700ms);
|
||||
((player_command*)command::get(RAGE_JOAAT("breakup")))->call(player, {});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void reaction::process(player_ptr player)
|
||||
{
|
||||
if (!player->is_valid())
|
||||
return;
|
||||
|
||||
if (announce_in_chat)
|
||||
{
|
||||
g_fiber_pool->queue_job([player, this]
|
||||
{
|
||||
char chat[255];
|
||||
snprintf(chat, sizeof(chat), std::format("{} {}", g.session.chat_output_prefix, m_announce_message).data(), player->get_name());
|
||||
|
||||
if (g_hooking->get_original<hooks::send_chat_message>()(*g_pointers->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);
|
||||
});
|
||||
}
|
||||
|
||||
process_common(player);
|
||||
}
|
||||
}
|
30
src/backend/reactions/reaction.hpp
Normal file
30
src/backend/reactions/reaction.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
namespace big
|
||||
{
|
||||
class player;
|
||||
using player_ptr = std::shared_ptr<player>;
|
||||
|
||||
class reaction
|
||||
{
|
||||
protected:
|
||||
void process_common(player_ptr player);
|
||||
|
||||
public:
|
||||
bool announce_in_chat = false;
|
||||
bool notify = true;
|
||||
bool log = false;
|
||||
bool add_to_player_db = false;
|
||||
bool block_joins = false;
|
||||
bool kick = false;
|
||||
|
||||
const char* m_event_name;
|
||||
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)
|
||||
|
||||
reaction(const char* event_name, const char* notify_message, const char* announce_message);
|
||||
virtual void process(player_ptr player);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user