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.

Netsplit detection msg to channel

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Netsplit detection msg to channel

Post by awyeah »

Hi!

I am trying to accomplish this thing. Err well it works as detects users splitting with a quit message, and then it has to display on all channels the bot is on that a netsplit has occurred.

So this netsplit detection is for DALnet and it is detected by the quit message of the user. The netsplit cannot be faked. This is the message to detect a netsplit.
* spliff (~spliff@adslfixo-b3-127-230.telepac.pt) Quit (brain.hub.eu.dal.net hotspeed.sg.as.dal.net)
* ismokealo (~ismokealo@c-71-201-208-32.hsd1.il.comcast.net) Quit (brain.hub.eu.dal.net hotspeed.sg.as.dal.net)
* bamford6 (~bamford6@user-544487d3.lns5-c10.dsl.pol.co.uk) Quit (brain.hub.eu.dal.net hotspeed.sg.as.dal.net)
This is the script which I came up with, but it doesn't seems to work or give any response whatsoever. Any suggestions?

Code: Select all

bind sign - "*" detect:netsplit

proc detect:netsplit {nick uhost hand chan text} {
 global detect_netsplit
 if {[info exists detect_netsplit]} { return 0 }
 if {[string equal "Quit:" [string map {" " ""} [lindex $text 0]]]} { return 0 }
  if {[string equal "2" [llength $text]] && [regexp {^(.*) (.*)$} $text] && [string is lower [string map {"." "" " " ""} $text]] && ([regexp -all {[0-9]} $text]] == "0") && ([regexp -all {\.} [lindex $text 0]] >= 3) && ([regexp -all {\.} [lindex $text 1]] >= 3)} {
   set server1 [string map {" " "."} [lrange [split [lindex $text 0] "."] [expr [llength [split [lindex $text 0] "."]] - 2] end]]
   set server2 [string map {" " "."} [lrange [split [lindex $text 1] "."] [expr [llength [split [lindex $text 1] "."]] - 2] end]]
    if {[string equal "dal.net" $server1] && [string equal "dal.net" $server2]} {
     foreach chan [channels] {
      putquick "PRIVMSG $chan :Netsplit detected: $server1 just split from $server2" -next
      set detect_netsplit 1; utimer 20 [list "unset detect_netsplit"]
      }
    }
  }
}
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, use lindex, llenght, and lrange on lists only...
One good way to keep track of lists and texts, is to split your text into a list, and store it in a separate variable, at the beginning of the proc (applies for those strings you intend to use list-commands on later on).

Also, the sign-binding should not trigger when a split occurs, as eggdrop has its own detection. In this case the splt-binding will trigger instead.
Checking wether the binding has been triggered might be a good start... (use .binds for this).

Also worth noting, your current proc will create one timer (to unset the globalspace variable detect_netsplit) for each channel it monitors.
NML_375
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Okay thanks, I will split my text into a list at the beginning of the proc.

Yes the binding does not fire, hence I thought that was the main problem, since the proc didn't execute at all, so I guess bind splt should be used here in this case. The global var detect_netsplit was intended since the bind will detect the netsplit message for all people who quit in the netsplit, hence the netsplit message should be only displayed once on the channel for everyone who splits (not for everyone individually who splits - causing a flood).

Anyway, thanks! I will try the splt binding and keep you upto date as to what happens.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

However I see that, for bind split:
SPLT (stackable)

bind splt <flags> <mask> <proc>
procname <nick> <user@host> <handle> <channel>

