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 

Netsplit detection msg to channel

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Jun 11, 2007 10:41 am    Post subject: Netsplit detection msg to channel Reply with quote

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.

Quote:

* 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:

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Mon Jun 11, 2007 11:42 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Jun 11, 2007 8:34 pm    Post subject: Reply with quote

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Jun 11, 2007 9:48 pm    Post subject: Reply with quote

However I see that, for bind split:

Quote:

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Mon Jun 11, 2007 10:02 pm    Post subject: Reply with quote

Yup.
One option might be to monitor &servers for server notices, which might allow you to detect more netsplits.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jun 12, 2007 5:20 am    Post subject: Reply with quote

How about a raw-bind to catch quits and do the parsing of the reason by yourself.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Tue Jun 12, 2007 5:25 am    Post subject: Reply with quote

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jun 12, 2007 5:30 am    Post subject: Reply with quote

Since the mIRC client displays splits as normal quits then my guess is that it is a raw QUIT.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Wed Jun 13, 2007 4:01 am    Post subject: Reply with quote

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

Code:

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Wed Jun 13, 2007 9:25 am    Post subject: Reply with quote

That is odd, as it really should..

Looking through the rest of the code, this caught my attention tho:
Code:
     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:
     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".
_________________
NML_375, idling at #eggdrop@IrcNET


Last edited by nml375 on Wed Jun 13, 2007 10:14 am; edited 1 time in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Wed Jun 13, 2007 10:08 am    Post subject: Reply with quote

Perhaps considder something alot simpler, such as this?
Code:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Wed Jun 13, 2007 10:59 am    Post subject: Reply with quote

Just tested, the raw binding works just fine for me on 1.6.17:
Code:
<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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Thu Jun 14, 2007 5:32 am    Post subject: Reply with quote

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:

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.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2846

PostPosted: Thu Jun 14, 2007 8:33 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Fraud
Op


Joined: 19 May 2008
Posts: 101

PostPosted: Tue Nov 23, 2010 4:11 pm    Post subject: Reply with quote

well, this is quit an old thread, but could any do a recode for Quakenet?! Thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
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