Author Topic: serverCmdMessageSent source  (Read 3132 times)

I would like to request the source for the function serverCmdMessageSent and possibly various other functions (like messageAll and stuff)
It would be useful for many add-on makers
« Last Edit: January 26, 2014, 05:29:41 PM by Electrk. »

Greek has made a decent replication in Slayer, but the original would be nice. The function itself kinda needs to be segmented off. Filtering a message for e-tard and spam and link parsing should be in its own function, so if you have something like team chat or some other channel, you can simply apply the same function and mods only have to update the one.

Edit: On this note, I think minigameCanDamage and GameConnection::onDeath would also be valuable.
« Last Edit: January 26, 2014, 11:38:44 PM by -Jetz- »

like messageAll

Code: [Select]
function messageAll(%cmd, %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r)
{
%count = clientGroup.getCount();
for(%index = 0; %index < %count; %index ++)
messageClient(clientGroup.getObject(%index), %cmd, %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r);
}

< Greek2Me wore it better >
« Last Edit: January 28, 2014, 01:55:41 AM by Color »

Code: [Select]
package messageSentPackage {
   function serverCmdMessageSent(%client, %text) {

      if(spamAlert(%client))
         return; //flood?

      %obj = %client.player;
      if(isObject(%obj)) {

         %obj.playthread(0,"talk");
         %obj.schedule(strlen(%text) * 50, stopthread, 0);

      }

      %text=stripMlControlChars(%text);
      %text=lTrim(trim(%text));
      //missing link parsing (RTB has this)
      if(strlen(%text) >= $Pref::Server::MaxChatLen)
         %text = getSubStr(%text, 0, $Pref::Server::MaxChatLen);

      %entiremessage = '\c7%1\c3%2\c7%3\c6: %4'@"\c7"@%client.clanprefix @ "\c3" @ %client.name @ "\c7" @     %client.clansuffix @ "\c6" @ ": " @ %text;
      commandToAll('chatMessage',%client,'','',%entiremessage, %client.clanprefix,%client.name,%client.clansuffix, %text);

   }
};
activatepackage(messageSentPackage);

Uh.. feels like there's a ton missing in that.

Uh.. feels like there's a ton missing in that.
There is. That isn't how spam detection is done for starters, nor-flood detection, e-tard is missing, never strips out control characters, and link parsing is absent. Again, if you want a good replica of it, take Greek's from Slayer.

There is.

serverCmdStopTalking and a few other things are also missing.

nor-flood detection

     if(spamAlert(%client))
         return; //flood?


Albeit checks for successive messages are missing.

never strips out control characters

     %text=stripMlControlChars(%text);



There's a ton of really weird stuff in here.

     %text=lTrim(trim(%text));

Actually, it's not even gonna work.

> %entiremessage = '\c7%1\c3%2\c7%3\c6: %4'@"
>                                          ^ syntax error
« Last Edit: January 27, 2014, 08:59:29 AM by Port »

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");
}
}
« Last Edit: January 27, 2014, 11:02:15 AM by Greek2me »

      if(spamAlert(%client))
         return; //flood?

I'm pretty sure that doesn't actually do anything to prevent spam.

serverCmdStopTalking and a few other things are also missing.
Was just going over the big things.

      %text=stripMlControlChars(%text);
Didn't see that.

Code: [Select]
function messageAll(%cmd, %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r)
{
%count = clientGroup.getCount();
for(%index = 0; %index < %count; %index ++)
messageClient(clientGroup.getObject(%index), %cmd, %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r);
}

but you can't edit the message at all without screwing everything up

but you can't edit the message at all without screwing everything up

Huh? What are you trying to do? You asked for the source code; that's about as close as it gets.

Huh? What are you trying to do? You asked for the source code; that's about as close as it gets.

For things that use %1 %2 etc. it screws it up and just shows a number

Post the code of what you're trying to do.

function messageAll(%cmd, %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r)
{
   %count = clientGroup.getCount();
   for(%index = 0; %index < %count; %index ++)
      messageClient(clientGroup.getObject(%index), %cmd, "<font:calibri:30>" @ %msg, %a, %b, %c, %d, %e, %f, %g, %h, %i, %j, %k, %l, %m, %n, %o, %p, %q, %r);
}


I have tried single quotes as well