Skip to content

Commit

Permalink
Merge pull request #20 from iBoonie/votefix
Browse files Browse the repository at this point in the history
Validate vote
  • Loading branch information
sapphonie authored Aug 15, 2022
2 parents 3fe840f + e6cc93f commit d42f2f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
13 changes: 5 additions & 8 deletions addons/sourcemod/scripting/nativevotes.sp
Original file line number Diff line number Diff line change
Expand Up @@ -676,22 +676,19 @@ public Action Command_Vote(int client, const char[] command, int argc)

int item = Game_ParseVote(option);

bool cancel;

if (item == NATIVEVOTES_VOTE_INVALID)
// Make sure we don't go out of bounds on the vote
if (item == NATIVEVOTES_VOTE_INVALID || item > g_Items)
{
cancel = true;
return Plugin_Handled;
}

bool cancel;

if (Data_GetFlags(g_hCurVote) & MENUFLAG_BUTTON_NOVOTE && item == 0)
{
cancel = true;
}

/*
* If they choose no vote or the vote is invalid (typed command), then
* treat it as no vote and adjust the numbers.
*/
if (cancel)
{
OnCancel(g_hCurVote, client, MenuCancel_Exit);
Expand Down
23 changes: 14 additions & 9 deletions addons/sourcemod/scripting/nativevotes/game.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,20 +2142,25 @@ static int TF2_ParseVote(const char[] option)
// the update on 2022-06-22 changed the params passed to the `vote` command
// previously it was a single string "optionN", where N was the option to be selected
// now it's two arguments "X optionN", where X is the vote index being acted on
char arg1[8];
int iArg2 = BreakString(option, arg1, sizeof(arg1));

char argOption[64];
strcopy(argOption, sizeof(argOption), option[iArg2]);
if (strlen(option) == 0 || GetCmdArgs() != 2)
{
return NATIVEVOTES_VOTE_INVALID;
}

// int voteidx = GetCmdArgInt(1);

char voteOption[16];
GetCmdArg(2, voteOption, sizeof(voteOption));

int voteidx = StringToInt(arg1);
// option1 <-- 7 characters exactly
if (strlen(argOption) != 7)
// voteOption's last character should be numeric
if (strlen(voteOption) != 7 || !IsCharNumeric(voteOption[6]))
{
return NATIVEVOTES_VOTE_INVALID;
}

return StringToInt(argOption[6]) - 1;
return StringToInt(voteOption[6]) - 1;
}

static void CSGO_ClientSelectedItem(NativeVote vote, int client, int item)
Expand Down Expand Up @@ -2370,7 +2375,7 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients)
else
{
BfWrite bfStart = UserMessageToBfWrite(voteStart);
bfStart.WriteByte(team);
bfStart.WriteByte(team);
bfStart.WriteNum(s_nNativeVoteIdx);
bfStart.WriteByte(Data_GetInitiator(vote));
bfStart.WriteString(translation);
Expand Down

0 comments on commit d42f2f4

Please sign in to comment.