All pastes #796363 Raw Edit

Stuff

public text v1 · immutable
#796363 ·published 2007-11-25 00:35 UTC
rendered paste body
; ––––––––––––––––––––––––––––––––––––––––
;     Query Blocker 0.81 for NNScript
;         © 2003-2004 by Phreak
; ––––––––––––––––––––––––––––––––––––––––
; The core functions were found in some
; scripting forum, so I can't take credit
; for them. They are heavily modified and
; extended though (originally they had
; about 15 lines of code).
; ––––––––––––––––––––––––––––––––––––––––
; Check this site for updates:
;      http://www.gerald-online.de
; ––––––––––––––––––––––––––––––––––––––––

on 1:START:{
  hmake qb.authlist 300
  hmake qb.blocklist 300
  if ($exists(qb_auths.dat)) hload -ob qb.authlist qb_auths.dat
  if ($exists(qb_blocks.dat)) hload -ob qb.blocklist qb_blocks.dat
  kte_echo -s Query Blocker %qb.version © 2003-2004 by Phreak loaded, blocker: $sd($iif(%qb.disabled == 0,enabled,disabled)) $+ , notify: $sd($iif(%qb.notify == 1,enabled,disabled)) $+ , allowed hostmasks: $sd($hget(qb.authlist,0).item) $+ , blocked/unknown hostmasks: $sd($hget(qb.blocklist,0).item) $+ , blocked queries: $sd(%qb.blocked)
}

on 1:LOAD:{
  if (%version < 3.8) {
    if ($input(NoNameScript is required to run this script. Download it from http://www.nnscript.com,o)) {
      unload -rs $script
    }
  }
  set %qb.disabled 0
  set %qb.notify 1
  set %qb.notadd 1
  set %qb.messages 1
  set %qb.status 1
  set %qb.awaylog 1
  set %qb.balloon 1
  set %qb.showmsg 1
  set %qb.version 0.81
  set %qb.message Your Query has been blocked! Only authorized users may send private messages to <me>
  set %qb.addmsg You have been added to the allow query list of <me> with '<address>'
  hmake qb.authlist 300
  hmake qb.blocklist 300
  if ($exists(qb_auths.dat)) hload -ob qb.authlist qb_auths.dat
  if ($exists(qb_blocks.dat)) hload -ob qb.blocklist qb_blocks.dat
  kte_echo -a Query Blocker %qb.version loaded. © 2003-2004 by Phreak
  if ($input(This is the first time you run the query blocker. Do you want to set it up now?)) qbsetup
}

on 1:unload:{
  unset %qb.disabled 
  unset %qb.notify 
  unset %qb.notadd
  unset %qb.messages
  unset %qb.status
  unset %qb.awaylog
  unset %qb.balloon
  unset %qb.message
  unset %qb.showmsg
  unset %qb.addmsg
  kte_echo -a Query Blocker %qb.version unloaded. © 2003-2004 by Phreak
  unset %qb.version
}

on 1:exit: {
  $iif($hget(qb.authlist,0).item > 0,hsave -ob qb.authlist qb_auths.dat, $iif($isfile(qb_auths.dat),remove qb_auths.dat))
  $iif($hget(qb.blocklist,0).item > 0,hsave -ob qb.blocklist qb_blocks.dat, $iif($isfile(qb_blocks.dat),remove qb_blocks.dat))
}

ctcp 1:version:*:{
  if (%qb.notify == 1) .ctcpreply $nick VERSION 12( Query Blocker %qb.version for NNScript © 2003-2004 by Phreak 12)
}

; here comes the core script
on ^*:open:?:*:{
  if (%qb.disabled == 1) { return }
  ; don't block messages from psybnc and from bnc internal chat
  if ($nick iswm -psyBNC) { return }
  if (mavine isin $nick) { return }
  if (int~ isin $nick) { return }
  if ($nick iswm $me) { return }
  var %i $comchan($nick,0)
  while (%i) {
    var %chans = %chans $iif($nick isop $comchan($nick,%i),@) $+ $iif($nick isvoice $comchan($nick,%i),+) $+ $comchan($nick,%i)
    dec %i
  }
  if ($address($nick,3) == $null) {
    .msg $nick I'm unable to determine your hostmask. Please join a channel I'm on or wait a few seconds until my IAL is updated.
    qbmessage Unable to determine hostmask of $sd($nick) $+ , blocking the message $iif(%qb.showmsg,$sd($1-)) $+ . Common channels: $sd($iif(%chans,%chans,none))  
    halt
  }
  var %j 10
  while (%j) {
    dec %j
    if ($hfind(qb.authlist,$address($nick,%j)) iswm $address($nick,%j)) { return }
  }
  haltdef
  .ignore -pntiu120 $address($nick,3)
  if (%qb.notify == 1) .msg $nick $replace(%qb.message,<me>,$me,<nick>,$nick)
  inc %qb.blocked
  if ($hfind(qb.blocklist,$address($nick,3)) !iswm $address($nick,3)) {
    hadd -m qb.blocklist $address($nick,3)
    qbmessage $iif(%qb.showmsg,message $sd($1-),A message) from $sd($nick) was blocked. $sd($comchan($nick,0) comchan $+ $iif($comchan($nick,0) > 1,s) $+ : %chans))  
    if ($away) && (%qb.awaylog == 1) kte_echo $away.logwin $gtd(Query Blocker) A query from $sd($nick) was blocked. Common channels: $sd(%chans) $iif(%qb.showmsg == 0,message: $sd($1-))
    if ($balloon.trig) && (q isin %nntray) && (%qb.balloon == 1) { stdll Balloon 1 1 > Queryblocker > query from $puform($nbr($nick) was blocked!) }
  }
  else {
    qbmessage -s $iif(%qb.showmsg,message $sd($1-),A message) from $sd($nick) was blocked. $sd($comchan($nick,0) comchan $+ $iif($comchan($nick,0) > 1,s) $+ : %chans))  
  }
  halt
}

; menus
menu nicklist,query {
  $iif($1,Query Blocker)
  .$iif(%qb.notadd == 1,$style(1)) Notify enquirer: %qb.notadd = $iif(%qb.notadd,0,1)
  .-
  .$iif(($checkqueryauth($1,0)==1),$style(1)) $+ allow Queries $address($1,0):qb_edit $1 0
  .$iif(($checkqueryauth($1,1)==1),$style(1)) $+ allow Queries $address($1,1):qb_edit $1 1
  .$iif(($checkqueryauth($1,2)==1),$style(1)) $+ allow Queries $address($1,2):qb_edit $1 2
  .$iif(($checkqueryauth($1,3)==1),$style(1)) $+ allow Queries $address($1,3):qb_edit $1 3
  .$iif(($checkqueryauth($1,4)==1),$style(1)) $+ allow Queries $address($1,4):qb_edit $1 4
  .$iif(($checkqueryauth($1,5)==1),$style(1)) $+ allow Queries $address($1,5):qb_edit $1 5
  .$iif(($checkqueryauth($1,6)==1),$style(1)) $+ allow Queries $address($1,6):qb_edit $1 6
  .$iif(($checkqueryauth($1,7)==1),$style(1)) $+ allow Queries $address($1,7):qb_edit $1 7
  .$iif(($checkqueryauth($1,8)==1),$style(1)) $+ allow Queries $address($1,8):qb_edit $1 8
  .$iif(($checkqueryauth($1,9)==1),$style(1)) $+ allow Queries $address($1,9):qb_edit $1 9
}

menu menubar {
  -
  Query Blocker
  .$iif(%qb.disabled != 1,$style(1)) Enabled:%qb.disabled = $iif(%qb.disabled != 1,1,0)
  .$iif(%qb.notadd == 1,$style(1)) Notify enquirer: %qb.notadd = $iif(%qb.notadd,0,1)
  .-
  .Setup:qbsetup
  .Readme:qbreadme
  -
}

menu @QueryBlocker {
  $style(2) [QueryBlocker]:x
  -
  clear:qbclwnd
  clear and close:qbclwnd -c
}

; the dialogs
dialog -l qbsetup {
  title "Query Blocker [/qbsetup]"
  size -1 -1 179 122
  option dbu
  tab "Settings", 1, 0 -2 178 110
  box "show messages", 6, 2 11 174 45, tab 1
  radio "in active Window", 7, 5 19 54 10, tab 1
  radio "in own window", 9, 5 27 51 10, tab 1
  radio "never", 10, 5 35 50 10, tab 1
  check "log in status window", 11, 71 35 60 10, tab 1
  box "Messages", 12, 2 56 175 51, tab 1
  check "enable", 16, 139 62 29 10, tab 1
  check "show balloon tips", 28, 71 19 50 10, tab 1
  check "show in away log", 36, 71 27 50 10, tab 1
  box "", 38, 61 14 1 39, tab 1
  edit "", 13, 7 72 139 10, tab 1 autohs
  text "block message (<me>, <nick>)", 14, 7 63 79 8, tab 1
  button "set", 15, 148 72 21 10, tab 1
  edit "", 43, 7 93 139 10, tab 1 autohs
  text "add message (<me>, <nick>, <address>)", 42, 7 84 104 8, tab 1
  check "enable", 44, 139 83 29 10, tab 1
  button "set", 45, 148 93 21 10, tab 1
  check "hide query messages", 35, 71 43 68 10, tab 1
  tab "Authed", 2
  list 17, 3 14 174 80, tab 2 sort size
  button "Add", 18, 62 95 37 12, tab 2
  button "Remove", 19, 101 95 37 12, disable tab 2
  button "Clear all", 20, 140 95 37 12, disable tab 2
  text "Total:", 23, 3 97 15 8, tab 2
  edit "0", 24, 20 96 25 10, tab 2 read
  tab "Blocked", 3
  list 25, 3 14 174 80, tab 3 sort size
  button "Clear all", 26, 140 95 37 12, disable tab 3
  button "Remove", 27, 101 95 37 12, disable tab 3
  edit "0", 29, 20 96 25 10, tab 3 read
  text "Total:", 30, 3 97 15 8, tab 3
  tab "Readme", 4
  edit "", 34, 3 14 173 92, tab 4 read multi autovs vsbar
  tab "About", 5
  text Query Blocker %qb.version, 31, 102 19 75 8, tab 5 center
  text "© 2003-2004 by Phreak", 32, 108 30 62 8, tab 5
  link "http://www.gerald-online.de/", 33, 53 93 76 8, tab 5
  box "Statistics", 21, 3 13 96 42, tab 5
  text "$num queries blocked", 39, 8 21 84 8, tab 5
  text "$num hostmasks allowed", 41, 8 41 84 8, tab 5
  text "$num hostmasks blocked", 40, 8 31 84 8, tab 5
  button "Close", 22, 142 110 37 12, ok
  check "disable blocker", 37, 1 110 52 10
}

