(stdin)

#
#  ATTENTION:  THIS IS AN ALPHA VERSION  #
#

# This script require at moment my ModeD.tcl script from myself
# http://cybex.b0rk.de/files/tcl/myown/beta/
# I have the timed whois and stuff there and i dont wanna doit twice.
# later comes

# first edit: 17.Mar.2004
# last edit: 19.Mar.2004

if {![info e ::ModeD::build]} {
   putlog "can't find ModeD.tcl! ABORT! Download from http://cybex.b0rk.de/files/tcl/myown/beta/ "
   return
}

namespace eval ::QNet:: {
#
# QNet.tcl startet 17.03.2004 by CyBex
#
# any problems or suggestions? write to Script-QNet@CyBex.has.nolife.org
#
# This script handle the QuakeNet Auth with your Botuser Files
# it add hostmask to a handle, when QNet Auth match, remove old
# hostmask
#
# Feel free to change this script, but please submit me your changes :-)
#
# Testet with Eggdrop 1.6.15
#
# config

   # Auto add/remove unknown user (ignore every user with this flags: fvogamn)
   set UserAutoAdd 0
   set UserAutoDel 0

   # special flag, to identify autoadded users
   set UserAutoFlag A

   # remove chars like [] {} \
   set UserRemoveChars 0

   # use only one special user and add there every hostmask/auth
   set UserUseSpecial 0
   set UserSpecial Guest

   # when not special, use nick or auth to add? (one must be 1, or UserAutoAdd is auto 0)
   set UserUseNick 0
   set UserUseAuth 0

   ## not reqied to edit below this commet

   # my bot configs
   if {$::nick=="NewS-FlasH"} {
      putcmdlog "QNet: load $::nick config"
      set UserAutoAdd 1; set UserAutoDel 1;
      set UserUseSpecial 1
   } elseif {$::nick=="WebChat"} {
      putcmdlog "QNet: Load $::nick config"
      set UserAutoAdd 1; set UserAutoDel 1
      set UserUseAuth 1; set UserRemoveChars 1
   }

   # switch debug by default on/off
   if {![info exists ::QNet::debug]} { set ::QNet::debug 0 }

   ## vars

   set ::QNet::develop 0
   if { $::nick=="Honecker" || $::nick=="Berlin" || $::nick=="NewS-FlasH" || $::nick=="WebChat" } { set ::QNet::develop 1 }

   set ::QNet::major 0
   set ::QNet::minor 1
   if {![info exist ::QNet::build] || !$::QNet::develop} { set ::QNet::build 1 } { incr ::QNet::build }
   if {![info exist ::QNet::run]} { set ::QNet::run 1 } { incr ::QNet::run }
   set ::lateststable 0.1.1

   ### helper
   if $::QNet::debug { putcmdlog "Warning! Debug Mode ist \002ON\002!" }
   if {$::lateststable!="$major.$minor.$build"} { if $develop { putcmdlog "Warning! Developer Mode \002ON\002! Latest stable: $::lateststable" } { putcmdlog "Warning! Unstable Version! Latest stable: $::lateststable" } }

   ### binds

   bind raw - 330 ::QNet::raw330
   bind time - * ::QNet::user:timecheck
   bind dcc n qnet {::QNet::partyline QNet}
   bind dcc n bodytest ::bodytest

   # permadd, permdel, permrem, permlist
   ### procs

   proc qauth:check {hand auth} {
      set XTRA [getuser $hand XTRA auth:$auth]
      #if $::QNet::debug { putcmdlog "::QNet::qauth:check h: $hand a: $auth X: $XTRA" }
      if {$XTRA==""} {return 0} {return 1}
   }

