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.

Detecting identical nicks within time frame

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

Detecting identical nicks within time frame

Post by simo »

greetz gentz,

i was messing with an msl code to detect identical nicks joining and if threshold of 2 is reached to start kicking and banning :

17:23:05 Join: Dronedchpeekvq [ident: Mibbit] *!*@cloaked-ux3.w8z.052.145.IP
17:23:05 Join: Dronedmosktlukhp [ident: Mibbit] *!*@cloaked-zlo.fp5.405.511.IP
17:23:05 Join: Dronedfdlplkl [ident: Mibbit] *!*@cloaked-viy.7y5.823.453.IP
17:23:05 Join: Dronedrcua [ident: Mibbit] *!*@cloaked-de5.712.436.528.IP
17:23:05 Join: Dronedjhphd [ident: Mibbit] *!*@cloaked-jyt.3el.520.282.IP
17:23:06 +Simo Sets Mode on #test to: +bbbb *!*@*.fp5.405.511.IP *!*@*.7y5.823.453.IP *!*@*.712.436.528.IP *!*@*.3el.520.282.IP
unfortunatly i didnt find a way to also include the first nick (Dronedchpeekvq) that was the start of the counted idendtical nicks



this is the msl version i wondered if it could be translated into tcl :


Code: Select all

On !^*:JOIN:#: {
  if ($nick(#,$me,@&~%)) {  
    var %clonednicks.flood = $+($left($nick,5),*!*@*)
    if (%clonesjoin. [ $+ [ # ] $+ . $+ [ %clonednicks.flood ] ] == $null) {
      set -u3 %clonesjoin. [ $+ [ # ] $+ . $+ [ %clonednicks.flood ] ] 1       
    }
    else { inc %clonesjoin. [ $+ [ # ] $+ . $+ [ %clonednicks.flood ] ] }
    if (%clonesjoin. [ $+ [ # ] $+ . $+ [ %clonednicks.flood ] ] > 1) {
      set -u3 %clnicks1 $addtok(%clnicks1,$nick,44) 
      putmode $chan +b $mask($fulladdress,4)  

      if (%modechan1MR != $true) {
        .raw mode  $chan +MRb  %clonednicks.flood   
        set -u15 %modechan1MR $true
        .timermjs1RM 1 30 mode $unsafe($chan) -MR
      }
      if ($nick(#,$me,@%&~)) { var %mcln 4 | while (%clnicks1) { kick $chan $gettok(%clnicks1,1- %mcln,44) Cloned Nicks )  Detected | %clnicks1 = $deltok(%clnicks1,1- %mcln,44) } } 
    }  
  }
}  
what this basically does is: if 2 or more identical first 5 chars match after 2 or more nicks join within threshold of 3 sec it starts sending out bans and kicks for matching nicks
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

sometimes they come with 2 or 3 nicks so using mass join tcl wich already exists isnt optional as that would trigger to quick

i cant find a way to store and increase if it matches the patern

this is what i have so far:

Code: Select all

bind join - * join:clonednicks
proc join:clonednicks {nick uhost hand chan} {
       set clonednicks  [string range $nick 0 4]

}
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Small script, untested:

Code: Select all

bind join - * join:clonednicks

set joindelay 3

proc join:clonednicks {nick uhost hand chan} {
	set vict [string range [string tolower $nick] 0 4]
	if {![info exists ::clonednicks($vict)] || $::clonednicks($vict)<1} {
		set ::clonednicks($vict) 1
	} else {
		incr ::clonednicks($vict) 1
	}
	utimer $::joindelay [list incr ::clonednicks($vict) -1]
	if {$::clonednicks($vict) >= 2} {
		pushmode $chan +b ${vict}*!*@*
		foreach $kvict [chanlist $chan] {
			if {[string match -nocase ${vict}* $kvict]} {
				putkick $chan $kvict "1 is enough, go out"
			}
		}
	}
} 
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CC i tried your posted code it seems a bit slow sending out the kicks and
bans tho

i tried this to stack the bans and kicks but it didnt seem to be any faster

Code: Select all


bind join - * join:clonednicks

set joindelay 3

proc join:clonednicks {nick uhost hand chan} {

   set umasks [list]
   set knicks [list]

   set vict [string range [string tolower $nick] 0 4]
   if {![info exists ::clonednicks($vict)] || $::clonednicks($vict)<1} {
      set ::clonednicks($vict) 1
   } else {
      incr ::clonednicks($vict) 1
   }
   utimer $::joindelay [list incr ::clonednicks($vict) -1]
   if {$::clonednicks($vict) >= 2} {
       lock:chan $chan
       lappend umasks *!*@[lindex [split $uhost @] 1] 
 
      foreach kvict [chanlist $chan] {
         if {[string match -nocase ${vict}* $kvict]} {
        lappend knicks $kvict     
         }
      }
   }
                  if {[info exists umasks]} {  stackBans3z $chan $umasks }
                  if {[info exists knicks]} {  stackKicks $chan $knicks "!!! Indentical nicks !!!" }

}

proc stackBans3z {chan banlist {max 10}} {
      set count [llength $banlist]
      while {$count > 0} {
         if {$count> $max} {
            set mode [string repeat "b" $max]
            set masks [join [lrange $banlist 0 [expr {$max - 1}]]]
            set banlist [lrange $banlist $max end]
            incr count -$max
         } else {
            set mode [string repeat "b" $count]
            set masks [join $banlist]
            set count 0
         }
        putnow "MODE $chan +$mode $masks"
      }
   }

proc stackKicks {chan kicklist reason {max 4}} {
		set count [llength $kicklist]
		while {$count > 0} {
			if {$count > $max} {
				set users [join [lrange $kicklist 0 [expr {$max - 1}]] ","]
				set kicklist [lrange $kicklist $max end]
				incr count -$max
			} else {
				set users [join $kicklist ","]
				set count 0
			}
			putnow "KICK $chan $users $reason"
		}
	}



proc lock:chan {chan} {
  global botnick chan_flooded

  if {![info exists chan_flooded($chan)]} {
    set chan_flooded($chan) 1
    putquick "MODE $chan +Rb ${vict}*!*@*"
    utimer 5 "putquick \"MODE $chan -R\""
    utimer 5 [list unset -nocomplain chan_flooded($chan)]
    #unset clonednick
  }
}
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i will poke at it some more to see if i can get it to work as desired
thanks CC much apreciated
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

If the ban is too slow, you can try replace the ban line:

Code: Select all

pushmode $chan +b ${vict}*!*@*
with the putquick command:

Code: Select all

putquick "MODE $chan +b ${vict}*!*@*"
Concerning kicks, it depends on the chanlist size, but you can also use a putquick rather than a putkick.
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CC for your response but that would send each kicks and bans as a single command while the ircd allows stacked kicks and bans

perhaps it would be possible to send the bans and kicks after the +R has been set to make sure it halts incoming nicks for a moment so bans and kicks can be send in stacked packet
wich will make it less spammy and less chances of gettin disconnected for too many commands sent
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

CrazyCat wrote:If the ban is too slow, you can try replace the ban line:

Code: Select all

pushmode $chan +b ${vict}*!*@*
with the putquick command:

Code: Select all

putquick "MODE $chan +b ${vict}*!*@*"
Concerning kicks, it depends on the chanlist size, but you can also use a putquick rather than a putkick.
It needs to actually set bans on the hosts as well as the patern
and masskick out the identical nicks
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Here is the way to ban on the host:

Code: Select all

bind join - * join:clonednicks

set joindelay 3

proc join:clonednicks {nick uhost hand chan} {
	set vict [string range [string tolower $nick] 0 4]
	if {![info exists ::clonednicks($vict)] || $::clonednicks($vict)<1} {
		set ::clonednicks($vict) 1
	} else {
		incr ::clonednicks($vict) 1
	}
	utimer $::joindelay [list incr ::clonednicks($vict) -1]
	if {$::clonednicks($vict) >= 2} {
		foreach $kvict [chanlist $chan] {
			if {[string match -nocase ${vict}* $kvict]} {
				set khost [lindex [split [getchanhost $kvict $chan] @] 1]
				pushmode $chan +b *!*@$khost
				putkick $chan $kvict "1 is enough, go out"
			}
		}
		flushmode $chan
	}
}
Note 1 : this will slow the ban because you have to loop on chanlist to get all the corresponding hosts
Note 2 : no need to create a "stack" proc as eggdrop may manage the modes added with pushmode and stack them (have a look on pushmode and flushmode documentation)
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks CC i tried that code and it seems to set ban on eggdrop as well if rejoining channel and it still seems slow to execute bans and kicks i was hoping there was a way to stack bans and kicks and send in 1 go in packets of 4 kicks and 6 modes at a time

i was hoping we could utilize channel mode +R to have it send the bans and kicks after +R has been set this should make sure it has enough time to stack all the bans and kicks and bans to send in 1 or 2 go's

because for the moment even pusmode doesn't have enough time to stack the bans
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

rem out the flushmode line
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

You can't stack kicks, you're forced to send them one per one.

Imho, the better thing to do to avoid mass-join is to use an autolimit script, have a look on http://tclarchive.org/search.php?str=limit
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

SpiKe^^ wrote:rem out the flushmode line
i did just that and it took a while for it to gather it

i used your custom qkick code to gather all the kicks and stack as much as possible that seems to work somewhat better but did take quite a while to get them all when i stress tested

your anti mass join tcl had a special method in it sent out the kicks and bans after a +R wich is much more effective when gathering nicks in mass to kick and ban not sure if we could aply that here as well
Last edited by simo on Tue Nov 23, 2021 12:48 pm, edited 2 times in total.
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

CrazyCat wrote:You can't stack kicks, you're forced to send them one per one.

Imho, the better thing to do to avoid mass-join is to use an autolimit script, have a look on http://tclarchive.org/search.php?str=limit

auto limit wont do much like for example on dalnet autolimit doesnt do much as abusers just mass join/part without the autolimit being much of use
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

clonednicks.tcl ver 0.1 by SpiKe^^

Post by SpiKe^^ »

untested. goodluck.

Code: Select all

#### clonednicks.tcl ver 0.1 by SpiKe^^ (24Nov2021) ####


bind join - * join:clonednicks

proc join:clonednicks {nick uhost hand chan} {
  global cnicks cnickq

  if {[isbotnick $nick] || ([string length $nick] < 6)} { return 0 }
  if {[matchattr $hand f|f $chan]} { return 0 }

  set chan [string tolower $chan]
  set key [string tolower [string range $nick 0 4]]
  set now [clock milliseconds]

  if {[info exists cnicks(${key},$chan)]} {
    ## just expire any old entries ##
    set old [expr {$now - (3 * 1000)}]
    set newls [list]
    foreach joined $cnicks(${key},$chan) {
      if {[lindex [split $joined ","] 1] > $old} { lappend newls $joined }
    }
    if {![llength $newls]} {  unset cnicks(${key},$chan)
    } else {  set cnicks(${key},$chan) $newls  }
  }
  if {![info exists cnicks(${key},$chan)]} {
    set cnicks(${key},$chan) [list "0,${now},${nick}!$uhost"]
    return 0
  }

  if {![info exists cnickq($chan)]} {
    after 1000 [list dobans:clonednicks $chan]
  }
  if {[string match "0,*" [set first [lindex $cnicks(${key},$chan) 0]]]} {
    set cnicks(${key},$chan) [list "1,[string range $first 2 end]"]
    lappend cnickq($chan) [lindex [split $first ","] 2]
  }

  lappend cnicks(${key},$chan) "1,${now},${nick}!$uhost"
  lappend cnickq($chan) "${nick}!$uhost"
  return 0
}


proc dobans:clonednicks {chan} {
  global cnickq

  if {![info exists cnickq($chan)]} { return 0 }
  if {![llength $cnickq($chan)] || ![botisop $chan]} {
    unset cnickq($chan)  ;  return 0
  }

  set bmasks [list]  ;  set knicks [list]
  foreach nkuhost $cnickq($chan) {
    lassign [split $nkuhost "!@"] n u h
    lappend knicks $n
    lappend bmasks *!*@$h
  }

  set max 10
  while {[set len [llength $bmasks]] > 0} {
    if {$len > $max} {
      set mode [string repeat "b" $max]
      set masks [join [lrange $bmasks 0 [expr {$max - 1}]]]
      set bmasks [lrange $bmasks $max end]
    } else {
      set mode [string repeat "b" $len]
      set masks [join $bmasks]
      set bmasks ""
    }
    putquick "MODE $chan +$mode $masks"
  }

  set max 4
  while {[set len [llength $knicks]] > 0} {
    if {$len > $max} {
      set nicks [join [lrange $knicks 0 [expr {$max - 1}]] ","]
      set knicks [lrange $knicks $max end]
    } else {
      set nicks [join $knicks ","]
      set knicks ""
    }
    ##putserv "KICK $ch $nicks :!!! Indentical nicks !!!"
    putserv "KICK $chan $nicks :!!! Indentical nicks !!!"

  }

  unset cnickq($chan)  ;  return 0
}


bind cron - {*/10 * * * *} cleanup:clonednicks

proc cleanup:clonednicks {mn hr da mo wd} {
  global cnicks
  set old [expr {[clock milliseconds] - (3 * 1000)}]

  foreach {key val} [array get cnicks] {
    set newls [list]
    foreach joined $val {
      if {[lindex [split $joined ","] 1] > $old} { lappend newls $joined }
    }
    if {![llength $newls]} {  unset cnicks($key)
    } else {  set cnicks($key) $newls  }
  }
}

putlog "clonednicks.tcl ver 0.1 by SpiKe^^ Loaded."


FIXED a variable naming issue from some reused code in proc dobans:clonednicks
Last edited by SpiKe^^ on Thu Nov 25, 2021 12:12 am, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply