All pastes #167144 Raw Edit

by SoLDaT

public text v1 · immutable
·published 2006-09-11 18:27 UTC
rendered paste body
Tim|Dark;; PVT blocker

dialog pvtblock {
  title "PVT blocker"
  size -1 -1 266 259
  option pixels
  button "Ok", 14, 159 236 50 20, ok
  button "Cancel", 15, 211 236 50 20, cancel
  tab "Hostmasks", 25, 5 5 255 232
  check "Enable pvt blocking", 1, 13 35 160 20, tab 25
  list 19, 12 59 240 117, tab 25 size
  check "Block everyone", 23, 13 181 96 16, tab 25
  button "Add", 20, 112 179 45 20, tab 25
  button "Delete", 21, 159 179 45 20, tab 25
  button "Clear", 22, 206 179 45 20, tab 25
  text "", 16, 13 211 236 16, disable tab 25
  edit "", 13, 12 204 239 2, tab 25
  tab "Options", 26
  text "Exempt from blocking if user is:", 3, 13 35 237 16, disable tab 26
  edit "", 4, 14 58 239 2, tab 26
  check "Notify", 5, 15 63 56 16, tab 26
  check "Auto-voice", 8, 15 82 78 16, tab 26
  check "Users list", 9, 101 82 71 16, tab 26
  check "Protect", 6, 101 63 64 16, tab 26
  check "Auto-op", 7, 183 63 65 16, tab 26
  check "Service", 24, 183 82 65 16, tab 26
  edit "", 10, 14 120 239 2, tab 26
  check "Keep a log of the blocked queries", 12, 15 144 236 16, tab 26
  check "Warn users that they've been blocked", 11, 15 182 224 16, tab 26
  edit "", 17, 14 202 239 2, tab 26
  check "psyBNC", 2, 15 101 70 16, tab 26
  check "IRCop", 18, 101 101 70 16, tab 26
  check "Notify me when somebody gets blocked", 27, 15 163 226 16, tab 26
  check "Block DCC chats as well", 28, 15 125 222 16, tab 26
  text "Message:", 29, 13 209 50 16, tab 26
  edit "", 30, 65 207 188 21, tab 26 autohs
  button "", 40, 0 0 0 0 hide
}

on *:dialog:pvtblock:*:*:{
  if ($devent == init) {
    seticon 45
    setmdx
    sethelp 40
    mdx SetControlMDX $dname 19 listview rowselect report single showsel > $views
    mdx SetBorderStyle $dname 4,10,13,17 staticedge
    mdx SetBorderStyle $dname 20,21,22 clientedge
    mdx SetFont $dname 3,16 ANSI 13 700 Tahoma
    did -i $dname 19 1 headerdims 210
    did -i $dname 19 1 headertext Hostmasks to block:
    did -a $dname 16 $fkeyt(blocklog) to view logs
    .fopen pvtblock $utilpath(pvtblock.ac)
    while (1) {
      var %t = $fread(pvtblock)
      if (!%t) break
      did -a $dname 19 $lv(%t)
    }
    .fclose pvtblock
    if ($hget(pvtblock,pvtblock)) did -c $dname 1
    if ($hget(pvtblock,notify)) did -c $dname 5
    if ($hget(pvtblock,protect)) did -c $dname 6
    if ($hget(pvtblock,autoop)) did -c $dname 7
    if ($hget(pvtblock,autovoice)) did -c $dname 8
    if ($hget(pvtblock,userslist)) did -c $dname 9
    if ($hget(pvtblock,service)) did -c $dname 24
    if ($hget(pvtblock,psybnc)) did -c $dname 2
    if ($hget(pvtblock,ircop)) did -c $dname 18
    if ($hget(pvtblock,chat)) did -c $dname 28
    if ($hget(pvtblock,notice)) did -c $dname 27
    if ($hget(pvtblock,warn)) did -c $dname 11
    if ($hget(pvtblock,log)) did -c $dname 12
    if ($hget(pvtblock,everyone)) did -c $dname 23
    did -a $dname 30 $hget(pvtblock,msg)
  }
  elseif ($devent == sclick) {
    if ($did == 14) {
      utilsave pvtblock pvtblock $did($dname,1).state
      utilsave pvtblock notify $did($dname,5).state
      utilsave pvtblock protect $did($dname,6).state
      utilsave pvtblock autoop $did($dname,7).state
      utilsave pvtblock autovoice $did($dname,8).state
      utilsave pvtblock userslist $did($dname,9).state
      utilsave pvtblock service $did($dname,24).state
      utilsave pvtblock psybnc $did($dname,2).state
      utilsave pvtblock ircop $did($dname,18).state
      utilsave pvtblock chat $did($dname,28).state
      utilsave pvtblock notice $did($dname,27).state
      utilsave pvtblock warn $did($dname,11).state
      utilsave pvtblock log $did($dname,12).state
      utilsave pvtblock everyone $did($dname,23).state
      utilsave pvtblock msg $dlgnotnull(30,Your query/dcc chat has been rejected (pvt blocker))
      .fopen -no pvtblock $utilpath(pvtblock.ac)
      var %i = 2
      while ($did($dname,19,%i)) {
        .fwrite -n pvtblock $nolv($v1)
        inc %i
      }
      .fclose pvtblock
    }
    elseif ($did == 20) {
      var %t = $anainp(Hostmask:)
      if (* !isin %t) && ($chr(33) !isin %t) var %t = %t $+ !*@*
      did -a $dname 19 %t
    }
    elseif ($did == 21) {
      if ($did($dname,19).sel) {
        var %t = $v1
        did -d $dname 19 %t
        if ($did($dname,19,2)) {
          if ($did($dname,19).lines >= %t) did -c $dname 19 %t
          else did -c $dname 19 $calc(%t - 1)
        }
      }
    }
    elseif ($did == 22) did -r $dname 19
    elseif ($did == 40) adoc utilities 6
  }
}