   proc qauth:set {hand auth host} {
   #if $::QNet::debug { putcmdlog "::QNet::auth:set hand $hand auth $auth host $host" }
      if ![qauth:check $hand $auth] {qauth:add $hand $auth $host}
      set XTRA [getuser $hand XTRA auth:$auth]
      if $::QNet::debug { putcmdlog "::QNet::qauth:set $hand XTRA: $XTRA" }
      set create [lindex $XTRA 0]
      set modify [lindex $XTRA 1]
      set lasthosts [lindex $XTRA 2]
      set num 0;
      putcmdlog "lasthost1 $lasthosts"
      foreach {hostl timel} $lasthosts {
         if {![string is digit $timel]} {
            putcmdlog "second par is no digit - host $host"
            qauth:add $hand $auth $host
            qauth:set $hand $auth $host
            return
         }
         set lnum [lsearch -exact $lasthosts $hostl]
         if {$lnum!=$num} {putcmdlog "num != lnum == $num != $lnum == [lindex $lasthosts $num] != [lindex $lasthosts $lnum]"}
         if {[string match $host $hostl] || [string equal $host $hostl]} {
            putcmdlog "lasthost2 $lasthosts"
            set lasthosts [lreplace $lasthosts [expr 1+$num] [expr 1+$num] [unixtime]]
            putcmdlog "lasthost3 $lasthosts"
         }
         #putcmdlog "num $num/$lnum host $host from lh $hostl timel $timel"
         incr num 2
      }
      #putcmdlog "lasthosts $lasthosts"
      #if $::QNet::debug { putcmdlog "::QNet::qauth:set old XTRA: $XTRA" }
      set XTRAN "$create [unixtime] $lasthosts"
      #if $::QNet::debug { putcmdlog "::QNet::qauth:set new XTRA: $XTRAN" }
      if {$XTRA!=$XTRAN} {
         if $::QNet::debug {
            putcmdlog "::QNet::auth:set diff found in XTRA - $XTRAN - $XTRA"
            putcmdlog "::QNet::auth:set new: $XTRAN"
            putcmdlog "::QNet::auth:set old: $XTRA"
         }
         ###setuser $hand XTRA auth:$auth $XTRAN
      } {
         if $::QNet::debug { putcmdlog "::QNet::auth:set no diff in XTRA" }
      }
      putcmdlog "auth:set getuser [getuser $hand XTRA auth:$auth]"
   }
   proc qauth:get {hand auth} {
      set XTRA [getuser $hand XTRA auth:$auth]
      if {$XTRA==""} {return -1} {return $XTRA}
   }
   proc qauth:add {hand auth host} {
      if $::QNet::debug {  putcmdlog "::QNet::auth:add hand $hand auth $auth host $host" }
      ###setuser $hand XTRA auth:$auth "[unixtime] [unixtime] [split $host] [unixtime]"
      putcmdlog "auth:add getuser [getuser $hand XTRA auth:$auth]"
   }

