mIRC Home    About    Download    Register    News    Help

Print Thread
#206405 14/11/08 01:02 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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.

Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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.. =)


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Sep 2008
Posts: 62
_
Babel fish
Offline
Babel fish
_
Joined: Sep 2008
Posts: 62
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.

Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
This don't have anything to do with me flooding, it's if someone else flood the channel with allot of line.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Sep 2008
Posts: 62
_
Babel fish
Offline
Babel fish
_
Joined: Sep 2008
Posts: 62
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 =)

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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 ] ]
}

Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
"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.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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
  }

  ; ...

}

Last edited by Horstl; 15/11/08 03:22 AM.
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
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..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
after the kick, simply hdel -w flood $+($cid,$chr(10),$chan,$chr(10),$nick,$chr(10),*)

Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I left out -w, but it working as it should now smile


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
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.


Link Copied to Clipboard