Description: triggered when someone gets netsplit on the channel. Be aware that this may be a false alarm (it's easy to fake a netsplit signoff message on some networks); mask may contain wildcards and is matched against '#channel nick!user@host'. Anyone who is SPLT will trigger a REJN or SIGN within the next wait-split (defined in the config file) minutes.

Module: irc
There are no parameters in the proc to display any text. So how would I be able to display which server split off from the network in that case? Any suggestions? Bind raw maybe, with a specific keyword?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Yup.
One option might be to monitor &servers for server notices, which might allow you to detect more netsplits.
NML_375
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

How about a raw-bind to catch quits and do the parsing of the reason by yourself.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Will the raw bind with keyword QUIT trigger for people who split from a channel?

If so, I could parse the reason in the argument to determine if a netsplit occured or not, that would be simple.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Since the mIRC client displays splits as normal quits then my guess is that it is a raw QUIT.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Weird, the proc doesn't fire on bind raw with keyword QUIT also. Heres the script I use:

Code: Select all

bind raw - QUIT detect:netsplit

proc detect:netsplit {from key arg} {
 global netsplit_detected
 if {[info exists netsplit_detected]} { return 0 }
 set arg [string trimleft [stripcodes bcruag $arg] :]
 if {[string equal "Quit:" [string range $arg 0 4]]} { return 0 }; set arg [split $arg]
  if {([llength $arg] == "2") && [regexp {^(.*) (.*)$} $arg] && [string is lower [string map {"." "" " " ""} $arg]] && ([regexp {[0-9]} $arg] == "0") && ([string length [string map {"." "" " " ""} $arg]] == [regexp -all {[a-z]} $arg]) && ([regexp -all {\.} [lindex $arg 0]] >= 3) && ([regexp -all {\.} [lindex $arg 1]] >= 3)} {
   set server1 [string map {" " "."} [lrange [split [lindex $arg 0] "."] [expr [llength [split [lindex $arg 0] "."]] - 2] end]]
   set server2 [string map {" " "."} [lrange [split [lindex $arg 1] "."] [expr [llength [split [lindex $arg 1] "."]] - 2] end]]
    if {[string equal "dal.net" $server1] && [string equal "dal.net" $server2]} {
     foreach chan [channels] {
      putquick "NOTICE $chan :Netsplit detected: $server1 just split from $server2" -next
      set netsplit_detected 1; utimer 20 [list do:netsplit:unlock]; return 1
      }
    }
  }
}

proc do:netsplit:unlock {} {
 global netsplit_detected
 if {[info exists netsplit_detected]} {
  unset netsplit_detected
  }
}
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That is odd, as it really should..

Looking through the rest of the code, this caught my attention tho:

Code: Select all

     foreach chan [channels] {
      putquick "NOTICE $chan :Netsplit detected: $server1 just split from $server2" -next
      set netsplit_detected 1; utimer 20 [list do:netsplit:unlock]; return 1
     } 
I'm not sure why you have a return-statement there, and especially not why you use the returncode 1 (this can seriously screw things up for you).

Perhaps considder something like this instead?

Code: Select all

     foreach chan [channels] {
      putquick "NOTICE $chan :Netsplit detected: $server1 just split from $server2" -next
     }
     set netsplit_detected 1
     utimer 20 [list do:netsplit:unlock]
Also solves the issue of multiple timers...

Finally, your method for extracting the servernames from the textline seems... owerworked and way more complex than it has to be...
"string map {" " "."}" isn't really a good replacement for join..

Also, your notification will always say: "Netsplit detected: dal.net just splitted from dal.net", not sure if that's what you intended it todo.

You can also use "end offsets" with lrange (and the other list manipulation commands), such as "lrange $somelist end-2 end".
Last edited by nml375 on Wed Jun 13, 2007 10:14 am, edited 1 time in total.
NML_375
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Perhaps considder something alot simpler, such as this?

Code: Select all

proc detect:netsplit {from key arg} {
 global netsplit_detected

 if {[info exists netsplit_detected]} { return 0 }

 set arg [string trimleft [stripcodes bcruag $arg] :]
 if {[string equal "Quit:" [string range $arg 0 4]]} {return 0}

 if {![regexp -- {^([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $arg _arg server1 server2]} {return 0}

 if {[string match "*.dal.net" $server1] && [string match "*.dal.net" $server2]} {
  foreach chan [channels] {
   putquick "NOTICE $chan :Netsplit detected: $server1 just split from $server2" -next
  }
  set netsplit_detected 1
  utimer 20 [list do:netsplit:unlock]
 }
}
NML_375
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Just tested, the raw binding works just fine for me on 1.6.17:

Code: Select all

<NML_375> .binds raw
<(bot> [16:56] #NML_375# binds raw
<(bot> Command bindings:
<(bot>   TYPE FLGS     COMMAND              HITS BINDING (TCL)
<(bot>   raw  -|-      QUIT                    5 dump
Dump is a simple proc that just sends any and all parameters to my dcc session.
NML_375
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Thanks alot nml375, your script works exactly the way I want it to. It does detect split users correctly. Maybe because of my so many if statements with all those regexp's and string manipulation commands, your one regexp was sufficient to replace all of them with.

Code: Select all

if {![regexp -- {^([[:alnum:][:punct:]]+)[[:space:]]([[:alnum:][:punct:]]+)$} $arg _arg server1 server2]} {return 0} 
I am not even sure how this works, basically the match words.
[:alnum:] = alphanumeric characters?
[:punct:] = punctuation?
[:space:] = space

I can't even find these match words in the regexp TCL manual. Do you know any good website where I can refer to for more of these and how to use them properly in my scripts?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

They're documented in the tcl-manual, under the keyword re_syntax. You'll find them documented under "character class" under "bracket expressions".
NML_375
F
Fraud
Op
Posts: 101
Joined: Mon May 19, 2008 7:57 am

Post by Fraud »

well, this is quit an old thread, but could any do a recode for Quakenet?! Thanks
Post Reply