Fixed sm_play to allow file with spaces. Also allowed file name to be in quotes or not.
authorPhong Dang <teame06@gmail.com>
Mon Jul 30 17:27:30 2007 +0000 (2007-07-30)
changeset 1214e829a7ed101e
parent 1213 130f09fae7d3
child 1215 1969daef3f00
Fixed sm_play to allow file with spaces. Also allowed file name to be in quotes or not.
plugins/basefuncommands.sp
     1.1 --- a/plugins/basefuncommands.sp	Mon Jul 30 04:55:35 2007 +0000
     1.2 +++ b/plugins/basefuncommands.sp	Mon Jul 30 17:27:30 2007 +0000
     1.3 @@ -41,18 +41,21 @@
     1.4  	RegAdminCmd("sm_burn", Command_Burn, ADMFLAG_SLAY, "sm_burn <#userid|name> [time]");
     1.5  	RegAdminCmd("sm_slap", Command_Slap, ADMFLAG_SLAY, "sm_slap <#userid|name> [damage]");
     1.6  	RegAdminCmd("sm_slay", Command_Slay, ADMFLAG_SLAY, "sm_slay <#userid|name>");
     1.7 -	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> [filename]");
     1.8 +	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
     1.9  }
    1.10  
    1.11  public Action:Command_Play(client, args)
    1.12  {
    1.13  	if(args < 2)
    1.14  	{
    1.15 -		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> [sound]");
    1.16 +		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
    1.17  	}
    1.18  
    1.19 -	decl String:Arg[65];
    1.20 -	GetCmdArg(1, Arg, sizeof(Arg));
    1.21 +	new String:Arguments[PLATFORM_MAX_PATH + 65];
    1.22 +	GetCmdArgString(Arguments, sizeof(Arguments));
    1.23 +
    1.24 + 	decl String:Arg[65];
    1.25 +	new len = BreakString(Arguments, Arg, sizeof(Arg));
    1.26  
    1.27  	new target = FindTarget(client, Arg);
    1.28  	if (target == -1)
    1.29 @@ -60,14 +63,30 @@
    1.30  		return Plugin_Handled;
    1.31  	}
    1.32  
    1.33 -	decl String:SoundFile[PLATFORM_MAX_PATH];
    1.34 -	GetCmdArg(2, SoundFile, sizeof(SoundFile));
    1.35 -	GetClientName(target, Arg, sizeof(Arg));
    1.36 +	/* Make sure it does not go out of bound by doing "sm_play user  "*/
    1.37 +	if(len == -1)
    1.38 +	{
    1.39 +		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
    1.40 +		return Plugin_Handled;
    1.41 +	}
    1.42  
    1.43 +	/* Incase they put quotes and white spaces after the quotes */
    1.44 +	if(Arguments[len] == '"')
    1.45 +	{
    1.46 +		len++;
    1.47 +		new FileLen = TrimString(Arguments[len]) + len;
    1.48 +
    1.49 +		if(Arguments[FileLen - 1] == '"')
    1.50 +		{
    1.51 +			Arguments[FileLen - 1] = '\0';
    1.52 +		}
    1.53 +	}
    1.54 +
    1.55 +	GetClientName(target, Arg, sizeof(Arg));
    1.56  	ShowActivity(client, "%t", "Played Sound", Arg);
    1.57 -	LogMessage("\"%L\" played sound on \"%L\" (file \"%s\")", client, target, SoundFile);
    1.58 +	LogMessage("\"%L\" played sound on \"%L\" (file \"%s\")", client, target, Arguments[len]);
    1.59  
    1.60 -	ClientCommand(target, "playgamesound %s", SoundFile);
    1.61 +	ClientCommand(target, "playgamesound \"%s\"", Arguments[len]);
    1.62  
    1.63  	return Plugin_Handled;
    1.64  }