This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

anti repeat from multi host/ip

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

error is gone but still no effect
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Alright, corrected a few typos and rookie mistakes I've made in previous code. Now you need to get on DCC Chat to enable this for each individual channel with .chanset #channel +hashCheck

As always, haven't tested anything so report back if you get any issues.

Code: Select all

namespace eval hashCheck {
	setudef flag hashCheck
	bind pubm - * [namespace current]::hashCheck
	set setup [dict create limit 3 time 10]
	
	proc hashCheck {nick uhost hand chan text} {
		if {![channel get $chan hashCheck]} return
		variable setup
		variable md5hashes
		set hash [md5 [split $text]]
		if {[info exists md5hashes]} {
			if {[lsearch [dict keys [dict get $md5hashes $chan] $hash] != -1} {
				set hosts [dict get $md5hashes $chan $hash]
				if {[llength $hosts] > [dict get $setup limit]} {
					hashPunish $chan $hosts
					dict unset md5hashes $chan $hash
				} else {
					dict set md5hashes $chan $hash [list [dict get $md5hashes $chan $hash] $uhost]
					utimer [dict get $setup time] [list [namespace current]::hashPurge $chan $hash $uhost]
				}
			}
		} else {
			dict set md5hashes $chan $hash $uhost
		}
	}
	
	proc hashPurge {chan hash uhost} {
		variable md5hashes
		set hosts [dict get $md5hashes $chan $hash]
		set pos [lsearch -nocase $hosts $uhost]
		if {$pos!=-1} {
			set hosts [lreplace $hosts $pos $pos]
			dict set md5hashes $chan $hash $hosts
		}
		foreach key [dict keys [dict get $md5hashes $chan]] {
			if {![llength [dict get $md5hashes $chan $key]]} {
				dict unset md5hashes $chan $key
			}
		}
	}
}
From here onwards will extend it to remove hashes upon kick, ban, quit, part, and so on. For now want to see if this is working or not.

Edit: Fixed typo.
Last edited by caesar on Tue Mar 24, 2015 7:03 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

after replacing it with your latest code it gives me this error
09:26:36 <SeCuRiTy> [04:13:44] Tcl error [::hashCheck::hashCheck]: missing close-bracket
09:26:36 <SeCuRiTy> in expression "[lsearch [dict keys [di..."
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Replace:

Code: Select all

if {[lsearch [dict keys [dict get $md5hashes $chan]] $hash != -1} { 
with:

Code: Select all

if {[lsearch [dict keys [dict get $md5hashes $clan]] $hash] != -1} {
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

after doing that it still doesnt trigger error is gone tho
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Got a testing bot up and running and realized that this isn't going to won't work as I hoped and found a couple of issues I'll try to correct.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

ok sir all your efforts are much apreciated
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Her ya go, untested, good luck, let me know:)

Code: Select all

# multi-host-repeat.tcl v1.0 by SpiKe^^, closely based on
# repeat.tcl v1.1 (9 April 1999) by slennox <slenny@ozemail.com.au>

# Repeat flood, kick-ban on repeats:seconds #
set rp_bflood 5:60

# Repeat flood kick-ban reason #
set rp_breason "repeat flood"

# Length of time in minutes to ban Repeat flooders #
set rp_btime 60

# After a valid Repeat flood, script will continue to #
# kick-ban offenders for an additional 'x' seconds    #
set rp_blinger 10

# END OF SETTINGS # Don't edit below unless you know what you're doing #

bind pubm - * rp_pubmsg

set rp_bflood [split $rp_bflood :]

proc rp_pubmsg {nick uhost hand chan text} {
  global rp_bcount rp_bflood rp_breason rp_btime rp_blinger
  set uhost [string tolower $nick!$uhost]
  set chan [string tolower $chan]
  set text [string map [list \017 ""] [stripcodes abcgru $text]]
  set text [string tolower $text]
  if {[isbotnick $nick]} {  return 0  }
  if {[matchattr $hand f|f $chan]} {  return 0  }
  set utnow [unixtime]
  set target [lindex $rp_bflood 0]

  if {[info exists rp_bcount($chan:$text)]} {
    set uhlist [lassign $rp_bcount($chan:$text) cnt ut]
    set utend [expr {$ut + [lindex $rp_bflood 1]}]
    set expire [expr {$utend + $rp_blinger}]
    if {$cnt < $target} {
      if {$utnow > $utend} {  unset rp_bcount($chan:$text)  }
    } elseif {$utnow > $expire} {  unset rp_bcount($chan:$text)  }
  }

  if {![info exists rp_bcount($chan:$text)]} {
    set rp_bcount($chan:$text) [list 1 $utnow $uhost]
    return 0
  }

  if {$utnow <= $utend} {
    incr cnt
    if {[lsearch $uhlist $uhost] == "-1"} {  lappend uhlist $uhost  }
    set rp_bcount($chan:$text) [linsert $uhlist 0 $cnt $ut]
    if {$cnt < $target} {  return 0  }
    if {$cnt == $target} {  rp_dobans $chan $uhlist
    } else {  rp_dobans $chan [list $uhost]  }
  } elseif {$cnt >= $target} {  rp_dobans $chan [list $uhost]  }

  return 0
}

proc rp_dobans {chan uhlist} {
  global rp_breason rp_btime
  set hslist ""

  foreach uhost $uhlist {
    foreach {nk un hs} [split $uhost !@] { break }
    if {[botisop $chan] && [onchan $nk $chan]} {
      putserv "KICK $chan $nk :$rp_breason"
    }
    if {[lsearch $hslist $hs] == "-1"} {
      newchanban $chan *!*@$hs multi-host-repeat $rp_breason $rp_btime
      lappend hslist $hs
    }
  }
}

proc rp_breset {} {
  global rp_bcount rp_bflood rp_blinger
  set utnow [unixtime]
  set target [lindex $rp_bflood 0]

  foreach {key val} [array get rp_bcount] {
    lassign $val cnt ut
    set utend [expr {$ut + [lindex $rp_bflood 1]}]
    set expire [expr {$utend + $rp_blinger}]
    if {$cnt < $target} {
      if {$utnow > $utend} {  unset rp_bcount($key)  }
    } elseif {$utnow > $expire} {  unset rp_bcount($key)  }
  }

  utimer 30 [list rp_breset]
}

if {![info exists rp_running]} {
  utimer 30 [list rp_breset]
  set rp_running 1
}

putlog "Loaded multi-host-repeat.tcl v1.0 by SpiKe^^"

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

it works excellent except it doesn't kick ban instant it takes time for it to ban and kick all text repeating flooding bots i would rather see it ban and kick instant and push as much mode settings in 1 line as possible other than that is works nicely good job sir
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh i forgot to mention i also would like it not to stickban just regular ban so the channel ops can remove if they see fit

tnx
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this is what i have so far seems to work only it doesnt compress ban modes it does each ban seperate also when this type of flood accures how would we integrate for it also to lock channel for set amount of time

Code: Select all

# multi-host-repeat.tcl v1.0 by SpiKe^^, closely based on
# repeat.tcl v1.1 (9 April 1999) by slennox <slenny@ozemail.com.au>

# Repeat flood, kick-ban on repeats:seconds #
set rp_bflood 2:10

# Repeat flood kick-ban reason #
set rp_breason "repeat flood"

# Length of time in minutes to ban Repeat flooders #
set rp_btime 1

# After a valid Repeat flood, script will continue to #
# kick-ban offenders for an additional 'x' seconds    #
set rp_blinger 10

# END OF SETTINGS # Don't edit below unless you know what you're doing #

bind pubm - * rp_pubmsg

set rp_bflood [split $rp_bflood :]

proc rp_pubmsg {nick uhost hand chan text} {
  global rp_bcount rp_bflood rp_breason rp_btime rp_blinger
  set uhost [string tolower $nick!$uhost]
  set chan [string tolower $chan]
  set text [string map [list \017 ""] [stripcodes abcgru $text]]
  set text [string tolower $text]
  if {[isbotnick $nick]} {  return 0  }
  if {[matchattr $hand f|f $chan]} {  return 0  }
  set utnow [unixtime]
  set target [lindex $rp_bflood 0]

  if {[info exists rp_bcount($chan:$text)]} {
    set uhlist [lassign $rp_bcount($chan:$text) cnt ut]
    set utend [expr {$ut + [lindex $rp_bflood 1]}]
    set expire [expr {$utend + $rp_blinger}]
    if {$cnt < $target} {
      if {$utnow > $utend} {  unset rp_bcount($chan:$text)  }
    } elseif {$utnow > $expire} {  unset rp_bcount($chan:$text)  }
  }

  if {![info exists rp_bcount($chan:$text)]} {
    set rp_bcount($chan:$text) [list 1 $utnow $uhost]
    return 0
  }

  if {$utnow <= $utend} {
    incr cnt
    if {[lsearch $uhlist $uhost] == "-1"} {  lappend uhlist $uhost  }
    set rp_bcount($chan:$text) [linsert $uhlist 0 $cnt $ut]
    if {$cnt < $target} {  return 0  }
    if {$cnt == $target} {  rp_dobans $chan $uhlist
    } else {  rp_dobans $chan [list $uhost]  }
  } elseif {$cnt >= $target} {  rp_dobans $chan [list $uhost]  }

  return 0
}

proc rp_dobans {chan uhlist} {
  global rp_breason rp_btime
  set hslist ""

  foreach uhost $uhlist {
    foreach {nk un hs} [split $uhost !@] { break }
    if {[botisop $chan] && [onchan $nk $chan]} {
      putserv "KICK $chan $nk :$rp_breason"
    }
    if {[lsearch $hslist $hs] == "-1"} {
            putquick "MODE $chan +b *!*@$hs" 
#     newchanban $chan *!*@$hs multi-host-repeat $rp_breason $rp_btime
      lappend hslist $hs
    }
  }
}

proc rp_breset {} {
  global rp_bcount rp_bflood rp_blinger
  set utnow [unixtime]
  set target [lindex $rp_bflood 0]

  foreach {key val} [array get rp_bcount] {
    lassign $val cnt ut
    set utend [expr {$ut + [lindex $rp_bflood 1]}]
    set expire [expr {$utend + $rp_blinger}]
    if {$cnt < $target} {
      if {$utnow > $utend} {  unset rp_bcount($key)  }
    } elseif {$utnow > $expire} {  unset rp_bcount($key)  }
  }

  utimer 30 [list rp_breset]
}

if {![info exists rp_running]} {
  utimer 30 [list rp_breset]
  set rp_running 1
}

putlog "Loaded multi-host-repeat.tcl v1.0 by SpiKe^^" 
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i noticed it kicks first then it bans i would like it to see set ban first so they wont get choice to quik rejoin
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

also i noticed it doesnt excempt halfop and above from beeing effected
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Ahh, I see SpiKe beat me to the punch. :D

To be honest I would stick with hashing the texts rather than having to strip them out and so on.

You should take out

Code: Select all

# if the bot isn't OP then no point into continuing
    if {[botisop $chan] && [onchan $nk $chan]} {
      putserv "KICK $chan $nk :$rp_breason"
    } 
from the foreach loop. As for multiple kicks/bans in a single line I think this should do it.

Code: Select all

proc rp_dobans {chan uhlist} {
	# if the bot isn't OP there's no point to continue
	if {![botisop $chan]} return
	set blist ""
	set klist ""

	# loop through uhosts
	foreach uhost $uhlist {

		# filter out any duplicates
		if {[lsearch $blist $uhost] != -1} continue

		# set the ban mask as you want
		scan $uhost {%[^@]@%s} user host

		# save the list with masks to ban
		lappend blist "*!*@$host"

		# save the list with masks to get nicks from later on cos we will destroy the $blist
		lappend klist $uhost
	}

	# push 6 ban masks (or change to match how many bans per line the server you are on allows) at a time until the list is empty
	while {[llength $blist] != 0} {
		puthelp "MODE $chan +bbbbbb [join [lrange $blist 0 6] " "]"
		set blist [lrange $blist 6 end]
	}
	   
	# from the given uhosts we ban make a list of nicks to kick and again filter out duplicates
	set nlist ""
	set userlist [lreplace [chanlist $chan] 0 0]
	foreach u [split $userlist] {
		set uhost [getchanhost $user $chan]
		scan $uhost {%[^@]@%s} user host
		if {[lsearch $klist $uhost] != -1} continue
		lappend nlist $u
	}

	# use putkick to do 6 kicks per a single line sent to server
	while {[llength $nlist] != 0} {
		putkick $chan [join [lrange $nlist 0 6] ","] "repeat flood"
		set nlist [lrange $nlist 6 end]
	}
}
Haven't tested anything. :P

Edit: Fixed missing variable.
Last edited by caesar on Wed Mar 25, 2015 9:04 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
s
simo
Revered One
Posts: 1072
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

after changint that i get this error
13:18:42 <SeCuRiTy> [08:05:48] Tcl error [rp_pubmsg]: illegal channel: ChanServ,AmaziGH,Lilli,Avila,Orourke,Rima,Oglesby
Post Reply