Peace & Protection 4.00 — File Browser

PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / ADDONS / NICKSERV.MRC

NICKSERV.MRC — 18.01 KB — Download this file

; #= ppnserv -rs
; ########################################
; Peace & Protection
; NickServ support (standard addon)
; ########################################

;;; auto-add to access list
;;; auto-ghosting/recovery
;;; after a ghost/recovery, autotake, check on kill notices, fkey to release nick after recover
;;; notice hiding (same on cs, x/w)

alias -l _warpnick return $replace($1,[,~,],+)
alias -l _unwarpnick return $replace($1,~,[,+,])

dialog nickserv {
  title "NickServ Logins"
  size -1 -1 300 290

  text "View NickServ logins for:", 1, 10 15 128 20, right
  combo 2, 140 11 150 100, drop sort

  box "", 3, 10 40 280 130
  list 4, 20 58 190 110, sort
  button "Add...", 11, 220 60 55 25
  button "Edit...", 12, 220 95 55 25, disable
  button "Remove", 13, 220 130 55 25, disable

  check "Auto-login on every connect / nick change", 20, 20 182 250 16
  check "Auto-add / remove logins when you register / drop", 21, 20 202 300 16
  check "Auto-ghost", 22, 20 222 120 16, disable
  check "Auto-recovery", 23, 140 222 120 16, disable

  button "Close", 100, 15 250 80 25, cancel default
  button "Remove all", 50, 105 250 80 25
  button "Login to all...", 80, 195 250 85 25
}
on *:DIALOG:nickserv:init:*:{
  if (%`ns.autologin) did -c $dname 20
  if (%`ns.autoupdate) did -c $dname 21
  if (%`ns.autoghost) did -c $dname 22
  if (%`ns.autorecover) did -c $dname 23
  var %nets = $readini -n $_cfg(pw.ini) ns nets,%num = $numtok(%nets,32),%net
  :loop | if (%num > 0) { %net = $gettok(%nets,%num,32) | did -a $+ $iif(%!net == %net,c) $dname 2 %net | dec %num | goto loop }
  did -a $+ $iif($did(2,0).sel == 0,c) $dname 2 (all networks)
  _nsdupd
}
on *:DIALOG:nickserv:sclick:20:if ($did(20).state) `set ns.autologin 1 | else `set ns.autologin
on *:DIALOG:nickserv:sclick:21:if ($did(21).state) `set ns.autoupdate 1 | else `set ns.autoupdate
on *:DIALOG:nickserv:sclick:22:if ($did(22).state) `set ns.autoghost 1 | else `set ns.auoghost
on *:DIALOG:nickserv:sclick:23:if ($did(23).state) `set ns.autorecover 1 | else `set ns.autorecover
on *:DIALOG:nickserv:sclick:50:_juryrig .ns auto clear
on *:DIALOG:nickserv:sclick:80:_juryrig .ns auto all
on *:DIALOG:nickserv:sclick:2:_nsdupd
on *:DIALOG:nickserv:sclick:4:_nsseld
alias -l _nsseld if ($did(nickserv,4,0).sel) did -e nickserv 12,13 | else did -b nickserv 12,13
alias -l _nsdupd {
  did -r nickserv 4
  var %nets = $did(nickserv,2,$did(nickserv,2).sel).text,%net,%num,%nicks
  if ($chr(32) isin %nets) %nets = $readini -n $_cfg(pw.ini) ns nets
  if (%nets == $null) goto done
  window -hln @.nsupd
  :nloop
  %net = $gettok(%nets,1,32)
  %nets = $gettok(%nets,2-,32)
  loadbuf -tns- $+ %net @.nsupd $_cfg(pw.ini)
  %num = $line(@.nsupd,0)
  :loop | if (%num > 0) { did -a nickserv 4 $_unwarpnick($gettok($line(@.nsupd,%num),1,61)) ( $+ %net $+ ) | dec %num | goto loop }
  if (%nets) { clear @.nsupd | goto nloop }
  window -c @.nsupd
  :done
  _nsseld
}
on *:DIALOG:nickserv:sclick:11:dialog -am nsadd nsadd
on *:DIALOG:nickserv:sclick:12:_nsedit
on *:DIALOG:nickserv:sclick:13:_juryrig _nsrem
on *:DIALOG:nickserv:dclick:4:_nsedit
alias -l _nsedit {
  var %sel = $$did(nickserv,4,$did(nickserv,4).sel).text,%net = $right($left($gettok(%sel,2,32),-1),-1),%nick = $gettok(%sel,1,32)
  set %.net %net
  set %.nick %nick
  dialog -am nsadd nsadd
}
alias -l _nsrem {
  var %sel = $$did(nickserv,4,$did(nickserv,4).sel).text,%net = $right($left($gettok(%sel,2,32),-1),-1),%nick = $gettok(%sel,1,32)
  _okcancel 1 Remove NickServ login for %nick on %net $+ ?
  .ns auto del %net %nick
}
dialog nsadd {
  title "Add NickServ Login"
  size -1 -1 190 145

  text "Network:", 1, 10 14 68 20, right
  combo 11, 81 11 98 100, drop edit sort
  text "Nickname:", 2, 10 39 68 20, right
  edit "", 12, 80 35 100 22, autohs
  text "Password:", 3, 10 64 68 20, right
  edit "", 13, 80 60 100 22, autohs pass

  button "OK", 100, 10 105 70 25, OK default
  button "Cancel", 101, 110 105 70 25, cancel
}
on *:DIALOG:nsadd:init:*:{
  var %nets = $readini -n $_cfg(pw.ini) ns nets,%num,%net
  if ((%.net == $null) && (%!net != Offline)) set -u %.net %!net
  if (%!net) %nets = $addtok(%nets,%!net,32)
  if (%.net) %nets = $addtok(%nets,%.net,32)
  %num = $numtok(%nets,32)
  :loop | if (%num > 0) { %net = $gettok(%nets,%num,32) | did -a $+ $iif(%.net == %net,c) $dname 11 %net | dec %num | goto loop }
  if (%.nick) {
    did -a $dname 12 %.nick
    var %pw = $readini -n $_cfg(pw.ini) ns- [ $+ [ %.net ] ] $_warpnick(%.nick)
    did -a $dname 13 $_pw.enc(%pw)
  }
  else did -a $dname 12 $me
  unset %.net %.nick
}
on *:DIALOG:nsadd:sclick:100:{
  if ($did(11) == $null) _error You must select or enter a network name.NickServ logins are network specific.
  if ($did(12) == $null) _error You must enter a nickname.NickServ logins are for one nickname only.
  if ($did(13) == $null) _error You must enter a password.A login cannot be performed without the password.
  .ns auto add $did(11) $did(12) $did(13)
}

