egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

mass-join-protection by SpiKe^^- Netsplits Problems.
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Master


Joined: 22 Mar 2015
Posts: 330

PostPosted: Wed Nov 14, 2018 5:17 am    Post subject: Reply with quote

Quote:
As this stands then it's possible to trick the bot into thinking that I left in a netsplit if would set my quit line like 'paradigm.hub.dal.net diamond.hub.dal.net' for example.


i tried doing that on dalnet and afaict its not possible to reproduce or manipulate that as the way i used is to check first and second param of quit message and if i tried to reproduce a netsplit quit it always displays as

Quote:
Quit: paradigm.hub.dal.net diamond.hub.dal.net


wich wont trigger the quit event to store the variable

in other words the server wont allow manipulation of quit message to mimic a netsplit


Last edited by simo on Thu Nov 15, 2018 7:46 am; edited 1 time in total
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Thu Nov 15, 2018 4:44 am    Post subject: Reply with quote

If anyone have ceaser or simo if you both understand the problem please edit the TCL and Resubmit here, Because I am facing problem here.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3584
Location: Mint Factory

PostPosted: Thu Nov 15, 2018 8:24 am    Post subject: Reply with quote

I would go with a raw quit bind instead of splt or sign. Take this post by nml375 where he offered a nice solution for detecting a net-split.

With this you can:

1) replace the foreach loop and instead of a message make it to add members into an array and when they join check if they are in this array ans except them from any punishment, and obviously purge the array after 2-3 minutes (or whatever time you think the servers would be linked again)

2) if maintaining an array is a messy solution then remove the loop entirely and the stick with that netsplit_detected variable in you checks and just lock the channel with whatever modes you set at mjp(mode) and stop with punishments if a net-split was detected and start re-applying them after 2-3 minutes when the servers that just split got linked again.

For #2 something like this should do the trick:
Code:

set netsplit_detected 0

bind raw - QUIT netsplit:detect

