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.

multi lines max text length 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: 1107
Joined: Sun Mar 22, 2015 2:41 pm

multi lines max text length within time frame

Post by simo »

i was wondering if this could be modified to count the total text length per line to some up a total within a time frame and set ban if threshold is reached:

Code: Select all

bind pubm - * Text:Bytes

set longline(txt_len) 300

proc Text:Bytes {nick uhost hand chan txt} {
  if {![botisop $chan] || [isbotnick $nick] || [isop $nick $chan] || [matchattr $hand b] || [matchattr $hand f|f $chan] || [matchattr $hand mo|mo $chan]} {
    return
  }
  if {[string length $txt] >= $::longline(txt_len)} {
    putquick "MODE $chan +b [maskhost $uhost 2]" 
  }
}
i found this somewhere not sure where tho wether forum or archives
most tcls available use per line checking text length unlike multiple lines we
look for

like for example 300:3 300 chars within 3 sec
Last edited by simo on Fri Jun 19, 2020 6:19 pm, edited 4 times in total.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

oh i found author :

Long Text Protection (v1.3) by fyre
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i havent found a single tcl that counts text chars and gets a total within a time threshold and chars value threshold
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this is an msl variant of it stripped from color/bold/underlined codes:

Code: Select all

ON ^*:text:*:#:{ 
    if ($nick(#,$me,@&~%) && !$nick(#,$nick,@&~%)) { 
      inc -u5 %bytes. [ $+ [ $site ] $+ ] . [ $+ [ $chan ] ]  $calc($regex($1-,/\S/gSu) + 50)
      if (%bytes. [ $+ [ $site ] $+ ] . [ $+ [ $chan ] ] >= 300) {  ban -k $chan $nick 4  Bytes Flood }
  }
}
the added + 50 in calculation part is to counter the evading by staying under the limit in some cases when spamming slow and using view chars
User avatar
grumpy
Voice
Posts: 9
Joined: Fri Jan 10, 2014 3:23 pm
Location: Europe/London

Post by grumpy »

Code: Select all

% string bytelength
wrong # args: should be "string bytelength string"
% string bytelength "teststring"
10
%
https://www.tcl.tk/man/tcl8.3/TclCmd/string.htm#M5

Maybe something like the following
:arrow: dont need to check for isbotnick

Code: Select all

set byte_flood 300

bind pubm - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global byte_flood
 # if the bots not opped, we dont do anything
 if {![botisop $chan]} {return}
 # if its a channel op exempt them
 if {[isop $nick $chan]} {return}
 # if its a validuser and they have +b or +fmo|fmo flags exempt them
 if {([validuser $hand]) && ([matchattr $hand bfmo|fmo $chan])} {return}
 if {([string bytelength $string] == $::byte_flood)} {
  putserv "MODE $chan +b [maskhost "$nick!$host" 2]"
  return
 }
}
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thnx grumpy i tried it and it returns this error:

Tcl error [pubm:byteflood]: can't read "string": no such variable

and also this seems to only count in 1 line and not count total sent lines to reach threshold :


if {([string bytelength $string] == $::byte_flood)} {
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

this works but it doesnt count total used chars from multiple lines to get end result and compare against threshold for example 300:5 300 or more chars used within 5 secs

Code: Select all

set byte_flood 300

bind pubm - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global byte_flood
 # if the bots not opped, we dont do anything
 if {![botisop $chan]} {return}
 # if its a channel op exempt them
 if {[isop $nick $chan]} {return}
 # if its a validuser and they have +b or +fmo|fmo flags exempt them
 if {([validuser $hand]) && ([matchattr $hand bfmo|fmo $chan])} {return}
 if {([string bytelength $text] >= $::byte_flood)} { 
 if {[isvoice $nick $chan]} {  pushmode $chan -v $nick }
  pushmode $chan +b [maskhost "$nick!$host" 2] 
 }
} 
this is somewhat the same as i posted in the first post
User avatar
grumpy
Voice
Posts: 9
Joined: Fri Jan 10, 2014 3:23 pm
Location: Europe/London

Post by grumpy »