dialog nsway {
  title "NickServ access setup"
  size -1 -1 250 155

  text "", 1, 10 10 180 40
  radio "Use /msg NickServ", 2, 20 45 230 22
  radio "Use /nickserv", 3, 20 68 230 22
  radio "Use /msg NickServ@services.blah.net", 4, 20 91 230 22

  edit "", 50, 1 1 1 1, autohs hide result

  button "OK", 100, 10 122 80 25, ok default
  button "Cancel", 101, 160 122 80 25, cancel
}
on *:DIALOG:nsway:init:*:{
  did -c $dname 2
  did -o $dname 1 1 For %.net $+ , how should I access NickServ?
  unset %.net
}
on *:DIALOG:nsway:sclick:100:did -o $dname 50 1 $iif($did(3).state,/,$iif($did(4).state,@))

; /ns command [params]
; /ns auto add|etc [network] nick pw
; /ns on|off [network]
; not mentioned but work- HELP
; REGISTER <password>
; IDENTIFY <password>
; DROP <nick> (must identify)
; RECOVER <nick> [<password>]
; ACC <nick>
; INFO <nick>
; RELEASE <nick> [password]
; GHOST <nick> [<password>]
; SET PASSWD <newpass> (must identify)
; SET KILL [ON|OFF]
; SET URL [<URL>]
; SET NOMEMO ON|OFF
; SET NOOP ON|OFF
; SET EMAIL [<EMAIL ADDRESS>]
; SET SHOWEMAIL ON|OFF
; ACCESS ADD <user@host mask>
; ACCESS DEL <user@host mask>
; ACCESS LIST
; (also, ACCESS and SET alone list options)
;;; add config for settings? access list in window?
alias ns {
  if (($1 == $null) || ($istok(edit config cfg,$1,32))) { dialog -am nickserv nickserv | return }
  if ($1 == on) {
    var %net = $2
    if ($2 == $null) %net = %!net
    if (%net == offline) _error Use /ns on while connected.Or, use "/ns on network".
    set %.net %net
    var %opt = $$dialog(nsway,nsway,-4)
    if (($server) && (%net == %!net)) {
      %!serv = $addtok(%!serv,ns,44)
      %!servnick = $addtok(%!servnick,NickServ,32)
      %!servopt = %!servopt $+ %opt
    }
    writeini $_cfg(pw.ini) nsforce %net 1 %opt
    dispa NickServ support enabled for $:s(%net) $+ .
    return
  }
  if ($1 == off) {
    var %net = $2
    if ($2 == $null) %net = %!net
    if (%net == offline) _error Use /ns off while connected.Or, use "/ns off network".
    if (($server) && (%net == %!net)) {
      %!serv = $remtok(%!serv,ns,44)
      %!servnick = $remtok(%!servnick,NickServ,32)
      %!servopt = $remove(%!servopt,@,/)
    }
    remini $_cfg(pw.ini) nsforce %net
    dispa NickServ support disabled for $:s(%net) $+ .
    return
  }
  if (($_isserv(ns) == $false) && ($1 != auto)) _error /ns only works on networks with NickServ.If there is NickServ on this network, type /ns on
  if ($1 == auto) {
    if ($2 == add) {
      if ($4 == $null) { dispa Syntax: /ns auto add [network] nick pw | editbox -ap /ns auto add | halt }
      if ($5) var %net = $3,%nick = $4,%pw = $5
      else var %net = %!net,%nick = $3,%pw = $4
      dispa Added NickServ login for $:t(%nick) on %net
      writeini $_cfg(pw.ini) ns- $+ %net $_warpnick(%nick) $_pw.enc(%pw)
      var %nets = $readini -n $_cfg(pw.ini) ns nets
      writeini $_cfg(pw.ini) ns nets $addtok(%nets,%net,32)
      if ($dialog(nickserv)) {
        _ddadd nickserv 2 $did(11)
        _nsdupd
      }
    }
    elseif ($2 == del) {
      if ($3 == $null) { dispa Syntax: /ns auto del [network] nick | editbox -ap /ns auto del | halt }
      if ($4) var %net = $3,%nick = $4
      else var %net = %!net,%nick = $3
      var %old = $readini -n $_cfg(pw.ini) ns- $+ %net $_warpnick(%nick),%nets = $readini -n $_cfg(pw.ini) ns nets
      remini $_cfg(pw.ini) ns- $+ %net %nick
      if (%old) {
        %nicks = $_countns(%net)
        if (%nicks == 0) {
          remini $_cfg(pw.ini) ns- $+ %net
          %nets = $remtok(%nets,%net,1,32)
          if (%nets) writeini $_cfg(pw.ini) ns nets %nets
          else remini $_cfg(pw.ini) ns
          if ($dialog(nickserv)) {
            if ($_finddid(nickserv,2,%net)) {
              did -d nickserv 2 $ifmatch
              if ($did(nickserv,2,0).sel == 0) did -c nickserv 2 1
            }
          }
        }
        dispa Removed auto-login for $:t(%nick) on %net
        if ($dialog(nickserv)) _nsdupd
      }
      else dispa No auto-login exists for $:t(%nick) on %net
    }
    elseif ($2 == all) {
      var %count = $_countns(%!net)
      if (%count == 0) _error No NickServ logins defined.(on this network- %!net $+ )
      if ($3 == $null) {
        var %time = $calc(%count * 3)
        if (%time > 60) %time = $round($calc(%time / 60),1) minutes.
        else %time = %time seconds.
        _okcancel 1 This will login to the %count $iif(%count == 1,nick,nicks) you own, and will take about %time (you can chat normally during this time)
      }
      window -hln @.loginall
      loadbuf -tns- $+ %!net @.loginall $_cfg(pw.ini)
      var %count = $line(@.loginall,0),%delay = 0
      :loop
      var %line = $line(@.loginall,%count)
      .timer 1 %delay .msgns IDENTIFY $_unwarpnick($gettok(%line,1,61)) $_pw.enc($mid(%line,$calc($pos(%line,=) + 1),$len(%line)))
      if (%count > 1) { dec %count | inc %delay 3 | goto loop }
      window -c @.loginall
    }
    elseif ($2 == clear) {
      if ($3) {
        _okcancel 1 Clear all NickServ logins on $3?
        remini $_cfg(pw.ini) ns- $+ $3
        var %nets = $readini -n $_cfg(pw.ini) ns nets
        %nets = $remtok(%nets,$3,1,32)
        if (%nets) writeini $_cfg(pw.ini) ns nets %nets
        else remini $_cfg(pw.ini) ns
        dispa Removed all NickServ auto-logins on $3
      }
      else {
        _okcancel 1 Clear ALL NickServ logins?
        var %nets = $readini -n $_cfg(pw.ini) ns nets
        :cloop
        if ($gettok(%nets,1,32)) {
          remini $_cfg(pw.ini) ns- $+ $ifmatch
          %nets = $gettok(%nets,2-,32)
          goto cloop
        }
        remini $_cfg(pw.ini) ns
        dispa Removed all NickServ auto-logins
      }
      if ($dialog(nickserv)) {
        did -r nickserv 2
        did -ac nickserv 2 (all networks)
        _nsdupd
      }
    }
    else {
      var %pw = $readini -n $_cfg(pw.ini) ns- $+ %!net $_warpnick($me)
      if (%pw == $null) _error No auto login defined for $me $+ .(on this network- %!net $+ )
      else msgns IDENTIFY $_pw.enc(%pw)
    }
  }
  elseif ($1 == info) {
    if ($2) var %who = $_nc($2)
    else var %who = $_entry(-1,$null,Nickname to get info on?)
    msgns $upper($1) %who
  }
  elseif (($2 == $null) && ($istok(register identify set drop recover release ghost acc access,$1,32))) {
    var %send = msgns $upper($1) | goto $1

    :access
    editbox -ap /ns $1
    dispa Specify one of the following actions:
    dispa - $:l(Add Del List)
    return

    :set
    editbox -ap /ns $1
    dispa Specify one of the following settings:
    dispa - $:l(PassWd Kill NoMemo NoOp)
    dispa - $:l(URL EMail ShowEMail)
    return

    :identify | %send $$?*="Password to identify?" |  return
    :acc | %send $_entry(-1,$null,Nickname to look check access for?) | return

    :register
    var %pw = $$?*="Registering $me - New password?"
    if ($$?*="Please retype password to confirm:" != %pw) _error Passwords do not match.
    %send %pw
    return

    :drop
    var %pw = $readini -n $_cfg(pw.ini) ns- $+ %!net $_warpnick($me)
    if (%pw == $null) %pw = $$?*="Password to identify and drop?"
    else {
      _okcancel 1 Drop $me from NickServ?
      %pw = $_pw.enc(%pw)
    }
    msgns IDENTIFY %pw
    %send $me
    return

    :recover
    :release
    :ghost
    var %nick = $_entry(-1,$null,Nickname,$iif($1 == ghost,of,to),$lower($1),?)
    var %pw = $readini -n $_cfg(pw.ini) ns- $+ %!net $_warpnick(%nick)
    if (%pw == $null) %pw = $?*="Password for nickname? (blank to use none)"
    else %pw = $_pw.enc(%pw)
    %send %nick %pw
    return
  }
  elseif (($1 == set) && ($3 == $null) && ($istok(passwd kill url nomemo noop email showemail,$2,32))) {
    var %send = msgns SET $upper($2) | goto $2

    :passwd
    var %oldpw = $readini -n $_cfg(pw.ini) ns- $+ %!net $_warpnick($me)
    if (%oldpw == $null) %oldpw = $?*="Old password for $me ? (blank ok if you've already identified)"
    else %oldpw = $_pw.enc(%oldpw)
    var %newpw = $$?*="New password for $me ?"
    if ($$?*="Please retype new password to confirm:" != %newpw) _error Passwords do not match.
    if (%oldpw) msgns IDENTIFY %oldpw
    %send %newpw
    return

    :kill | %send $upper($_tf2o($_yesno(1,Have NickServ prevent others from using,$me,?))) | return
    :url | %send $_entry(1,$null,URL to show in your NickServ info?(blank for none)) | return
    :nomemo | %send $upper($_tf2o($_yesno(0,Disallow people to send you memos?))) | return
    :noop | %send $upper($_tf2o($_yesno(0,Disallow people adding your nick to AOP/SOP lists?))) | return
    :email | %send $_entry(-1,$email,E-Mail to store in NickServ?(blank for none)) | return
    :showemail | %send $upper($_tf2o($_yesno(1,Show your e-mail address in NickServ info?))) | return
  }
  elseif (($1 == access) && ($3 == $null) && ($istok(add del list,$2,32))) {
    if ($2 == list) msgns ACCESS LIST
    else msgns ACCESS $upper($2) $_entry(-1,$_usermask(%!myself),User mask to,$iif($2 == add,add to,delete from),your access list?)
    return
  }
  else msgns $upper($1) $2-
}