proc netsplit:detect {from key arg} {
   global netsplit_detected
   if {[info exists netsplit_detected]} return
   set arg [string trimleft [stripcodes bcruag $arg] :]
   if {[string equal "Quit:" [string range $arg 0 4]]} return
   if {![regexp -- {^([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $text _arg s1 s2]} return
   if {[string match "*.dal.net" $s1] && [string match "*.dal.net" $s2]} {
      set netsplit_detected 1
      utimer 180 [list netsplit:unlock]
   }
}

proc netsplit:unlock args {
   global netsplit_detected
   set netsplit_detected 0
}

and inside mjp_dobans proc just add:
Code:

global netsplit_detected
if {$netsplit_detected} return

so it will just lock the channel and won't punish anyone for 3 minutes.

Keep in mind that haven't tested anything. Rolling Eyes

Edit: Fixed regexp.
_________________
I tawt I taw a puddy tat!


Last edited by caesar on Fri Feb 08, 2019 2:57 am; edited 1 time in total
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Thu Nov 15, 2018 9:27 am    Post subject: Reply with quote

caesar: I have load it to my Eggdrop with the help of SIMO now waiting for the Netsplits Lets see hope for the Best Smile
Back to top
View user's profile Send private message
gamble27
Halfop


Joined: 05 Aug 2008
Posts: 70

PostPosted: Wed Nov 21, 2018 4:41 am    Post subject: Any updates Reply with quote

Fahad any update on the tcl?
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3584
Location: Mint Factory

PostPosted: Wed Nov 21, 2018 6:05 am    Post subject: Reply with quote

I remember messing with regexp and just noticed that I did a mistake in the initial code. Embarassed

This:
Code:

if {![regexp -- {"Quit:"([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $text _arg s1 s2]} return

should in fact be:
Code:

if {![regexp -- {^([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $text _arg s1 s2]} return

_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Wed Nov 21, 2018 10:37 am    Post subject: Re: Any updates Reply with quote

gamble27 wrote:
Fahad any update on the tcl?


Till now netsplits happens but no kicks yet. lets see again.
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Wed Nov 21, 2018 10:38 am    Post subject: Reply with quote

OK Thanks I'll update
Back to top
View user's profile Send private message
gamble27
Halfop


Joined: 05 Aug 2008
Posts: 70

PostPosted: Wed Nov 21, 2018 11:16 am    Post subject: Reply with quote

Did it kick normal massjoin Fahad?
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Wed Nov 21, 2018 12:17 pm    Post subject: Reply with quote

gamble27 wrote:
Did it kick normal massjoin Fahad?


Yes normal.
Back to top
View user's profile Send private message
gamble27
Halfop


Joined: 05 Aug 2008
Posts: 70

PostPosted: Thu Nov 22, 2018 12:14 am    Post subject: Reply with quote

Can you paste the tcl after the editing, thanks
Back to top
View user's profile Send private message
Fahad
Op


Joined: 29 Aug 2016
Posts: 116

PostPosted: Thu Nov 22, 2018 9:39 am    Post subject: Reply with quote

gamble27 wrote:
Can you paste the tcl after the editing, thanks

There you go!
Code:

## mass-join-protection.tcl v1.6.1 (29Feb2016) by SpiKe^^ ##
# Mass joins, kick-ban on joins:seconds #
set mjp(flood) 3:2

# Mass joins kick-ban reason #
set mjp(reasn) "14Possible/Flooder/Spammer"

# Max number of bans to stack in one mode command #
set mjp(maxb) 6

# Max number of kicks to stack in one kick command #          <- NEW SETTING <-
# NOTE: many networks allow more than one nick to be kicked per command. #
#       set this at or below the max for your network.
set mjp(maxk) 3

# Length of time in minutes to ban mass join flooders #
# - set 0 to disable this script removing bans (ex. set mjp(btime) 0) #
set mjp(btime) 30

# After a valid mass join flood, script will continue #
# to kick-ban offenders for an additional 'x' seconds #
set mjp(xpire) 10

# Set the type of ban masks to use #
#  1 = use host/ip specific bans (ex. *!*@some.host.com) #
#  2 = use wide masked host/ip bans (ex. *!*@*.host.com) #
#      note: setting 2 requires eggdrop 1.6.20 or newer. #
set mjp(btype) 2

# Set protected host(s) that should not be wide masked #
# - Example:  set mjp(phost) "*.undernet.org"
#  Note: this setting only applies to ban type 2 above! #
#  Note: set empty to not protect any hosts (ex. set mjp(phost) "") #
#  Note: space separated if listing more than one protected host #
set mjp(phost) ""

# Set channel mode(s) on flood detected. #
# - set empty to disable setting channel modes (ex. set mjp(mode) "") #
set mjp(mode) "Rm"

# Remove these channel modes after how many seconds? #
set mjp(mrem) 60000

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

bind join - * mjp_bindjoin

proc mjp_bindjoin {nick uhost hand chan} {
  global mjp mjpc mjpq

  if {[isbotnick $nick]} { return 0 }
  if {[matchattr $hand f|f $chan]} { return 0 }

  set uhost [string tolower $nick!$uhost]
  set chan [string tolower $chan]
  set utnow [unixtime]
  set target [lindex $mjp(flood) 0]

  if {[info exists mjpc($chan)]} {
    set uhlist [lassign $mjpc($chan) cnt ut]
    set utend [expr {$ut + [lindex $mjp(flood) 1]}]
    set expire [expr {$utend + $mjp(xpire)}]
    if {$cnt < $target} {
      if {$utnow > $utend} { unset mjpc($chan) }
    } elseif {$utnow > $expire} { unset mjpc($chan) }
  }
  if {![info exists mjpc($chan)]} {
    set mjpc($chan) [list 1 $utnow $uhost]
    return 0
  }

  incr cnt
  if {$cnt <= $target} {
    if {[lsearch $uhlist $uhost] == -1} { lappend uhlist $uhost }
    if {$cnt < $target} {
      set mjpc($chan) [linsert $uhlist 0 $cnt $ut]
    } else {
      set mjpc($chan) [list $cnt $ut]
      if {$mjp(mode) ne "" && [string is digit -strict $mjp(mrem)]} {
        putquick "MODE $chan +$mjp(mode)"
        utimer $mjp(mrem) [list putquick "MODE $chan -$mjp(mode)"]
      }
      mjp_dobans $chan $uhlist
    }
    return 0
  }

  if {![info exists mjpq($chan)]} {
    utimer 2 [list mjp_bque $chan]
    set mjpq($chan) [list $uhost]
  } elseif {[lsearch $mjpq($chan) $uhost] == -1} {
    lappend mjpq($chan) $uhost
  }

  if {[llength $mjpq($chan)] >= $mjp(maxb)} {
    mjp_dobans $chan $mjpq($chan)
    set mjpq($chan) ""
  }

  return 0
}

proc mjp_dobans {chan uhlist} {
  global mjp netsplit_detected
  if {$netsplit_detected} return
  if {![botisop $chan]} return
  set banList ""
  set nickList ""
  foreach ele $uhlist {
    scan $ele {%[^!]!%[^@]@%s} nick user host


    if {$mjp(btype) == 2} {
      set type 4

      foreach ph $mjp(phost) {
        if {[string match -nocase $ph $host]} {
          set type 2  ;  break
        }
      }

      set bmask [maskhost $ele $type]

    } else {  set bmask "*!*@$host"  }


    if {[lsearch $banList $bmask] == -1} { lappend banList $bmask }
    if {[lsearch $nickList $nick] == -1} { lappend nickList $nick }
  }
  stack_bans $chan $mjp(maxb) $banList

  # begin new kick code #
  foreach nk $nickList {
    if {[onchan $nk $chan]} {  lappend nkls $nk  } else { continue }
    if {[llength $nkls] == $mjp(maxk)} {
      putquick "KICK $chan [join $nkls ,] :$mjp(reasn)"
      unset nkls
    }
  }
  if {[info exists nkls]} {
    putquick "KICK $chan [join $nkls ,] :$mjp(reasn)"
  }
  # end new kick code #

  if {$mjp(btime) > 0} {
    set expire [expr {[unixtime] + $mjp(btime)}]
    lappend mjp(rmls) [list $expire $chan $banList]
  }
}

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

proc mjp_bque {chan} {
  global mjpq
  if {![info exists mjpq($chan)]} { return }
  if {$mjpq($chan) eq ""} { unset mjpq($chan) ; return }
  mjp_dobans $chan $mjpq($chan)
  unset mjpq($chan)
}

proc mjp_breset {} {
  global mjpc mjp
  set utnow [unixtime]
  set target [lindex $mjp(flood) 0]
  foreach {key val} [array get mjpc] {
    lassign $val cnt ut
    set utend [expr {$ut + [lindex $mjp(flood) 1]}]
    set expire [expr {$utend + $mjp(xpire)}]
    if {$cnt < $target} {
      if {$utnow > $utend} { unset mjpc($key) }
    } elseif {$utnow > $expire} { unset mjpc($key) }
  }

  if {[info exists mjp(rmls)]} {
    while {[llength $mjp(rmls)]} {
      set next [lindex $mjp(rmls) 0]
      lassign $next expire chan banList
      if {$expire > $utnow} {  break  }
      set mjp(rmls) [lreplace $mjp(rmls) 0 0]
      if {![info exists rmAra($chan)]} {  set rmAra($chan) $banList
      } else {  set rmAra($chan) [concat $rmAra($chan) $banList]  }
    }
    foreach {key val} [array get rmAra] {
      set banList ""
      foreach mask $val {
        if {![ischanban $mask $key]} {  continue  }
        lappend banList $mask
      }
      if {$banList eq ""} {  continue  }
      if {![botisop $key]} {
        set mjp(rmls) [linsert $mjp(rmls) 0 [list $utnow $key $banList]]
      } else {  stack_bans $key $mjp(maxb) $banList -  }
    }
    if {![llength $mjp(rmls)]} {  unset mjp(rmls)  }
  }

  utimer 30 [list mjp_breset]
}

if {![info exists mjp_running]} {
  utimer 20 [list mjp_breset]
  set mjp_running 1
}

set mjp(flood) [split $mjp(flood) :]
set mjp(btime) [expr {$mjp(btime) * 60}]
set mjp(phost) [split [string trim $mjp(phost)]]
if {$mjp(btime)==0 && [info exists mjp(rmls)]} {  unset mjp(rmls)  }

proc rdsb_unlock {chan lock} {
   if {![botisop $chan]} return
   set cm [lindex [split [getchanmode $chan] +] 1]
   foreach m [split $lock ""] {
      if {[lsearch -exact $cm $m] != -1} {
         pushmode $chan -$m
      }
   }
}

set netsplit_detected 0

bind raw - QUIT netsplit:detect

proc netsplit:detect {from key arg} {
   global netsplit_detected
   if {[info exists netsplit_detected]} return
   set arg [string trimleft [stripcodes bcruag $arg] :]
   if {[string equal "Quit:" [string range $arg 0 4]]} return
   if {![regexp -- {^([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $text _arg s1 s2]} return
   if {[string match "*.dal.net" $s1] && [string match "*.dal.net" $s2]} {
      set netsplit_detected 1
      utimer 180 [list netsplit:unlock]
   }
}

proc netsplit:unlock args {
   global netsplit_detected
   set netsplit_detected 0
}

putlog "Loaded mass-join-protection.tcl v1.6.1 by SpiKe^^"

Back to top
View user's profile Send private message
gamble27
Halfop


Joined: 05 Aug 2008
Posts: 70

PostPosted: Fri Nov 23, 2018 5:52 am    Post subject: Reply with quote

hello fahad, please keep us updated if the new fix is working. It should exempt the netsplit users and only kick for normal mass join. Thanks
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3584
Location: Mint Factory

PostPosted: Fri Feb 08, 2019 2:50 am    Post subject: Reply with quote

F|irT had an issue here and looked at what he posted and given that the first member that left and first that returned are within the 180 seconds time frame means that the netsplit_detected would have been set to 1.

Given the posted code when mjp_bindjoin is triggered by joins it should have stopped with just locking the channel, and not continue with bans as mjp_dobans has that
Code:
if {$netsplit_detected} return

that would stop it on it's tracks, so this doesn't really make sense.

Only two options come into my mind that may cause this issue:
- since he posted the same code and said he loaded that chances he didn't rehash/restart the bot until now are slim... so..
- most likely the netsplit_detected variable overwritten in some other code and it's set to 0 when it should be 1 in that 180 seconds time frame

My recommendation is to look in what other scripts you have loaded and see if there's a netsplit_detected variable that is being overwritten and either rename the variable in this code or in that, so you don't have duplicated variables.
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
F|irT
Voice


Joined: 30 Apr 2015
Posts: 30
Location: Pakistan

PostPosted: Sat Feb 09, 2019 12:43 pm    Post subject: Another Request Reply with quote

If we can have kick counter on it so will be gr8 thanks.


F|irT
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber