From 30943ed17119277369403228593f63d4be0150a5 Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 14 Oct 2008 09:00:38 +0000 Subject: [PATCH] ignore empty "say" commands, make all argv_start_index calls check if the index is in range git-svn-id: svn://svn.icculus.org/nexuiz/trunk@4746 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/clientcommands.qc | 10 ++++++---- data/qcsrc/server/vote.qc | 16 +++++++++++----- data/qcsrc/server/vote.qh | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/data/qcsrc/server/clientcommands.qc b/data/qcsrc/server/clientcommands.qc index e92d160c3..ce85a3caf 100644 --- a/data/qcsrc/server/clientcommands.qc +++ b/data/qcsrc/server/clientcommands.qc @@ -223,9 +223,9 @@ entity GetPlayer(string name) //float ctf_clientcommand(); void SV_ParseClientCommand(string s) { local string cmd; - local float i; + local float i, tokens; - tokenize_sane(s); + tokens = tokenize_sane(s); if(GameCommand_Vote(s, self)) { return; @@ -371,10 +371,12 @@ void SV_ParseClientCommand(string s) { } else if(argv(0) == "voice") { VoiceMessage(argv(1)); } else if(argv(0) == "say") { - Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); + if(tokens >= 2) + Say(self, FALSE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); //clientcommand(self, formatmessage(s)); } else if(argv(0) == "say_team") { - Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); + if(tokens >= 2) + Say(self, TRUE, substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); //clientcommand(self, formatmessage(s)); } else if(argv(0) == "info") { cmd = cvar_string(strcat("sv_info_", argv(1))); diff --git a/data/qcsrc/server/vote.qc b/data/qcsrc/server/vote.qc index ec749a421..9f46c4072 100644 --- a/data/qcsrc/server/vote.qc +++ b/data/qcsrc/server/vote.qc @@ -37,7 +37,10 @@ entity GetKickVoteVictim(string vote, string cmd, entity caller) if(ns != "") { - GetKickVoteVictim_reason = substring(vote, argv_start_index(t), argv_end_index(-1) - argv_start_index(t)); + if(t < tokens) + GetKickVoteVictim_reason = substring(vote, argv_start_index(t), argv_end_index(-1) - argv_start_index(t)); + else + GetKickVoteVictim_reason = ""; n = stof(ns); if(ns == ftos(n)) if(n >= 1) if(n <= maxclients) @@ -108,7 +111,8 @@ float RemapVote(string vote, string cmd, entity e) } float GameCommand_Vote(string s, entity e) { - tokenize_sane(s); + float argc; + argc = tokenize_sane(s); if(argv(0) == "help") { print_to(e, " vote COMMANDS ARGUMENTS. See 'vote help' for more info."); return TRUE; @@ -135,7 +139,7 @@ float GameCommand_Vote(string s, entity e) { print_to(e, "^1There is already a vote called."); } else { local string vote; - vote = VoteParse(s); + vote = VoteParse(s, argc); if(vote == "") { print_to(e, "^1Your vote is empty. See help for more info."); } else if(e @@ -205,7 +209,7 @@ float GameCommand_Vote(string s, entity e) { } else if(argv(1) == "do") { if(!e || e.vote_master) { local string dovote; - dovote = VoteParse(s); + dovote = VoteParse(s, argc); if(dovote == "") { print_to(e, "^1Your command was empty. See help for more info."); } else if(VoteCheckNasty(dovote)) { @@ -375,7 +379,9 @@ void VoteThink() { } } -string VoteParse(string all) { +string VoteParse(string all, float argc) { + if(argc < 3) + return ""; return substring(all, argv_start_index(2), argv_end_index(-1) - argv_start_index(2)); } diff --git a/data/qcsrc/server/vote.qh b/data/qcsrc/server/vote.qh index 7007b7eb3..407b88afb 100644 --- a/data/qcsrc/server/vote.qh +++ b/data/qcsrc/server/vote.qh @@ -8,7 +8,7 @@ void VoteHelp(entity e); string VoteNetname(entity e); string ValidateMap(string m, entity e); void VoteThink(); -string VoteParse(string s); +string VoteParse(string s, float tokens); float VoteAllowed(string votecommand); void VoteReset(); void VoteAccept(); -- 2.39.2