Merge pull request #457 from diamante0018/develop

[Vote] Handle client commands for kick & tempbanuser
This commit is contained in:
Dss0 2022-08-24 18:06:25 +02:00 committed by GitHub
commit 807217436b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -11,6 +11,8 @@ namespace Components
{"typemap", HandleTypemap},
{"map", HandleMap},
{"g_gametype", HandleGametype},
{"kick", HandleKick},
{"tempBanUser", HandleKick}
};
void Vote::DisplayVote(const Game::gentity_s* ent)
@ -150,6 +152,35 @@ namespace Components
return true;
}
bool Vote::HandleKick(const Game::gentity_s* ent, const Command::ServerParams* params)
{
char cleanName[0x40]{};
auto kicknum = Game::level->maxclients;
for (auto i = 0; i < Game::level->maxclients; ++i)
{
if (Game::level->clients[i].sess.connected == Game::CON_CONNECTED)
{
strncpy_s(cleanName, Game::level->clients[i].sess.cs.name, _TRUNCATE);
Game::I_CleanStr(cleanName);
if (Utils::String::Compare(cleanName, params->get(2)))
{
kicknum = i;
}
}
}
if (kicknum == Game::level->maxclients)
{
Game::SV_GameSendServerCommand(ent - Game::g_entities, Game::SV_CMD_CAN_IGNORE, VA("%c \"GAME_CLIENTNOTONSERVER\"", 0x65));
return false;
}
sprintf_s(Game::level->voteString, "%s \"%d\"", "tempBanClient", kicknum); // kick and tempBanClient do the same thing
sprintf_s(Game::level->voteDisplayString, "GAME_VOTE_KICK\x15(%i)%s", kicknum, Game::level->clients[kicknum].sess.cs.name);
return true;
}
void Vote::Scr_VoteCalled(Game::gentity_s* self, const char* command, const char* param1, const char* param2)
{
Game::Scr_AddString(param2);
@ -286,6 +317,9 @@ namespace Components
Vote::Vote()
{
// Replicate g_allowVote
Utils::Hook::Set<DWORD>(0x5E3A4F, Game::DVAR_INTERNAL | Game::DVAR_CODINFO);
ClientCommand::Add("callvote", Cmd_CallVote_f);
ClientCommand::Add("vote", Cmd_Vote_f);

View File

@ -12,7 +12,7 @@ namespace Components
static std::unordered_map<std::string, CommandHandler> VoteCommands;
static constexpr auto* CallVoteDesc = "%c \"GAME_VOTECOMMANDSARE\x15 map_restart, map_rotate, map <mapname>, g_gametype <typename>, typemap <typename> <mapname>, "
" kick <player>, tempBanUser <player>\"";
"kick <player>, tempBanUser <player>\"";
static void DisplayVote(const Game::gentity_s* ent);
static bool IsInvalidVoteString(const std::string& input);
@ -22,6 +22,7 @@ namespace Components
static bool HandleTypemap(const Game::gentity_s* ent, const Command::ServerParams* params);
static bool HandleMap(const Game::gentity_s* ent, const Command::ServerParams* params);
static bool HandleGametype(const Game::gentity_s* ent, const Command::ServerParams* params);
static bool HandleKick(const Game::gentity_s* ent, const Command::ServerParams* params);
static void Scr_VoteCalled(Game::gentity_s* self, const char* command, const char* param1, const char* param2);
static void Scr_PlayerVote(Game::gentity_s* self, const char* option);