Chat is a sensitive thing that breaks if you don't do things right, so please check my function to make sure I'm not doing anything wrong.
function servercmdMessageSent(%client,%msg)
{
%msg = stripMLControlChars(trim(%msg));
%time = getSimTime();
if(%msg $= "")
return;
%mini = getMinigameFromObject(%client);
%team = %client.getTeam();
%name = %client.getPlayerName();
%pre = %client.clanPrefix;
%suf = %client.clanSuffix;
if(%mini.isSlayerMinigame)
{
if(%client.dead() && !%mini.allowDeadTalk)
{
messageClient(%client,'',"\c5No, you can't talk. How many dead people do you know that can talk?");
return;
}
if(isObject(%team))
{
%tColor = %team.getPref("Chat","Name Color");
if(%tColor $= "" || strLen(%tColor) != 6)
%color = %team.getColorHex();
else
%color = "<color:" @ %tColor @ ">";
switch(%mini.chat_teamDisplayMode)
{
case 1:
%all = '%5%1\c3%2%5%3\c6: %4';
case 2:
%all = '\c7%1%5%2\c7%3\c6: %4';
case 3:
%all = '\c7[%5%6\c7] %1\c3%2\c7%3\c6: %4';
}
}
}
if(%all $= "")
%all = '\c7%1\c3%2\c7%3\c6: %4';
//did they repeat the same message recently?
if(%msg $= %client.lastMsg && %time-%client.lastMsgTime < $SPAM_PROTECTION_PERIOD)
{
if(!%client.isSpamming)
{
messageClient(%client,'',"\c5Do not repeat yourself.");
if(!%client.isAdmin)
{
%client.isSpamming = 1;
%client.spamProtectStart = %time;
%client.schedule($SPAM_PENALTY_PERIOD,spamReset);
}
}
}
//are they sending messages too quickly?
if(!%client.isAdmin && !%client.isSpamming)
{
if(%client.spamMessageCount >= $SPAM_MESSAGE_THRESHOLD)
{
%client.isSpamming = 1;
%client.spamProtectStart = %time;
%client.schedule($SPAM_PENALTY_PERIOD,spamReset);
}
else
{
%client.spamMessageCount ++;
%client.schedule($SPAM_PROTECTION_PERIOD,spamMessageTimeout);
}
}
//tell them they're spamming and block the message
if(%client.isSpamming)
{
spamAlert(%client);
return;
}
//eTard Filter, which I hate, but have to include
if($Pref::Server::eTardFilter)
{
%list = strReplace($Pref::Server::eTardList,",","\t");
for(%i=0; %i < getFieldCount(%list); %i++)
{
%wrd = getField(%list,%i);
if(strStr(" " @ %msg @ " ",%wrd) != -1)
{
messageClient(%client,'',"\c5This is a civilized game. Please use full words.");
return;
}
}
}
//URLs
%pos = striPos(%msg,"http://");
if(%pos >= 0)
{
%url = getSubStr(%msg,%pos+7,striPos(%msg," ",%pos));
%msg = strReplace(%msg,"http://" @ %url,"<a:" @ %url @ ">" @ %url @ "</a>");
}
commandToAll('chatMessage',%client,'','',%all,%pre,%name,%suf,%msg,%color,%team.name);
echo(%client.getPlayerName() @ ":" SPC %msg);
%client.lastMsg = %msg;
%client.lastMsgTime = %time;
if(%mini.isSlayerMinigame)
{
if(isFunction("Slayer_" @ %mini.mode @ "_onChat"))
call("Slayer_" @ %mini.mode @ "_onChat",%mini,%client,%msg);
}
}