on *:dialog:qbsetup:*:*:{
  if ($devent == init) {
    mdx MarkDialog $dname $dialog($dname).hwnd
    mdx SetControlMDX $dname 17,25 ListView report showsel single rowselect > script\mdx\views.mdx
    did -i $dname 17,25 1 headerdims 200:1 100:2 
    did -i $dname 17,25 1 headertext + 0 Hostmask	+ 0 nick
    mdx SetFont $dname 2 11 300 Tahoma
    var %i 0
    while (%i < $hget(qb.authlist,0).item) {
      inc %i
      var %j 0
      while (%j < $ial($hget(qb.authlist,%i).item,0)) {
        inc %j
        var %authnicks = %authnicks $+ $iif(%j > 1,$chr(44)) $+ $ial($hget(qb.authlist,%i).item,%j).nick
      }
      did -a $dname 17 $hget(qb.authlist,%i).item 	+ 0 $iif(%authnicks,%authnicks,unknown)
      unset %authnicks
      unset %j
    }
    if (%i isnum) {
      did -ra $dname 24 %i
      did -e $dname 20
    }
    var %i 0
    while (%i < $hget(qb.blocklist,0).item) {
      inc %i
      var %j 0
      while (%j < $ial($hget(qb.blocklist,%i).item,0)) {
        inc %j
        var %authnicks = %authnicks $+ $iif(%j > 1,$chr(44)) $+ $ial($hget(qb.blocklist,%i).item,%j).nick
      }
      did -a $dname 25 $hget(qb.blocklist,%i).item 	+ 0 $iif(%authnicks,%authnicks,unknown)
      unset %authnicks
      unset %j
    }
    if (%i isnum) {
      did -ra $dname 29 %i
      did -e $dname 26
    }
    unset %i
    did $iif(%qb.disabled == 1,-c,-u) $dname 37
    did -ra $dname 39 $iif(%qb.blocked,%qb.blocked,0) queries blocked
    did -ra $dname 40 $hget(qb.blocklist,0).item hostmasks blocked
    did -ra $dname 41 $hget(qb.authlist,0).item hostmasks allowed
    did $iif(%qb.messages == 0,-c,-u) $dname 10
    did $iif(%qb.messages == 1,-c,-u) $dname 9
    did $iif(%qb.messages == 2,-c,-u) $dname 7
    did $iif(%qb.balloon == 1,-c,-u) $dname 28
    did $iif(%qb.status == 1,-c,-u) $dname 11
    did $iif(%qb.notify == 1,-e,-b) $dname 13
    did $iif(%qb.notify == 1,-e,-b) $dname 15
    did $iif(%qb.notify == 1,-c,-u) $dname 16
    did $iif(%qb.showmsg == 1,-u,-c) $dname 35
    did $iif(%qb.awaylog == 1,-c,-u) $dname 36
    did $iif(%qb.notadd == 1,-e,-b) $dname 43
    did $iif(%qb.notadd == 1,-c,-u) $dname 44
    did $iif(%qb.notadd == 1,-e,-b) $dname 45
    if (!$balloon.trig) did -ub $dname 28
    did -ra $dname 13 %qb.message
    did -ra $dname 43 %qb.addmsg
    var %i 1
    var %rm $read(qblocker.txt,1)
    while (%rm) {
      did -a $dname 34 %rm $+ $crlf
      inc %i
      %rm = $read(qblocker.txt,%i)
    }
  }
  elseif ($devent == sclick) {
    if ($did == 1) {
    }
    elseif ($did == 7) {
      %qb.messages = 2
    }
    elseif ($did == 9) {
      %qb.messages = 1
    }
    elseif ($did == 10) {
      %qb.messages = 0
    }
    elseif ($did == 11) {
      %qb.status = $did($dname,11).state
      if (%qb.status == 0) {
        kte_echo -s $gtd(Query Blocker) stopped logging to the status window
      }
      else {
        qbmessage -s now logging to the status window
      }
    }
    elseif ($did == 15) {
      %qb.message = $did($dname,13).text
    }
    elseif ($did == 16) {
      %qb.notify = $did($dname,16).state
      did $iif($did($dname,16).state == 1,-e,-b) $dname 13
      did $iif($did($dname,16).state == 1,-e,-b) $dname 15
    }
    elseif ($did == 17) {
      did $iif($did($did).sel,-e,-b) $dname 19
    }
    elseif ($did == 18) {
      dialog -m qbadd qbadd
    }
    elseif ($did == 19) {
      if ($did(17).sel) {
        if ($input(do yo really want to remove $+(',$gettok($gettok($did(17).seltext,1,9),6,32),',?),y)) {
          hdel qb.authlist $gettok($gettok($did(17).seltext,1,9),6,32)
          did -d $dname 17 $did(17).sel
          did -ra $dname 24 $calc($did(24).text - 1)
        }
      }
    }
    elseif ($did == 20) {
      if ($?!="Are you sure you want to remove all hostmasks?") {
        $iif($hget(qb.authlist,0).item > 0,hfree qb.authlist)
        did -r $dname 17
        did -ra $dname 24 0
        qbmessage -s Removed all entries from auth list.
      }
    }
    elseif ($did == 25) {
      did $iif($did($did).sel,-e,-b) $dname 27
    }
    elseif ($did == 26) {
      if ($?!="Are you sure you want to remove all hostmasks?") {
        $iif($hget(qb.blocklist,0).item > 0,hfree qb.blocklist)
        did -r $dname 25
        did -ra $dname 29 0
        qbmessage -s Removed all entries from blocked list.
      }
    }
    elseif ($did == 27) {
      if ($did(25).sel) {
        if ($input(do yo really want to remove $+(',$gettok($gettok($did(25).seltext,1,9),6,32),',?),y)) {
          hdel qb.blocklist $gettok($gettok($did(25).seltext,1,9),6,32)
          did -d $dname 25 $did(25).sel
          did -ra $dname 29 $calc($did(29).text - 1)
        }
      }
    }
    elseif ($did == 28) {
      %qb.balloon = $did($dname,28).state
      qbmessage -s balloon tips are now $sd($iif(%qb.balloon == 1,enabled,disabled))
    }
    elseif ($did == 33) {
      run http://www.gerald-online.de
    }
    elseif ($did == 35) {
      %qb.showmsg = $iif($did($dname,35).state,0,1)
    }
    elseif ($did == 36) {
      %qb.awaylog = $did($dname,36).state
      qbmessage -s away log is now $sd($iif(%qb.awaylog == 1,enabled,disabled))
    }
    elseif ($did == 37) {
      %qb.disabled = $did($dname,37).state
      qbmessage -s Blocker is now $sd($iif($did($dname,37).state == 0,enabled,disabled))
    }
    elseif ($did == 44) {
      %qb.notadd = $did($dname,44).state
      did $iif($did($dname,44).state == 1,-e,-b) $dname 43
      did $iif($did($dname,44).state == 1,-e,-b) $dname 45
    }
    elseif ($did == 45) {
      %qb.addmsg = $did($dname,43).text
    }
  }
}