; pass network, counts ns logins
alias -l _countns {
  var %nets = $readini -n $_cfg(pw.ini) ns nets
  if ($istok(%nets,$1,32) == $null) return 0
  window -hln @.autosc
  loadbuf -tns- $+ $1 @.autosc $_cfg(pw.ini)
  var %count = $line(@.autosc,0)
  window -c @.autosc
  return %count
}

; /msgns full command
alias msgns {
  if (@ isin %!servopt) {
    var %bits = $numtok($server,46)
    %bits = $calc(%bits - 1) $+ - $+ %bits
    _linedance .raw privmsg NickServ@services. $+ $gettok($server,%bits,46) : $+ $1-
  }
  elseif (/ isin %!servopt) _linedance .raw nickserv $1-
  else _linedance .raw privmsg NickServ : $+ $1-
  if (($istok(register identify recover ghost,$1,32)) || (($1 == set) && ($2 == passwd))) {
    if ($3) {
      dispa Using $:t(NickServ) for command: $:h($1-2,?????)
    }
    elseif (($1 == recover) || ($1 == ghost)) {
      dispa Using $:t(NickServ) for command: $:h($1-2)
    }
    else {
      dispa Using $:t(NickServ) for command: $:h($1,?????)
    }
  }
  else dispa Using $:t(NickServ) for command: $:h($1-)
}

