Merge pull request #1005 from nullworks/votelogger

Log votes to [Cat] chat by default instead of party chat
This commit is contained in:
TotallyNotElite 2020-05-13 16:32:29 +02:00 committed by GitHub
commit 16207c7d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 21 deletions

View File

@ -118,10 +118,11 @@
<AutoVariable width="fill" target="votelogger.autovote.yes" label="Autovote Yes"/>
<AutoVariable width="fill" target="votelogger.autovote.no" label="Autovote No"/>
<AutoVariable width="fill" target="votelogger.autovote.no.rage" label="Kick RAGE status"/>
<AutoVariable width="fill" target="votelogger.partysay" label="Log Votes to Party"/>
<AutoVariable width="fill" target="votelogger.partysay-casts" label="Log Casts to Party"/>
<AutoVariable width="fill" target="votelogger.partysay-casts.f1-only" label="F1 Cast Log Only"/>
<AutoVariable width="fill" target="votelogger.restart-on-kick" label="Crash When Kicked"/>
<AutoVariable width="fill" target="votelogger.chat" label="Log votes" tooltip="Shows you new votekicks in your personal chat."/>
<AutoVariable width="fill" target="votelogger.chat.partysay" label="Log votes to Party"/>
<AutoVariable width="fill" target="votelogger.chat.casts" label="Log casts" tooltip="Also log individual vote casts (F1/F2)"/>
<AutoVariable width="fill" target="votelogger.chat.casts.f1-only" label="Log F1 casts only" tooltip="Log exclusively F1 casts."/>
<AutoVariable width="fill" target="votelogger.restart-on-kick" label="Crash when kicked"/>
</List>
</Box>
<Box name="Command & Control" width="content" height="content" padding="12 6 6 6" y="235">

View File

@ -226,9 +226,11 @@ struct migration_struct
};
/* clang-format off */
// Use one per line, from -> to
static std::array<migration_struct, 2> migrations({
static std::array<migration_struct, 4> migrations({
migration_struct{ "misc.semi-auto", "misc.full-auto" },
migration_struct{ "cat-bot.abandon-if.bots-gte", "cat-bot.abandon-if.ipc-bots-gte" }
migration_struct{ "cat-bot.abandon-if.bots-gte", "cat-bot.abandon-if.ipc-bots-gte" },
migration_struct{ "votelogger.partysay-casts", "votelogger.chat.casts" },
migration_struct{ "votelogger.partysay-casts.f1-only", "votelogger.chat.casts.f1-only" }
});
/* clang-format on */
void settings::SettingsReader::finishString(bool complete)

View File

@ -14,9 +14,11 @@
static settings::Boolean vote_kicky{ "votelogger.autovote.yes", "false" };
static settings::Boolean vote_kickn{ "votelogger.autovote.no", "false" };
static settings::Boolean vote_rage_vote{ "votelogger.autovote.no.rage", "false" };
static settings::Boolean party_say{ "votelogger.partysay", "true" };
static settings::Boolean party_say_casts{ "votelogger.partysay-casts", "false" };
static settings::Boolean party_say_f1_only{ "votelogger.partysay-casts.f1-only", "true" };
static settings::Boolean chat{ "votelogger.chat", "true" };
static settings::Boolean chat_partysay{ "votelogger.chat.partysay", "false" };
static settings::Boolean chat_casts{ "votelogger.chat.casts", "false" };
static settings::Boolean chat_casts_f1_only{ "votelogger.chat.casts.f1-only", "true" };
// Leave party and crash, useful for personal party bots
static settings::Boolean abandon_and_crash_on_kick{ "votelogger.restart-on-kick", "false" };
namespace votelogger
@ -82,19 +84,19 @@ void dispatchUserMessage(bf_read &buffer, int type)
char name[64];
buffer.ReadString(reason, 64, false, nullptr);
buffer.ReadString(name, 64, false, nullptr);
auto eid = (unsigned char) buffer.ReadByte();
auto target = (unsigned char) buffer.ReadByte();
buffer.Seek(0);
eid >>= 1;
target >>= 1;
// info is the person getting kicked,
// info2 is the person calling the kick.
player_info_s info{}, info2{};
if (!g_IEngine->GetPlayerInfo(eid, &info) || !g_IEngine->GetPlayerInfo(caller, &info2))
if (!g_IEngine->GetPlayerInfo(target, &info) || !g_IEngine->GetPlayerInfo(caller, &info2))
break;
kicked_player = eid;
kicked_player = target;
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)
if (target == LOCAL_E->m_IDX)
{
was_local_player = true;
local_kick_timer.update();
@ -122,12 +124,15 @@ void dispatchUserMessage(bf_read &buffer, int type)
vote_command.timer.update();
}
}
if (*party_say)
if (*chat_partysay)
{
char formated_string[256];
std::snprintf(formated_string, sizeof(formated_string), "[CAT] votekick called: %s => %s (%s)", info2.name, info.name, reason);
re::CTFPartyClient::GTFPartyClient()->SendPartyChat(formated_string);
if (chat_partysay)
re::CTFPartyClient::GTFPartyClient()->SendPartyChat(formated_string);
}
if (chat)
PrintChat("Votekick called: \x07%06X%s\x01 => \x07%06X%s\x01 (%s)", colors::chat::team(g_pPlayerResource->getTeam(caller)), info2.name, colors::chat::team(g_pPlayerResource->getTeam(target)), info.name, reason);
break;
}
case 47:
@ -205,22 +210,28 @@ class VoteEventListener : public IGameEventListener
public:
void FireGameEvent(KeyValues *event) override
{
if (!*party_say_casts || !*party_say)
if (!*chat_casts || (!*chat_partysay && !chat))
return;
const char *name = event->GetName();
if (!strcmp(name, "vote_cast"))
{
bool vote_option = event->GetInt("vote_option");
if (*party_say_f1_only && vote_option)
if (*chat_casts_f1_only && vote_option)
return;
int eid = event->GetInt("entityid");
player_info_s info{};
if (!g_IEngine->GetPlayerInfo(eid, &info))
return;
char formated_string[256];
std::snprintf(formated_string, sizeof(formated_string), "[CAT] %s [U:1:%u] %s", info.name, info.friendsID, vote_option ? "F2" : "F1");
re::CTFPartyClient::GTFPartyClient()->SendPartyChat(formated_string);
if (chat_partysay)
{
char formated_string[256];
std::snprintf(formated_string, sizeof(formated_string), "[CAT] %s [U:1:%u] %s", info.name, info.friendsID, vote_option ? "F2" : "F1");
re::CTFPartyClient::GTFPartyClient()->SendPartyChat(formated_string);
}
if (chat)
PrintChat("\x07%06X%s\x01 [U:1:%u] %s", colors::chat::team(g_pPlayerResource->getTeam(eid)), info.name, info.friendsID, vote_option ? "F2" : "F1");
}
}
};