chat.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //---------------------------------------------------------------------------
  2. // Server side client chat'n
  3. //---------------------------------------------------------------------------
  4. //---------------------------------------------------------------------------
  5. // silly spam protection...
  6. $SPAM_PROTECTION_PERIOD = 10000;
  7. $SPAM_MESSAGE_THRESHOLD = 4;
  8. $SPAM_PENALTY_PERIOD = 10000;
  9. $SPAM_MESSAGE = '\c3FLOOD PROTECTION:\cr You must wait another %1 seconds.';
  10. function GameConnection::spamMessageTimeout(%this)
  11. {
  12. if(%this.spamMessageCount > 0)
  13. %this.spamMessageCount--;
  14. }
  15. function GameConnection::spamReset(%this)
  16. {
  17. %this.isSpamming = false;
  18. }
  19. function spamAlert(%client)
  20. {
  21. if($Pref::Server::FloodProtectionEnabled != true)
  22. return(false);
  23. if(!%client.isSpamming && (%client.spamMessageCount >= $SPAM_MESSAGE_THRESHOLD))
  24. {
  25. %client.spamProtectStart = getSimTime();
  26. %client.isSpamming = true;
  27. %client.schedule($SPAM_PENALTY_PERIOD, spamReset);
  28. }
  29. if(%client.isSpamming)
  30. {
  31. %wait = mFloor(($SPAM_PENALTY_PERIOD - (getSimTime() - %client.spamProtectStart)) / 1000);
  32. messageClient(%client, "", $SPAM_MESSAGE, %wait);
  33. return(true);
  34. }
  35. %client.spamMessageCount++;
  36. %client.schedule($SPAM_PROTECTION_PERIOD, spamMessageTimeout);
  37. return(false);
  38. }
  39. //---------------------------------------------------------------------------
  40. function chatMessageClient( %client, %sender, %voiceTag, %voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  41. {
  42. //see if the client has muted the sender
  43. if ( !%client.muted[%sender] )
  44. commandToClient( %client, 'ChatMessage', %sender, %voiceTag, %voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  45. }
  46. function chatMessageTeam( %sender, %team, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  47. {
  48. if ( ( %msgString $= "" ) || spamAlert( %sender ) )
  49. return;
  50. %count = ClientGroup.getCount();
  51. for ( %i = 0; %i < %count; %i++ )
  52. {
  53. %obj = ClientGroup.getObject( %i );
  54. if ( %obj.team == %sender.team )
  55. chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  56. }
  57. }
  58. function chatMessageAll( %sender, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 )
  59. {
  60. if ( ( %msgString $= "" ) || spamAlert( %sender ) )
  61. return;
  62. %count = ClientGroup.getCount();
  63. for ( %i = 0; %i < %count; %i++ )
  64. {
  65. %obj = ClientGroup.getObject( %i );
  66. if(%sender.team != 0)
  67. chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  68. else
  69. {
  70. // message sender is an observer -- only send message to other observers
  71. if(%obj.team == %sender.team)
  72. chatMessageClient( %obj, %sender, %sender.voiceTag, %sender.voicePitch, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10 );
  73. }
  74. }
  75. }