Fix regressions in b2f7d97b1ea7 and update plugins for OnClientSayCommand changes (bug 5986, r=psychonic).

This commit is contained in:
SystematicMania 2014-02-28 10:38:36 -05:00
parent 8987a34078
commit 10f878d8c7
4 changed files with 38 additions and 73 deletions

View File

@ -221,22 +221,34 @@ void ChatTriggers::OnSayCommand_Pre()
/* Save these off for post hook as the command data returned from the engine in older engine versions /* Save these off for post hook as the command data returned from the engine in older engine versions
* can be NULL, despite the data still being there and valid. */ * can be NULL, despite the data still being there and valid. */
m_Arg0Backup = command.Arg(0); m_Arg0Backup = command.Arg(0);
/* Handle quoted string sets */
bool is_quoted = false;
size_t len = strlen(args); size_t len = strlen(args);
/* The engine does not display empty say commands. #if SOURCE_ENGINE == SE_EPISODEONE
* So to prevent forwarding it, let's block it. */ if (m_bIsINS)
if (len == 0)
{ {
RETURN_META(MRES_SUPERCEDE); if (strcmp(m_Arg0Backup, "say2") == 0 && len >= 4)
{
args += 4;
len -= 4;
}
if (len == 0)
{
RETURN_META(MRES_SUPERCEDE);
}
} }
#endif
/* The first pair of quotes are stripped from client say commands, but not console ones. /* The first pair of quotes are stripped from client say commands, but not console ones.
* We do not want the forwards to differ from what is displayed. * We do not want the forwards to differ from what is displayed.
* So only strip the first pair of quotes from client say commands. */ * So only strip the first pair of quotes from client say commands. */
if (client != 0 && args[0] == '"' && args[len-1] == '"') bool is_quoted = false;
if (
#if SOURCE_ENGINE == SE_EPISODEONE
!m_bIsINS &&
#endif
client != 0 && args[0] == '"' && args[len-1] == '"')
{ {
/* The server normally won't display empty say commands, but in this case it does. /* The server normally won't display empty say commands, but in this case it does.
* I don't think it's desired so let's block it. */ * I don't think it's desired so let's block it. */
@ -249,7 +261,7 @@ void ChatTriggers::OnSayCommand_Pre()
len--; len--;
is_quoted = true; is_quoted = true;
} }
/* Some? engines strip the last quote when printing the string to chat. /* Some? engines strip the last quote when printing the string to chat.
* This results in having a double-quoted message passed to the OnClientSayCommand ("message") forward, * This results in having a double-quoted message passed to the OnClientSayCommand ("message") forward,
* but losing the last quote in the OnClientSayCommand_Post ("message) forward. * but losing the last quote in the OnClientSayCommand_Post ("message) forward.
@ -306,27 +318,20 @@ void ChatTriggers::OnSayCommand_Pre()
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }
#if SOURCE_ENGINE == SE_EPISODEONE
if (m_bIsINS && strcmp(m_Arg0Backup, "say2") == 0 && strlen(args) >= 4)
{
args += 4;
}
#endif
bool is_trigger = false; bool is_trigger = false;
bool is_silent = false; bool is_silent = false;
/* Check for either trigger */ /* Check for either trigger */
if (m_PubTriggerSize && strncmp(args, m_PubTrigger, m_PubTriggerSize) == 0) if (m_PubTriggerSize && strncmp(m_ArgSBackup, m_PubTrigger, m_PubTriggerSize) == 0)
{ {
is_trigger = true; is_trigger = true;
args = &args[m_PubTriggerSize]; args = &m_ArgSBackup[m_PubTriggerSize];
} }
else if (m_PrivTriggerSize && strncmp(args, m_PrivTrigger, m_PrivTriggerSize) == 0) else if (m_PrivTriggerSize && strncmp(m_ArgSBackup, m_PrivTrigger, m_PrivTriggerSize) == 0)
{ {
is_trigger = true; is_trigger = true;
is_silent = true; is_silent = true;
args = &args[m_PrivTriggerSize]; args = &m_ArgSBackup[m_PrivTriggerSize];
} }
/** /**

View File

@ -398,14 +398,9 @@ public Action:OnClientSayCommand(client, const String:command[], const String:sA
if(g_IsWaitingForChatReason[client]) if(g_IsWaitingForChatReason[client])
{ {
g_IsWaitingForChatReason[client] = false; g_IsWaitingForChatReason[client] = false;
PrepareBan(client, g_BanTarget[client], g_BanTime[client], sArgs);
decl String:message[192]; return Plugin_Stop;
GetCmdArgString(message, sizeof(message));
StripQuotes(message);
PrepareBan(client, g_BanTarget[client], g_BanTime[client], message);
return Plugin_Handled;
} }
return Plugin_Continue; return Plugin_Continue;
} }

View File

@ -98,22 +98,6 @@ public OnPluginStart()
{ {
OnAdminMenuReady(topmenu); OnAdminMenuReady(topmenu);
} }
// Normally, OnClientSayCommand would be aqequate and more appropirate here, but it does
// not catch attempted chat triggers, which we also want to be blocked if a player is gagged.
AddCommandListener(Command_Say, "say");
AddCommandListener(Command_Say, "say_team");
new String:gameDir[64];
GetGameFolderName(gameDir, sizeof(gameDir));
if (StrEqual(gameDir, "insurgency", false))
{
AddCommandListener(Command_Say, "say2");
}
else if (StrEqual(gameDir, "nucleardawn", false))
{
AddCommandListener(Command_Say, "say_squad");
}
} }
public OnAdminMenuReady(Handle:topmenu) public OnAdminMenuReady(Handle:topmenu)
@ -167,14 +151,11 @@ public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
return true; return true;
} }
public Action:Command_Say(client, const String:command[], argc) public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
{ {
if (client) if (client && g_Gagged[client])
{ {
if (g_Gagged[client]) return Plugin_Stop;
{
return Plugin_Stop;
}
} }
return Plugin_Continue; return Plugin_Continue;

View File

@ -251,27 +251,11 @@ public Action:Command_FriendlyFire(client, args)
public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[]) public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[])
{ {
decl String:text[192]; if (strcmp(sArgs, "timeleft", false) == 0)
new startidx = 0;
if (strcopy(text, sizeof(text), sArgs) < 1)
{
return;
}
if (text[0] == '"')
{
startidx = 1;
}
if ((strcmp(command, "say2", false) == 0) && strlen(sArgs) >= 4)
startidx += 4;
if (strcmp(text[startidx], "timeleft", false) == 0)
{ {
ShowTimeLeft(client, TIMELEFT_ALL_MAYBE); ShowTimeLeft(client, TIMELEFT_ALL_MAYBE);
} }
else if (strcmp(text[startidx], "thetime", false) == 0) else if (strcmp(sArgs, "thetime", false) == 0)
{ {
decl String:ctime[64]; decl String:ctime[64];
FormatTime(ctime, 64, NULL_STRING); FormatTime(ctime, 64, NULL_STRING);
@ -285,11 +269,11 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg
PrintToChat(client,"[SM] %t", "Thetime", ctime); PrintToChat(client,"[SM] %t", "Thetime", ctime);
} }
} }
else if (strcmp(text[startidx], "ff", false) == 0) else if (strcmp(sArgs, "ff", false) == 0)
{ {
ShowFriendlyFire(client); ShowFriendlyFire(client);
} }
else if (strcmp(text[startidx], "currentmap", false) == 0) else if (strcmp(sArgs, "currentmap", false) == 0)
{ {
decl String:map[64]; decl String:map[64];
GetCurrentMap(map, sizeof(map)); GetCurrentMap(map, sizeof(map));
@ -303,7 +287,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg
PrintToChat(client,"[SM] %t", "Current Map", map); PrintToChat(client,"[SM] %t", "Current Map", map);
} }
} }
else if (strcmp(text[startidx], "nextmap", false) == 0) else if (strcmp(sArgs, "nextmap", false) == 0)
{ {
decl String:map[32]; decl String:map[32];
GetNextMap(map, sizeof(map)); GetNextMap(map, sizeof(map));
@ -331,7 +315,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg
} }
} }
} }
else if (strcmp(text[startidx], "motd", false) == 0) else if (strcmp(sArgs, "motd", false) == 0)
{ {
ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX); ShowMOTDPanel(client, "Message Of The Day", "motd", MOTDPANEL_TYPE_INDEX);
} }