alias ispvtb {
  if ($hget(pvtblock,isblocked)) return 1
  elseif (!$hget(pvtblock,pvtblock)) return
  elseif ($hget(pvtblock,notify)) && ($notify($nick)) return
  elseif ($hget(pvtblock,protect)) && (($protect($fulladdress)) || ($protect($nick))) return
  elseif ($hget(pvtblock,autoop)) && (($aop($fulladdress)) || ($aop($nick))) return
  elseif ($hget(pvtblock,autovoice)) && (($avoice($fulladdress)) || ($avoice($nick))) return
  elseif ($hget(pvtblock,userslist)) && ($level($fulladdress) != $dlevel) return
  elseif ($hget(pvtblock,service)) && ($netret($anet,smask) iswm $fulladdress) return
  elseif ($hget(pvtblock,psybnc)) && ($nick == -psyBNC) return
  elseif ($hget(pvtblock,ircop)) && ($netret($anet,sircop) iswm $fulladdress) return
  else {
    if ($hget(pvtblock,everyone)) {
      hadd -m pvtblock isblocked 1
      var %t = 1
    }
    else {
      .fopen pvtblock $utilpath(pvtblock.ac)
      while (1) {
        var %n = $fread(pvtblock)
        if (!%n) break
        if (%n iswm $fulladdress) {
          hadd -m pvtblock isblocked 1
          var %t = 1
          break
        }
      }
      .fclose pvtblock
    }
    return %t
  }
}

on ^*:OPEN:?:{
  if ($ispvtb) blockit $1-
}

ctcp *:*:?:{
  if ($1 == DCC) && ($2 == CHAT) && (($3 == chat) || ($3 == talk)) && ($4 isnum) && ($5 isnum) && ($hget(pvtblock,chat)) && ($ispvtb) blockit (DCC CHAT request)
}

alias -l blockit {
  hdel pvtblock isblocked
  if (!$halted) {
    if ($hget(pvtblock,warn)) .notice $nick $hget(pvtblock,msg)
    if ($hget(pvtblock,notice)) actdisp $iif($event == OPEN,Query,DCC chat) from  $+ $nick ( $+ $address $+ ) has been blocked ( $+ $fkeyt(blocklog) to view log $+ )
    if ($hget(pvtblock,log)) write $utilpath(pvtblock.log) $atime $anet (CID $cid $+ ) $nick $address $1-
    $iif($event == OPEN,haltdef,halt)
  }
}

alias blocklog {
  var %f = $utilpath(pvtblock.log)
  if ($lines(%f)) {
    if ($window(@pvtblock)) window -c @pvtblock
    window -hk[0]  @pvtblock
    mircustom Titlebar -w $window(@pvtblock).hwnd Pvt blocking log ( $+ $fkeyt(blockerase) to clear this log $+ )
    loadbuf -p @pvtblock %f
    window -a @pvtblock
  }
  else actdisp No entries on pvtblocker log
}

alias blockerase {
  write -c $utilpath(pvtblock.log)
  clear @pvtblock
}