add votelogger.restart_on_kick to make catbots restart on kick and quit party

This commit is contained in:
bencat07 2019-05-02 19:00:31 +02:00
parent 3a903863df
commit 0b9893a5cb
4 changed files with 60 additions and 9 deletions

View File

@ -13,4 +13,5 @@ namespace votelogger
{
void dispatchUserMessage(bf_read &buffer, int type);
}
void onShutdown(std::string message);
} // namespace votelogger

View File

@ -80,15 +80,18 @@ static void updateAntiAfk()
}
else
{
if (anti_afk_timer.check(60000))
static auto afk_timer = g_ICvar->FindVar("mp_idlemaxtime");
if (!afk_timer)
afk_timer = g_ICvar->FindVar("mp_idlemaxtime");
// Trigger 10 seconds before kick
else if (afk_timer->m_nValue != 0 && anti_afk_timer.check(afk_timer->m_nValue*60*1000-10000))
{
// Send random commands
current_user_cmd->sidemove = RandFloatRange(-450.0, 450.0);
current_user_cmd->forwardmove = RandFloatRange(-450.0, 450.0);
current_user_cmd->buttons = rand();
// Prevent attack command
current_user_cmd->buttons &= ~(IN_ATTACK | IN_ATTACK2);
if (anti_afk_timer.check(61000))
// Just duck tf
if (current_user_cmd->buttons & IN_DUCK)
current_user_cmd->buttons &= ~IN_DUCK;
else
current_user_cmd->buttons = IN_DUCK;
if (anti_afk_timer.check(afk_timer->m_nValue*60*1000+1000))
{
anti_afk_timer.update();
}

View File

@ -44,6 +44,8 @@ DEFINE_HOOKED_METHOD(Shutdown, void, INetChannel *this_, const char *reason)
if (autoabandon)
tfmm::disconnectAndAbandon();
hacks::shared::autojoin::onShutdown();
std::string message = reason;
votelogger::onShutdown(message);
if (*random_name)
{
static TextFile file;

View File

@ -13,11 +13,13 @@ static settings::Bool vote_kicky{ "votelogger.autovote.yes", "false" };
static settings::Bool vote_kickn{ "votelogger.autovote.no", "false" };
static settings::Bool vote_rage_vote{ "votelogger.autovote.no.rage", "false" };
static settings::Bool party_say{ "votelogger.partysay", "true" };
static settings::Bool abandon_and_crash_on_kick{ "votelogger.restart-on-kick", "false" };
namespace votelogger
{
static bool was_local_player{ false };
static Timer local_kick_timer{};
static void vote_rage_back()
{
@ -79,7 +81,10 @@ void dispatchUserMessage(bf_read &buffer, int type)
logging::Info("Vote called to kick %s [U:1:%u] for %s by %s [U:1:%u]", info.name, info.friendsID, reason, info2.name, info2.friendsID);
if (eid == LOCAL_E->m_IDX)
{
was_local_player = true;
local_kick_timer.update();
}
if (*vote_kickn || *vote_kicky)
{
@ -108,10 +113,12 @@ void dispatchUserMessage(bf_read &buffer, int type)
break;
}
case 47:
{
logging::Info("Vote passed");
// if (was_local_player && requeue)
// tfmm::startQueue();
break;
}
case 48:
logging::Info("Vote failed");
break;
@ -122,6 +129,43 @@ void dispatchUserMessage(bf_read &buffer, int type)
break;
}
}
static bool found_message = false;
void onShutdown(std::string message)
{
if (message.find("Generic_Kicked") == message.npos)
{
found_message = false;
return;
}
if (local_kick_timer.check(60000) || !was_local_player)
{
found_message = false;
return;
}
if (abandon_and_crash_on_kick)
{
found_message = true;
g_IEngine->ClientCmd_Unrestricted("tf_party_leave");
local_kick_timer.update();
}
else
found_message = false;
}
static void setup_paint_abandon()
{
EC::Register(
EC::Paint,
[]() {
if (!found_message)
return;
if (local_kick_timer.check(60000) || !local_kick_timer.test_and_set(10000) || !was_local_player)
return;
if (abandon_and_crash_on_kick)
*(int *) 0 = 0;
},
"vote_abandon_restart");
}
static void setup_vote_rage()
{
@ -136,6 +180,7 @@ static void reset_vote_rage()
static InitRoutine init([]() {
if (*vote_rage_vote)
setup_vote_rage();
setup_paint_abandon();
vote_rage_vote.installChangeCallback([](settings::VariableBase<bool> &var, bool new_val) {
if (new_val)