@@ -225,11 +225,22 @@ void SayConCommand::Dispatch( const CCommand& command )
225225 bool bTeamOnly = strcmp (command.Arg (0 ), " say_team" ) == 0 ;
226226
227227 // Create a new CCommand object that does not contain the first argument
228- // (say or say_team) as that is redundant
229- // CCommand( int nArgC, const char **ppArgV )
230- const char ** argv = command.ArgV ();
231- argv++;
232- const CCommand stripped_command = CCommand (command.ArgC () - 1 , argv);
228+ // (say or say_team) and is properly splitted
229+ CCommand stripped_command = CCommand ();
230+ char * szCommand = (char *) command.ArgS ();
231+
232+ // Remove quotes (if existant), so the arguments are not recognized as a
233+ // single argument.
234+ int iLastCharPos = strlen (szCommand) - 1 ;
235+ if (szCommand[0 ] == ' "' && szCommand[iLastCharPos] == ' "' ) {
236+ szCommand[iLastCharPos] = ' \0 ' ;
237+ szCommand++;
238+ }
239+
240+ if (!stripped_command.Tokenize (szCommand)) {
241+ PythonLog (0 , " Failed to tokenize '%s'." , command.GetCommandString ());
242+ return ;
243+ }
233244
234245 // Loop through all registered Say Filter callbacks
235246 for (int i = 0 ; i < s_SayFilters.m_vecCallables .Count (); i++)
@@ -252,39 +263,18 @@ void SayConCommand::Dispatch( const CCommand& command )
252263 END_BOOST_PY_NORET ()
253264 }
254265
255- // Get the name of the command used
256- std::string szCommandString (stripped_command.Arg (0 ));
257-
258- // Don't handle empty command strings. This would cause a crash.
259- if (!szCommandString.empty ())
266+ // Find if the command is registered
267+ SayCommandMap::iterator commandMapIter = g_SayCommandMap.find (szCommand);
268+ if ( commandMapIter != g_SayCommandMap.end () )
260269 {
261-
262- // Copy the string to get a char instance
263- char * szCopyCommandString = new char [szCommandString.length () + 1 ];
264- std::strcpy (szCopyCommandString, szCommandString.c_str ());
265-
266- // Split the command using <space> as the delimiter
267- // This should be the actual Say Command
268- char * szCommand = std::strtok (szCopyCommandString, " " );
269-
270- // Is there a command?
271- // This check fixes https://github.com/Source-Python-Dev-Team/Source.Python/issues/17
272- if (szCommand)
273- {
274- // Find if the command is registered
275- SayCommandMap::iterator commandMapIter = g_SayCommandMap.find (szCommand);
276- if ( commandMapIter != g_SayCommandMap.end () )
277- {
278- // Get the CSayCommandManager instance for the command
279- CSayCommandManager* pCSayCommandManager = commandMapIter->second ;
270+ // Get the CSayCommandManager instance for the command
271+ CSayCommandManager* pCSayCommandManager = commandMapIter->second ;
280272
281- // Call the command and see it wants to block the command
282- if ( pCSayCommandManager->Dispatch (stripped_command, iIndex, bTeamOnly) == BLOCK)
283- {
284- // Block the command
285- return ;
286- }
287- }
273+ // Call the command and see it wants to block the command
274+ if ( pCSayCommandManager->Dispatch (stripped_command, iIndex, bTeamOnly) == BLOCK)
275+ {
276+ // Block the command
277+ return ;
288278 }
289279 }
290280
0 commit comments