Coders-IRC


IRC for Coders

AntiFlood v1.0


image
#####################################################################
#   AntiFlood v1.0
#   Description: Catching different types of flood on channels
#   Author: Epic
#####################################################################

alias af_data {
  .hadd -m af check-mess true
  .hadd -m af check-rep true
  .hadd -m af check-words true
  .hadd -m af check-mode true
  .hadd -m af check-kick true
  ;---------------------------
  .hadd -m af max-mess 5
  .hadd -m af max-mess-sec 3
  .hadd -m af max-rep 3
  .hadd -m af max-rep-sec 10
  .hadd -m af max-words 200
  .hadd -m af max-words-sec 10
  .hadd -m af mode +m
  .hadd -m af demode -m
  .hadd -m af mode-sec 300
  .hadd -m af reason flood/spam
}
====================================================
alias afcheck {
  var %af_check count- $+ $1 $+ $2
  if ($prop == rep) return $hget(af_rep,%af_check)
  if ($prop == rsec) return $hget(af_rsec,%af_check)
  if ($prop == mes) return $hget(af_mess,%af_check)
  if ($prop == msec) return $hget(af_msec,%af_check)
  if ($prop == words) return $hget(af_words,%af_check)
  if ($prop == wsec) return $hget(af_wsec,%af_check)
}
alias af_count_mes {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_msec,%af_count)) .hadd -mz af_msec %af_count $hget(af,max-mess-sec)
  if (!$hget(af_mess,%af_count)) .hadd -mu $+ $hget(af,max-mess-sec) af_mess %af_count 0
  if ($hget(af_msec,%af_count) > 0) .hinc -m af_mess %af_count 1
}
alias af_count_rep {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_rsec,%af_count)) || ($3- !isin $hget(af_rep_text,%af_count)) {
    .hadd -mz af_rsec %af_count $hget(af,max-rep-sec)
    .hadd -mu $+ $hget(af,max-rep-sec) af_rep %af_count 0
    .hadd -m af_rep_text %af_count $3-
  }
  else { .hinc -mu $+ $hget(af,max-rep-sec) af_rep %af_count 1 }
}
alias af_count_words {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_wsec,%af_count)) .hadd -mz af_wsec %af_count $hget(af,max-words-sec)
  if (!$hget(af_words,%af_count)) .hadd -mu $+ $hget(af,max-words-sec) af_words %af_count 0
  if ($hget(af_wsec,%af_count) > 0) .hinc -m af_words %af_count $numtok($3-,32)
}
====================================================
on *:TEXT:*:#:{
  af_data | var %af_count count- $+ $nick $+ $chan
  if ($hget(af,check-mess) == true) af_count_mes $nick $chan
  if ($hget(af,check-rep) == true) af_count_rep $nick $chan $1-
  if ($hget(af,check-words) == true) af_count_words $nick $chan $strip($1-)

  ;# Debug check script echo
  ;/echo -s 28debug:18 $nick $chan 28 message:53 $hget(af_mess,%af_count) $hget(af_msec,%af_count) 28 repeat:41 $hget(af_rep,%af_count) $hget(af_rsec,%af_count) 28 words:29 $hget(af_words,%af_count) $hget(af_wsec,%af_count)

  if ($afcheck($nick,$chan).mes >= $hget(af,max-mess) && $afcheck($nick,$chan).msec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).mes messages in40 $hget(af,max-mess-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_mess,%af_count)) .hdel -sw af_mess count-* | if ($hget(af_msec,%af_count)) .hdel -sw af_msec count-*
  }
  if ($afcheck($nick,$chan).rep >= $hget(af,max-rep) && $afcheck($nick,$chan).rsec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).rep reps in40 $hget(af,max-rep-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_rep,%af_count)) .hdel -sw af_rep count-* | if ($hget(af_rsec,%af_count)) .hdel -sw af_rsec count-*
  }
  if ($afcheck($nick,$chan).words >= $hget(af,max-words) && $afcheck($nick,$chan).wsec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).words words in40 $hget(af,max-words-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_words,%af_count)) .hdel -sw af_words count-* | if ($hget(af_wsec,%af_count)) .hdel -sw af_wsec count-*
  }
}
====================================================
alias af_mode_chan {
  if ($hget(af,check-kick) == true) /kick $2 $1 $hget(af,reason)
  if (!$timer(AF $+ $2)) {
    /mode $2 $hget(af,mode)
    .timerAF $+ $2 1 $hget(af,mode-sec) /mode $2 $hget(af,demode)
  }
}
====================================================

Comments 0