alias -l _nschk if (($_isserv(ns)) && ($nick === NickServ)) return | $$$
on *:NOTICE:Your password is & - please write it down for later use.:?:_nschk | if (%`ns.autoupdate) .ns auto add %!net $me $strip($4)
on *:NOTICE:Password changed. Your new password is & - remember it.:?:_nschk | if (%`ns.autoupdate) .ns auto add %!net $me $strip($7)
on *:NOTICE:Dropped nick &:?:_nschk | if (%`ns.autoupdate) .ns auto del %!net $strip($3)
on *:NOTICE:This nick is owned by someone else. Please choose another.:?:_nschk | .ns auto

raw &433:*nick*:{
  if ($server) _nsnch1 $2
  else %_nsnch1 = $2
}
on me:*:NICK:if (%`ns.autologin) .ns auto
alias _ns.connect {
  if ($readini -n $_cfg(pw.ini) nsforce %!net) {
    %!servopt = %!servopt $+ $gettok($ifmatch,2,32)
    %!serv = $addtok(%!serv,ns,44)
    %!servnick = $addtok(%!servnick,NickServ,32)
  }

  ;;; remove after betas over
  remini $_cfg(pw.ini) ns- $+ %!net !all

  if (%`ns.autologin) .ns auto
  if (%_nsnch1) { _nsnch1 $ifmatch | unset %_nsnch1 }
}
alias -l _nsnch1 {
  if (($nick != $2) && ($_isserv(nv)) && ($readini -n $_cfg(pw.ini) ns- $+ %!net $_warpnick($2))) {
    _Q.userhost _nsnch2&n&a halt $2
  }
}
alias _nsnch2 {
  if ($2 == $gettok(%!myself,2-,33)) {
    _Q.fkey 1 $calc($ctime + 180) ns ghost $1
    disps $:n($1) You have a NickServ password- $:s($result) to kill your ghost
  }
  else {
    _Q.fkey 1 $calc($ctime + 180) ns recover $1
    disps $:n($1) You have a NickServ password- $:s($result) to recover this nickname
  }
}

; For nicklist popups
alias _nsnpop if (($_isserv(ns)) && ($server)) return 1
; Status popups for nickserv
alias -l _nsspop if (($_isserv(ns)) && ($server)) { if ($null != $readini -n $_cfg(pw.ini) ns- [ $+ [ %!net ] ] $_warpnick($me)) set -u %.ident 1 | else unset %.ident | set -u %.ns NickServ } | else unset %.ns
menu status {
  $_nsspop:{ }
  %.ns
  .Register $me $+ ...:ns register
  .Drop $me $+ ...:ns drop
  .Identify as $me $+ ...:ns identify
  .-
  .Auto-login
  ..$iif(%.ident == $null,Add for [ [ $me ] $+ [ ... ] ] ):{
    var %pw = $$?*="Password for auto-login for $me ?"
    if ($$?*="Please retype password to confirm:" != %pw) _error Passwords do not match.
    ns auto add $me %pw
  }
  ..$iif(%.ident,Perform now):ns auto
  ..$iif(%.ident,Remove for [ $me ] ):ns auto del $me
  ..-
  ..Edit auto-logins...:ns
  ..Clear all auto-logins...:ns auto clear
  ..-
  ..Perform ALL auto-logins...:ns auto all
  .Recovery
  ..Ghost a nick...:ns ghost
  ..-
  ..Recover a nick...:ns recover
  ..Release a nick...:ns release
  .-
  .Access list
  ..Add mask...:ns access add
  ..Delete mask...:ns access del
  ..-
  ..List:ns access list
  .Config ( $+ $me $+ )
  ..Password...:ns set passwd
  ..Kill...:ns set kill
  ..-
  ..URL...:ns set url
  ..E-Mail...:ns set email
  ..Show e-mail...:ns set showemail
  ..-
  ..No memos...:ns set nomemo
  ..No AOP/SOP...:ns set noop
  .-
  .Get info...:ns info
}