add sv_votesrequired dvar

This commit is contained in:
mxve 2024-05-21 05:29:56 +02:00
parent 4394864b99
commit 231f2c2d69
2 changed files with 24 additions and 2 deletions

View File

@ -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<std::string, Vote::CommandHandler> 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<int>();
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<std::uint32_t>(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);

View File

@ -11,11 +11,14 @@ namespace Components
using CommandHandler = std::function<bool(const Game::gentity_s* ent, const Command::ServerParams* params)>;
static std::unordered_map<std::string, CommandHandler> VoteCommands;
static Dvar::Var SV_VotesRequired;
static constexpr auto* CallVoteDesc = "%c \"GAME_VOTECOMMANDSARE\x15 map_restart, map_rotate, map <mapname>, g_gametype <typename>, typemap <typename> <mapname>, "
"kick <player>, tempBanUser <player>\"";
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);