Not really sure about the error, I kind of just wrote an example of using string bytelength while replying :oops:

Maybe add a utimer unset for 5 seconds? and keep a byte count against the hostmask, so when they go over the limit they get banned. :?

Code: Select all

set byteflood(count) 300
set byteflood(time) 5

bind pub - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global byteflood
 if {(![botisop $chan]) || ([isop $nick $chan]) || ([validuser $hand]) && ([matchattr $hand +bfmo|fmo $chan])} {return}
 set bytes [string bytelength $text]
 set mask [maskhost "$nick!$host" 2]
 if {[info exists ::byteflood($mask)]} {
  set ::byteflood($mask) [expr {$::byteflood($mask) + $bytes}]
  if {($::byteflood($mask) > $::byteflood(count))} {
   putquick "MODE $chan +b $mask"
   unset ::byteflood($mask)
   return
  }
  utimer $::byteflood(time) "unset ::byteflood($mask)"
  return
 } else {
  set ::byteflood($mask) $bytes
  utimer $::byteflood(time) "unset ::byteflood($mask)"
  return
 }
}
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tested it grumpy it doesnt seem to work as nothing happens and i dont get anhy errors in PL

also im not sure about that variable what would happen if 2 or more users with different IPS type text whos would it count ?

perhaps it should have channel and nick!user@host atached to the variable so it counts for each nick seperate just like the one i posted for msl

and after reading about bytes in docs it seems different from text length perhaps in this case we should use text length rather than bytes
User avatar
grumpy
Voice
Posts: 9
Joined: Fri Jan 10, 2014 3:23 pm
Location: Europe/London

Post by grumpy »

Yeah, i don't think bytelength is what your looking for

Code: Select all

[13:21:00] <+afk-dead> this is going to be over 200 lines of text hopefully? thought am not sure how long the line needs to be to trigger a bytes flood or not. Maybe just keep typing and see what happends? thats usually the best way?
[13:21:01] <@eggie> Bytes Count. 210
[13:21:23] <+afk-dead> thisisgoingtobeover200linesoftexthopefully?thoughtamnotsurehowlongthelineneedstobetotriggerabytesfloodornot.Maybejustkeeptypingandsee whathappends?thatsusuallythebestway?
         [ didn't trigger without spaces ]
         [ note i set it trigger on over 200 bytes ]
[13:21:37] <+afk-dead> thisisgoingtobeover200linesoftexthopefully?thoughtamnotsurehowlongthelineneedstobetotriggerabytesfloodornot.Maybejustkeeptypingandsee whathappends?thatsusuallythebestway?thisisgoingtobeover200linesoftexthopefully?thoughtamnotsurehowlongthelineneedstobetotriggerabytesfloodornot.Maybejustkeeptypingandsee whathappends?thatsusuallythebestway?
[13:21:38] <@eggie> Bytes Count. 340

[13:24:21] <+afk-dead> .tcl info patchlevel
[13:24:21] <@eggie> OK: 8.6.9 - 0.115 ms
User avatar
grumpy
Voice
Posts: 9
Joined: Fri Jan 10, 2014 3:23 pm
Location: Europe/London

Post by grumpy »

Code: Select all

set bflood(maxlength) 300
set bflood(unsettime) 5

bind pub - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global bflood

 # ignore if bot not opped, ignore if its a chanop, ignore if the user has +bfmo globally or +fmo for the channel
 if {(![botisop $chan]) || ([isop $nick $chan]) || ([validuser $hand]) && ([matchattr $hand +bfmo|fmo $chan])} {return}

 # get the length of the text
 set length [llength $text]

 # ban mask
 set bmask [maskhost "$nick!$host" 2]

 # look up if we have them already
 set nick [string tolower $nick]
 set chan [string tolower $chan]
 if {[info exists ::bflood($chan:$nick)]} {

  # increase the count by current length of text
  set ::bflood($chan:$nick) [expr {$::bflood($chan:$nick) + $length}]

  # check they haven't gone over the limit
  if {($::bflood($chan:$nick) > $::bflood(maxlength))} {

   # they have gone over the 'maxlength'
   # devoice them if they are +v
   if {[isvoice $nick $chan]} {pushmode $chan -v $nick}

   # set the ban
   putquick "MODE $chan +b $bmask"

   # unset from array
   unset ::bflood($chan:$nick)

   # finished
   return
  }

  # they haven't gone over the limit, lets set a timer
  utimer $::bflood(unsettime) "unset ::bflood($chan:$nick)"

  # finished
  return

 # they are within the time limit
 # we start again
 } else {
  # add them
  set ::bflood($chan:$nick) $length

  # set a time limit on them
  utimer $::bflood(unsettime) "unset ::bflood($chan:$nick)"

  # finished
  return
 }
}
This will keep a line count going for them per channel against each nickname,
if they go over 'bflood(maxlength)' total text length in 'bflood(unsettime)' seconds.

