Author Topic: serverCmdMessageSent Source [Solved]  (Read 1962 times)

I know someone posted it before(might have been Port), but I can't find it.
« Last Edit: April 17, 2014, 06:57:14 AM by jes00 »


Code: [Select]
function serverCmdMessageSent(%client, %text)
{
if(strlen(%text) >= $Pref::Server::MaxChatLen)
%text = getSubStr(%text, 0, $Pref::Server::MaxChatLen);
chatMessageAll(%client, '\c4%1: %2', %client.playerName, %text);
}


function chatMessageAll(%sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10)
{
if ((%msgString $= "") || spamAlert(%sender))
return;

%count = ClientGroup.getCount();

for (%i = 0; %i < %count; %i++)
{
%obj = ClientGroup.getObject(%i);

if(%sender.team != 0)
chatMessageClient(%obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
else
{
// message sender is an observer -- only send message to other observers
if(%obj.team == %sender.team)
chatMessageClient(%obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10);
}
}
}

function spamAlert(%client)
{
if($Pref::Server::FloodProtectionEnabled != true)
return(false);

if(!%client.isSpamming && (%client.spamMessageCount >= $SPAM_MESSAGE_THRESHOLD))
{
%client.spamProtectStart = getSimTime();
%client.isSpamming = true;
%client.schedule($SPAM_PENALTY_PERIOD, spamReset);
}

if(%client.isSpamming)
{
%wait = mFloor(($SPAM_PENALTY_PERIOD - (getSimTime() - %client.spamProtectStart)) / 1000);
messageClient(%client, "", $SPAM_MESSAGE, %wait);
return(true);
}

%client.spamMessageCount++;
%client.schedule($SPAM_PROTECTION_PERIOD, spamMessageTimeout);
return(false);
}

-snip-

You are missing alot. Ill post the proper source tommorow if no one gets to it. Can't do it from tablet :(

I'm pretty sure you can't use return as a function there, could be wrong though.

Slayer has a better source.

This is basically what I use in Slayer.

Keep in mind that only one mod can use this at a time, so users might be annoyed if your mod breaks other mods.

Code: [Select]
function serverCmdMessageSent(%client, %msg)
{
serverCmdStopTalking(%client);

%msg = stripMLControlChars(trim(%msg));

%length = strLen(%msg);
if(!%length)
return;

%time = getSimTime();

if(!%client.isSpamming)
{
//did they repeat the same message recently?
if(%msg $= %client.lastMsg && %time - %client.lastMsgTime < $SPAM_PROTECTION_PERIOD)
{
messageClient(%client,'',"\c5Do not repeat yourself.");
if(!%client.isAdmin)
{

%client.isSpamming = true;
%client.spamProtectStart = %time;
%client.schedule($SPAM_PENALTY_PERIOD,spamReset);
}
}

//are they sending messages too quickly?
if(!%client.isAdmin)
{
if(%client.spamMessageCount >= $SPAM_MESSAGE_THRESHOLD)
{
%client.isSpamming = true;
%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 = trim(getField(%list,%i));
if(%wrd $= "")
continue;
if(striPos(" " @ %msg @ " "," " @ %wrd @ " ") >= 0)
{
messageClient(%client,'',"\c5This is a civilized game. Please use full words.");
return;
}
}
}

//URLs
for(%i = 0; %i < getWordCount(%msg); %i ++)
{
%word = getWord(%msg, %i);
%pos = strPos(%word, "://") + 3;
%pro = getSubStr(%word, 0, %pos);
%url = getSubStr(%word, %pos, strLen(%word));

if((%pro $= "http://" || %pro $= "https://") && strPos(%url, ":") == -1)
{
%word = "<sPush><a:" @ %url @ ">" @ %url @ "</a><sPop>";
%msg = setWord(%msg, %i, %word);
}
}

//MESSAGE FORMAT
%all  = '\c7%1\c3%2\c7%3\c6: %4';
%name = %client.getPlayerName();
%pre  = %client.clanPrefix;
%suf  = %client.clanSuffix;

commandToAll('chatMessage', %client, '', '', %all, %pre, %name, %suf, %msg);

echo(%client.getSimpleName() @ ":" SPC %msg);

%client.lastMsg = %msg;
%client.lastMsgTime = %time;

if(isObject(%client.player))
{
%client.player.playThread(3, "talk");
%client.player.schedule(%length * 50, playThread, 3, "root");
}
}

That should cover everything.

tat quot was litraly frum da thred i linkd :(

Thanks Greek and Otto.

That should cover everything.

Wait, so Slayer has to overwrite this function or something?

Wait, so Slayer has to overwrite this function or something?

Yes. Chat is not modularized in any way so if you want to do something such as change the name color then you have to overwrite the entire thing.

edit: Just had a very simple idea to make this easier. PMing Badspot...



My PM:
Quote
Currently, to modify something to do with chat (such as the name color), one needs to rewrite the entire serverCmdMessageSent function.

The default tagged string is '\c7%1\c3%2\c7%3\c6: %4'. Simply set that to a global variable so that modders can change it easily. Also create variables for the arguments.

For example:
Code: [Select]
$chat::string = '\c7%1\c3%2\c7%3\c6: %4';
$chat::arg1 = %client.clanPrefix;
$chat::arg2 = %client.getPlayerName();
//etc...

Modifying the chat is a very frequent topic in Coding Help, and this will simplify it immensely. It will also allow more than one add-on to modify the chat at once. (it's currently limited to one because the function must be overwritten)

Thanks
« Last Edit: April 17, 2014, 04:28:15 PM by Greek2me »

Yes. Chat is not modularized in any way so if you want to do something such as change the name color then you have to overwrite the entire thing.

edit: Just had a very simple idea to make this easier. PMing Badspot...



My PM:

Doubt he's gunna implement this.

Doubt he's gunna implement this.

It would take him two seconds.