diff --git a/src/Components/Modules/Vote.cpp b/src/Components/Modules/Vote.cpp index 9679907d..8a2d6c2c 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,10 @@ 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, "Set the amount of votes required for a vote to pass.\n0 = (players / 2) + 1"); + }); + 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);