Switch more base plugins to OnClientSayCommand from say hooks (bug 5986, r=psychonic).
authorSystematicMania <systematicmania@gmail.com>
Tue Mar 25 11:57:00 2014 -0400 (2014-03-25)
changeset 4298a9ea10a66000
parent 4297 c05238822c32
child 4299 e8c324cbf8e6
Switch more base plugins to OnClientSayCommand from say hooks (bug 5986, r=psychonic).
plugins/basechat.sp
plugins/nominations.sp
plugins/rockthevote.sp
     1.1 --- a/plugins/basechat.sp	Sun Mar 23 22:11:06 2014 -0600
     1.2 +++ b/plugins/basechat.sp	Tue Mar 25 11:57:00 2014 -0400
     1.3 @@ -61,8 +61,6 @@
     1.4  
     1.5  	g_Cvar_Chatmode = CreateConVar("sm_chat_mode", "1", "Allows player's to send messages to admin chat.", 0, true, 0.0, true, 1.0);
     1.6  
     1.7 -	RegConsoleCmd("say", Command_SayChat);
     1.8 -	RegConsoleCmd("say_team", Command_SayAdmin);		
     1.9  	RegAdminCmd("sm_say", Command_SmSay, ADMFLAG_CHAT, "sm_say <message> - sends message to all players");
    1.10  	RegAdminCmd("sm_csay", Command_SmCsay, ADMFLAG_CHAT, "sm_csay <message> - sends centered message to all players");
    1.11  	
    1.12 @@ -78,98 +76,78 @@
    1.13  	RegAdminCmd("sm_msay", Command_SmMsay, ADMFLAG_CHAT, "sm_msay <message> - sends message as a menu panel");
    1.14  }
    1.15  
    1.16 -public Action:Command_SayChat(client, args)
    1.17 -{	
    1.18 -	decl String:text[192];
    1.19 -	if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
    1.20 -	{
    1.21 -		return Plugin_Continue;
    1.22 -	}
    1.23 -	
    1.24 +public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
    1.25 +{
    1.26  	new startidx;
    1.27 -	if (text[strlen(text)-1] == '"')
    1.28 -	{
    1.29 -		text[strlen(text)-1] = '\0';
    1.30 -		startidx = 1;
    1.31 -	}
    1.32 -	
    1.33 -	if (text[startidx] != CHAT_SYMBOL)
    1.34 +	if (sArgs[startidx] != CHAT_SYMBOL)
    1.35  		return Plugin_Continue;
    1.36  	
    1.37 -	new msgStart = 1;
    1.38 +	startidx++;
    1.39  	
    1.40 -	if (text[startidx+1] == CHAT_SYMBOL)
    1.41 +	if (strcmp(command, "say", false) == 0)
    1.42  	{
    1.43 -		msgStart = 2;
    1.44 +		if (sArgs[startidx] != CHAT_SYMBOL) // sm_say alias
    1.45 +		{
    1.46 +			if (!CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT))
    1.47 +			{
    1.48 +				return Plugin_Continue;
    1.49 +			}
    1.50 +			
    1.51 +			SendChatToAll(client, sArgs[startidx]);
    1.52 +			LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, sArgs[startidx]);
    1.53 +			
    1.54 +			return Plugin_Stop;
    1.55 +		}
    1.56  		
    1.57 -		if (text[startidx+2] == CHAT_SYMBOL)
    1.58 -			msgStart = 3;
    1.59 +		startidx++;
    1.60 +
    1.61 +		if (sArgs[startidx] != CHAT_SYMBOL) // sm_psay alias
    1.62 +		{
    1.63 +			if (!CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT))
    1.64 +			{
    1.65 +				return Plugin_Continue;
    1.66 +			}
    1.67 +			
    1.68 +			decl String:arg[64];
    1.69 +			
    1.70 +			new len = BreakString(sArgs[startidx], arg, sizeof(arg));
    1.71 +			new target = FindTarget(client, arg, true, false);
    1.72 +			
    1.73 +			if (target == -1 || len == -1)
    1.74 +				return Plugin_Stop;
    1.75 +			
    1.76 +			SendPrivateChat(client, target, sArgs[startidx+len]);
    1.77 +			
    1.78 +			return Plugin_Stop;
    1.79 +		}
    1.80 +		
    1.81 +		startidx++;
    1.82 +		
    1.83 +		// sm_csay alias
    1.84 +		if (!CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT))
    1.85 +		{
    1.86 +			return Plugin_Continue;
    1.87 +		}
    1.88 +		
    1.89 +		DisplayCenterTextToAll(client, sArgs[startidx]);
    1.90 +		LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, sArgs[startidx]);
    1.91 +		
    1.92 +		return Plugin_Stop;
    1.93 +	}
    1.94 +	else if (strcmp(command, "say_team", false) == 0 || strcmp(command, "say_squad", false) == 0)
    1.95 +	{
    1.96 +		if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
    1.97 +		{
    1.98 +			return Plugin_Continue;
    1.99 +		}
   1.100 +		
   1.101 +		SendChatToAdmins(client, sArgs[startidx]);
   1.102 +		LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, sArgs[startidx]);
   1.103 +		
   1.104 +		return Plugin_Stop;
   1.105  	}
   1.106  	
   1.107 -	decl String:message[192];
   1.108 -	strcopy(message, 192, text[startidx+msgStart]);
   1.109 -	
   1.110 -	if (msgStart == 1 && CheckCommandAccess(client, "sm_say", ADMFLAG_CHAT)) // sm_say alias
   1.111 -	{
   1.112 -		SendChatToAll(client, message);
   1.113 -		LogAction(client, -1, "\"%L\" triggered sm_say (text %s)", client, message);
   1.114 -	}
   1.115 -	else if (msgStart == 3 && CheckCommandAccess(client, "sm_csay", ADMFLAG_CHAT)) // sm_csay alias
   1.116 -	{
   1.117 -		DisplayCenterTextToAll(client, message);
   1.118 -		LogAction(client, -1, "\"%L\" triggered sm_csay (text %s)", client, text);		
   1.119 -	}	
   1.120 -	else if (msgStart == 2 && CheckCommandAccess(client, "sm_psay", ADMFLAG_CHAT)) // sm_psay alias
   1.121 -	{
   1.122 -		decl String:arg[64];
   1.123 -	
   1.124 -		new len = BreakString(message, arg, sizeof(arg));
   1.125 -		new target = FindTarget(client, arg, true, false);
   1.126 -		
   1.127 -		if (target == -1 || len == -1)
   1.128 -			return Plugin_Handled;
   1.129 -	
   1.130 -		PrintToChat(client, "\x04(Private to %N) %N: \x01%s", target, client, message[len]);
   1.131 -		PrintToChat(target, "\x04(Private to %N) %N: \x01%s", target, client, message[len]);
   1.132 -
   1.133 -		LogAction(client, -1, "\"%L\" triggered sm_psay to \"%L\" (text %s)", client, target, message);		
   1.134 -	}
   1.135 -	else
   1.136 -		return Plugin_Continue;
   1.137 -	
   1.138 -	return Plugin_Handled;	
   1.139 -}
   1.140 -
   1.141 -public Action:Command_SayAdmin(client, args)
   1.142 -{
   1.143 -	if (!CheckCommandAccess(client, "sm_chat", ADMFLAG_CHAT) && !GetConVarBool(g_Cvar_Chatmode))
   1.144 -	{
   1.145 -		return Plugin_Continue;	
   1.146 -	}
   1.147 -	
   1.148 -	decl String:text[192];
   1.149 -	if (IsChatTrigger() || GetCmdArgString(text, sizeof(text)) < 1)
   1.150 -	{
   1.151 -		return Plugin_Continue;
   1.152 -	}
   1.153 -	
   1.154 -	new startidx;
   1.155 -	if (text[strlen(text)-1] == '"')
   1.156 -	{
   1.157 -		text[strlen(text)-1] = '\0';
   1.158 -		startidx = 1;
   1.159 -	}
   1.160 -	
   1.161 -	if (text[startidx] != CHAT_SYMBOL)
   1.162 -		return Plugin_Continue;
   1.163 -	
   1.164 -	decl String:message[192];
   1.165 -	strcopy(message, 192, text[startidx+1]);
   1.166 -
   1.167 -	SendChatToAdmins(client, message);
   1.168 -	LogAction(client, -1, "\"%L\" triggered sm_chat (text %s)", client, message);
   1.169 -	
   1.170 -	return Plugin_Handled;	
   1.171 +	return Plugin_Continue;
   1.172  }
   1.173  
   1.174  public Action:Command_SmSay(client, args)
   1.175 @@ -307,29 +285,8 @@
   1.176  		
   1.177  	if (target == -1)
   1.178  		return Plugin_Handled;	
   1.179 -		
   1.180 -	decl String:name[64];
   1.181 -
   1.182 -	if (client == 0)
   1.183 -	{
   1.184 -		name = "Console";
   1.185 -	}
   1.186 -	else
   1.187 -	{
   1.188 -		GetClientName(client, name, sizeof(name));
   1.189 -	}
   1.190 -
   1.191 -	if (client == 0)
   1.192 -	{
   1.193 -		PrintToServer("(Private: %N) %s: %s", target, name, message);
   1.194 -	}
   1.195 -	else if (target != client)
   1.196 -	{
   1.197 -		PrintToChat(client, "\x04(Private: %N) %s: \x01%s", target, name, message);
   1.198 -	}
   1.199 -
   1.200 -	PrintToChat(target, "\x04(Private: %N) %s: \x01%s", target, name, message);
   1.201 -	LogAction(client, -1, "\"%L\" triggered sm_psay to \"%L\" (text %s)", client, target, message);
   1.202 +	
   1.203 +	SendPrivateChat(client, target, message);
   1.204  	
   1.205  	return Plugin_Handled;	
   1.206  }
   1.207 @@ -363,7 +320,7 @@
   1.208  	return -1;
   1.209  }
   1.210  
   1.211 -SendChatToAll(client, String:message[])
   1.212 +SendChatToAll(client, const String:message[])
   1.213  {
   1.214  	new String:nameBuf[MAX_NAME_LENGTH];
   1.215  	
   1.216 @@ -379,7 +336,7 @@
   1.217  	}
   1.218  }
   1.219  
   1.220 -DisplayCenterTextToAll(client, String:message[])
   1.221 +DisplayCenterTextToAll(client, const String:message[])
   1.222  {
   1.223  	new String:nameBuf[MAX_NAME_LENGTH];
   1.224  	
   1.225 @@ -394,7 +351,7 @@
   1.226  	}
   1.227  }
   1.228  
   1.229 -SendChatToAdmins(from, String:message[])
   1.230 +SendChatToAdmins(from, const String:message[])
   1.231  {
   1.232  	new fromAdmin = CheckCommandAccess(from, "sm_chat", ADMFLAG_CHAT);
   1.233  	for (new i = 1; i <= MaxClients; i++)
   1.234 @@ -406,7 +363,7 @@
   1.235  	}
   1.236  }
   1.237  
   1.238 -SendDialogToOne(client, color, String:text[], any:...)
   1.239 +SendDialogToOne(client, color, const String:text[], any:...)
   1.240  {
   1.241  	new String:message[100];
   1.242  	VFormat(message, sizeof(message), text, 4);	
   1.243 @@ -421,6 +378,21 @@
   1.244  	CloseHandle(kv);	
   1.245  }
   1.246  
   1.247 +SendPrivateChat(client, target, const String:message[])
   1.248 +{
   1.249 +	if (!client)
   1.250 +	{
   1.251 +		PrintToServer("(Private to %N) %N: %s", target, client, message);
   1.252 +	}
   1.253 +	else if (target != client)
   1.254 +	{
   1.255 +		PrintToChat(client, "\x04(Private to %N) %N: \x01%s", target, client, message);
   1.256 +	}
   1.257 +
   1.258 +	PrintToChat(target, "\x04(Private to %N) %N: \x01%s", target, client, message);
   1.259 +	LogAction(client, -1, "\"%L\" triggered sm_psay to \"%L\" (text %s)", client, target, message);
   1.260 +}
   1.261 +
   1.262  SendPanelToAll(from, String:message[])
   1.263  {
   1.264  	decl String:title[100];
     2.1 --- a/plugins/nominations.sp	Sun Mar 23 22:11:06 2014 -0600
     2.2 +++ b/plugins/nominations.sp	Tue Mar 25 11:57:00 2014 -0400
     2.3 @@ -71,9 +71,6 @@
     2.4  	g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0);
     2.5  	g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0);
     2.6  	
     2.7 -	RegConsoleCmd("say", Command_Say);
     2.8 -	RegConsoleCmd("say_team", Command_Say);
     2.9 -	
    2.10  	RegConsoleCmd("sm_nominate", Command_Nominate);
    2.11  	
    2.12  	RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap <mapname> - Forces a map to be on the next mapvote.");
    2.13 @@ -156,36 +153,21 @@
    2.14  	return Plugin_Handled;		
    2.15  }
    2.16  
    2.17 -public Action:Command_Say(client, args)
    2.18 +public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[])
    2.19  {
    2.20  	if (!client)
    2.21  	{
    2.22 -		return Plugin_Continue;
    2.23 -	}
    2.24 -
    2.25 -	decl String:text[192];
    2.26 -	if (!GetCmdArgString(text, sizeof(text)))
    2.27 -	{
    2.28 -		return Plugin_Continue;
    2.29 +		return;
    2.30  	}
    2.31  	
    2.32 -	new startidx = 0;
    2.33 -	if(text[strlen(text)-1] == '"')
    2.34 +	if (strcmp(sArgs, "nominate", false) == 0)
    2.35  	{
    2.36 -		text[strlen(text)-1] = '\0';
    2.37 -		startidx = 1;
    2.38 +		new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
    2.39 +		
    2.40 +		AttemptNominate(client);
    2.41 +		
    2.42 +		SetCmdReplySource(old);
    2.43  	}
    2.44 -	
    2.45 -	new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
    2.46 -	
    2.47 -	if (strcmp(text[startidx], "nominate", false) == 0)
    2.48 -	{
    2.49 -		AttemptNominate(client);
    2.50 -	}
    2.51 -	
    2.52 -	SetCmdReplySource(old);
    2.53 -	
    2.54 -	return Plugin_Continue;	
    2.55  }
    2.56  
    2.57  public Action:Command_Nominate(client, args)
     3.1 --- a/plugins/rockthevote.sp	Sun Mar 23 22:11:06 2014 -0600
     3.2 +++ b/plugins/rockthevote.sp	Tue Mar 25 11:57:00 2014 -0400
     3.3 @@ -74,9 +74,6 @@
     3.4  	g_Cvar_ChangeTime = CreateConVar("sm_rtv_changetime", "0", "When to change the map after a succesful RTV: 0 - Instant, 1 - RoundEnd, 2 - MapEnd", _, true, 0.0, true, 2.0);
     3.5  	g_Cvar_RTVPostVoteAction = CreateConVar("sm_rtv_postvoteaction", "0", "What to do with RTV's after a mapvote has completed. 0 - Allow, success = instant change, 1 - Deny", _, true, 0.0, true, 1.0);
     3.6  	
     3.7 -	RegConsoleCmd("say", Command_Say);
     3.8 -	RegConsoleCmd("say_team", Command_Say);
     3.9 -	
    3.10  	RegConsoleCmd("sm_rtv", Command_RTV);
    3.11  	
    3.12  	AutoExecConfig(true, "rtv");
    3.13 @@ -158,6 +155,23 @@
    3.14  	}	
    3.15  }
    3.16  
    3.17 +public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[])
    3.18 +{
    3.19 +	if (!g_CanRTV || !client)
    3.20 +	{
    3.21 +		return;
    3.22 +	}
    3.23 +	
    3.24 +	if (strcmp(sArgs, "rtv", false) == 0 || strcmp(sArgs, "rockthevote", false) == 0)
    3.25 +	{
    3.26 +		new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
    3.27 +		
    3.28 +		AttemptRTV(client);
    3.29 +		
    3.30 +		SetCmdReplySource(old);
    3.31 +	}
    3.32 +}
    3.33 +
    3.34  public Action:Command_RTV(client, args)
    3.35  {
    3.36  	if (!g_CanRTV || !client)
    3.37 @@ -170,38 +184,6 @@
    3.38  	return Plugin_Handled;
    3.39  }
    3.40  
    3.41 -public Action:Command_Say(client, args)
    3.42 -{
    3.43 -	if (!g_CanRTV || !client)
    3.44 -	{
    3.45 -		return Plugin_Continue;
    3.46 -	}
    3.47 -	
    3.48 -	decl String:text[192];
    3.49 -	if (!GetCmdArgString(text, sizeof(text)))
    3.50 -	{
    3.51 -		return Plugin_Continue;
    3.52 -	}
    3.53 -	
    3.54 -	new startidx = 0;
    3.55 -	if(text[strlen(text)-1] == '"')
    3.56 -	{
    3.57 -		text[strlen(text)-1] = '\0';
    3.58 -		startidx = 1;
    3.59 -	}
    3.60 -	
    3.61 -	new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT);
    3.62 -	
    3.63 -	if (strcmp(text[startidx], "rtv", false) == 0 || strcmp(text[startidx], "rockthevote", false) == 0)
    3.64 -	{
    3.65 -		AttemptRTV(client);
    3.66 -	}
    3.67 -	
    3.68 -	SetCmdReplySource(old);
    3.69 -	
    3.70 -	return Plugin_Continue;	
    3.71 -}
    3.72 -
    3.73  AttemptRTV(client)
    3.74  {
    3.75  	if (!g_RTVAllowed  || (GetConVarInt(g_Cvar_RTVPostVoteAction) == 1 && HasEndOfMapVoteFinished()))