dialog -l qbadd {
  title "Add Hostmask"
  size -1 -1 189 117
  option dbu
  box "Channel and Nick", 1, 1 1 67 114
  combo 2, 4 9 62 50, sort size drop
  list 3, 3 20 63 83, sort size
  box "Hostmask", 4, 69 1 118 100
  list 5, 71 8 114 80, size
  button "Add", 6, 150 103 37 12
  button "Cancel", 7, 111 103 37 12, cancel
  edit "", 8, 71 88 114 10
  edit "", 9, 18 103 48 10
  text "Filter:", 10, 4 104 14 8
}

on *:dialog:qbadd:*:*:{
  if ($devent == init) {
    mdx MarkDialog $dname $dialog($dname).hwnd
    var %i $chan(0)
    while (%i) {
      did -a $dname 2 $chan(%i)
      dec %i
    }
    unset %i
  }
  elseif ($devent == sclick) {
    if ($did == 2) {
      if ($did(2).sel) {
        did -r $dname 3
        var %i $nick($did(2).seltext,0)
        while (%i) {
          if ($isauthed($nick($did(2).seltext,%i)) == 0) did -a $dname 3 $iif($nick($did(2).seltext,%i) isop $did(2).seltext,@) $+ $iif($nick($did(2).seltext,%i) isvoice $did(2).seltext,+) $+ $nick($did(2).seltext,%i)
          dec %i
        }
        unset %i
      }
    }
    elseif ($did == 3) {
      if ($did(3).sel) {
        did -r $dname 5
        var %i 0
        while (%i < 10) {
          did -a $dname 5 $address($iif($left($did(3).seltext,1) isin @ +,$right($did(3).seltext,-1),$did(3).seltext),%i)
          inc %i
        }
        did -c $dname 5 4
        did -ra $dname 8 $did(5).seltext
        unset %i
      }
    }
    elseif ($did == 5) {
      if ($did(5).sel) {
        did -ra $dname 8 $did(5).seltext
      }
    }
    elseif ($did == 6) {
      if ($did(5).sel) {
        did -a qbsetup 17 $did(8).text 	+ 0 $iif($ial($did(8).text,1).nick,$ial($did(8).text,1).nick,unknown)
        hadd -m qb.authlist $did(8).text
        did -ra qbsetup 24 $calc($did(24).text + 1)
        qbmessage -s Added $sd($iif($ial($did(8).text,1).nick,$ial($did(8).text,1).nick,unknown)) to allow query list with $sd($did(8).text)
      }
    }
  }
  elseif ($devent == edit) {
    if ($did == 9) {
      if ($did(2).sel) {
        did -r $dname 3
        var %i $nick($did(2).seltext,0)
        while (%i) {
          if ($isauthed($nick($did(2).seltext,%i)) == 0) && (($did(9).text isin $nick($did(2).seltext,%i)) || ($did(9).text == $null)) did -a $dname 3 $nick($did(2).seltext,%i)
          dec %i
        }
        unset %i
      }
    }
  }
}

