mIRC Homepage
Posted By: sparta text flood protection. - 14/11/08 01:02 PM
I wrote this little code:
Code:
on *:text:*:#:{
  inc -u [ $+ [ %txtflood.secs ] ] %flood.lines. [ $+ [ $nick ] ]
  if (%flood.lines. [ $+ [ $nick ] ] == %txtflood.lines) {
    .msg #test -> txt flood by $nick
  }
}

//set %txtflood.secs 10
//set %txtflood.lines 4

And i was wondering if it's a better way to do this? and if i really need to calculate the length/bytes of the text sent to the channel, or is this enough ? (and the %var's is set for testing, not the actual protection) haven't figured out how many lines in X seconds i should use. smile
Posted By: RusselB Re: text flood protection. - 14/11/08 05:18 PM
As a recommendation, I would allow more than 4 lines every 10 seconds, which is what your code appears to be currently allowing.

The default timing for the /play command is one line per second, which, for most channels/networks is good to prevent flooding, and it's still a good speed for most people to be able to read the line being displayed before the next line is displayed.

If the network uses UnrealIRCd, you might consider using the +f channel mode. More details on this are available on UnrealIRCd's documentation website.
Posted By: sparta Re: text flood protection. - 14/11/08 06:06 PM
Quote:
and the %var's is set for testing, not the actual protection

You didn't see that part? wink i was thinking of something like 7 lines in 3 seconds, not many people write faster then that wink and if the do they often only sending repeats or pasting a log file or something.. =)
Posted By: _Memo Re: text flood protection. - 14/11/08 07:00 PM
Have you looked into using mIRC's built-in flood protection?

Quote:

Queue own messages
If this is enabled, all of your own messages, such as notice and private messages, are queued in the flood queue.
Posted By: sparta Re: text flood protection. - 14/11/08 07:26 PM
This don't have anything to do with me flooding, it's if someone else flood the channel with allot of line.
Posted By: _Memo Re: text flood protection. - 14/11/08 09:37 PM
Doh! Sorry my mind doesn't work too well in the morning. I was reading another post that had to do with on input and I my mindset was obviously still on that post =)
Posted By: DJ_Sol Re: text flood protection. - 14/11/08 10:49 PM
Well I udnerstand why you use all the variables. It's nice for OTHER people to adjust easily.

$+(-u,%txtflood.secs) would be just fine.

Also, I like to check for flood on the first line, and inc the variable on the last line. This way, the first thing that happens in the script is it checks if it's a flood, not setting a variable. I'd also add the "if ($me !isop $chan) { return }" prefix to the event.

One more thing, with a flood you will want to check if the variable number is equal to or higher than the allowed number. It's a safe measure.



Code:
on @*:text:*:#:{
  if (%flood.lines. [ $+ [ $nick ] ] >= %txtflood.lines) { .msg #test -> txt flood by $nick | return }
  inc $+(-u,%txtflood.secs) %flood.lines. [ $+ [ $nick ] ]
}
Posted By: sparta Re: text flood protection. - 14/11/08 11:05 PM
"if ($me isop $chan)" was added when i was done with the code smile same with the equal to, just there when i tested the code.
Posted By: Horstl Re: text flood protection. - 15/11/08 03:10 AM
Maybe I go overboard, but the "inc -uN <singlevar>" approach for flood protections might act different than intended.
For example, you call a limit "4 lines in 10 seconds". Now, if someone's sending 4 messages with 8 seconds offset, your script will trigger regardless of the fact that the 4 lines are spread over 24seconds (the -uN timer restarts for each new line).
You might use the method outlined here, using $ticks or $rand.

As you are familiar with hash tables, you might used them instead of %vars (the variables section remains clean; and after a crash, nothing remains there).

I'm sure you want to take $chan into account (or an /amsg with many comchans might trigger your flood protection), and $cid as well. Last, on action could be added smile

More simple version:
Code:
on *:text:*:#: {
  var %unset = 10, %limit = 4

  ; add to a TABLE "flood" the ITEM "<$cid><$chan><$nick><randomnumber> with DATA <dummy-char>
  hadd $+(-mu,%unset) flood $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),$rand(1,999)) x

  if ($hfind( flood, $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),*) ,0,w) >= %limit) {
    echo $chan $nick wrote $v1 lines on $chan in %unset seconds. limit is $v2
  }
}


