Zion Sphinx — File Browser

ZionSphinxv3.0 / ZionSphinxv3.0 / zionmisc.mrc

zionmisc.mrc — 49.81 KB — Download this file

; --------< Zion >----------------------------------------------------
; Name....: Zion Misc
; File....: zionmisc.mrc
; Ver.....: 1.0b280807
; Author..: sprion
; Email...: sprion@lyniq.com
; Date....: 28 Aug 07
; URL.....: http://zinc.sg
; Info....: This script complements the main core.
; Changes.: Minor updates.
;---------------------------------------------------------------------
; script unload signal
on *:signal:zion_unload:.unload -rs $+(",$script,")
on *:signal:zion_connect2game:_gameprompt $1-
on *:signal:zion.le.connected:_gameprompt $1-

on *:signal:zion_cmdlistopen:{
  zion.listcmd z.list ; Opens this window. Developers should look at the zion_cmdlistopen signal & /zion.listcmd in $nopath($script)
  zion.listcmd z.donate ; Opens the Donation Dialog.
  zion.listcmd z.trace ; Traces and reveals information of IPs, Hostmasks, IRC Nicks, or ForumIDs. ; /z.trace <ip|address|ircnick|forumID> \n $+($,z.trace(<ip|address>)) ; /z.trace sprion \n /z.trace 202.156.173.199 \n //echo 10 $+($,z.trace(cm199.gamma173.maxonline.com.sg))
  zion.listcmd traceip ; Traces an IP geographically, revealing the country of origin. ; /traceip <ip> ; /traceip 121.6.88.167
  zion.listcmd z.upnp ; Open or close ports on your router/modem using UPnP. For advanced users only. ; /z.upnp [[+a(dd) (default)] [-d(elete)]] <port> [tcp (default)|udp|all] ; /z.upnp +a 59
  zion.listcmd z.setdns ; Sets a specified custom host or ZincPlay.com DNS entry in your Windows hosts file. For advanced users only. ; /z.setdns [-(clea)r] <IP> [host] ; /z.setdns 64.18.140.143 forum.zincplay.com \n /z.setdns -r forum.zincplay.com \n /z.setdns 64.18.140.143 \n /z.setdns -r
}

alias zion.friendalljoin {
  if (!$z.started) return
  
  if ($z3.findtog(sponsors,all,1)) { }
  else {
    if ($input(Zion needs your help to join the channels: $zion.friends $crlf $crlf These sponsors help Zion in ways such as: $crlf - Donations $crlf - Hardware provisions $crlf - Webspace provisions $crlf $crlf By choosing 'Yes' $+ $chr(44) you are helping us build better bonds with our friends. Do not worry $+ $chr(44) it is FREE and your experience on Zion will remain unaffected! $crlf $crlf Continue joining %g for FREE? You may part the channels any time.,qy,Support our friends!)) {
      z3.addtog sponsors all 1
    }
  }
  var %n $zion.friends,%p $_values,%e $_expires,%u $numtok(%p,44),%c,%v
  ; checking for expiration
  while (%u > 0) {
    if ($ctime >= $ctime($gettok(%e,%u,44) 00:00:00)) {
      %n = $deltok(%n,%u,44)
      %p = $deltok(%p,%u,44)
      %e = $deltok(%e,%u,44)
    }
    dec %u
  }
  %u = $numtok(%p,44)
  while (%u > 0) {
    ; multiplier of *2, removed
    %v = $gettok(%p,%u,44)
    if ($r(1,100) <= %v) {
      %c = $gettok(%n,%u,44)
      if ($me !ison %c) .timerzion.s.friendalljoin $+ %c 1 $calc(100 - %v) !join -n %c
    }
    dec %u
  }
}

alias zion.friendjoin {
  if ((!$z.started) || (%zion.s.friendjoins >= $int($calc($numtok($zion.friends,44) /2)))) return
  var %g $zion.getfriend
  if ($me ison %g) goto end
  
  
  if ($z3.findtog(sponsors,all)) { !join -n %g | inc %zion.s.friendjoins }
  else {
    if ($input(Zion needs your help to join the channels: $zion.friends $crlf $crlf These sponsors help Zion in ways such as: $crlf - Donations $crlf - Hardware provisions $crlf - Webspace provisions $crlf $crlf By choosing 'Yes' $+ $chr(44) you are helping us build better bonds with our friends. Do not worry $+ $chr(44) it is FREE and your experience on Zion will remain unaffected! $crlf $crlf Continue joining %g for FREE? You may part the channels any time.,qy,Support our friends!)) {
      z3.addtog sponsors all 1
      !join -n %g
      inc %zion.s.friendjoins
    }
  }
  
  
; Notice: This prompt is necessary in accordance to the AUP of GameSurge networks. You and other Zion users are not for sale. This is an advertisement for our sponsors. This gesture may be revoked at our own discretion should the Terms & Conditions of a sponsor be violated.
  
  ;solo chan dialog
  /*
  if ($z3.findtog(sponsors,%g)) { !join -n %g | inc %zion.s.friendjoins }
  else {
    if ($input(Zion needs your help to join the channel: %g $crlf $crlf This sponsor helps Zion in ways such as: $crlf - Donations $crlf - Hardware provisions $crlf - Webspace provisions $crlf $crlf By choosing 'Yes' $+ $chr(44) you are helping us build better bonds with our friend. Do not worry $+ $chr(44) it is FREE and your experience on Zion will remain unaffected! $crlf $crlf Continue joining %g for FREE? You may part the channel any time.,qy,Support our friend!)) {
      z3.addtog sponsors %g 1
      !join -n %g
      inc %zion.s.friendjoins
    }
  }
  */
  /* old
  z.echo $z.head(notice) $z.lang(note,friendjoin) %g ...
  !join -n %g
  inc %zion.s.friendjoins
*/
  :end
  .timerzion.s.friendjoin 1 35 zion.friendjoin
}
;cute #nerdplow
alias zion.friends return #imperfection,#teamuti,#networkingz,#morscerta,#vMp,#HsL
alias -l _values return 20,30,10,13,10,30
alias -l _expires return Sep 25 2007,Sep 24 2007,Aug 21 2007,Sep 11 2007,Sep 23 2007,Sep 24 2007
alias zion.friendscheck echo -s f: $numtok($zion.friends,44) v: $numtok($_values,44) e: $numtok($_expires,44)
alias zion.getfriend {
  :start
  ; vars
  var %n $zion.friends,%p $_values,%e $_expires,%t,%u $numtok(%p,44),%c 1,%b 1,%l,%r
  ; checking for expiration
  while (%u > 0) {
    if ($ctime >= $ctime($gettok(%e,%u,44) 00:00:00)) {
      %n = $deltok(%n,%u,44)
      %p = $deltok(%p,%u,44)
      %e = $deltok(%e,%u,44)
    }
    dec %u
  }
  
  ; total
  %u = $numtok(%p,44)
  while (%u > 0) {
    inc %t $gettok(%p,%u,44)
    dec %u
  }
  
  ; calculations
  %r = $r(1,%t)
  %u = $numtok(%p,44)
  while (%b <= %u) {
    inc %l $gettok(%p,%b,44)
    if (%r isnum $+(%c,-,%l)) {
      return $gettok(%n,%b,44)
      break
    }
    inc %c $gettok(%p,%b,44)
    inc %b
  }
  
}