   proc user:check {nick hand auth {host ""}} {
      if $::QNet::debug {  putcmdlog "::QNet::user:check $nick $hand $auth $host [qauth:check $hand $auth]" }
      if {$hand!="" && $hand!="*" && $auth!="" && $auth!="*"} {
         if {$host==""} {set host [getchanhost $nick]}
         if {$host=="" && [info ex ::ModeD::build] && [info ex ::ModeD::users($nick)]} { set host [lindex [split $::ModeD::users($nick) !] 1] }
         set ohost $host; set onick $nick
         if {[string match *@*.users.quakenet.org $host]} { set nick "*"; set host "*@[lindex [split $host @] 1]" }
         if {$host=="" || $host=="*"} { return 0	}

         # check for XTRA hostmask
         set found 0; set fhost ""
         foreach {chost ctime} [getuser $hand xtra permhost] { if {[string match $chost $nick!$host] || [string equal $chost $nick!$host]} { set fhost $chost; set found 1 } }
         foreach {chost ctime} [getuser $hand xtra delhost] { if {[string match $chost $nick!$host] || [string equal $chost $nick!$host]} { set fhost $chost; set found 1 } }
         foreach {chost ctime} [lindex [getuser $hand xtra auth:$auth] 2] { if {[string match $chost $nick!$host] || [string equal $chost $nick!$host]} { set fhost $chost; set found 1 } }
         if !$found {
            putcmdlog "::QNet::user:check add XTRA hostmask $nick!$host to $hand"
            set XTRA [getuser $hand XTRA auth:$auth]; set create [lindex $XTRA 0]; set modify [lindex $XTRA 1]
            set lasthosts [lindex $XTRA 2]; set lasthosts [linsert $lasthosts 0 $nick!$host [unixtime]]
            if {$create==""} {set create [unixtime]}
            set XTRAN "$create [unixtime] $lasthosts"
            if {$XTRA!=$XTRAN} {
               if $::QNet::debug {
                  putcmdlog "::QNet::user:check diff found in XTRA"
                  putcmdlog "::QNet::user:check new: $XTRAN"
                  putcmdlog "::QNet::user:check old: $XTRA"
               }
               ###setuser $hand XTRA auth:$auth $XTRAN
            } {
               if $::QNet::debug { putcmdlog "::QNet::user:check no diff in XTRA" }
            }

            addhost $hand $nick!$host
            #putcmdlog "qauth:set $hand $auth $nick!$host "
            qauth:set $hand $auth $nick!$host
         } {
         # check host in userfile
         #if $::QNet::debug { putcmdlog "::QNet::user:check hostmask in users hosts" }
            set found 0; foreach chost [getuser $hand hosts] { if {[string match $chost $nick!$host] || [string equal $chost $nick!$host]} { set found 1 } }
            if !$found { if $::QNet::debug { putcmdlog "::QNet::user:check add user hostmask $nick!$host to $hand" };  addhost $hand $nick!$host }
            #putcmdlog "qauth:set $hand $auth $nick!$host "
            qauth:set $hand $auth $nick!$host
         }

      }
   }
   proc user:bigcheck args {
   # remove old hosts, cleanup userfile
      foreach user [userlist] {
      # at moment only self testing
         if {$user=="CyBex"} {
         }
      }
   }
   proc user:timecheck args {
      proc user:add {mask} {
      #if $::QNet::debug { putcmdlog " u:a start : $mask" }
         if ![info exist ::QNet::userlist] {set ::QNet::userlist [list]}
         set found 0;
         foreach {name time} $::QNet::userlist {
            if {$name==$mask || [string equal $mask $name] || [string match $mask $name]} {
               set found 1; break
            }
         }
         if !$found { lappend ::QNet::userlist $mask; lappend ::QNet::userlist [expr [unixtime]+20-[rand 60]] }
         return $found
      }
      proc user:del {} {
         set num 0; foreach {name last} $::QNet::userlist {
            set time [expr [unixtime]-$last]
            #3595
            if {$time>3595} {
            #set num [lsearch $::QNet::userlist $name];
               if $::QNet::debug { putcmdlog "nick $name last [duration $time] deleted" }
               set ::QNet::userlist [lreplace $ModeD::userlist $num [expr $num+1]]
            } { incr num 2 }
            #putcmdlog "nick $name last $time"
         }
      }
      proc user:whois {chan} {
      #putcmdlog "::QNet::user:timecheck user:whois";
         set whois [list]; set skip [list]
         foreach user [chanlist $chan] {
            if [string eq -noc fishbot $user] continue
            set found [user:add $user]
            if $found { lappend skip $user } { lappend whois $user; utimer [expr 10+[rand 5]+[rand 5]+[rand 5]+[rand 5]+[rand 5]] [list puthelp [subst -nocommands -nobackslashes {WHOIS $user}]] }
         }
         set text "::QNet::user:timecheck \002whois:\002$whois \002skip:\002$skip"
         set text [string map -nocase {{cybex} {C*B*x} {never} {n*v*r} {securetohopethatneverthiswordcomes} {andthisonetwoorbettertoorevenbettertoo} {die} {d**}} $text]
         if {$whois!=[list]} { if $::QNet::debug { putcmdlog $text } }
         user:del
      }
      user:whois $::ModeD::channel
      #	putcmdlog "whois"
      foreach user [userlist ] {
      #		putcmdlog "foreach"
         set hosts [getuser $user hosts]
         set xtra [getuser $user xtra]
         #putcmdlog "user $user host $hosts [llength $hosts] xtra $xtra [llength $xtra]"
         set hostl [list]; set hostd [list]
         set authfound 0; set delfound 0;
         foreach item $xtra {
         #set item [split $item]
         #			putcmdlog "foreach2 $item"
            if {[string match auth:* [lindex $item 0]]} {
            #				putcmdlog "if string match auth:* [lindex $item 0] [string match auth:* [lindex $item 0]]"
               foreach host [lindex [lindex $item 1] 2] {
               #					putcmdlog "foreach3"
                  set authfound 1;
                  lappend hostl $host
               }
            }
            #1
            #			putcmdlog "if string match permhost [lindex $item 0] [string match permhost [lindex $item 0]]"
            if {[string match "permhost" [lindex $item 0]]} {
               set authfound 1;
               foreach host [lindex $item 1] { lappend hostl $host }
            }
            if {[string match "delhost" [lindex $item 0]]} {
               set delfound 1;
               foreach host [lindex $item 1] { lappend hostd $host }
            }

         }
         #2
         #		putcmdlog "set found"
         set found 0; foreach host $hosts {
            foreach hostls $hostl {
            #putcmdlog "user $user [string match $host $hostls]  [string match $hostls $host]  [string equal $host $hostls]  host $host hostl $hostls"
               if {[string match $host $hostls] || [string equal $host $hostls]} {
               #putcmdlog "found: [string match $host $hostls] || [string equal $host $hostls] h: \002$host\002 hls: \002$hostls\002"
                  set found 1
               } {
               #putcmdlog "not found: [string match $host $hostls] || [string equal $host $hostls] h: $host hls: $hostls"
               }
            }
         }
         #		putcmdlog "found $found"
         #if !$found { putcmdlog "not" } { putcmdlog "!not" }

      }
      #	putcmdlog "found"

   }
   proc user:add {args} {
      if $::QNet::debug { putcmdlog "::QNet::user:add $args" }
   }
   #set UserAutoAdd 0 ; set UserAutoDel 0 ; set UserAutoFlag A ; set UserRemoveChars 1 ;
   #set UserUseSpecial 0 ; set UserSpecial Guest ; set UserUseNick 0 ; set UserUseAuth 0
   proc user:autoadd {nick auth {host ""}} {
      if {$nick==$::botnick} {return 0}

      if $::QNet::debug { putcmdlog "::QNet::user:autoadd $nick $auth $host" }

      proc removechar {text} {
      # clantag
      #if [regexp {\[.+].+} $text] { regsub -all {\[.+]} $text {\|} text }
      #if [regexp {].+\[.+} $text] { regsub -all {].+\[} $text {\|} text }
         set text [string map {\\ \| \[ \| \] \| \{ \| \} \| \" \|} $text]
         putcmdlog "removechar text $text"
         set num -1; set max -1; set name "";
         foreach teil [split $text |] {
            incr num; if {[string len $teil]>[string len $name]} {
            #putcmdlog "$teil is longer then [lindex [split $text |] $max]"
               set max $num; set name $teil
            }
         };
         if {$max>-1 && [string len $name]>2} { set text $name;  }

         # chars
         return [string map {\\ "" \[ "" \] "" \{ "" \} "" \| "" \" ""} $text]
      }

      #putcmdlog "get host"
      set hand ""
      if {$host==""} {set host [getchanhost $nick]}
      if {$host=="" && [info e ::ModeD::build] && [info e ::ModeD::userlist]} {
         if [info exist ::ModeD::users($nick)] {
            set host [lindex [split $::ModeD::users($nick) !] 1]
         }
      }
      #putcmdlog "get hand"
      if {$host!=""} {
         set hand [auth2hand $auth]
         if {$hand=="" || $hand=="*"} { set hand [nick2hand $nick] }
         if {$hand=="" || $hand=="*"} { set hand [finduser $host] }
         if {$hand!="" && $hand!="*"} {
            if ![qauth:check $hand $auth] {
               if $::QNet::debug { putcmdlog "::QNet::user:autoadd qauth:check failed" }
               qauth:add $hand $auth $host
            }
            if $::QNet::debug { putcmdlog "::QNet::user:autoadd dont add $nick, is $hand" }
            user:check $nick $hand $auth $host
            return
         }
      }
      #putcmdlog "add"

      if {$hand==""} {set hand "*"}
      if {$::QNet::UserAutoAdd && $hand=="*"} {
      #putcmdlog "hand $hand"
         if {[string match *@*.users.quakenet.org $host]} {
            set nick "*"
            set host "*@[lindex [split $host @] 1]"
            #if $::QNet::debug { putcmdlog "::QNet::user:autoadd rewrite host to $host" }
         }
         if {!$::QNet::UserUseSpecial && !$::QNet::UserUseNick && !$::QNet::UserUseAuth} {
            putlog "No UserUse\002MODE\002 defined, abort AutoAdd"
            set ::QNet::UserAutoAdd 0
            return
         }
         if {$::QNet::UserUseSpecial} {
            if $::QNet::debug { putcmdlog "::QNet::user:autoadd use special" }
            if ![validuser $::QNet::UserSpecial] {
               if $::QNet::debug { putcmdlog "::QNet::user:autoadd add user $::QNet::UserSpecial" }
               adduser $::QNet::UserSpecial
               chattr $::QNet::UserSpecial $::QNet::UserAutoFlag
            }
            if {$host!="" && $host!="*"} {
               if {[lsearch -exact [getuser $::QNet::UserSpecial HOSTS] $nick!$host]!=-1} {
                  if $::QNet::debug { putcmdlog "::QNet::user:autoadd dont add host, allready known" }
               } {
                  if $::QNet::debug { putcmdlog "::QNet::user:autoadd add host $::QNet::UserSpecial $nick!$host" }
                  addhost $::QNet::UserSpecial $nick!$host
               }
            }
            #putcmdlog "user:autoadd qauth:set $::QNet::UserSpecial $auth $nick!$host"
            qauth:set $::QNet::UserSpecial $auth $nick!$host

         } elseif {$::QNet::UserUseNick} {
            if $::QNet::debug { putcmdlog "::QNet::user:autoadd use nick" }
         } elseif {$::QNet::UserUseAuth} {
            if $::QNet::UserRemoveChars { set cauth [removechar $auth] } { set cauth $auth }
            putcmdlog "::QNet::user:autoadd use auth $cauth ($auth)"
            if ![validuser $cauth] {
               adduser $cauth
               chattr $cauth $::QNet::UserAutoFlag
               if {$host!="" && $host!="*"} {
                  if {[lsearch -exact [getuser $cauth HOSTS] $nick!$host]!=-1} {
                     if $::QNet::debug { putcmdlog "::QNet::user:autoadd dont add host, allready known" }
                  } {
                     if $::QNet::debug { putcmdlog "::QNet::user:autoadd add host $cauth $nick!$host" }
                     addhost $cauth $nick!$host
                  }
               }
               qauth:set $cauth $auth $nick!$host
               if $::QNet::debug { putcmdlog "::QNet::user:autoadd use auth $cauth ($auth)" }
            }
         } else { if $::QNet::debug { putcmdlog "::QNet::user:autoadd failed - $nick $auth" } }
      }
   }
   proc auth2hand {auth} {
      foreach user [userlist] {
         set XTRA [getuser $user XTRA auth:$auth]
         if {$XTRA!=""} { return $user }
      }
      return ""
   }

   ### bind procs

   proc raw330 {from signal args} {
      if $::QNet::debug { putcmdlog "::QNet::raw330 from $from signal $signal args $args" }
      set args [lindex $args 0]
      set botn ""; set nick ""; set auth ""; set hand ""; set host "";
      regexp {^(.*) (.*) :is authed as (.*)} $args args botn nick auth
      regexp {^(.*) (.*) (.*) :is authed as} $args args botn nick auth
      if {$nick==$::botnick} {return}
      if {$nick!="" && $auth!=""} {
         set hand [nick2hand $nick]; set host ""
         if {$hand=="" || $hand=="*"} {set hand [auth2hand $auth]}
         if [info exist ::ModeD::users($nick)] { set host [lindex [split $::ModeD::users($nick) !] 1] }
         if {$hand!="" && $hand!="*" && $host!="" && $host!="*"} { set hand [finduser $nick!$host] }
         if {$hand=="" || $hand=="*"} {
            if $::QNet::debug { putcmdlog "::QNet::raw330 handle from $nick/$auth is clear or not uniqe, check/add" }
            user:autoadd $nick $auth
         } { user:check $nick $hand $auth $host }
      }
   }

   bind dcc n qnet {::QNet::partyline QNet}
   proc partyline {cmd hand idx text} {
      if $::QNet::debug { putcmdlog "::QNet::partyline $cmd $hand $idx $text" }
   }

}

bind dcc n test clearA
proc bodytest args {
   putcmdlog "load script"
   namespace eval :: {
      if {$::nick=="NewS-FlasH"} {
      #source scripts.NewsFlash/ModeD.tcl;
         source scripts.NewsFlash/QNet.tcl
      } elseif {$::nick=="WebChat"} {
      #source scripts.Berlin/ModeD.tcl;
         source scripts.Chatter/QNet.tcl
      }
   }
   set ::QNet::userlist [list]; set ::ModeD::userlist [list]
   putcmdlog "ModeD timecheck"
   ::ModeD::time:check 01 01 01 01 01
   putcmdlog "QNet timecheck"
   ::QNet::user:timecheck
}
proc clearA args {
   foreach user [userlist] {
      foreach item [getuser $user xtra] {
         if [string match auth:* $item] {
            set auth [string range $item 5 [expr [string first " " $item]-1]]
            #setuser $user xtra auth:$auth
            putcmdlog "user $user auth $auth item $item"
         }
      }
      if {$user!="CyBex" && [matchattr $user A]} {
      #putcmdlog "delete $user"
         deluser $user
      }
   }
   putcmdlog "bodytest"
   bodytest
}

namespace eval ::QNet:: {

   #set ::QNet::develop 0

   putlog "QNet.tcl loaded version $major.$minor.$build.$run"
   return "$major.$minor.$build.$run"
}




Generated by GNU enscript 1.6.4.