; some usefull aliases
alias qbsetup {
  dialog -m qbsetup qbsetup
}

alias -l qb.openwin {
  if ($window(@QueryBlocker) == $null) {
    window -znk0 +betns @QueryBlocker
  }
}

alias -l qbmessage {
  if (%qb.status == 1) kte_echo -s $gtd(Query Blocker) $iif($1 iswm -s,$2-,$1-)
  if (%qb.messages == 1) {
    qb.openwin
    aline $iif($1 iswm -s,-p,-hp) @QueryBlocker $sd($time) $iif($1 iswm -s,$2-,$1-)
  }
  elseif (%qb.messages == 2) {
    kte_echo -a $gtd(Query Blocker) $iif($1 iswm -s,$2-,$1-)
  }
  return
}

alias -l isauthed {
  var %j 0
  while (%j < 10) {
    if ($hfind(qb.authlist,$address($1,%j)) iswm $address($1,%j)) return 1
    inc %j
  }
  return 0
}

alias -l qb_edit {
  if ($address($1,$2) != $null) {
    if ($hfind(qb.authlist,$address($1,$2)) iswm $address($1,$2)) {
      hdel qb.authlist $address($1,$2)
      qbmessage -s  Removed $sd($1) from allow query list with $sd($address($1,$2))
    }
    else {
      hadd -m qb.authlist $address($1,$2)
      qbmessage -s Added $sd($1) to allow query list with $sd($address($1,$2)) $iif(%qb.notadd == 0,$sd(without notify))
      if (%qb.notadd == 1) .notice $1 $replace(%qb.addmsg,<me>,$me,<nick>,$1,<address>,$address($1,$2))
      .ignore -r $address($1,3)
    }
  }
  else { kte_error -a unknown user. Please wait for the IAL to update. }
}

alias -l qbclwnd {
  dline @QueryBlocker $line(@QueryBlocker,0)
  if ($1 iswm -c) {
    window -c @QueryBlocker
  }
}

alias -l checkqueryauth {
  if ($hfind(qb.authlist,$address($1,$2)) iswm $address($1,$2)) return 1
  return 0
}

alias qbreadme {
  if (!$isfile(qblocker.txt)) return
  window -kf +betl @QBReadme -1 -1 376 392 Lucida Console 12
  titlebar @QBReadme
  loadbuf @QBReadme " $+ qblocker.txt $+ "
  sline @QBReadme 25
}

; ––––––––––––––––––––––––––––––––––––––––
; End of file
; ––––––––––––––––––––––––––––––––––––––––