From 231f2c2d69766727446117b0b5deda86065be0a1 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Tue, 21 May 2024 05:29:56 +0200 Subject: [PATCH 1/2] add sv_votesrequired dvar --- src/Components/Modules/Vote.cpp | 23 +++++++++++++++++++++-- src/Components/Modules/Vote.hpp | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Vote.cpp b/src/Components/Modules/Vote.cpp index 9679907d..b149198f 100644 --- a/src/Components/Modules/Vote.cpp +++ b/src/Components/Modules/Vote.cpp @@ -2,11 +2,14 @@ #include "ClientCommand.hpp" #include "MapRotation.hpp" #include "Vote.hpp" +#include "Events.hpp" using namespace Utils::String; namespace Components { + Dvar::Var Vote::SV_VotesRequired; + std::unordered_map Vote::VoteCommands = { {"map_restart", HandleMapRestart}, @@ -37,6 +40,17 @@ namespace Components Game::SV_SetConfigstring(Game::CS_VOTE_NO, VA("%i", Game::level->voteNo)); } + int Vote::VotesRequired() + { + auto votesRequired = Vote::SV_VotesRequired.get(); + + if (votesRequired > 0) + { + return votesRequired; + } + return Game::level->numConnectedClients / 2 + 1; + } + bool Vote::IsInvalidVoteString(const std::string& input) { static const char* separators[] = { "\n", "\r", ";" }; @@ -204,7 +218,7 @@ namespace Components return; } - if (Game::level->numConnectedClients < 2) + if (Game::level->numConnectedClients < VotesRequired()) { Game::SV_GameSendServerCommand(ent - Game::g_entities, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_VOTINGNOTENOUGHPLAYERS\"", 0x65)); return; @@ -218,7 +232,7 @@ namespace Components return; } - if (ent->client->sess.voteCount >= 3) + if (ent->client->sess.voteCount >= VotesRequired()) { Game::SV_GameSendServerCommand(ent - Game::g_entities, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_MAXVOTESCALLED\"", 0x65)); return; @@ -321,6 +335,11 @@ namespace Components // Replicate g_allowVote Utils::Hook::Set(0x5E3A4F, Game::DVAR_INTERNAL | Game::DVAR_CODINFO); + Events::OnDvarInit([]() + { + Vote::SV_VotesRequired = Game::Dvar_RegisterInt("sv_votesRequired", 0, 0, 18, Game::DVAR_NONE, ""); + }); + ClientCommand::Add("callvote", Cmd_CallVote_f); ClientCommand::Add("vote", Cmd_Vote_f); diff --git a/src/Components/Modules/Vote.hpp b/src/Components/Modules/Vote.hpp index 82b35d22..ac4f4405 100644 --- a/src/Components/Modules/Vote.hpp +++ b/src/Components/Modules/Vote.hpp @@ -11,11 +11,14 @@ namespace Components using CommandHandler = std::function; static std::unordered_map VoteCommands; + static Dvar::Var SV_VotesRequired; + static constexpr auto* CallVoteDesc = "%c \"GAME_VOTECOMMANDSARE\x15 map_restart, map_rotate, map , g_gametype , typemap , " "kick , tempBanUser \""; static void DisplayVote(const Game::gentity_s* ent); static bool IsInvalidVoteString(const std::string& input); + static int VotesRequired(); static bool HandleMapRestart(const Game::gentity_s* ent, const Command::ServerParams* params); static bool HandleMapRotate(const Game::gentity_s* ent, const Command::ServerParams* params); From 41039f9b19b05ef313e6588342fe06f30c5654cb Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Tue, 21 May 2024 05:35:40 +0200 Subject: [PATCH 2/2] add sv_votesrequired description --- src/Components/Modules/Vote.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Components/Modules/Vote.cpp b/src/Components/Modules/Vote.cpp index b149198f..8a2d6c2c 100644 --- a/src/Components/Modules/Vote.cpp +++ b/src/Components/Modules/Vote.cpp @@ -335,9 +335,8 @@ namespace Components // Replicate g_allowVote Utils::Hook::Set(0x5E3A4F, Game::DVAR_INTERNAL | Game::DVAR_CODINFO); - Events::OnDvarInit([]() - { - Vote::SV_VotesRequired = Game::Dvar_RegisterInt("sv_votesRequired", 0, 0, 18, Game::DVAR_NONE, ""); + Events::OnDvarInit([]{ + Vote::SV_VotesRequired = Game::Dvar_RegisterInt("sv_votesRequired", 0, 0, 18, Game::DVAR_NONE, "Set the amount of votes required for a vote to pass.\n0 = (players / 2) + 1"); }); ClientCommand::Add("callvote", Cmd_CallVote_f);