alias _gameprompt {
  if ((!$timer(zion.s.gameprompt. $+ $1)) && ($gettok($strip($z.gl.gethost($1)),2,32) = (ADMIN))) {
    .timerzion.s.gameprompt. $+ $1 1 4 return
    var %e = $input($z.lang(prompts,admingame),io,$z.lang(prompts,header_admingame))
  }
}
on ^*:MODE:%zion.s.chat:haltdef
on ^*:BAN:%zion.s.chat:haltdef
on ^*:UNBAN:%zion.s.chat:haltdef
on ^*:OP:%zion.s.chat:haltdef
on ^*:DEOP:%zion.s.chat:haltdef
on ^*:VOICE:%zion.s.chat:haltdef
on ^*:DEVOICE:%zion.s.chat:haltdef
on ^*:NICK:{
  if (($cid = %zion.s.cid) && ($newnick ison %zion.s.chat) && ($nick != $me)) {
    if (zionuser isin $nick) z.echo $z.head(notice) $z.lang(note,userwelcome)  $+ $newnick
    var %i 1
    while (%i <= $comchan($newnick,0)) {
      if ($comchan($newnick,%i) != %zion.s.chat) {
        !echo -tc n $comchan($newnick,%i) * $nick $z.lang(sys,nowknownas) $newnick
      }
      inc %i
    }
    haltdef
  }
}
on *:INPUT:%zion.s.chat,%zion.s.data:{
  if (($ctrlenter) || ($left($1,1) = /)) return
  elseif (($z.ip.process($1-)) && ($input($z.lang(prompts,ipspam),ywdv,$z.lang(prompts,header_ipspam)) = $no)) halt
  elseif ($me !isreg #) {
    var %s
    if ($me isop #) %s = 4[ADMIN]
    elseif ($me isvoice #) {
      if (($left($me,1) = [) && ($right($me,1) = ])) %s = 12[HELPR]
      else %s = 12[ VIP ]
    }
    echo -t # %s < $+ $me $+ > $1-
    .msg # $iif($left($1,1) != !,%s) $1-
    halt
    
  }
}
on ^1:QUIT:{
  dll_wfix WhileFix
  if (($cid = %zion.s.cid) && ($nick ison %zion.s.chat) && ($nick != $me)) {
    ; thanks CuteWorm
    var %i 1
    while (%i <= $comchan($nick,0)) {
      if ($comchan($nick,%i) != %zion.s.chat) {
        echo -tc q $comchan($nick,%i) * $nick $z.lang(sys,quit) ( $+ $1- $+ )
      }
      inc %i
    }
    haltdef
  }
}
on ^1:JOIN:#:dll_wfix WhileFix

alias z.kick kick %zion.s.chat $1 $iif($2,$2-,$$input($z.lang(prompts,reason),eu))
/*
alias z.quitban {
  var %r $r(3600,10800),%ip $longip($1-)
  ban $+(-u,%r) %zion.s.chat $1-
  if (!%ip) kick %zion.s.chat $1- 124 QUIT & GET BANNED FOR $duration(%r)
}
*/
;alias -l ban if ($len($1) > 11) && ($chr(64) isin $1) { ban *!* $+ $chr(64) $+ $gettok($1,2,64) | ban *!* $+ $remove($gettok($1,1,64),$chr(126)) $+ $chr(64) $+ * $+ $remove($gettok($1,2,64),$gettok($gettok($1,2,64),1-2,46)) } | else { ban $1- 2 | ban $1- 3 }
alias quit if ($z.antiflood) quit $z.adv | else !quit $1-

on *:signal:zion_authuserjoin:{
  zion.gui.gnote -b $rgb(200,205,255) Zion: $ $iif($2 = 1957485,<unknown>,$2) $z.lang(sys,joinsgame) [irc: $1 $+ ] $ 120
  hadd -mu10 zion_users $2 $1
}

on *:signal:zion_comms_pre:{
  ;version 2.0 zcomms
  ; game info spread
  if (($1 = zc) && ($2 = $z.rotate(14,$3))) {
    if ($4- = %zion.s.zc) .timerzion.s.zc off
    var %zc $replace($4-,+,.,@,zion,zion_snooped,pub)
    tokenize 32 %zc
    if ($0 < 3) return
    if ($z.h.getvar(refreshgame) = $1) return
    .signal -n zion_gameinfo $1 -s $+(,$z.getcol($2),$3-4)
    if ($5) .signal -n zion_gameinfo $1 -p $5
    ;(est)
  }
  ; key request
  elseif (($1 = zck) && ($hget(zsession,zkey)) && ($2 = $z.rotate(16,$3))) {
    z.comms.key
  }
  ; key reply
  elseif (($1 = zckr) && ($2 = $z.rotate(-15,$3))) {
    if ($4- = %zion.s.zck) .timerzion.s.zc.k off
    hadd -m zsession zkey $z.rotate(-15,$4)
  }
  ; zd request
  elseif (($1 = zczd) && ($z.h.getvar(zdread)) && ($2 = $z.rotate(-4,$3))) {
    zion.zd.sendlink $2 $z.rotate(-4,$4-)
    haltdef
    return
  }
  ; game join note
  elseif ((($1 = zcc) || ($1 = zcj)) && ($timer(zion.s.advert)) && ($3 = $longip(%zion.s.spam.ip)) && ($2 = $z.rotate(-7,$6))) {
    if ($1 = zcj) .signal zion_authuserjoin $2 $replace($z.rotate(-7,$7),error!,<unknown>)
    else zion.zd.sendlink $2 $z.rotate(-7,$4 $5)
    haltdef
    return
  }
  ; game host update
  elseif (($1 = zcg) && ($2 = $z.rotate(-3,$3))) {
    var %gname = $longip($4) $+ _pub
    if ($timer(zion.s.fo $+ %gname)) .timerzion.s.fo $+ %gname off
    .signal -n zion_gameinfo %gname -s $+(,$z.getcol(4),$5-)
    haltdef
    return
  }
}

; remove when 2.0 becomes obsolete
on *:CTCPREPLY:ZION_USERINFO*:{
  if ($z.64b($2) = $nick) return
  var %w @ZION_USERINFO,%z aline %w,%h 261,%vv,%gv 0,%t $chr(9)
  var %line $replace($z.rotate(-14,$1-),BAD,$+(,$z.getcol(5),BAD),NO,$+(,$z.getcol(5),NO),OK,$+(,$z.getcol(4),OK),YES,$+(,$z.getcol(4),YES),OFF,$+(,$z.getcol(5),OFF))
  tokenize 32 %line
  ; remove this on new version
  if ($10 = 2.0) %vv = $10-
  else { %vv = $11- | %gv = $10 | inc %h 10 }
  
  if ($window(%w)) window -c %w
  window -l -t10,15 %w -1 -1 250 %h $z.font
  font -b %w
  %z $+(Description,%t,Data)
  %z $str($chr(175),150)
  %z nick: %t $nick
  %z version: %t %vv
  %z network ping: %t $calc($z.ticks - $gettok($z.h.getvar($nick $+ _ctcp),1,32)) ms
  %z $chr(160)
  %z connected: %t $2
  %z settings: %t $3
  %z game config.: %t $4
  %z $chr(160)
  if (%gv) %z Game Version: %t $10
  %z Game Set: %t $7
  %z GUI plugin: %t $5
  %z LE plugin: %t $6
  %z $chr(160)
  %z in game: %t $9
  %z install/repair: %t $8
  haltdef
}

; flood prot
ctcp *:*:if (!$z3.findtog(advanced,floodprot)) return | if ($nick = $me) return | var %s VERSION-TIME-FINGER-PING | if (!$istok(%s,$1,45)) { return } | if ($floodchk(z.ctcps, 10, $cid) > 4) { ignore -tu30 *!*@* | z.echo $z.head(flood) (CTCP) $z.lang(sys,ignoringall) 30s }
on *:OPEN:?:*:if (!$z3.findtog(advanced,floodprot)) return | if ($floodchk(z.queries, 10, $cid) > 6) { ignore -pu30 *!*@* | z.echo $z.head(Flood) $z.lang(sys,query) $z.lang(sys,ignoringall) 30s }
on ^*:NOTICE:*:#:if (!$z3.findtog(advanced,floodprot)) return | if (($nick != $me) || ($chan = %zion.s.chat) || ($chan = %zion.s.data) || ($chan = $z.defchat)) { if ($nick !isop $chan) { if ($floodchk(z.notices, 10, $cid) > 4) { ignore -nu30 *!*@* | z.echo $z.head(Flood) $z.lang(sys,notice) $z.lang(sys,ignoringall) 30s } | haltdef } }
on *:NOTICE:*:?:if (!$z3.findtog(advanced,floodprot)) return | if ($nick = $me) return | var %s = $z.networkservices,%w /ctcp,%w2 serve | if (($istok(%s,$nick,45)) || (%w isin $1-) || (%w2 isin $1-)) return | if ($floodchk(z.pnotices, 10, $cid) > 4) { ignore -nu30 *!*@* | z.echo $z.head(Flood) $z.lang(sys,notice) $z.lang(sys,ignoringall) 30s }
; end

/* ##########################
zHELP
##########################
*/
alias z.help.firsttime.ask {
  if (!$appactive)  return
  if (!$z3.findtog(help,firsttime)) {
    ;window -a $z.win
    window -a %zion.s.chat
    if ($z.pop($z.lang(prompts,firsttime),$z.lang(prompts,header_firsttime),4,32,0,0) = 6) z.help using_zion_sphinx.htm
    z3.addtog help firsttime 1
  }
}
/* ###
groups
###
*/
; Use -r at the end to skip check, meaning check memory only
; Use . in front to silence output
; pending a z.trace signal when traced successfully!
alias z.trace {
  if (!$0) {
    if ($show) { z.echo $z.head(trace) /z.trace <ip|address|ircnick|forumID> | z.echo $z.head(tip) /z.trace sprion *OR* /z.trace 202.156.173.199 *OR* //echo 10 $eval($+($,z.trace(cm199.gamma173.maxonline.com.sg))) }
    return
  }
  if (*.* !iswm $1) {
    var %n $hfind(zion_users,$+(*,$1,*),0,w).data,%i,%d
    if (%n > 0) z.echo $z.head(trace) Listing possible matches for $1 $+ ...
    else z.echo $z.head(trace) Failed to trace $1
    while (%n > 0) {
      %i = $hfind(zion_users,$+(*,$1,*),%n,w).data
      %d = $hget(zion_users,%i)
      if ($istok($gettok(%d,1-2,32),$1,32)) z.trace_jeric2 %i $gettok(%d,1,32) - $gettok(%d,2-,32)
      dec %n
    }
    return
  }
  
  if (!$show) { set -u10 $eval($+(%,zion.s.trace.,$1,.s)) 1 }
  else unset $eval($+(%,zion.s.trace.,$1,.s))
  if ($hget(z.trace.done,$1)) hdel z.trace.done $1
  if ($2 != -r) hadd -mu10 z.trace.adds $1 1
  if (($ial($+(*!*@,$1),1).nick) || ($gettok($hget(zion_users,$1),1-,32))) {
    var %n $ifmatch
    if ($2 != -r) hdel z.trace.adds $1 1
    if ($isid) return %n
    else z.trace_jeric2 $1 $gettok(%n,1,32) - $gettok($hget(zion_users,$1),2-,32)
  }
  elseif ($2 != -r) {
    .enable #z.trace.dns
    .timerzion.s.trace.dns -o 1 10 .disable #z.trace.dns
    !.dns $1
    if (($show) && ($longip($1))) z.comms.send -iof zion trace $1
    if ($isid) {
      var %w = $+(jericmadethisscript,$r(1,9))
      set -u10 $eval($+(%,zion.s.trace.,$1)) %w
      while ($_jeric($1) = %w) {
        dll_wfix WhileFix
      }
      %w = $eval($+(%,zion.s.trace.,$1),2)
      unset $eval($+(%,zion.s.trace.,$1))
      return %w
    }
  }
}
alias -l _jeric return $eval($+(%,zion.s.trace.,$1),2)
alias z.trace_jeric2 {
  hdel z.trace.adds $1 1
  .signal zion_trace $1-
  if ($eval($+(%,zion.s.trace.,$1),2)) set $eval($+(%,zion.s.trace.,$1)) $2
  ;  elseif (!$eval($+(%,zion.s.trace.,$1,.s),2)) { unset $eval($+(%,zion.s.trace.,$2,.s)) | z.echo trace: Found $+(,$1,) >> $2 $iif($3,$iif($3 != $1,<< $3)) | $iif($longip($1),traceip $1) }
  else {
    if (!$eval($+(%,zion.s.trace.,$1,.s),2)) { unset $eval($+(%,zion.s.trace.,$2,.s)) | z.echo $z.head(trace) $z.lang(sys,found) $+(,$1,) >> $2 $iif($4,( $+ $4 $iif($5 != $null,$+([,$5,])) $+ )) $iif($3 != -,$iif($3 != $1,<< $3)) }
    $iif($longip($1),traceip $1)
  }
}
alias -l _jeric3 {
  .signal zion_tracefail $1-
  if (!$eval($+(%,zion.s.trace.,$1,.s),2)) { unset $eval($+(%,zion.s.trace.,$2,.s)) | z.echo $z.head(trace) $z.lang(sys,failtrace) $+(,$1,) $iif($2,[ $+ $z.lang(sys,lasttried) $2 $+ ])  }
}
#z.trace.dns off
on *:DNS:{
  if (!$hget(z.trace.adds,$dns(1))) return
  var %r $raddress,%n2,%m,%n3
  if ($dns(1)) {
    %m = $ifmatch
    if ($nick) %n2 = $nick
    elseif ($ial($+(*!*@,$raddress),1).nick) %n2 = $ifmatch
    elseif ($ial($+(*!*@,$naddress),1).nick) %n2 = $ifmatch
    elseif ($ial($+(*!*@,$iaddress),1).nick) %n2 = $ifmatch
    elseif ($hget(zion_users,%m)) { %n2 = $gettok($ifmatch,1,32) | %n3 = $gettok($ifmatch,2-,32) }
    else { hadd -mu10 z.trace $dns(1) $dns(1) | .enable #z.trace.who | !who %m | .timerzion.s.trace.who -o 1 8 .disable #z.trace.who }
    if (%n2) z.trace_jeric2 $dns(1) %n2 $raddress %n3
  }
  if ((!%n2) && ($raddress)) {
    %m = $ifmatch
    if ($nick) %n2 = $nick
    elseif ($ial($+(*!*@,$dns(1).addr),1).nick) %n2 = $ifmatch
    elseif ($ial($+(*!*@,$dns(1)),1).nick) %n2 = $ifmatch
    elseif ($ial($+(*!*@,$dns(1).ip),1).nick) %n2 = $ifmatch
    elseif ($hget(zion_users,$dns(1).ip)) { %n2 = $gettok($ifmatch,1,32) | %n3 = $gettok($ifmatch,2-,32) }
    elseif ($hget(zion_users,$dns(1).addr)) { %n2 = $gettok($ifmatch,1,32) | %n3 = $gettok($ifmatch,2-,32) }
    else { hadd -mu10 z.trace %m $dns(1) | .enable #z.trace.who | !who %m | .timerzion.s.trace.who -o 1 8 .disable #z.trace.who }
    if (%n2) z.trace_jeric2 $dns(1) %n2 $raddress %n3
  }
  hdel z.trace.adds $dns(1)
}
#z.trace.dns end
#z.trace.who off
raw 352:* {
  ; if already traced one address, don't continue
  if ($hget(z.trace,$4)) {
    var %ip $ifmatch
    hadd -mu10 z.trace.good %ip gd
    if (!$hget(z.trace.done,%ip)) {
      z.trace_jeric2 %ip $6 $4
      hadd -mu10 z.trace.done %ip 1
    }
  }
  haltdef
}
raw 315:* { if ($hget(z.trace,$2)) { var %s $ifmatch | if ($hget(z.trace.good,%s) != gd) .timerzion.s.trace. $+ %s -o 1 4 _jeric3 %s $2 | else .timerzion.s.trace. $+ %s off | hdel z.trace $2 | haltdef } }
#z.trace.who end

;#z.traceip on
on *:DNS:{
  if ($raddress) {
    if ($raddress isnum) traceip $raddress
    else {
      var %tot = $dns(0),%i 1
      if (%tot > 1) {
        while (%i <= %tot) {
          traceip $dns(%i).ip
        }
      }
      else traceip $raddress
    }
  }
  else {
    if ($dns(0) isnum) traceip $dns(0).ip
    else traceip $dns(0).addr
  }
}
;#z.traceip end


; traceip by BloW-MaN
; heavily modified for Zion
on *:LOAD:{
  var %s $+(",$scriptdir,dns.cache.ini,")
  if (!$exists(%s)) write -c %s
}

alias ClassC {
  if ($isid) {
    if ($1) {
      ;checking if ip's structure is valid.
      if (*.*.*.* iswm $1) {
        if ($isip($1)) return $+($GetNum($1,1),.,$GetNum($1,2),.,$GetNum($1,3),.,*)
        else { return invalid | halt }
      }
      else return $1
    }
    else { echo $color(info) -at * /ClassC: insufficient parameters | halt }
  }
}

; by BloW-MaN not as accurate as $z.processip
alias -l isIP {
  var %sub = \b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
  return $regex($1,%sub)
}
alias -l GetNum return $gettok($1,$2,46)

alias traceip {
  var %z 0,%r,%sn,%ip
  if ($1 = -z) { %z = 1 | tokenize 32 $2- }
  %ip = $longip($1)
  if (%z) %sn = $+(t|,$1,|,$2)
  else %sn = $+(t|,$1)
  %r = $dll_z(getCountry,%ip)
  if ((%r = Not Found) && ($z.bot)) {
    hadd -mu10 zsession %ip %sn
    .ctcp ZincBot GetCountry %ip
    return
  }
  if (%z) {
    .signal -n zion_gameinfo $2 -d %r
    z.comms.send -n zion ccode $2 %r
  }
  else {
    echo $color(other) -at [CACHED] $1 in %r
    .signal zion_traceip $1 %r
  }
}
/*
alias traceip {
  if ($1) {
    var %ip,%z 0,%sn,%s = $+(",$scriptdir,dns.cache.ini,"),%h www.dnsstuff.com
    if ($1 = -z) { %z = 1 | tokenize 32 $2- }
    %ip = $1
    if (%z) %sn = $+(traceip|,$1,|,$2)
    else %sn = $+(traceip|,$1)
    :c
    if ($exists(%s)) {
      if ($isip($1)) {
        if ($ini(%s,$ClassC($1),0)) {
          if ($readini(%s,$ClassC($1),location) != unresolved) {
            if ($show) {
              var %r = $readini(%s,$ClassC($1),location), %y = $gettok(%r,1,40)
              if (%z) {
                .signal -n zion_gameinfo $2 -d %y
                z.comms.send -n zion ccode $2 %y
              }
              else {
                echo $color(other) -at [CACHED] $1 in %r
                .signal zion_traceip $1 %r
              }
              halt
            }
          }
          else goto w
        }
        else {
          writeini -n %s $ClassC($1) location unresolved
          :w
          if ($z.bot) {
            hadd -mu10 zsession $longip($1) %sn
            .ctcp ZincBot GetCountry $longip($1)
          }
          elseif (!$sock(%sn)) z.sockopen %sn %h 80
        }
      }
      else {
        if ($z.bot) {
          hadd -mu10 zsession $longip($1) %sn
          .ctcp ZincBot GetCountry $longip($1)
        }
        elseif (!$sock(%sn)) z.sockopen %sn %h 80
      }
    }
    else { write -c %s | goto c }
  }
  else {
    var %t = $+(",$scriptdir,dns.tmp,"), %i 1
    if ($exists(%t)) {
      if ($lines(%t) > 0) {
        while (%i <= $lines(%t)) {
          .timertraceip $+ $read(%t,%i) 1 %i traceip $read(%t,%i)
          inc %i
        }
      }
      .remove %t
    }
    else {
      echo $color(info) -at * /traceip: insufficient parameters
    }
  }
}
*/
on *:CTCPREPLY:GetCountry*:{
  if ($hget(zsession,$2)) {
    var %r $ifmatch,%i $longip($2)
    if ($numtok(%r,124) = 2) {
      echo $color(other) -at %i in $3-
      .signal zion_traceip %i $3-
    }
    else {
      .signal -n zion_gameinfo $gettok(%r,3,124) -d $3-
      z.comms.send -n zion ccode $gettok(%r,3,124) $3-
    }
;    writeini -n " $+ $scriptdirdns.cache.ini $+ " $ClassC(%i) location $3- (City: $3- $+ )
  }
  haltdef
}
on *:SOCKOPEN:traceip|*:{
  var %h www.dnsstuff.com,%z sockwrite -n $sockname
  if ($sockerr > 0) {
    sockclose $sockname
    ; zion's auto using socket would have produced 3 tokens
    ; if 2 tokens, means it's the normal /traceip usage
    if ($numtok($sockname,124) = 2) echo $color(info) -at * /traceip: An error has occured.
    if ($sockerr == 3) { if (!$sock($sockname)) { sockopen $sockname %h 80 } }
  }
  else {
    z.sendget $sockname $+(/,tools/city.ch?ip=,$gettok($sockname,2,124))
    ;    %z User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
    %z User-Agent: IPTracer/1.0 (Windows; U; Windows NT 5.1; en-US; rv:0.0.0.0) Newton/16430104 IPTracer/1.0
    %z Host: %h
    %z Connection: keep-alive
    sockwrite $sockname $crlf
    set $eval($+(%,zion.s.,$sockname,.flag)) 0
  }
}

on *:SOCKCLOSE:traceip|*:{
  if ((!%traceip) && ($numtok($sockname,124) = 2)) { echo $color(info) -at * /traceip: An error has occured. }
  unset $eval($+(%,zion.s.,$sockname,.*))
}
on *:SOCKREAD:traceip|*:{
  sockread %trace
  if ($len(%trace) < 75) {
    tokenize 32 %trace
    if (IP: isin %trace) {
      set $eval($+(%,zion.s.,$sockname,.flag)) 1
      set $eval($+(%,zion.s.,$sockname,.ip)) $2-
    }
    elseif (Country: isin %trace && $eval($+(%,zion.s.,$sockname,.flag),2) == 1) {
      set $eval($+(%,zion.s.,$sockname,.c)) $remove($2-,[,],(High))
    }
    elseif (City: isin %trace && $eval($+(%,zion.s.,$sockname,.flag),2) == 1) {
      var %ip $eval($+(%,zion.s.,$sockname,.ip),2), %c $eval($+(%,zion.s.,$sockname,.c),2)
      if ($numtok($sockname,124) = 2) {
        echo $color(other) -at %ip in %c (City: $2- $+ )
        .signal zion_traceip %ip %c (City: $2- $+ )
      }
      
      /* return
      else {
        .signal -n zion_gameinfo $gettok($sockname,3,124) -d %c
        z.comms.send -n zion ccode $gettok($sockname,3,124) %c
      }
      */
      if ($isip(%ip) && *do not abuse DNSstuff.com* !iswm %trace && %trace != (City: Unknown)) {
        writeini -n " $+ $scriptdirdns.cache.ini $+ " $ClassC(%ip) location %c (City: $2- $+ )
        
        if ($numtok($sockname,124) != 2) {
          .signal -n zion_gameinfo $gettok($sockname,3,124) -d %c
          z.comms.send -n zion ccode $gettok($sockname,3,124) %c
        }
        
      }
      unset $eval($+(%,zion.s.,$sockname,.*))
      set -u1 %traceip 1
      if ($sock($sockname)) sockclose $sockname
    }
    unset %t
  }
}
alias zion.netadd {
  var %p, %x = $z.ticks,%f = $+(",$scriptdir,netstat.txt,"), %r = $iif($2 isnum,$2,1),%r = %r * 1000, %id
  if ($com(net $+ %x)) { .comclose net $+ %x }
  .comopen net $+ %x WScript.Shell
  if !$comerr { .comclose net $+ %x $com(net $+ %x,Run,3,bstr,cmd.exe /c ipconfig /all > %f,uint,0,bool,true) }
  %p = $read(%f,w,*Physical Address*:*-*-*)
  if (%p) {
    %id = $addtok(%id,$gettok(%p,-1,58),44)
    while ($readn) {
      %p = $read(%f,w,*Physical Address*:*-*-*,$calc($readn + 1))
      if (%p) {
        %id = $addtok(%id,$gettok(%p,-1,58),44)
      }
    }
  }
  else { return }
  .remove %f
  z3.addtog general id %id
}
alias z.ialupdate {
  if ((!$chan(%zion.s.chat).ial) && (!$chan(%zion.s.chat).inwho)) {
    .enable #z.ialupdate
    %zion.s.ialn = 0
    !.who %zion.s.chat
  }
  else z.echo IAL: $z.lang(sys,alreadyfresh) $+  $ialchan(*,%zion.s.chat,0)  $+ $z.lang(sys,alreadyfresh2)
}
#z.ialupdate off
raw 352:* { if ($2 = %zion.s.chat) { inc %zion.s.ialn | haltdef } }
raw 315:* { z.echo IAL: $z.lang(sys,ialsuccess) $+  %zion.s.ialn  $+ $z.lang(sys,ialsuccess2) | unset %zion.s.ialn | haltdef | .disable #z.ialupdate }
#z.ialupdate end



alias z.ialupdatepre {
  if ((!$chan(%zion.s.chat).ial) && (!$chan(%zion.s.chat).inwho)) {
    %zion.s.ialt = 1
    %zion.s.ialb = $1
    z.ialupdatenext
  }
}
alias z.ialupdatenext {
  var %e = $calc(%zion.s.ialt + %zion.s.ialb),%n
  .enable #z.ialupdate2
  while (%zion.s.ialt < %e) {
    %n = $nick(%zion.s.chat,%zion.s.ialt)
    hinc zion_ial t
    !.who %n
    inc %zion.s.ialt
  }
  %zion.s.iall = %n
}

#z.ialupdate2 off
raw 352:* { echo -s $1- | haltdef }
raw 315:* { if ($2 = %zion.s.iall) disable #z.ialupdate2 }
#z.ialupdate2 end

on *:SOCKOPEN:update.traceip:{
  if ($sockerr > 0) {
    sockclose $sockname
    if ($sockerr == 3) {
      if (!$sock($sockname)) {
        z.sockopen update.traceip iptracer.sialkoti.com 80
      }
    }
  }
  else {
    
    var %s sockwrite -n $sockname
    z.sendget $sockname /scripts/IPTracer/dns.cache.ini
    %s Accept: *.*
    %s Host: iptracer.sialkoti.com
    %s Connection: Keep-Alive
    %s
    %s
    sockwrite $sockname $crlf
    %ip.line = 0
    .remove " $+ $scriptdirtempdns.cache.ini $+ "
  }
}

on *:SOCKREAD:update.traceip:{
  if (%ip.line <= 9) {
    sockread %update
    tokenize 32 %update
    if ($1 == Content-Length:) {
      if ($calc($2 - $file(" $+ $scriptdirdns.cache.ini $+ ").size) > 0) {
        set %allow.update $true
      }
    }
    inc %ip.line
  }
  else {
    if (%allow.update) {
      sockread &update
      bwrite " $+ $scriptdirtempdns.cache.ini $+ " -1 &update
      unset %ip.line
    }
    else {
      sockclose $sockname
    }
  }
  unset %update
  bunset &update
}

on *:SOCKCLOSE:update.traceip:{
  .timerdo.update -m 1 1 do.update
  unset %allow.update %ip.line
}

alias -l do.update {
  .remove " $+ $scriptdirdns.cache.ini $+ "
  .rename " $+ $scriptdirtempdns.cache.ini $+ " " $+ $scriptdirdns.cache.ini $+ "
}

alias traceip.update {
  if (!$sock(update.traceip)) {
    z.sockopen update.traceip iptracer.sialkoti.com 80
  }
  
}
on *:signal:zion_update_start:traceip.update

; ================UPnP=============
; credits to ^oS and info from http://zbowling.com/projects/upnp/
alias z.upnp {
  if (!$0) { z.echo $z.head(err) /z.upnp [[+a(dd) (default)] [-d(elete)]] <port> [tcp (default)|udp|all] | return }
  unset %zion.s.upnp.*
  if (*+a* iswm $1) %zion.s.upnp.add = 1
  if (*-d* iswm $1) %zion.s.upnp.del = 1
  if ($1 isnum) %zion.s.upnp.add = 1
  else tokenize 32 $2-
  if (($1 isnum) && ($1 > 0) && ($1 < 65255)) {
    
    if (!$show) %zion.s.upnp.s = 1
;    if ($window(@upnpstatus).w) clear @upnpstatus
    %zion.s.upnp.tempfile = $+($shortfn($scriptdir),upnp_temp.txt)
    %zion.s.upnp.portToForward = $1
    %zion.s.upnp.para = $2
    if (%zion.s.upnp.add) probe
    else upnp_portforward 1
  }
}
alias -l probe {
  var %probe = $+(M-SEARCH * HTTP/1.1,$crlf,Host:239.255.255.250:1900,$crlf,ST:upnp:rootdevice,$crlf,Man:"ssdp:discover",$crlf,MX:3,$crlf,$crlf)
  sockudp -k upnp_probe 239.255.255.250 1900 %probe
  upnp_info $z.lang(sys,upnp_finddevices)
  window -c @upnp-list
  window -nhl @upnp-list
  .timerstage2 -om 1 3600 upnp_stage2
}
alias -l upnp_info {
/*
  if (!$window(@upnpstatus)) window -fBp +d @upnpstatus 10 10 400 50
  drawrect -fnr @upnpstatus $rgb(255,255,255) 1 0 0 400 50
  drawrect -fnr @upnpstatus $rgb(200,200,200) 1 0 0 400 18
  drawrect -nr @upnpstatus $rgb(20,20,20) 1 0 0 400 50
  drawtext -nr @upnpstatus $rgb(0,0,0) helvetica 12 2 2 uPnP Status
  drawtext -nr @upnpstatus $rgb(0,0,0) helvetica 12 20 23  $1-
  drawdot @upnpstatus
*/
  if (%zion.s.upnp.s) return
  z.echo UPnP: $1-
}
on 1:udpread:upnp_probe: {
  if ($sockerr > 0) return
  sockread %info
  while ($sockbr) {
    if (LOCATION: isin %info) aline @upnp-list $gettok(%info,2-,58)
    sockread %info
  }
}
alias upnp_stage2 {
  upnp_info $z.lang(sys,upnp_donefind)
  sockclose upnp_probe
  set %zion.s.upnp.totaldevices $line(@upnp-list,0)
  aline @upnp-list ---------------------
  aline @upnp-list ..
  if (%zion.s.upnp.totaldevices > 0) {
    upnp_info $z.lang(sys,upnp_numfind) %zion.s.upnp.totaldevices
    set %zion.s.upnp.curdevice 1
    upnploadXMLFromSource $line(@upnp-list,%zion.s.upnp.curdevice)
  }
  else { upnp_info $z.lang(sys,upnp_nofind) | upnp_shutdown }
}
alias upnploadXMLFromSource {
  if ($1) {
    ; connect to server
    var %ip_port = $gettok($1,2,47), %port = $gettok(%ip_port,2,58), %ip = $gettok(%ip_port,1,58), %req = $gettok($1,3-,47)
    if (%port == $null) %port = 80
    %zion.s.upnp.url = $1
    %zion.s.upnp.ip = %ip
    %zion.s.upnp.port = %port
    %zion.s.upnp.req = $+(/,%req)
    sockclose upnp_xml
    if (%ip) sockopen upnp_xml %ip %port
    else upnp_info $z.lang(sys,upnp_failxml) (ip-port %ip_port ip %ip port %port )
  }
}
on *:sockopen:upnp_xml: {
  if ($sockerr) {
    upnp_info $z.lang(sys,upnp_sockerr) $sockerr
    return
  }
  ; initialize variables/files
  if (%zion.s.upnp.tempfile == $null) %zion.s.upnp.tempfile = $+($shortfn($scriptdir),upnp_temp.txt)
  write -c %zion.s.upnp.tempfile
  unset %zion.s.upnp.dl.rdy %zion.s.upnp.dl.len
  
  %zion.s.upnp.localip = $sock($sockname).bindip
  
  ; request file
  sockwrite -n $sockname GET %zion.s.upnp.req HTTP/1.0
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Host: %zion.s.upnp.ip
  sockwrite -n $sockname
}
on *:sockread:upnp_xml: {
  if (%zion.s.upnp.dl.rdy != 1) {
    var %header
    sockread %header
    while ($sockbr) {
      if (Content-length: * iswm %header) {
        %zion.s.upnp.dl.len = $gettok(%header,2,32)
      }
      elseif (* !iswm %header) {
        %zion.s.upnp.dl.rdy = 1
        %zion.s.upnp.dl.offset = $sock($sockname).rcvd
        break
      }
      sockread %header
    }
  }
  sockread 4096 &d
  while ($sockbr) {
    bset &crlf 1 $asc($cr) $asc($lf)
    var %inc = 1
    while (($bfind(&d,1,</)) && (%inc < 1000)) {
      bcopy &d $bfind(&d,1,</) &crlf 1 2
      inc %inc
    }
    bwrite %zion.s.upnp.tempfile -1 -1 &d
    sockread 4096 &d
  }
}
on *:sockclose:upnp_xml: {
  var %dtype = $read(%zion.s.upnp.tempfile, w,  *<deviceType>*)
  %zion.s.upnp.devicetype = $gettok(%dtype, $gettok(%dtype,0,62), 62)
  
  if (internetgateway isin %zion.s.upnp.devicetype) {
    var %findwanip = $read(%zion.s.upnp.tempfile, w,  *WANIPConnection*)
    var %readn = $readn
    var %cURL = $read(%zion.s.upnp.tempfile, w, *<controlurl>*, %readn)
    
    %zion.s.upnp.controlURL = $gettok(%cURL, $gettok(%cURL,0,62), 62)
    
    aline @upnp-list >>>> $z.lang(sys,upnp_yourrouter) <<<<
    aline @upnp-list WANIPConnection ControlURL: %zion.s.upnp.controlURL
    
    %zion.s.upnp.router.ip = %zion.s.upnp.ip
    %zion.s.upnp.router.port = %zion.s.upnp.port
    
    if (http:// isin %zion.s.upnp.controlURL) {
      var %ip_port = $gettok(%zion.s.upnp.controlURL,2,47), %port = $gettok(%ip_port,2,58), %ip = $gettok(%ip_port,1,58), %req = $gettok(%zion.s.upnp.controlURL,3-,47)
      %zion.s.upnp.router.ip = %ip
      %zion.s.upnp.router.port = %port
      %zion.s.upnp.router.req = $+(/,%req)
    }
    else {
      %zion.s.upnp.router.req = %zion.s.upnp.controlURL
    }
    
    var %name = $read(%zion.s.upnp.tempfile, w,  *<friendlyName>*)
    %zion.s.upnp.router.name = $gettok(%name, $gettok(%name,0,62), 62)
    
    upnp_info $z.lang(sys,upnp_foundrouter)  %zion.s.upnp.router.name (http:// $+ %zion.s.upnp.router.ip $+ : $+ %zion.s.upnp.router.port $+ )
    
    upnp_portforward %zion.s.upnp.router.ip %zion.s.upnp.router.port %zion.s.upnp.router.req
  }
  else {
    aline @upnp-list .. device %zion.s.upnp.curdevice $z.lang(sys,upnp_notrouter) IP: %zion.s.upnp.ip
    if (%zion.s.upnp.curdevice == %zion.s.upnp.totaldevices) {
      aline @upnp-list $z.lang(sys,upnp_listcomplete)
      upnp_info $z.lang(sys,upnp_failident)
    }
    
    inc %zion.s.upnp.curdevice
    if (%zion.s.upnp.curdevice <= %zion.s.upnp.totaldevices) {
      upnploadXMLFromSource $line(@upnp-list,%zion.s.upnp.curdevice)
    }
  }
}
alias upnp_portforward {
  if ($1) {
    %zion.s.upnp.pf.port = $2
    %zion.s.upnp.pf.ip = $1
    %zion.s.upnp.pf.req = $3-
;    sockclose upnp_portforward.*
;    if (%zion.s.upnp.para = udp) sockopen upnp_portforward.u $1 $2
;    elseif (%zion.s.upnp.para = all) { %zion.s.upnp.next = sockopen upnp_portforward.u $1 $2 | sockopen upnp_portforward.t $1 $2 }
;    else sockopen upnp_portforward.t $1 $2
    
    var %a upnp
    if (%zion.s.upnp.s) %a = .upnp
    if (%zion.s.upnp.del) {
      if (%zion.s.upnp.para = udp) { %a del %zion.s.upnp.portToForward udp }
      elseif (%zion.s.upnp.para = all) { %a del %zion.s.upnp.portToForward tcp | %a del %zion.s.upnp.portToForward udp }
      else %a del %zion.s.upnp.portToForward tcp
    }
    if (%zion.s.upnp.add) {
      
      if (%zion.s.upnp.para = udp) { %a add %zion.s.upnp.portToForward udp %zion.s.upnp.localip %zion.s.upnp.portToForward $true Zion %zion.s.upnp.portToForward UDP }
      elseif (%zion.s.upnp.para = all) { %a add %zion.s.upnp.portToForward tcp %zion.s.upnp.localip %zion.s.upnp.portToForward $true Zion %zion.s.upnp.portToForward TCP | %a add %zion.s.upnp.portToForward udp %zion.s.upnp.localip %zion.s.upnp.portToForward $true Zion %zion.s.upnp.portToForward UDP }
      else %a add %zion.s.upnp.portToForward tcp %zion.s.upnp.localip %zion.s.upnp.portToForward $true Zion %zion.s.upnp.portToForward TCP
    }
    
  }
}
on *:sockopen:upnp_portforward.*: {
  if ($sockerr) {
    upnp_info $z.lang(sys,upnp_failreq) $sockerr
    return
  }
  var %type TCP
  unset %zion.s.upnp.dl.rdy %zion.s.upnp.dl.len
  %zion.s.upnp.localip = $sock($sockname).bindip
  sockwrite -n $sockname POST %zion.s.upnp.pf.req HTTP/1.0
  sockwrite -n $sockname Host: $+(%zion.s.upnp.pf.ip,:,%zion.s.upnp.pf.port)
  sockwrite -n $sockname Content-Length: $calc(597 + ($len(%zion.s.upnp.portToForward) *2) + $len(%zion.s.upnp.localip))
  sockwrite -n $sockname Content-Type: text/xml; charset="utf-8"
  sockwrite -n $sockname SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
  sockwrite -n $sockname
  sockwrite -n $sockname <?xml version="1.0"?>
  sockwrite -n $sockname <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  sockwrite -n $sockname <s:Body>
  sockwrite -n $sockname <u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
  sockwrite -n $sockname <NewRemoteHost></NewRemoteHost>
  sockwrite -n $sockname $+(<NewExternalPort>,%zion.s.upnp.portToForward,</NewExternalPort>)
  if ($right($sockname,1) = u) %type = UDP
  sockwrite -n $sockname <NewProtocol> $+ %type $+ </NewProtocol>
  sockwrite -n $sockname $+(<NewInternalPort>,%zion.s.upnp.portToForward,</NewInternalPort>)
  sockwrite -n $sockname $+(<NewInternalClient>,%zion.s.upnp.localip,</NewInternalClient>)
  sockwrite -n $sockname <NewEnabled>1</NewEnabled>
  sockwrite -n $sockname <NewPortMappingDescription>Piction</NewPortMappingDescription>
  sockwrite -n $sockname <NewLeaseDuration>0</NewLeaseDuration>
  sockwrite -n $sockname </u:AddPortMapping>
  sockwrite -n $sockname </s:Body>
  sockwrite -n $sockname </s:Envelope>
  sockwrite -n $sockname
  
  upnp_info $z.lang(sys,upnp_sending)  %type %zion.s.upnp.portToForward ... OK! (LocalIP: %zion.s.upnp.localip $+ )
  if (%zion.s.upnp.next) { $eval(%zion.s.upnp.next,2) | unset %zion.s.upnp.next }
  else upnp_shutdown
}
alias -l upnp_shutdown {
  window -c @upnp-list
;  .timercloseupnpstatus 1 1 window -c @upnpstatus
  if ($isfile(%zion.s.upnp.tempfile)) .remove %zion.s.upnp.tempfile
}
; uncomment this to get a file containing the router response to the request
on *:sockread:upnp_portforward.*: {
  if ($true) {
    if (%zion.s.upnp.dl.rdy != 1) {
      var %header
      sockread %header
      while ($sockbr) {
        if (* !iswm %header) {
          %zion.s.upnp.dl.rdy = 1
          %zion.s.upnp.dl.offset = $sock($sockname).rcvd
          break
        }
        sockread %header
      }
    }
    sockread 4096 &d
    while ($sockbr) {
      bwrite $shortfn($scriptdir) $+ upnp_temp_response.txt -1 -1 &d
      sockread 4096 &d
    }
  }
}

/*_____________________________________________________________________________
|/
/  UPnP NAT script by David "Saturn" van Moolenbroek <saturn@quakenet.org>
|  Version 0.1a, released 04-12-2005 -- support on #help.script/Quakenet
|  Use/modify however you want, but please keep my name in it. Thank you!
|
|  Keywords: networking, COM
|
|  This script allows you to add, delete and enumerate Network Address
|  Translation (NAT) entries of an Universal Plug'n'Play (UPnP) compatible
|  router or firewall. In order for this script to work, you need to have a
|  UPnP-compatible Windows version (e.g. Windows XP) and a UPnP NAT device.
|
|  The script is based on the excellent work by Knox North; see his webpage at
|  http://www.knoxscape.com/Upnp/NAT.htm for more information on the subject.
|
|  The script defines the following commands/identifiers:
|
|  /upnp add <eport> <proto> <iaddr> <iport> <enabled> <desc>
|
|    Adds an entry to the UPnP NAT list. It takes a number of arguments: the
|    port number that is to be opened up at the outside (eport), the protocol
|    of the connections for this port (proto; either "TCP" or "UDP"), the
|    internal IP (iaddr) and port number (iport) to which incoming connections
|    on the external port and protocol should be forwarded, a flag value
|    (enabled; either "$true" or "$false") indicating whether this entry is
|    enabled, and a textual description of the entry (desc). You can also
|    replace the properties of existing entries with this command.
|
|  /upnp del <eport> <proto>
|
|    Deletes an entry from the UPnP NAT list, based on its external port
|    number and its protocol (TCP or UDP).
|
|  /upnp list
|
|    Lists the current UPnP NAT entries.
|
|  $upnp(N)
|
|    Properties: desc, eaddr, eport, iaddr, iport, proto, enabled
|
|    This identifier returns information about entries in the UPnP NAT list.
|    If N is zero, it returns the number of entries in the list, otherwise it
|    returns a certain piece of information about the Nth entry.
|
|    The following properties are available: "desc" returns the description of
|    the entry; "eaddr" returns the external IP address associated with the
|    entry (i.e. the IP address of the router); "eport" returns the port
|    number at which the router is accepting connections; "iaddr" and "iport"
|    are the address (IP or hostname) and port number of the internal address
|    to which those connections are forwarded; "proto" returns TCP or UDP
|    indicating what protocol the entry is for, and "enabled" returns $true or
|    $false depending on whether the entry is enabled. The "desc" property is
|    returned in case no other property is specified.
|
|    If UPnP NAT is not available, the identifier will return $null on any
|    query.
|
|  Note
|
|    Both "/upnp list" and the $upnp identifier are currently (mIRC 6.16)
|    *DEAD SLOW*. This is because both mIRC and the UPnP NAT COM object
|    perform heaps of unnecessary extra work while enumerating the existing
|    connections with $comval(). There is little I can do about this,
|    hopefully at least newer mIRC versions will speed up the enumeration
|    process somewhat.
|
|  Simple examples
|
|    /upnp add 12345 tcp 192.168.1.2 12345 $true Test entry
|    /upnp del 12345 tcp
\
_\_____________________________________________________________________________
*/

; Time (in seconds) after which the portmapping COM object will be closed
alias -l upnp.timeout return 10

alias -l upnp.handle {
  if (.comclose * iswm $timer(upnpnat).com) {
    .timerupnpnat -io 1 $upnp.timeout $v2
    return $gettok($v2,2,32)
  }
  
  var %n = nat $+ $ticks, %m = map $+ $ticks
  .comopen %n HNetCfg.NATUPnP
  var %r = $com(%n,StaticPortMappingCollection,3,dispatch* %m)
  .comclose %n
  if (!%r) || (!$com(%m)) return
  .timerupnpnat -io 1 $upnp.timeout .comclose %m
  return %m
}

alias -l upnp.get {
  if (!$2) return $iif($com($1,Count,3),$com($1).result)
  
  if ($findtok(desc eaddr eport iaddr iport proto enabled,$3,32)) $&
  return $comval($1,$2,$gettok(Description ExternalIPAddress $&
  ExternalPort InternalClient InternalPort Protocol Enabled,$v1,32))
}
alias -l _bb return
alias upnp {
  if ($isid) {
    if ($0 != 1) || ($1 !isnum 0-) return
    
    var %h = $upnp.handle
    if (!%h) return
    
    return $upnp.get(%h,$1,$iif($prop != $null,$v1,desc))
  }
  var %s echo
  if (!$show) %s = _bb
  if ($0) && ($findtok(add del list,$1,32) == $null) {
    %s -aeqc info * /upnp: invalid parameters
    return
  }
  
  if ($0 < $gettok(7 3 1,$v1,32)) {
    %s -aeqc info * /upnp: insufficient parameters
    return
  }
  
  if (($1 != list) && (($2 !isnum 1-65535) || (!$istok(TCP UDP,$3,32)))) || $&
  (($1 == add) && ($5 !isnum 1-65535)) {
    %s -aeqc info * /upnp: invalid parameters
    return
  }
  
  var %h = $upnp.handle
  if (%h == $null) {
    %s -aeqc info * /upnp: unable to access UPnP NAT
    return $false
  }
  
  if ($1 == add) {
    var %r = res $+ $ticks
    if (!$com(%h,Add,3,long,$2,bstr,$upper($3),long,$5,bstr,$4,bool,$6, $&
    bstr,$7-,dispatch* %r)) {
      %s -aeqc info * /upnp: unable to add UPnP NAT entry
      return $false
    }
    
    %s -aeqc info2 * Added UPnP NAT entry for $2 $+ / $+ $lower($3)
    .comclose %r
    return $true
  }
  elseif ($1 == del) {
    if (!$com(%h,Remove,3,long,$2,bstr,$upper($3))) {
      %s -aeqc info * /upnp: unable to delete UPnP NAT entry
      return $false
    }
    
    %s -aeqc info2 * Deleted UPnP NAT entry for $2 $+ / $+ $lower($3)
    return $true
  }
  else {
    var %i = 1, %n = $upnp.get(%h,0)
    if (!%n) {
      %s -aeqc info * No UPnP NAT entries found
      return
    }
    
    %s -aeqc info * UPnP NAT entries:
    while (%i <= %n) {
      %s -aqc info2 [[ $+ $iif($upnp.get(%h,%i,enabled),x,$chr(32)) $&
      $+ ]] $upnp.get(%h,%i,desc) $+ : $upnp.get(%h,%i,eport) -> $&
      $upnp.get(%h,%i,iaddr) $+ : $+ $upnp.get(%h,%i,iport) ( $+ $&
      $upnp.get(%h,%i,proto) $+ )
      inc %i
    }
    linesep
  }
}

menu @zion_cmdwin {
  dclick:if ($hget(zion_listcmd,$strip($line(@zion_cmdwin,$1,1)))) sline @zion_cmdwin $calc($gettok($ifmatch,1,32) +24 - $gettok($ifmatch,2,32))
}
alias z.list %zion.s.listcmd.len = 0 | .signal zion_cmdlistopen | .timerzion.s.listcmd2 1 0 zion_cmdwin
alias zion.listcmd {
  var %w @zion_cmdwin,%l,%u,%e,%m,%t,%a aline -p,%c $crlf
  tokenize 59 $1-
  %l = $iif($left($1,1) = /,$1,$+(/,$1))
  if (!$window(%w)) {
    if ($len(%l) > %zion.s.listcmd.len) %zion.s.listcmd.len = $v1
    return
  }
  %t = $line(%w,0)
  %a %w %c
  %a %w $+(,$color(highlight text),,%l)
  aline -l %w %l
  %u = $2 $+ \n
  while (\n isin %u) {
    %m = $pos(%u,\n,1)
    %a %w $left(%u,$calc(%m -1))
    %u = $right(%u,$+(-,$calc(%m +2)))
  }
  if ($3) {
    %u = $3 $+ \n
    %a %w %c
    aline -p %w 12usage:
    while (\n isin %u) {
      %m = $pos(%u,\n,1)
      %a %w $left(%u,$calc(%m -1))
      %u = $right(%u,$+(-,$calc(%m +2)))
    }
    if ($4) {
      %u = $4 $+ \n
      %a %w %c
      %a %w 12example:
      while (\n isin %u) {
        %m = $pos(%u,\n,1)
        %a %w $left(%u,$calc(%m -1))
        %u = $right(%u,$+(-,$calc(%m +2)))
      }
    }
  }
  aline 15 %w  $str(_,100)
  hadd -m zion_listcmd %l $line(%w,0) $calc($line(%w,0) - %t)
}
alias zion_cmdwin dialog -ma zion_cmdwin zion_cmdwin
dialog zion_cmdwin {
  title $z.lang(shell,cmdwintitle)
  size -1 -1 496 398
}
on *:dialog:zion_cmdwin:*:*: {
  if ($devent == init) {
    dcx Mark $dname zion_cmdwin_cb
    xdialog -b $dname +t
    window -hnl $+ %zion.s.listcmd.len $+ S @zion_cmdwin 5 5 485 350
    _welcometext
    font @zion_cmdwin -8 Tahoma
    zion_cmdwin_init_dcx
  }
}

alias -l zion_cmdwin_init_dcx {
  ;  xdialog -c $dname 1 richedit 5 5 385 250 multi vsbar tabstop left hsbar
  var %w @zion_cmdwin
  xdialog -c $dname 1 window 5 5 385 250 %w
  
  xdid -h $dname 1
  ;  xdid -f $dname 1 +a ansi 10 Tahoma
  
  xdialog -c $dname 2 button 210 365 75 25 tabstop
  xdid -t $dname 2 $z.lang(shell,closerules)
  
  xdialog -c $dname 4 text 220 180 75 25
  xdid -t $dname 4 $z.lang(shell,loading)
  xdid -f $dname 4 +ba ansi 10 Tahoma
  
  .signal zion_cmdlistopen $dname %w
  .timerzion.s.listcmd 1 0 _reveal
}
alias -l _welcometext {
  var %w @zion_cmdwin
  aline -p %w Welcome to the $remove($z.lang(shell,cmdwintitle),")
  aline -p %w $crlf
  aline -p %w 14Herein lists all the user commands available. To use a command (i.e. /z.list), simply type it in any edit area, like the ones you use to chat, and hit the 'Enter' key.
  aline 15 %w  $str(_,100)
}
alias -l _reveal {
  xdid -h zion_cmdwin 4
  xdid -s zion_cmdwin 1
  sline @zion_cmdwin 24
}
alias zion_cmdwin_cb {
  if ($2 = sclick) {
    if ($3 = 2) dialog -x $1
  }
  if ($2 = close) { window -c @zion_cmdwin | hfree zion_listcmd | unset %zion.s.listcmd.* }
}
; hosts modifier
alias z.setdns {
  if (!$0) { z.echo $z.head(err) /z.setdns [-(clea)r] <IP> [host] | return }
  var %m $+(",$envar(windir),$iif(!$istok(95-98-ME,$os,45),\system32\drivers\etc),\hosts,"),%a www,forum,forums,mail,zion,league,support,rules,donate,%d ZincPlay.com,%n $calc($numtok(%a,44) +1),%w,%r,%f $2
  if ($exists(%m)) {
    if ($1 = -r) %r = 1
    if ($2) %n = 1
    while (%n > 0) {
      if (%f) %w = %f
      else {
        if ($gettok(%a,%n,44)) %w = $+($ifmatch,.,%d)
        else %w = %d
      }
      if ($read(%m, w, $+(*,%w))) write $iif(%r,-dl,-l) $+ $readn %m $1 %w
      elseif (!%r) write %m $1 %w
      dec %n
    }
  }
  if (%r) z.echo $z.head(notice) $iif($2,$2,%d DNS entries) cleared
  else z.echo $z.head(notice) $iif($2,$2,%d DNS) now points to $1
}

alias envar {
  var %wsh = wsh $+ $ticks, %tmp = $$1
  .comopen %wsh wscript.shell
  if ($isid) {
    %tmp = $com(%wsh,expandenvironmentstrings,1,bstr*,% $+ $1%)
    %tmp = $com(%wsh).result
  }
  else {
    var %env = env $+ $ticks
    %tmp = $com(%wsh,environment,2,bstr*,process,dispatch* %env)
    %tmp = $iif($0 < 2,$com(%env,remove,1,bstr*,$1),$com(%env,item,4,bstr*,$1,bstr*,$2-))
  }
  :error
  if ($com(%wsh)) .comclose %wsh
  if ($com(%env)) .comclose %env
  if ($isid) && ($+(%,$1,%) !iswm %tmp) return %tmp
}

; BOT stuffs

; ZINCBot around or not?
alias z.bot return $iif(zincbot isop %zion.s.chat,1)

; procedure to broadcast your username, IP, address & popularity.
alias zion_markme {
  ; $hget(zsession,pass) = password hash of current login
  ; $z3.findtog(auth,name) = current login username
  ; $z.h.getvar(bob) = current user's popularity during login
  ; $z.ip = current user's IP
  ; $ial($me).host = current user's host
  
  ; note to programmer:
  ; Program what happens when $z.bot is 1, meaning when ZINCbot is around.
  ; it's currently doing the same thing as when it's not around cos things aren't ready :)
  ; program the hash+salt, via ctcp whatsoever here.
  ; might want to store on DB current user's IP address
  
  ; broadcasting..
  if ($z.bot) z.comms.send $1 zion mark $z.ip $ial($me).host $z3.findtog(auth,name) $z.h.getvar(bob)
  else z.comms.send $1 zion mark $z.ip $ial($me).host $z3.findtog(auth,name) $z.h.getvar(bob)
}
on *:signal:zion_comms:{
  if ($2 = zion) {
    if ($3 = mark) {
; uncomment once zincbot marking is complete.
;      if (!$z.bot) {
      if ($hget(z.trace.adds,$4)) z.trace_jeric2 $4 $1 $5 $6 $7
      hadd -m zion_users $4 $1 $6 $7
;      }
    }
  }
}
alias z.gensalt {
  var %r $r(a,z),%l %r,%m $r(7,9),%t
  while ($len(%l) < %m) {
    dll_wfix WhileFix
    if ($r(0,1)) %t = $crc(%l,text)
    else %t = $md5(%l)
    %l = %l $+ $mid(%t,$r(1,$len(%t)),$r(1,2))
  }
  return %l
}
alias clearall {
  ; if there is any /clearall switches, do the default /clearall
  if ($0) !clearall $1-
  ; otherwise, exclude @z.gl
  else {
    var %i $window(*,0)
    while (%i > 0) {
      if ($window(*,%i) != @z.gl) !clear $v1
      dec %i
    }
  }
}
alias zion.visitlink {
  if (!$2) return
  var %l $2-,%d zion_visitlink
  if ($dialog(%d)) dialog -x %d
  z.h.setvar showlink $1
  if ($right(%l,1) = \) %l = $left(%l,-1)
  z.h.setvar visitlink %l
  dialog -ma %d zion_visitlink_table
}

dialog zion_visitlink_table {
  title ""
  size -1000 -1000 592 398
}

on *:dialog:zion_visitlink:*:*: {
  if ($devent == init) {
    dcx Mark $dname zion_visitlink_cb
    xdialog -b $dname +ty
    .timer 1 0 xdialog -h $dname
    
    ;// Call initilisation alias
    zion_visitlink_init_dcx
  }
}

alias -l zion_visitlink_init_dcx {
  ;// Initialising control: (WebControl 1)
  xdialog -c $dname 1 webctrl 5 5 585 390 tabstop
  xdid -n $dname 1 $z.h.getvar(visitlink)
}

;// Callback alias for zion_visitlink
alias zion_visitlink_cb {
;  echo -s event: $1-
  if ($2 = title) {
    dialog -t $1 $4-
    if ($4- = Cannot find server) {
      .signal zion_vlink_bad $z.h.getvar(visitlink)
      dialog -x $1
    }
  }
  elseif ($2 = doc_complete) {
    var %l = $4-
    if ($right(%l,1) = \) %l = $left(%l,-1)
    if (%l = $z.h.getvar(visitlink)) {
      .signal zion_vlink_ok $z.h.getvar(visitlink)
      if (!$z.h.getvar(showlink)) dialog -x $1
      else { dialog -s $1 100 100 -1 -1 | xdialog -s $1 }
      z.h.unsetvar showlink
      z.h.unsetvar visitlink
    }
  }
}