They will be banned/an devoiced if they are +v :oops: i put comments on for you,

you should really play around it with and find out what works for you :idea:
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

tnx again grumpy for the reply i tried your last posted code and nothing seems to happen and no errors in PL
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I'm affraid you don't use utimer as you must:

Code: Select all

utimer $::bflood(unsettime) [list unset ::bflood($chan:$nick)]
Another point: why do you do "global bflood" if you use "::bflood" in proc ?
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

ive tried this but still nothing happens and no errors in PL:


Code: Select all

set bflood(maxlength) 300
set bflood(unsettime) 5

bind pub - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global bflood

 # ignore if bot not opped, ignore if its a chanop, ignore if the user has +bfmo globally or +fmo for the channel
 if {(![botisop $chan]) || ([isop $nick $chan]) || ([validuser $hand]) && ([matchattr $hand +bfmo|fmo $chan])} {return}

 # get the length of the text
 set length [llength $text]

 # ban mask
 set bmask [maskhost "$nick!$host" 2]

 # look up if we have them already
 set nick [string tolower $nick]
 set chan [string tolower $chan]
 if {[info exists bflood($chan:$nick)]} {

  # increase the count by current length of text
  set bflood($chan:$nick) [expr {$bflood($chan:$nick) + $length}]

  # check they haven't gone over the limit
  if {($bflood($chan:$nick) > $::bflood(maxlength))} {

   # they have gone over the 'maxlength'
   # devoice them if they are +v
   if {[isvoice $nick $chan]} {pushmode $chan -v $nick}

   # set the ban
   putquick "MODE $chan +b $bmask"

   # unset from array
   unset bflood($chan:$nick)

   # finished
   return
  }

  # they haven't gone over the limit, lets set a timer
  utimer $::bflood(unsettime) [list unset bflood($chan:$nick)]
  # finished
  return

 # they are within the time limit
 # we start again
 } else {
  # add them
  set bflood($chan:$nick) $length

  # set a time limit on them
  utimer $::bflood(unsettime) [list unset bflood($chan:$nick)]
  # finished
  return
 }
}
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

i tried again and been gettin this error:

Tcl error in script for 'timer104056':
can't unset "bflood(#test:knowles)": no such element in array


using this so far:

Code: Select all

set bflood(maxlength) 300
set bflood(unsettime) 5

bind pubm - * pubm:byteflood

proc pubm:byteflood {nick host hand chan text} {
 global bflood

 if {(![botisop $chan]) || ([isop $nick $chan]) || ([validuser $hand]) && ([matchattr $hand +bfmo|fmo $chan])} {return}

 set length [llength $text]

 set bmask [maskhost "$nick!$host" 2]

 set nick [string tolower $nick]
 set chan [string tolower $chan]
 if {[info exists bflood($chan:$nick)]} {

  set bflood($chan:$nick) [expr {$bflood($chan:$nick) + $length}]

  if {($bflood($chan:$nick) > $::bflood(maxlength))} {


   if {[isvoice $nick $chan]} {pushmode $chan -v $nick}

   putquick "MODE $chan +b $bmask"

   unset bflood($chan:$nick)

  }

  utimer $::bflood(unsettime) "unset bflood($chan:$nick)"

 } else {
  set bflood($chan:$nick) $length

  utimer $::bflood(unsettime) [list unset bflood($chan:$nick)]
 }
}
Post Reply