Another version, just to show the possibilities of $hfind. Most of the checks below certainly are useless for you smile
Code:
on *:text:*:#: {
  var %unset = 10

  ; add to a TABLE "flood<$cid>" the ITEM "<$chan><$nick><randomnumber>" 
  ; with DATA "<$chan><$nick><message>"
  hadd $+(-mu,%unset) $+(flood,$cid) $+($chan,$chr(10),$nick,$chr(10),$rand(1,999)) $+($chan,$chr(10),$nick,$chr(10),$1-)

  ; with hfind, you now can do multiple protections at once


  ; Floodcheck

  ; normal (x lines per y seconds per nick in that channel)
  if ($hfind( $+(flood,$cid) , $+($chan,$chr(10),$nick,$chr(10),*) ,0,w) > 3) {
    echo $chan $nick wrote $v1 lines on $chan in %unset seconds. limit is $v2
  }

  ; channel (x lines per y seconds in that channel)
  if ($hfind( $+(flood,$cid) , $+($chan,$chr(10),*) ,0,w) > 10) {
    echo $chan $v1 lines on $chan in %unset seconds. limit is $v2
  }

  ; global spam (all comchans: x lines per y seconds by that nick)
  if ($hfind( $+(flood,$cid) , $+(*,$chr(10),$nick,$chr(10),*) ,0,w) > 10) {
    echo -a $nick wrote $v1 lines on all comchans. limit is $v2
  }


  ; Repetitions 

  ; normal (x repetitions of a text in y seconds by a nick in a channel)
  if ($hfind( $+(flood,$cid) , $+($chan,$chr(10),$nick,$chr(10),$1-) ,0).data > 3) {
    echo $chan $nick repeated a text $v1 times in $chan . limit is $v2
  }

  ; global 1 (x repetitions of a text in y seconds by a nick in all comchans) - meant as a demo only.
  ; BEWARE of /amsg triggering this - but may be usefull in connection with "url spam checks" or the like.
  if ($hfind( $+(flood,$cid) , $+(*,$chr(10),$nick,$chr(10),$1-) ,0,w ).data > 3) {
    echo -a $nick repeated a text in all comchans $v1 times. limit is $v2
  }

  ; global2 (x repetitions of a text in y seconds in all comchans)
  if ($hfind( $+(flood,$cid) , $+(*,$chr(10),*,$chr(10),$1-) ,0,w ).data > 3) {
    echo -a A text has been repeated $v1 times in all comchans. limit is $v2
  }

  ; ...

}
Posted By: sparta Re: text flood protection. - 15/11/08 09:41 AM
tested your code:
Code:
on *:text:*:#: {
  var %unset = 10, %limit = 4

  ; add to a TABLE "flood" the ITEM "<$cid><$chan><$nick><randomnumber> with DATA <dummy-char>
  hadd $+(-mu,%unset) flood $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),$rand(1,999)) x

  if ($hfind( flood, $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),*) ,0,w) >= %limit) {
    echo $chan $nick wrote $v1 lines on $chan in %unset seconds. limit is $v2
  }
}

to see how it works, and it worked well, how ever shouldn't the flooding use be deleted after he/she have been kicked? cos i noticed 1 small problem, it kicked the same user after 2 lines when he returned to the channel and started to type..
Posted By: Horstl Re: text flood protection. - 15/11/08 10:07 AM
after the kick, simply hdel -w flood $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),*)
Posted By: sparta Re: text flood protection. - 15/11/08 12:20 PM
I left out -w, but it working as it should now smile
Posted By: DJ_Sol Re: text flood protection. - 15/11/08 05:27 PM
4 times in ten seconds is not a flood detect. As others have said that will trigger constantly.

Code:
if (%flood. [ $+ [ $nick ] ] >= 5) { return }
inc -u3 %flood. [ $+ [ $nick ] ]


This is closer to a flood detect.
© mIRC Discussion Forums