Zion Sphinx — File Browser

ZionSphinxv3.0 / ZionSphinxv3.0 / zion.mrc

zion.mrc — 83.55 KB — Download this file

; --------< Zion >----------------------------------------------------
; Name....: Zion Main
; File....: zion.mrc
; Ver.....: Sphinx 3.0
; Author..: sprion
; Email...: sprion@lyniq.com
; Date....: 30 Aug 07
; URL.....: http://zincplay.com
; Info....: Get this script from valid sources only. Thank you.
; Changes.: Minor updates.
;---------------------------------------------------------------------
;translatable
; signals in this script: zion_begin, zion_winmade, zion_start, zion_end, zion_unload
; ranked in order when /zion is done..
alias z.help run hh.exe mk:@MSITStore: $+ $scriptdir $+ zion.chm::html/ $+ $iif($1,$1,index.htm)
alias -l development return 0
alias colorbox .comopen cb WScript.Shell | .comclose cb $com(cb,SendKeys,3,bstr,$+(^,K))
; shft is + ctrl is ^ alt is %
alias -l d var %z $+(",$scriptdir,$1,") | if ($isid) return $dll(%z, $$2 ,$3-) | else dll %z $$2 $3-
alias dll_wfix d WhileFix.dll $1-
alias dll_wfx d WindowFX.dll $1-
alias dll_gt var %z $+(",$scriptdir,game_tools.dll,") | if ($isid) return $dll(%z, $$1 ,$2-) | else dll %z $$1 $2-
alias dll_mc {
  var %f system\mircustom.dll
  if ($isfile($+(",$scriptdir,%f,"))) d %f $1-
}
alias dll_z return $dll($+(",$scriptdir,system\zion.dll,"),$$1,$2-)
alias dll_z2 return $dll($+(",$scriptdir,system\zion2.dll,"),$$1,$2-)
alias dll_z3 return $dll($+(",$scriptdir,system\zion3.dll,"),$$1,$2-)
alias dll_ip return $dll($+(",$scriptdir,system\iptable.dll,"),$$1,$2-)
alias dll_z2p return $+(",$scriptdir,system\zion2.dll,")
;alias dll_nl3 var %z $+(",$scriptdir,system\nickLUST3.dll,") | if ($isid) return $dll(%z, $$1 ,$2-) | else dll %z $$1 $2-
; fixes display bug of the item
alias z.icl {
  if ($1) return $shortfn($+($scriptdir,system\img\zionico.dll)) $+ , $+ $1
  else return $shortfn($+($scriptdir,system\img\zionico.dll))
}
alias z.images {
  if ($1) return $shortfn($+($scriptdir,system\img\ $+ $1))
  else return $shortfn($+($scriptdir,system\img))
}
alias z.ticks return $dll_gt(ticks,.)
on *:signal:zion_cmdlistopen:{
  zion.listcmd z.help ; Opens the Help file.
  zion.listcmd cF12 ; Hit Ctrl+F12 to connect to a server and start Zion automatically.
  zion.listcmd zion ; Launches Zion.
  zion.listcmd zion.unload ; Unloads Zion from mIRC. You will still need to remove the files manually or run the uninstaller to remove Zion completely.
  zion.listcmd z.whereami ; Reveals the path/location of Zion on this computer.
  zion.listcmd z.changelog; Shows description of the last updates/changelog.
  zion.listcmd z.motd ; Shows the Message-of-the-Day from Zion.
  zion.listcmd z.userinfo ; Opens the Userinfo Window for a user. ; /z.userinfo <nick> ; /z.userinfo sprion
  zion.listcmd z.repair ; Repairs Zion when settings and files are corrupted. The -full parameter clears all your settings. ; /z.repair [-full] ; /z.repair \n /z.repair -full
}
; updateables
on *:signal:zion_update_start:{
  var %z .signal -n zion_update_addfile
;  %z $+(",$scriptdir,system\img\userlogin.bmp,")
  %z $+(",$scriptdir,system\dcx\dcx.dll,")
  %z $+(",$scriptdir,english.lang,")
  %z $+(",$scriptdir,servers.lst,")
;  %z $+(",$scriptdir,zion.chm,")
  %z $+(",$scriptdir,zionmisc.mrc,")
  %z $+(",$scriptdir,system\zion.dll,")
  %z $+(",$scriptdir,system\zion2.dll,")
  %z $+(",$scriptdir,system\zion3.dll,")
  %z $+(",$scriptdir,system\iptable.dll,")
;  %z $+(",$scriptdir,fx\reminder.wav,")
;  %z $+(",$scriptdir,system\img\girl.png,")
;  %z $+(",$scriptdir,system\img\girl_d.png,")
}
on *:signal:zion_update_complete:if ($1) zion.afterupdate
/* ##########################
SYSTEM ID
#########################
*/
alias z.fileinfo {
  var %p = $+(*,$2,$str(.,$calc(8 - $len($2))),:*),%r = $read($+(",$1,"), w, %p)
  return $iif(%r,$gettok(%r,2-,58),0)
}
alias z.font return Verdana 11
alias z.sysfolder return $scriptdir
alias z.gamefolder return $+($scriptdir,games\)
alias z.pluginfolder return $+($scriptdir,plugins\)
alias z.syscode return $encode(%zion.s.nick)
alias z.sys return $+(",$scriptdir,zion_settings.ini,")
alias z.servers return $+(",$scriptdir,servers.lst,")
alias z.remsettings .remove $z3.sys | hfree -w zion_3_config* | z.note $z.head(Notice) $ $z.lang(note,clearsettings)
alias z.z return $iif(%zion.s.z = 99,$true)
alias z.settingsok {
  if ((!$z3.findtog(personal,snd_welcome))) return $false
  return $true
}
alias z.gamesettingsok return $zion.game.ok
alias z.active return $iif((!$dialog($1).active),$false,$true)
alias z.rtip return $z.lang(tip,$r(1,$z.lang(tip,0)))
alias z.lang {
  if ($hget(zion_lang,$+($1,$2)) != $null) return $ifmatch
  else { var %v = $readini($+(",$scriptdir,$z3.findtog(general,langfile,english.lang),"),$1,$2) | hadd -m zion_lang $+($1,$2) %v | return %v }
}
alias z.head return $+($readini($+(",$scriptdir,$z3.findtog(general,langfile,english.lang),"),header,$1),:)
alias z.started return $iif($z.h.getvar(started) = 1,$true,$false)
alias z.getcol {
  if (!%zion.s.color) %zion.s.color = $z3.findtog(display,colours,$color(list) $color(listbox text) 3 12 5)
  return $base($gettok(%zion.s.color,$1,32),10,10,2)
}
alias z.msghost {
  var %w $z.win,%l $sline(%w,1).ln,%i = $z.gl.getName(%l),%n = $gettok($strip($z.gl.getHost(%l)),1,32),%ip $z.gl.getIP(%l)
  if ($z.trace(%ip,-r)) %n = $gettok($ifmatch,1,32)
  if (!$window(%w)) return
  if (_pub isin %i) {
    query %n
    window -a %n
    return
  }
  else z.echo $z.head(err) $z.lang(err,failquery)
}
; $rotate by [TrIpLe] (triple_irc@hotmail.com)
alias z.rotate {
  var %rotor $1,%txt $replace($2-,$chr(32),$chr(160)),%i 1,%cph,%l $len(%txt)
  while (%i <= %l) {
    dll_wfix WhileFix
    var %cur = $mid(%txt,%i,1)
    if (%cur !isalpha) { %cph = %cph $+ %cur | inc %i | continue }
    var %up $iif(%cur isupper,90,122),%lo $iif(%cur isupper,65,97),%tmp $calc($asc(%cur) + %rotor)
    if ($left(%rotor,1) != -) && (%tmp > %up) %tmp = $calc((%lo - 1) + (%tmp - %up))
    if ($left(%rotor,1) == -) && (%tmp < %lo) %tmp = $calc((%up + 1) - (%lo - %tmp))
    %cph = %cph $+ $chr(%tmp)
    inc %i
  }
  return $replace(%cph,$chr(160),$chr(32))
}
/* ##########################
REGISTRY & HASH
##########################
*/
alias z.antiflood return 0
alias z.defchat return #Zinc
alias z.defdata return #GameList
alias z.ver return Sphinx 3.0 (300807)
alias z.network return $z3.findtog(perm,network,GameSurge.net)
alias z.networkmask return GameSurge
alias z.goodsv return Gameservers.NJ.US.GameSurge.net 6668
alias z.networkservices return Global-ChanServ-AuthServ-HostServ-SpamServ-ZincServ-ZincBot
alias z.tagline return IRC Network Gaming Community
alias z.mircver return 6.17
alias z.adv if ($z.antiflood) return 11,7I play $iif($r(0,1),harder,games) with Zion $z.ver - http:// $+ $z.host - YAWLE | else return $null
alias z.privacystatement return http://docs.google.com/Doc?id=ddrzdg82_13g5p5b5
alias z.registerdoc return http://docs.google.com/Doc?id=ddrzdg82_14d2t83r
alias z.host return zion.zincplay.com
alias z.forumhost return forum.zincplay.com
alias z.forumpath return $null
alias z.newspath return /motd.txt
alias z.rulespath return /viewtopic.php?t=168
alias z.h.createhash {
  var %g zion_users$zion_settings,%n 2,%t,%z %zion.s.nick
  while (%n > 0) {
    %t = $gettok(%g,%n,36)
    if (!$hget(%t)) hmake %t 5
    dec %n
  }
}
alias z.h.path return zion_settings $1-
alias z.h.setvar {
  var %z zion_settings
  if (!$hget(%z)) hmake %z 10
  hadd %z $1-
}
alias z.h.getvar {
  var %z zion_settings
  if (!$hget(%z)) return $null
  return $hget(%z,$1)
}
alias z.h.unsetvar {
  var %e zion_settings
  if (!$hget(%e)) return
  if ($hget(%e)) hdel %e $1
}
;listview
alias z.h.adddata hadd zion_listview $1-
alias z.h.remdata hdel zion_listview $1
alias z.h.getdata return $hget(zion_listview,$1)
;ip
; nick_ip, ip
alias z.id.myadd {
  var %r $address($me,1)
  return $mid(%r,4,$mid(%r,4,0))
}
alias z.h.addhost hadd zion_users $remove($1,~) $2-
alias z.h.remhost hdel zion_users $1
alias z.h.setgamefound {
  ;$1 = name, $2 = gameNo
  hadd zion_users $+($1,_found) 1
}
alias z.h.getgamefound return $hget(zion_users,$+($1,_found))
/* ##########################
COMMANDS
##########################
*/
alias cF12 zion
alias zion {
  if ($z.started) {
    if ($input(You are already connected. $crlf $crlf Do you wish to log off and log in as another user?,yqd,Re-login)) z.deauth
    else return
  }
  if !$z.settingsok { z.echo $z.head(err) $z.lang(err,badsettings) | z.options | return }
  if $1 = -m {
    server $iif($server,-m) $iif(!$2,$z3.findtog(general,server,$z.goodsv))
    %zion.s.autoconn = 1
    return
  }
  if (!$server) {
;    if ($1 = -f) { .timer 1 0 zion -m | return }
    .timer 1 0 zion -m | return
;    z.echo $z.head(err) $z.lang(err,notconnected) | z.echo $z.head(tip) $z.lang(tip,11) | return
  }
  ; setting the cid to a gamesurge connection.
  z.setcid $1
  if ($cid != $z.getcid) {
    if $z.getcid = $null {
;      if ($1 = -f) { zion -m | return }
      .timer 1 0 zion -m | return
;      z.echo $z.head(err) $z.lang(err,badnetwork)
;      z.echo $z.head(tip) $z.lang(tip,12)
    }
    else scid $z.getcid zion
    return
  }
  if ($timer(zion.wait)) { var %v $calc($timer(zion.wait).secs +1) | .timerzion.connect 1 %v zion | z.echo $z.head(note) $z.lang(note,start) %v $+ s.. | return }
  if ($hget(zession,authed)) hdel zsession authed
  .signal -n zion_cmd $1-
  z.authdo z.init $1-
}
alias z.init {
  if (!$z.started) {
    .timerzion.s.* off
    unset %zion.s.*
    if ($1 = -d) %zion.s.debug = 1
    z.begin $1
    z.echo $z.head(didyouknow) $z.rtip
  }
}
on *:signal:zion_deauth:z.stop
alias zion.unload {
  z3.deltog general installed
  .signal -n zion_unload
  z.echo $z.head(notice) $z.lang(note,uninstalled)
  unset %zion.s.*
  .timerzion.s.* off
  hfree -w zion_*
  if ($dll(dcx.dll)) dll -u dcx.dll
  if ($dll(WindowFX.dll)) dll -u WindowFX.dll
  if ($dll(x-gui.dll)) dll -u x-gui.dll
  if ($dll(mircustom.dll)) dll -u mircustom.dll
  .timer -om 1 500 .unload -rs $nopath($script)
}
alias z.whereami var %v $nofile($script) | if ($isid) return %v | else z.echo $z.head(location) %v
alias z.linehash {
  var %c 1,%n z.linehash,%v
  z.h.unsetvar %n
  while ($hget($1,%c)) {
    dll_wfix WhileFix
    %v = $hget($1,%c)
    z.h.setvar %n $instok($z.h.getvar(%n),%v,9999,$2)
    inc %c
  }
  return $z.h.getvar(%n)
}
alias z.changelog {
  /*
  if (!$z.guiinstalled) return
  var %c 1,%n,%a advanced,%v changes
  if ((!$0) && ($z3.findtog(%a,%v))) tokenize 32 $ifmatch
  z3.addtog %a %v $1-
  while ($gettok($1-,%c,36)) {
    var %t $ifmatch,%s = $script(%t)
    if (%s) var %n2 = $gettok($read($+(",%s,"), w, *Name....:*),2-,58),%n = %n $+ $+(,%n2,\n-,$chr(160),$right($replace($gettok($read($+(",%s,"), w, *Changes.:*),2,58),$chr(59),$+(\n-,$chr(160))),-1),\n,$chr(160),\n)
    inc %c
  }
  if (%n) zion.gui.gnote -b $rgb(255,255,255) Changes: $ %n (click to close) $ 120
  */
  .timerzion.s.changelogshow 1 10 return
  z.echo $z.head(notice) Opening Changelog..
  run $+(http://,$z.forumhost,/viewtopic.php?t=411)
}
alias z.saveprocess {
  var %n $z.h.getvar(saveprocess),%r 1
  if (%n = $null) z.h.setvar saveprocess 1
  if ($isid) return %n
  if ($1 = 0) %r = 0
  z.h.setvar saveprocess %r
}
/* ##########################
SYSTEM
##########################
*/
alias z.source.fil {
  var %c $1,%2 %zion.s.chat
  if (!$1) %c = 7private
;  elseif (($2 ison %2) || ($1 = %zion.s.data)) %c = 0
  elseif ($1 = %zion.s.data) %c = 0
  return %c
}
alias z.sockopen {
  var %r $z3.findtog(proxy,sel,n),%n $1,%h $2,%p $3,%t z.h.setvar
  %t zsock_ $+ %n %h %p
  
  if (%r = i) {
    var %z HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Proxy
    if ($z.rr($+(%z,Enable))) {
      %h = $z.rr($+(%z,Server))
      %p = $gettok(%h,2,58)
      %h = $gettok(%h,1,58)
    }
  }
  elseif (%r = m) {
    var %r2 $z3.findtog(proxy,addrport)
    if ($numtok(%r2,58) = 2) {
      %h = $gettok(%r2,1,58)
      %p = $gettok(%r2,2,58)
    }
    else {
      z.sock.f
      return
    }
  }
  
  z.sock.chk
  sockopen %n %h %p
}
alias z.sock.chk .timerzion.s.schk 1 6 z.sock.f
alias z.sock.ok .timerzion.s.schk off
alias z.sock.f zion.gui.gnote Update: $ $z.lang(err,updatefail) $ 15 | z.echo $z.head(tip) $z.lang(err,updatefail) $z.lang(note,f5) | z.echo $z.head(tip) $z.lang(tip,13) | %zion.s.f5 = z.help options.htm#5_1 | .signal -n zion_proxyfail
alias z.sock.err {
  var %r $z3.findtog(proxy,sel,n)
  if (%r = i) {
    if (!$isalias(z.rr)) return $z.lang(err,ieproxynoregistry)
    else return $z.lang(err,ieproxy)
  }
  if (%r = n) return $z.lang(err,noproxy)
  if (%r = m) return $z.lang(err,badproxy)
}
alias z.sendget {
  z.sock.ok
  var %z sockwrite -n $1,%r $z.h.getvar($+(zsock_,$1)),%h = $gettok(%r,1,32),%p = $gettok(%r,2,32),%g HTTP/1.1,%t z.h.unsetvar,%a $2-
  if (http:// isin %a) %a = $+(/,$gettok(%a,3-,47))
  if ($z3.findtog(proxy,sel,n) = n) %z GET %a %g
  else %z GET $+(http://,%h,:,%p,%a) %g
  ;  %t useproxy
  %t $+(zsock_,$1)
}
alias z.loseactive {
  if ($lactive = Status Window) { window -hn @z 99999 99999 0 0 | window -a @z | window -c @z } | else { if ($lactive) window -a $lactive | elseif ($window($zion.s.chat)) window -a $zion.s.chat }
  :error
  return
}
alias z.splay {
  var %e = $z.soundmap,%f
  if ($1 isnum) %f = $gettok(%e,$1,44)
  else %f = $1
  var %r = $z3.findtog(personal,%f),%fp
  ; event missing/disabled
  if ((!%r) || ($gettok(%r,1,124) != 2)) return
  %fp = $gettok(%r,2,124)
  if ($mid(%fp,2,1) != :) %fp = $+($scriptdir,%fp)
  ; these sounds numbers play when not active
  var %d 4 3 2 7 8 5 10 11 12 snd_gamefull snd_gamestart snd_gamestarting snd_mapload snd_firstgame snd_fonline snd_leaver snd_cheater snd_reminder
  if (!$isfile(%fp)) z.echo $z.head(err) $z.lang(err,soundmissing) %fp
  elseif (($appactive) || ($1 isin %d)) {
    if ($right(%f,4) = .wav) dll_gt splay %fp
    else splay %fp
  }
}
; looks for the connection to gamesurge and sets cid to it
alias z.setcid {
  var %i 1,%all,%n 1,%no z.echo $z.head(notice)
  unset %zion.s.cid %zion.s.sv
  ; look for gnet con and store the cids into %all
  while %i <= $scon(0) {
    if $z.network isin $scon(%i).server {
      %all = $instok(%all,$scon(%i),0,44)
    }
    inc %i
  }
  ; if there is 1 or more gnet cids
  if (%all) {
    ; if more than 1 gnet cids..
    if ($numtok(%all,44) > 1) {
      ; if a choice is made, use it
      if ($1 isnum) { var %zz = $gettok(%all,$1,44) | if (%zz) z.cids %zz }
      ; use previous connection if found
      if ($istok(%all,%zion.s.cidf,44)) z.cids %zion.s.cidf
      ; if the active cid is a gnet cid
      elseif ($istok(%all,$cid,44)) z.cids $cid
      else {
        ; when unable to pick 1 cid automatically.. allow user to choose
        %no Multiple GameSurge connections found, please choose ONE
        %no Type '/zion N' where N is one of these:
        while ($gettok(%all,%n,44)) {
          %no  %n $+ . $scid($ifmatch).me on $scid($ifmatch).server
          inc %n
        }
        halt
      }
    }
    else z.cids %all
  }
}
alias z.cids %zion.s.cidf = $1 | %zion.s.cid = $1 | %zion.s.sv = $scid($1).server
alias z.getcid return $iif(%zion.s.cid,$ifmatch)
; processes lines with possible IPs in it and tries to get them.
alias z.ip.process {
  if ((!$regex($1,(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)))) || (*@*.* iswm $1) || (www.*.* iswm $1) || (http:// isin $1)) return 0
  var %r $regml(1)
  %r = $longip(%r)
  ;  if ($left(%r,1) = 0) %r = $right(%r,-1)
  ;  if ($wildtok(%r, 0?*, 0, 46)) return 0
  if (%r) return $longip(%r)
}
; creates the small popup window
alias z.note {
  if ($z.guiinstalled) z.gui.note $1-
  else {
    if ($1 = -) tokenize 32 $2-
    z.echo $remove($1-,$chr(36))
  }
}
; returns information to whether a GUI,LE,Game is installed
alias z.guiinstalled return $iif($isalias(z.gui.note),$true,$false)
alias z.leinstalled return $iif($isalias(z.connect),$true,$false)
alias z.gameinstalled return $iif($isalias(zion.game.id),$true,$false)
; the connect command
alias z.con {
  if ($z.leinstalled) z.connect $1-
  else z.note $z.head(err) $ $z.lang(err,nole)
}
alias z.userinfo zion.userinfo $1-
alias zion.userinfo {
  var %s $iif($gettok($z.h.getvar($+($1,_ctcp)),2,32),$ifmatch,$z.gensalt)
  .ctcp $1 zion_userinfo $z.b64($me) %s
  z.h.setvar $+($1,_ctcp) $z.ticks %s
  .timerzion.s.ctcpunset $+ $1 -o 1 20 z.h.unsetvar $+($1,_ctcp)
}
/* ##########################
zMENU
##########################
*/
menu nicklist,query {
  $iif($1 ison %zion.s.data,$style(1)) Zion $gettok($z.ver,2,32)
  .$z.lang(zmenu,game)
  ..$submenu($z.games.nicklist($1))
  .-
  .$z.lang(zmenu,send) Zion
  ..$iif(!%zion.s.dfile,$style(2)) $z.lang(zmenu,send) $nopath(%zion.s.dfile):dcc send $1 $+(",%zion.s.dfile,")
  ..$iif(!%zion.s.dfile,$style(2)) $z.lang(zmenu,rsend):dcc send $gettok($ial($1,1),2,64) $+ :59 $+(",%zion.s.dfile,")
  .-
  .$z.lang(zmenu,glocate):{
    !.userhost $$1
    if ($IsIP($remove($address($$1,2),*!*@))) {
      traceip $remove($address($$1,2),*!*@)
    }
    else {
;      .enable #z.traceip
      !.dns $$1
    }
  }
  .$z.lang(zmenu,viewuinfo):if ($1 = $me) z.myinfo | else zion.userinfo $1
}
menu Channel {
  $iif((# = %zion.s.chat) && (!$window($z.win)) ,$z.lang(zmenu,startzion) Zion $iif($timer(zion.wait),(delay $timer(zion.wait).secs $+ s))):zion /p
}
menu @z.gl {
  lbclick:if ($sline($z.win,1).ln >= 3) .signal zion_updateselected
  dclick:window -a $zion.s.chat | .signal zion_joinselected
  $style(2) $z.lang(zmenu,gamelistmenu) $iif(($sline($z.win,1).ln >= 3),$+($chr(40),$z.gl.getIP($sline($z.win,1).ln),$chr(41))):return
  -
  $iif(!$z.started,$z.lang(zmenu,connectzion)):zion
  $iif(%zion.s.dc,$z.lang(zmenu,connectto) %zion.s.data):!join -n %zion.s.data
  $iif($sline($z.win,1).ln >= 3,$z.lang(zmenu,join)):.signal zion_joinselected
  $iif(($sline($z.win,1).ln >= 3),$z.lang(zmenu,msghost)):z.msghost
  -
  $iif(($sline($z.win,1).ln >= 3),$z.lang(zmenu,copyip)):clipboard $z.gl.getIP($sline($z.win,1).ln)
  $iif(($sline($z.win,1).ln >= 3),$z.lang(zmenu,pinggame)):.signal zion_updateselected
  -
  $iif(%zion.s.pauselist,$z.lang(zmenu,startglist),$z.lang(zmenu,pauseglist)) $z.lang(zmenu,gamelist):z.pause
  -
  $iif(($sline($z.win,1).ln >= 3) && ($gettok($gettok($sline($z.win,1),2,9),1,32) ison %zion.s.data) && ($z.ip),$z.lang(zmenu,sendzdlan)):.signal zion_requestgamelink
  $iif($z.started,$z.lang(zmenu,getzdlan)):zion.zd.request
  $iif(%zion.s.lastgame,-)
  $iif(%zion.s.lastgame,$z.lang(zmenu,history))
  .$submenu($z.history($1))
  -
  $z.lang(zmenu,options):z.options -snooping
  
}
menu status,menubar {
  $iif(!$z.started,Zion $z.ver)
  .$style(2) $z.lang(zmenu,offlinemenu):return
  .-
  .$z.lang(zmenu,offlineconnect) Zion:zion $iif(!$server,-m)
  .-
  .$submenu($zion.le.menu($1))
  .$z.lang(zmenu,game)
  ..$submenu($z.games.submenu($1))
}
; ---- DYNAMIC MENU codes ----
alias z.history {
  if $1 = begin { return $style(2) $z.lang(zmenu,lastgameat) $z3.findtog(history,last) hrs:return }
  if ($1 = 1) return -
  var %z $1 - 1,%t $numtok(%zion.s.log,44) + 1,%endline %t + 1,%rejoin %endline + 1
  if ($1 <= %t) return %z $+ . $gettok(%zion.s.logn,%z,44) - $gettok(%zion.s.log,%z,44) : z.con $gettok(%zion.s.log,%z,44)
  if ($1 = %endline) return -
  if ($1 = %rejoin) return $z.lang(zmenu,rejoinlast):z.con %zion.s.lastgame
  if ($1 = end) return $z.lang(zmenu,clear):z.history.clear
}
alias z.history.clear unset %zion.s.log %zion.s.lastgame
; --- end ----
alias z.calccount {
  if ($z.findtog(display,count) = 2) return $calc($3 - ($2 - $1)) $3
  else return $1 $2
}
alias z.win.check if ((!$1) || ($1 < 0)) return -1 | else return $1
alias z.protect return 44,46
; echo
alias z.echo { if ($1 = -) var %c $chr(160) | else var %c 12,15 $+ $+(-=-,,$1,,,$color(highlight text)) $2- | if (!$appactive) !echo -qtsi16 %c | elseif ($active = $z.win) !echo -qti16 $zion.s.chat %c | else !echo -qtai16 %c }
; startup codes
alias z.begin {
  .signal -n zion_begin
  z.setcid $1
  
  ; get my settings
  var %f $z3.findtog(list,newfont,Tahoma|12|bold)
  %zion.s.listsize = $gettok(%f,2,124)
  %zion.s.listfont = $gettok(%f,1,124)
  %zion.s.listbold = $gettok(%f,3,124)
  
  %zion.s.snptimeout = $z3.findtog(list,timeout,45)
  
  z.h.createhash
  z.h.setvar started 1
  z.h.setvar connected_ctime $ctime
  z.h.setvar restremind_ctime $ctime
  z.ip
  %zion.s.data = $iif($hget(zsession,survive_data_value),$ifmatch,$z3.findtog(perm,data,$z.defdata))
  %zion.s.chat = $iif($hget(zsession,survive_chat_value),$ifmatch,$z3.findtog(perm,chat,$z.defchat))
  if ($findfile($scriptdir,zion*.exe,1,1)) %zion.s.dfile = $ifmatch
  elseif ($findfile($scriptdir,zion*.zip,1,1)) %zion.s.dfile = $ifmatch
  else unset %zion.s.dfile
  .flood on
  if ($me ison %zion.s.data) {
    ; true means connected
    z.connected
    z.n.isonline $me
  }
  else { !join -n %zion.s.data | %zion.s.process = 10 }
  var %z $hget(zsession,zkey)
  !join %zion.s.chat %z
  !join %zion.s.chat $z($len(%z),%z)
  if (!%zion.le.gamestart) %zion.s.lastlist = $ctime
  z.gl.refresh
  z3.snoop.update z3.snoop.join
}
alias z.connected {
  if (!%zion.s.debug) window -hn %zion.s.data
  .timerzion.s.closer 0 5 z.check
  if ((!$z.h.getvar(start_signaled)) && ($z.started)) .signal zion_start
}
alias z.n.isonline {
  if ($z.started) {
    z.note - $z.head(join) $ $1 $z.lang(note,userjoin)
  }
}
; saying to all channels 1 by 1, can specify the -a parameter to msg all.
alias z.snoop.say {
  var %e,%c = $z.h.getvar(snoopchan.spamable),%sv = $z.h.getvar(snoopchan.spamablesv)
  if ($z3.findtog(snoop,datachanspam) = 2) {
    %c = $+(%c,$chr(44),%zion.s.data)
    %sv = $+(%sv,$chr(44),$+(%zion.s.sv,:,$port))
  }
  if (%c) {
    if $1 = -a { tokenize 32 $2- | var %all 1 }
    
    var %i $numtok(%c,44)
    if ((!%all) && (%i > 1)) %i = $z.snoop.current
    
    while (%i > 0) {
      %ch = $gettok(%c,%i,44)
      %svh = $gettok(%sv,%i,44)
      if ($z.onserver($gettok($gettok(%svh,1,58),-2-,46),%ch)) {
        scid $ifmatch
        msg %ch $1-
      }
      
      if (!%all) break
      
      dec %i
    }
  }
  else { z.echo $z.head(err) $z.lang(err,nospamchan) | %zion.s.f5 = z.options -snooping | .signal zion_nospamchan }
}
; the looping codes for above
alias z.snoop.current {
  var %n snooploop,%e $z.h.getvar(%n),%s = $+($z.h.getvar(snoopchan.spamable),$chr(44),%zion.s.data),%i = $numtok(%s,44),%w z.h.setvar %n 1
  if (!%e) %w
  hinc $z.h.path(%n)
  if ($calc(%e +1) > %i) %w
  return %e
}

on *:signal:zion_options_save:{
  if ($z.started) z3.snoop.update z3.snoop.join z.snoop.winmanage
}
alias z3.snoop.update {
  var %i 1,%c = $z3.findtog(snoop,totalchan),%chans,%servers,%snoop,%spam,%visible,%spamable,%spamablesv,%cmd $1-
  while (%i <= %c) {
    dll_wfix WhileFix
    tokenize 124 $z3.findtog(snoop,%i)
    %chans = $instok(%chans,$1,0,44)
    %servers = $instok(%servers,$2,0,44)
    %snoop = $instok(%snoop,$3,0,44)
    %spam = $instok(%spam,$4,0,44)
    %visible = $instok(%visible,$5,0,44)
    if ($4 = 2) {
      %spamable = $instok(%spamable,$1,0,44)
      %spamablesv = $instok(%spamablesv,$2,0,44)
    }
    inc %i
  }
  z.h.setvar snoopchan %chans
  z.h.setvar snoopchan.server %servers
  z.h.setvar snoopchan.snoop %snoop
  z.h.setvar snoopchan.spam %spam
  z.h.setvar snoopchan.spamable %spamable
  z.h.setvar snoopchan.spamablesv %spamablesv
  z.h.setvar snoopchan.visible %visible
  
  if (%cmd) %cmd
}
alias z3.snoop.chan {
  var %c,%s $2,%n
  if ($1 !isnum) {
    if ($2) {
      %n = $findtok($z.h.getvar(snoopchan),$1,0,44)
      while (%n > 0) {
        if ($gettok($gettok($gettok($z.h.getvar(snoopchan.server),$findtok($z.h.getvar(snoopchan),$1,%n,44),44),1,58),-2-,46) = $gettok(%s,-2-,46)) %c = %n
        dec %n
      }
    }
    else %c = $findtok($z.h.getvar(snoopchan),$1,1,44)
  }
  if (!%c) return $null
  if ($prop = snoop) return $gettok($z.h.getvar(snoopchan.snoop),%c,44)
  elseif ($prop = spam) return $gettok($z.h.getvar(snoopchan.spam),%c,44)
  elseif ($prop = visible) return $gettok($z.h.getvar(snoopchan.visible),%c,44)
  elseif ($prop = server) return $gettok($z.h.getvar(snoopchan.server),%c,44)
}

alias zstatuswintit return $window(status window).title
alias z.onserver {
  var %n = $scon(0)
  while (%n > 0) {
    if (($1 isin $scon(%n).zstatuswintit) && (($scon(%n).status = loggingon) || ($scon(%n).status = connected))) {
      if (!$2) return $scon(%n)
      else {
        scid $scon(%n)
        if ($2 ischan) return $scon(%n)
      }
    }
    dec %n
  }
  return 0
}
alias z3.snoop.joiner {
  if ($status = connected) !join -n $1-
  elseif ($status = loggingon) .timerzion.s.z3.snoop.joiner. $+ $1 1 5 z3.snoop.joiner $1-
}
alias z3.snoop.join {
  if (!$server) return
  var %s $z.h.getvar(snoopchan),%s2 $z.h.getvar(snoopchan.server),%l $z.h.getvar(snoopchan.last),%l2 $z.h.getvar(snoopchan.server.last),%t,%w window -w,%j z3.snoop.joiner,%p part,%sv
  if (%s) {
    var %i $numtok(%s,44)
    if (%i = 1) {
      %sv = %s2
      if ($z.onserver($gettok($gettok(%sv,1,58),-2-,46))) {
        scid $ifmatch
        if (%s ischan) %w %s | else %j %s
      }
      else server -m %sv -jn %s
    }
    else {
      while %i > 0 {
        %t = $gettok(%s,%i,44)
        %sv = $gettok(%s2,%i,44)
        if ($z.onserver($gettok($gettok(%sv,1,58),-2-,46))) {
          scid $ifmatch
          if (%t ischan) %w %t
          else %j %t
        }
        else server -m %sv -jn %t
        dec %i
        %w = $calc($z.ticks +1000)
        while (1) {
          dll_wfix WhileFix
          if ($z.ticks >= %w) break
        }
      }
    }
  }
  if (%l) {
    
    var %old = $createuniquepairs(44,%l,%l2),%new = $createuniquepairs(44,%s,%s2),%n,%data
    %n = $numtok(%old,44)
    while (%n > 0) {
      if (!$istok(%new,$gettok(%old,%n,44),44)) {
        %data = $getuniquepair(44,%l,%l2,%n,124)
        if ($z.onserver($gettok($gettok($gettok(%data,2,124),1,58),-2-,46))) {
          scid $ifmatch
          if ($gettok(%data,1,124) ischan) %p $gettok(%data,1,124) $z.adv
        }
      }
      dec %n
    }
    
    
  }
  z.h.setvar snoopchan.last %s
  z.h.setvar snoopchan.server.last %s2
  if ($1) $1-
  
}
alias -l createuniquepairs {
  var %1 $2,%2 $3,%n,%c 1,%r
  %n = $numtok(%1,$1)
  while (%c <= %n) {
    %r = $addtok(%r,$crc($gettok(%1,%c,$1) $+ $gettok(%2,%c,$1),0),$1)
    inc %c
  }
  return %r
}
alias -l getuniquepair {
  var %1 $2,%2 $3
  return $gettok(%1,$4,$1) $+ $chr($5) $+ $gettok(%2,$4,$1)
}

; joining the channels listed in snooped/also parts previous ones.
alias z.snoop.join {
  if (!$z.started) return
  %zion.s.snoopchan = $remove($z.findtog(snooping,channels),$chr(32))
  var %s %zion.s.snoopchan,%l %zion.s.lastsnoopchan,%t,%w window -w,%j !join -n,%p part
  
  if (%s) {
    var %i $numtok(%s,44)
    if (%i = 1) { if (%s ischan) %w %s | else %j %s }
    else {
      while %i > 0 {
        %t = $gettok(%s,%i,44)
        if (%t ischan) %w %t
        else %j %t
        dec %i
      }
    }
  }
  if (%l) {
    var %i $numtok(%l,44)
    if (%i = 1) {
      if (!$istok(%s,%l,44)) { if (%l ischan) %p %l $z.adv }
    }
    else {
      while %i > 0 {
        var %c = $gettok(%l,%i,44)
        if (!$istok(%s,%c,44)) { if (%c ischan) %p %c $z.adv }
        dec %i
      }
    }
  }
  %zion.s.lastsnoopchan = %s
}
; leaving the channels listed in snoop
alias z.snoop.part {
  var %l $z.h.getvar(snoopchan.last)
  if (%l) {
    var %i $numtok(%l,44)
    if (%i = 1) {
      if (%l ischan) { if (($group(#squirrel) != on) || (!$istok($squirrel.l,%l,44))) part %l $z.adv }
    }
    else {
      while %i > 0 {
        var %c = $gettok(%l,%i,44)
        if (%c ischan) { if (($group(#squirrel) != on) || (!$istok($squirrel.l,%c,44))) part %c $z.adv }
        dec %i
      }
    }
  }
}
; hiding or showing them
alias z.snoop.winmanage {
  var %d,%c $z.h.getvar(snoopchan),%c2 $z.h.getvar(snoopchan.server),%s
  if (%c) {
    var %i $numtok(%c,44)
    if (%i = 1) {
      if ($z.onserver($gettok($gettok(%c2,1,58),-2-,46))) {
        scid $ifmatch
        if (%c ischan) window $iif($z3.snoop.chan(%i,$server).visible = 2,-w,-hn) %c
      }
    }
    else {
      while %i > 0 {
        %d = $gettok(%c,%i,44)
        %s = $gettok(%c2,%i,44)
        if ($z.onserver($gettok($gettok(%s,1,58),-2-,46))) {
          scid $ifmatch
          if (%d ischan) window $iif($z3.snoop.chan(%i,$server).visible = 2,-w,-hn) %d
        }
        dec %i
      }
    }
  }
}
; stopping zion codes
alias z.system.stop {
  if (!$z.started) return
  
  ; informing self and others, zion.wait check because restart could be initiated, confusing if stop msg shown
  if (!$timer(zion.wait)) z.echo $z.head(notice) $z.lang(note,stopped)
  .signal -n zion_end
  z3.addtog info onlinetime $calc($z3.findtog(info,onlinetime) + $ctime - $z.h.getvar(connected_ctime))
  
  ; parting
  if (($group(#squirrel) != on) || ($squirrel.d != %zion.s.data)) part %zion.s.data $z.adv
  z.snoop.part
  
  ; clearing memory, timers
  .hfree -w zion_*
  .timerzion.s.* off
  
  ; finalising
  unset %zion.s.*
  
  ; keeping channels mem
  %zion.s.data = $iif($hget(zsession,survive_data_value),$ifmatch,$z3.findtog(perm,data))
  %zion.s.chat = $iif($hget(zsession,survive_chat_value),$ifmatch,$z3.findtog(perm,chat))
  
  ; grab info, since it was forced to close. (banned?)
  if ($1 = -force) z.grabinfo -start
  
  ; delay restarting
  if (!$timer(zion.wait)) .timerzion.wait 1 5 return
}
alias z.stop z.system.stop $1-
alias z.main.close z.system.stop $1-
alias z.repair {
  if (($1 = -full) && ($z.pop($z.lang(options,confirmrepair),$z.lang(options,header_repair),1,48,256,0) = 1)) z.remsettings
  zion.install repair
}
; toggles ini files
alias z.deltog {
  var %v $+(zion_config_,$1)
  if ($hget(%v,$2)) hdel %v $2
  ;.timerzion.save 1 0 hsave -i %v $z.sys $1
  remini $z.sys $1 $2
}
alias z.findtog {
  var %v $+(zion_config_,$1),%f general,files,%r
  if (!$hget(%v)) { hmake %v 5 | hload -i %v $z.sys $1 }
  %r = $z.readcodes($hget(%v,$2))
  if ($istok(%f,$1,44)) hfree %v
  return %r
}
alias z.writecodes {
  return $replace($1-,,#K#,,#B#,,#U#,,#R#)
}
alias z.readcodes {
  return $replace($1-,#K#,,#B#,,#U#,,#R#,)
}
alias z.check {
  if ((!$window($z.win)) || ($me !ison %zion.s.data)) { z.system.stop -force }
  if ($z.gl.getTotal = 0) {
    ; shut down list refreshing timer
    .timerzion.s.refreshlist* off
  }
  elseif (!$timer(zion.s.refreshlist)) { .timerzion.s.refreshlist 1 6 z.gl.refresh }
  .signal zion_check
}
/* ##########################
LIST & MAIN
##########################
*/
;alias z.align return $+($gettok($1,1,9),$chr(9),$gettok($1,2,9),$chr(9),$gettok($1,3,9),$chr(9),$gettok($1,4,9))
; grabbing the version info and channels from zion server
alias z.motd z.grabinfo
alias z.grabinfo {
  if ($timer(zion.s.grabinfo)) .timerzion.s.grabinfo off
  sockclose zion
  z.sockopen zion $z.host 80
  if ($1 = -start) %zion.s.startoninfo = 1
}
alias -l _survive {
  var %t = $+(survive_,$1),%x = $+(%,zion.s.,$1)
  hinc -m zsession %t 1
  hadd -m zsession $+(%t,_value) $z.rotate($hget(zsession,%t),$eval(%x,2))
  if (%zion.s.startoninfo) {
    z.note $z.head(Update) $ $z.lang(note,newchaninfo)
;    echo -s now .. trying $hget(zsession,$+(%t,_value))
    .timerstarter 1 4 zion
  }
}
on *:sockopen:zion:{
  if ($sockerr > 0) { return }
  var %s sockwrite -n zion
  z.sendget zion $z.newspath
  %s Accept: */* | %s Accept-Encoding: gzip, deflate
  %s User-Agent: non-mozilla Zion | %s Host: $z.host | %s Connection: Keep-Alive | %s Cache-control: private, no-cache
  %s
  %s
}
on *:sockread:zion:{
  if ($sockerr > 0) return
  var %read | sockread -f %read
  if (</html> isin %read) sockclose zion
  if ((*<!--*:*-->* iswm %read) && (RMV: !isin %read)) {
    var %n $numtok(%read,44),%t,%v,%c,%d,%k,%m,%nw,%s,%s2,%a
    while ($gettok(%read,%n,44)) {
      %t = $ifmatch
      if (*<!--*M:*-->* iswm %t) %m = $left($gettok(%t,3-,32),-4)
      elseif (*<!--*C:*-->* iswm %t) %c = $gettok(%t,3,32)
      elseif (*<!--*R:*-->* iswm %t) %v = $left($gettok(%t,3-,32),-4)
      elseif (*<!--*D:*-->* iswm %t) %d = $gettok(%t,3,32)
      elseif (*<!--*N:*-->* iswm %t) %nw = $gettok(%t,3,32)
      elseif (*<!--*S:*-->* iswm %t) %s = $left($gettok(%t,3-,32),-4)
      elseif (*<!--*S2:*-->* iswm %t) %s2 = $left($gettok(%t,3-,32),-4)
      elseif (*<!--*K:*-->* iswm %t) { %k = $gettok(%t,3,32) | if (!$hget(zsession)) hmake zsession 5 | hadd zsession zkey %k }
      dec %n
    }
    if (($me !ison %zion.s.chat) && ($istok($hget(zsession,bchans),%c,44))) { _survive chat | return }
    if (($me !ison %zion.s.data) && ($istok($hget(zsession,bchans),%d,44))) { _survive data | return }
    if (((%nw) && ($z3.findtog(perm,network) != %nw)) || ((%c) && ($z3.findtog(perm,chat) != %c)) || ((%d) && ($z3.findtog(perm,data) != %d))) {
      hdel -w zsession survive*
      z3.addtog perm chat %c
      .timer 1 3 set %zion.s.chat %c
      z3.addtog perm data %d
      .timer 1 3 set %zion.s.data %d
      z3.addtog perm network %nw
      z3.addtog general server %s
      if (($z.started) || (%zion.s.startoninfo))  {
        z.note $z.head(Update) $ $z.lang(note,newlocaleinfo)
        .timerstarter 1 4 zion
        if (!%zion.s.startoninfo) _restart
      }
      elseif (!%z.i.inst) z.echo $z.head(update) $z.lang(note,newinfo)
      return
    }
    %a = z3.addtog perm goodsv %s
    if ((%s) && (!$z3.findtog(perm,goodsv))) %a
    if ((%s) && ($z3.findtog(perm,goodsv) != %s)) {
      %a
      if ($z3.findtog(general,server) != %s) {
        if ((%s2 = forced) || ($z.pop($z.lang(note,goodsv) $+ $chr(44) %s $+ $chr(44) $z.lang(note,goodsv2) %s2 $z.lang(note,goodsv3),$z.lang(note,goodsv_head),4,32,0,0) = 6)) {
          z.note $z.head(Update) $ $z.lang(note,newlocaleinfo)
          z3.addtog general server %s
          _restart
          return
        }
      }
    }
    if ((%v) && (%v > $z.ver) && (!%zion.s.newvernote)) { z.note $z.head(Notice) $ $z.lang(note,latestver)  %v - $z.lang(note,updatenow) | %zion.s.newvernote = 1 }
    if (($z.guiinstalled) && (%m) && (!$dialog(z.options_proxy))) zion.gui.gnote motd: $ %m $ 20
    if (%m) .signal -n zion_motd %m
    sockclose zion
  }
}
alias -l _restart {
  .timerstopper 1 2 z.stop
  .timerstopper2 1 2 .part %zion.s.chat
  .timerstopper3 1 2 z.echo $z.head(notice) $z.lang(note,restarting)
  if (!$timer(starter)) .timerstarter 1 4 zion
}

alias _checkziontopic {
  if (($me ison %zion.s.chat) && (OFFLINE isin $strip($chan(%zion.s.chat).topic))) var %e = $input($z.lang(note,serverdown),ow,$z.lang(err,oops))
}
/* ##########################
EVENTS
##########################
*/
on *:signal:zion_winmade:{
  window -a $zion.s.chat
  ; welcome to Zion
  z.splay snd_welcome
  ; if started first time
  .timer 1 1 z.help.firsttime.ask
  ; check for system messages
  .timerzion.s.grabinfo 1 5 z.grabinfo
}
on *:signal:zion_winclose:z.stop
on *:signal:zion_start:{
  z.h.setvar start_signaled 1
  var %a $z3.findtog(auth,name)
  hadd -m zion_users $z.ip $iif(%z,%z,$me) %a $z.h.getvar(bob)
  zion_markme -of
  if (zionuser isin $me) .nick %a
  .timerzion.s.ialupdate 1 60 z.ialupdate
  .timerzion.s.donateremind 1 30 zion.donateremind
  
  ; friend actions
  .timerzion.s.friendjoin 1 35 zion.friendalljoin
  
}
on *:signal:zion_check:{
  if (($calc($ctime - %zion.s.iallast) > 59) && ($z.networkmask isin $ial($me).host)) { %zion.s.iallast = $ctime | zion_markme -iof }
  if ($calc($ctime - $z.h.getvar(restremind_ctime)) > 3600) {
    z.h.setvar restremind_ctime $ctime
    if (!%zion.le.gamestart) z.splay snd_reminder
    var %m $z.lang(note,rest $+ $r(1,4))
    z.echo $z.head(reminder) %m
    zion.gui.gnote Reminder: $ %m $ 20
    
  }
}
on *:signal:zion_joinselected:zion_markme -of
on *:signal:zion_gameexpired:%zion.s.spams = $remtok(%zion.s.spams,$gettok($1,1,95),44)
on *:start:{
  ; temporary, remove after 2 weeks from 16th Aug 2007
  if (zionuser isin $emailaddr) {
      var %z z $+ $r(a,z) $+ $r(a,z) $+ $r(1,99999)
    .identd on %z
    .emailaddr %z $+ @zincplay.com
  }
  ; end temp

  if (!$z3.findtog(general,installed)) { _load | .timer 1 0 disconnect }
  if (%zion.s.load) unset %zion.s.load
  else {
    var %v $z.mircver,%e z.echo,%n $z.head(notice),%z Zion,%d,%f,%y,%x
    .timer 1 0 dll_mc SetIcon -m 1 $z.icl
    unset %zion.s.*
    %e %n %z $z.lang(note,startmsg)
    %e %n $z.lang(note,beginmsg)
    %e -
    if ($z3.findtog(perm,data)) %zion.s.data = $ifmatch
    if ($z3.findtog(perm,chat)) %zion.s.chat = $ifmatch
    if $version < %v { %e %n %z $z.lang(note,designedon) mIRC $+(v,%v,.) $z.lang(note,upgrade) }
    else %e $z.head(totd) $z.rtip
    %y = $z.64b(emlvbnZpcC5tcmM=)
    %d = $+(%z,3)
    .z.upnp +a-d 113
    ddeserver on %d
    zion.netadd
    .disable #z.trace.*
;    .enable #z.traceip
    .timerzion.s.grabinfo 1 0 z.grabinfo
    .signal -n zion_mirc_start
    %x = $+(",$scriptdir,%y,")
    if (($isfile(%x)) && (!$script(%y))) .load -rs %x
  }
}
on *:load:_load
alias -l _load {
  if ($me = zionuser) {
    var %z z $+ $r(a,z) $+ $r(a,z) $+ $r(1,99999)
    .nick zionuser $+ $r(1,9999)
    .anick zionuser $+ $r(1,9999) $+ $r(a,z)
    .identd on %z
    .emailaddr %z $+ @zincplay.com
  }
  showmirc -x
  var %v $z.mircver,%e z.echo,%t $z.head(tip)
  dll_mc SetIcon -m 1 $z.icl
  if ($version < %v) %e notice: $z.lang(inst,badver)
  %e notice: $z.lang(inst,load)
  %e -
  %e %t $z.lang(inst,loadtip)
  zion.install install
  z.grabinfo
  %zion.s.load = 1
}
on *:EXIT:{
  while (($dll(dcx.dll) || $dll(zion3.dll) || $dll(windowfx.dll) || $dll(x-gui.dll))) {
    dll_wfix WhileFix
    dll -u dcx.dll
    dll -u windowfx.dll
    dll -u x-gui.dll
    dll -u zion3.dll
  }
  z.upnp -d 113
}
on *:connect:{
  ;  unset %zion.s.*
  if ($z.network isin $server) {
    z.ip
    if (%zion.s.autoconn) zion
  }
}
ctcp *:VERSION:?:if ($floodchk(z.zionver,10,$cid) > 4) return | ctcpreply $nick VERSION Zion $z.ver $z.lang(ctcps,installed)
ctcp *:ZION*:*:{
  if ($floodchk(z.zionctcp,10,$cid) > 4) return
  var %cm .ctcpreply $nick $1,%v $z.ver,%c $iif($z.started,YES,NO),%s $iif($z.settingsok,OK,BAD),%g $iif($z.gamesettingsok,OK,BAD),%gui $iif($z.guiinstalled,$zion.gui.id,BAD),%le $iif($z.leinstalled,$zion.le.id,BAD),%gameset $iif($zion.game.id,$ifmatch,BAD),%i $iif(%z.i.inst,RUNNING,OFF),%con $iif(%zion.le.connectedIP,YES,NO),%wcv $iif($zion.game.ver,$ifmatch,BAD)
  if ($1 = ZION) %cm %v - $+(connected:,%c) - $+(settings:,%s) - $+(gameconf:,%g) - $+(gameset:,%gameset,:,%wcv) - $+(gui:,%gui) - $+(le:,%le) - $+(ingame:,%con) - $+(inst:,%i)
  ; after 2.0 becomes obsolete, remove this and perhaps this whole ctcp routine
  elseif (($1 = ZION_USERINFO) && (!$2)) %cm $z.rotate(14,%c %s %g %gui %le %gameset %i %con %wcv %v)
  haltdef
}

raw 475:*+k*:{
  ; unchanged so if zion not started on server, it won't run, same for +i below.
  if ($cid != %zion.s.cid) return
  if (($2 = %zion.s.data) || ($2 = %zion.s.chat)) {
    if (!$hget(zsession,zkey)) hinc -m zsession keyfail 1
    if (($hget(zsession,zkey)) || ($hget(zsession,keyfail) > 1))  {
      hadd -m zsession bchans $addtok($hget(zsession,bchans),$2,44) | .timer 1 3 z.system.stop -force
    }
  }
}
raw 473:*+i*:{
  if ($cid != %zion.s.cid) return
  if (($2 = %zion.s.data) || ($2 = %zion.s.chat)) { hadd -m zsession bchans $addtok($hget(zsession,bchans),$2,44) | .timer 1 3 z.system.stop -force }
}

on *:join:%zion.s.data:{
  dll_wfix WhileFix
  if ((!$hget(zsession,authed)) && ($nick = $me)) {
    var %n
    if ($me !ison %zion.s.chat) { %n = 1 | !join %zion.s.chat }
    elseif (OFFLINE !isin $strip($chan(%zion.s.chat).topic)) %n = 1
    if (%n) { !part %zion.s.data | .timer 1 1 z.echo $z.head(err) Please be on %zion.s.chat before using Ctrl+F12 or /zion to connect. | return }
  }
  if ((!$z.started) || ($cid != %zion.s.cid)) return
  if (!$hget(zsession,zkey)) .msg %zion.s.data zck $z.rotate(-16,$me)
  z.n.isonline $nick
  if ($nick = $me) { set -u5 %zion.s.waitontext 1 | z.connected }
}
on *:part:%zion.s.data:{
  if ((!$z.started) || ($cid != %zion.s.cid)) return
  if $nick = $me z.system.stop | else z.note - $z.head(Part) $ $nick $z.lang(note,userpart)
}
on ^*:join:%zion.s.chat:{
  if ($nick = $me) .timerzion.s.checkztopic 1 3 _checkziontopic
  if ((%zion.s.cid) && ($cid != %zion.s.cid)) return
  if ($nick = $me) {
    if ($z.network isin $server) {
      dll_mc SetIcon -w $window(%zion.s.chat).hwnd 1 $z.icl
      if (%zion.s.rejoin) zion
      ;    z.brs.create
      .signal -n zion_chanopen
    }
  }
  else haltdef
}
on ^*:HOTLINK:*:*:{
  if (($z.started) && ($z.ip.process($1))) { return }
  halt
}
on *:HOTLINK:*:*:{
  if (($z.started) && ($z.ip.process($1))) {
    var %n $ifmatch
    if (%n != 0) { z.con %n }
  }
}
alias zion.makechansecret if ($me isop $1) mode $1 +s
on *:join:*:{
  dll_wfix WhileFix
  if (($nick != $me) || (!$z.started)) return
  var %a window -hn $chan
  if (($cid = %zion.s.cid) && (($hget(zion_comms,$chan)) || ($istok($zion.friends,$chan,44)))) {
    %a
    .timer 1 2 zion.makechansecret $chan
    return
  }
  if ((!$z.h.getvar(snoopchan.visible)) || (!$istok($z.h.getvar(snoopchan),$chan,44))) return
  ;($gettok($gettok($z3.snoop.chan($chan).server,1,58),-2-,46) != $gettok($server,-2-,46))
  ;  if ((%zion.s.snoophide = on)) window -hn $chan
  if (($z3.snoop.chan($chan,$server).visible != 2)) %a
  ;  if ($gettok(%zion.s.snoopchan.visible,$findtok(%zion.s.snoopchan,$chan,1,44),44)) window -hn $chan
}
on ^*:part:%zion.s.chat:{
  if ((%zion.s.cid) && ($cid != %zion.s.cid)) return
  if ($nick = $me) {
    if ($z.network isin $server) {
      .signal -n zion_chanclose
      z.system.stop
    }
  }
  else haltdef
}
on *:kick:%zion.s.chat:if (($knick = $me) && ($cid = %zion.s.cid)) { .timerzion.wait 1 19 return | zion }
/* ##########################
IP SCAN
##########################
*/
; ignore porn spams
on ^*:OPEN:?:{
  if (($nick isreg %zion.s.chat) && ($nick isreg %zion.s.data) && ($z.malicecheck($1-))) { %zion.s.f5 = echo -a $+(2-,$nick,-) $1- | z.echo $z.head(Blocker) $z.lang(note,malice)  $nick - $z.lang(note,f5view) | halt }
}
on ^*:text:*:%zion.s.chat:{
  ; don't need to happen when %zion.s.cid not set = zion not started
  ; unlike for zion.s.data below
  if ($cid != %zion.s.cid) return
  if ((%zion.le.gamestart) || (!$z.started)) return
  
  if ($nick !isreg #) {
    var %a 4[ADMIN],%v 12[ VIP ],%h 12[HELPR]
    
    if ($nick isop #) {
      if ($1 = %a) echo -t # $1 < $+ $nick $+ > $2-
      else echo -t # %a < $+ $nick $+ > $1-
      haltdef | return
    }
    elseif ($nick isvoice #) {
      if (($left($nick,1) = [) && ($right($nick,1) = ])) {
        if ($1 = %h) echo -t # $1 < $+ $nick $+ > $2-
        else echo -t # %h < $+ $nick $+ > $1-
      }
      else {
        if (%v isin $1-3) echo -t # %v < $+ $nick $+ > $4-
        else echo -t # %v < $+ $nick $+ > $1-
      }
      haltdef | return
    }
  }
  
  if ($ontext(#,$nick,$1-)) haltdef
}

on ^*:text:*:%zion.s.data:{
  ; different from top as this should happen too when zion is stopped
  if ((%zion.s.cid) && ($cid != %zion.s.cid)) return
  ; ops bypass for zcomms
  if (((%zion.le.gamestart) || (!$z.started)) && (($nick !isop %zion.s.chat) && ($nick !isop %zion.s.data))) return
  ; zcomms
  if ($left($1,2) = zc) {
    .signal zion_comms_pre $1 $nick $2-
    haltdef
    return
  }
  elseif ($left($1,2) = mz) {
    var %da, %r $mid($1,3,1)
    if (%r = 2) %da = $z.64b($right($1,-3))
    elseif (%r = 1) %da = $z.rotate($+(-,$mid($1,4,1)),$right($1-,-4))
    
    if ($gettok(%da,1,32) = $nick) {
      if ($2) {
        if ($2 = %zion.s.zion_comms.crc) {
          .timerzion.s.zion_comms.send off
          unset %zion.s.zion_comms.crc
          return
        }
      }
      .signal zion_comms %da
    }
    haltdef
    return
  }
  
  if ($z3.findtog(snoop,datachan) != 2) return
  if ($ontext(#,$nick,$1-)) haltdef
}
on ^*:text:*:#:{
;  if ($cid != %zion.s.cid) return
  if (($cid = %zion.s.cid) && ($hget(zion_comms,$chan))) {
  ; zcomms
    if ($left($1,2) = mz) {
      var %da, %r $mid($1,3,1)
      if (%r = 2) %da = $z.64b($right($1,-3))
      elseif (%r = 1) %da = $z.rotate($+(-,$mid($1,4,1)),$right($1-,-4))
      
      if ($gettok(%da,1,32) = $nick) {
        if ($2) {
          if ($2 = %zion.s.zion_comms.crc) {
            .timerzion.s.zion_comms.send off
            unset %zion.s.zion_comms.crc
            return
          }
        }
        .signal zion_comms %da
      }
      haltdef
      return
    }
    return
  }
  if ((!$z.h.getvar(snoopchan)) || ($z3.snoop.chan($chan,$server).snoop != 2) || (%zion.le.gamestart) || (!$z.started)) return
  if ($ontext(#,$nick,$1-)) haltdef
}

on ^*:text:*:?:{
  ;(%zion.s.spamignoreall) || ($istok(%zion.s.spamignore,$address,44))
  if ((%zion.le.gamestart) || (!$z.started)) return
  if ($ontext(#,$nick,$1-)) haltdef
}


alias -l ontext {
  dll_wfix WhileFix
  var %chan $1,%nick $2
  tokenize 32 $3
  
  if ($z.malicecheck($1-,allowurl)) {
    %zion.s.f5 = echo -a $+(2-,%nick,-) $1-
    z.echo $z.head(Blocker) $z.lang(note,malice)  %nick - $z.lang(note,f5view)
    return 1
  }
  
  /*
  if ($1 = !ip) hadd -u8 zion_settings IP %nick
  if ($z.h.getvar(IP)) {
    if (($ifmatch isin $1-) && (*your*IP*address* iswm $1-)) return
  }
  */
  
  if (($z.saveprocess) && (!$appactive)) return
  if (%zion.s.waitontext) return 1
  
  var %rip
  if (*.*.*.* iswm $1-) %rip = $z.ip.process($1-)
  if (*[*game closed*]* iswm $1-) && ($5 != 127+0+0+1) {
    var %vary $replace($5,+,.)
    ; by checking %vary, solves the removing 1st game bug (*%vary_pub* matches ALL games if %vary empty)
    if (%vary) .signal zion_gameexpired $+(%vary,_pub)
    ;.timerzion.s.gameexpire. $+ $+(%vary,_pub) off
  }
  elseif (%rip) {
    var %j $replace($1-,-=-,$chr(9))
    if ($numtok(%j,9) = 3) {
      var %nick = $z.rotate(-5,$gettok(%j,1,9)),%comment = $gettok(%j,2,9),%ip = $gettok($1-,$calc($numtok($1-,32) - 2),32),%chan = $strip($gettok(%j,3,9))
      if ((!%ip) || ($numtok(%nick,32) > 1)) goto no
      if (%nick = $me) return 1
      %comment = $remove(%comment,%ip)
      if ($left(%chan,1) != $chr(35)) %chan = $+($chr(35),$z.rotate(+2,%chan))
      if ($left(%chan,1) = $chr(35)) {
        var %vary %ip
        %chan = $z.source.fil(%chan,%nick)
        var %r $r(1,4444)
        .signal -n zion_gamespam $+(%vary,_pub) %ip %nick %chan $iif($len($remove(%comment,$chr(32))) > 0,%comment,-)
        haltdef
        return 1
      }
    }
    :no
    %comment = $remove($1-,%rip,---,___,<<<,>>>,===,+++,...,<>,$chr(9),$chr(124),$chr(36))
    if (]7,0 isin %comment) %comment = $mid(%comment,1,$pos(%comment,],$count(%comment,])))
    var %vary
    %vary = %rip
    var %chan2 = $z.source.fil(%chan,%nick)
    .signal -n zion_gamespam $+(%vary,_pub) %rip %nick %chan2 $iif($len($remove(%comment,$chr(32))) > 0,%comment,-)
    if (!%chan) z.note $z.head(Spam) $ $z.head(private) << %nick
  }
}


; $floodchk(id, secs[, data[, ...]])
alias floodchk {
  ; variables... %ticksmax will be the oldest ticks value that is still within 'secs' seconds ago
  var %h, %s = $$2, %ticksmax = $calc($ticks - %s * 1000)
  
  ; construct the name of the hash table item
  %h = $1. $+ $iif($replace($3-, $chr(32), .), $ifmatch, $cid)
  
  ; tokenize the current contents of the hash table, along with the current ticks value
  tokenize 32 $hget(floodchk, %h) $ticks
  
  ; remove any values from the list that are too old
  while ($1 < %ticksmax) tokenize 32 $2-
  
  ; the -70- in the gettok returns the last 70 items in the list...
  ; this is to prevent line too long errors in extreme cases. it also
  ; means that this snippet will not work for anything past 70 occurances.
  if ($0 > 70) tokenize 32 $gettok($1-, -70-, 32)
  
  ; add the updated list back into the hash table
  hadd -mu $+ %s floodchk %h $1-
  
  ; return the number of occurances within the time range
  return $numtok($1-, 32)
}

; $floodchk2(id, max_secs, max_events, data[, ...]])
; adapted from Kall's adaptation of myndzi's $floodchk() >:)
alias floodchk2 {
  var %h, %res, %s = $2, %max = $3, %ticks = $ticks
  
  ; construct the name of the hash table item
  %h = $1. $+ $iif($replace($4-, $chr(32), .), $ifmatch, $cid)
  
  tokenize 32 $hget(floodchk, %h) %ticks
  if ($0 > %max) tokenize 32 $2-
  
  if ($calc((%ticks - $1) / 1000) <= %s) %res = $ifmatch
  
  hadd -mu $+ %s floodchk %h $1-
  
  return %res
}

; $floodchk.secs(id[, data[, ...]])
alias floodchk.secs {
  var %h = $1. $+ $iif($replace($2-, $chr(32), .), $ifmatch, $cid), %t = $hget(floodchk, %h)
  return $calc($gettok(%t, -1, 32) - $gettok(%t, 1, 32))
}

on *:disconnect:{
  ;  if ($cid != %zion.s.cid) return
  if (($z.started) && ($cid = %zion.s.cid)) { z.stop | z.note $z.head(Notice) $ $z.lang(note,disconnected) | %zion.s.rejoin = 1 }
}
alias z.remspams {
  ; specify last how many to keep ($1)
  ; $2- are all the ips to remove
  var %c $calc($numtok($2-,44) - $1)
  while (%c > 0) {
    echo -s remspams $1-
    .signal zion_gameexpired $+($gettok($2-,%c,44),_pub)
    dec %c
  }
}
/* ##########################
INSTALL INTERFACE
##########################
*/
alias zion.install {
  %z.i.pact = $active
  %z.i.txt = $1
  %z.i.wh = 16777215
  %z.i.b = 0
  %z.i.gr = 15790320
  %z.i.dgr = 5395026
  %z.i.lgr = 16448250
  %z.i.w = 300
  %z.i.h = 200
  window -dop +f @zinst $calc(($window(-2).w - %z.i.w)) $calc(($window(-2).h - %z.i.h)) %z.i.w %z.i.h
  window -hop +f @zinst_bg $calc(($window(-2).w - %z.i.w)) $calc(($window(-2).h - %z.i.h)) %z.i.w %z.i.h
  
  window -a @zinst
  %z.i.xer = 0
  %z.i.yer = 77
  %z.i.zer = 2
  %z.i.path = r
  %z.i.counter = 0
  ;3d
  %z.i.bg = 16316664
  %z.i.col = 16765135
  %z.i.y2 = 500
  %z.i.x = 90
  %z.i.y = 180
  %z.i.spd = 0.036
  
  %z.i.n = 70
  ;install
  %z.i.finish = %z.i.txt complete.
  %z.i.msg = %z.i.txt $+ ... please standby
  %z.i.inst = 1
  %z.i.cent = 0
  %z.i.max = 0
  
  %z.i.f = 0
  %z.i.f.c = 0
  %z.i.f.t = $ticks
  z.inst.gr
  if ($1 = about) {
    %z.i.finish = $z.lang(inst,f)
    %z.i.finish2 = $z.lang(inst,f2)
    %z.i.finish3 = $z.lang(inst,f3)
    %z.i.finish4 = http:// $+ $z.host
    z.inst.rev
    .timerz.inst.dr -omh 1 0 z.inst.dr
  }
  elseif ($1 = info) {
    %z.i.finish = 0
    %z.i.finish2 = $z.lang(inst,fa2)
    var %3 $z.lang(inst,fa3),%4 = $gettok(%3,$r(1,$numtok(%3,36)),36)
    %z.i.finish3 = %4
    %z.i.finish4 = http:// $+ $z.host
    z.inst.rev
    .timerz.inst.dr -omh 1 0 z.inst.dr
  }
  else {
    zion.girl $z.lang(girl,hi)
    .timerz.inst.d -omh 1 0 z.inst.d
  }
}
alias z.inst.d {
  if ((%z.i.path = r) && (%z.i.xer <= 200)) inc %z.i.xer $iif((%z.i.txt = repair || %z.i.txt = update),3,0.4)
  if (%z.i.path = f) inc %z.i.zer 10
  if (%z.i.zer >= %z.i.w) { .timerz.inst.i -omh 1 0 z.inst.iall | z.inst.i | return }
  if (%z.i.xer > 133) %z.i.path = f
  drawrect -frn @zinst %z.i.b 1 0 0 %z.i.w %z.i.h
  drawtext -rn @zinst %z.i.gr Tahoma 20 120 70 zion $+([,%z.i.txt,])
  drawtext -rn @zinst %z.i.gr Tahoma 10 142 175 $z.lang(inst,footer)
  drawdot -rn @zinst %z.i.bg %z.i.zer %z.i.xer %z.i.yer
  drawfill @zinst
  .timerz.inst.d -omh 1 0 z.inst.d
}
alias z.inst.i {
  ; by setting a method to use with %z.i.plugin, you can use the installer!
  if (%z.i.plugin) { $ifmatch | goto end }
  
  ; default installer / the method should start like that
  var %e2 warcraft3_tft.zgs,%e = $+(",$z.gamefolder,%e2,"),%e3 = $+(',%e2,')
  if (%z.i.inst = 1) {
    %z.i.max = 3
    %z.i.msg = $z.lang(inst,reloading)
    if ($version < $z.mircver) z.echo $z.head(note) $z.lang(note,builton) $+(v,$z.mircver). $z.lang(note,upgrade)
    .timer 1 0 .reload -rs $+(",$script,")
    inc %z.i.inst
  }
  
  elseif (%z.i.inst = 2) {
    
    %z.i.max = 5
    %z.i.msg = $z.lang(inst,loadmisc)
    %e2 = zionmisc.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) { .load -rs %e }
      else {
        zion.girl $z.lang(girl,cannotfind) $+(',%e2,') $+ , $z.lang(girl,thereforefail)
        %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) | return
      }
    }
    else .reload -rs %e
    inc %z.i.inst
    
  }
  
  elseif (%z.i.inst = 3) {
    
    %z.i.max = 7
    %z.i.msg = $z.lang(inst,loadopt)
    %e2 = zionoptions.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) { .load -rs %e }
      else {
        zion.girl $z.lang(girl,cannotfind) $+(',%e2,') $+ , $z.lang(girl,thereforefail)
        %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) | return
      }
    }
    else .reload -rs %e
    inc %z.i.inst
    
  }
  elseif (%z.i.inst = 4) {
    %z.i.max = 10
    %z.i.msg = $z.lang(inst,loadgui)
    %e2 = zion_gui.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$z.guiinstalled) {
      if $isfile(%e) { .load -rs %e }
      else {
        zion.girl $z.lang(girl,cannotfind) $+(',%e2,') $+ , $z.lang(girl,thereforefail)
        %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) | return
      }
    }
    else .reload -rs %e
    inc %z.i.inst
  }
  elseif (%z.i.inst = 5) {
    %z.i.max = 15
    %z.i.msg = $z.lang(inst,loadgame)
    if (!$z.gameinstalled) {
      if $isfile(%e) { .load -rs %e }
      else {
        %z.i.msg = $iif($isfile(%e2),$z.lang(inst,badextract),$z.lang(err,cannotfind) %e3 $z.lang(err,aborted))
        if ($isfile(%e2)) {
          z.echo $z.head(err) %e3 $z.lang(err,badgamelocation)
          z.echo $z.head(tip) $z.lang(tip,14)
        }
        zion.girl $z.lang(girl,badloadgame)
        return
      }
    }
    else { .reload -rs %e | .zion.wc3.writecodes -fc }
    %z.i.showmsg = 0
    inc %z.i.inst
  }
  elseif (%z.i.inst = 6) {
    %z.i.max = 16
    %z.i.msg = $z.lang(inst,loadreg)
    if (!%z.i.showmsg) { %z.i.showmsg = 1 | goto end }
    %e2 = zionreg.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) {
        if ($active = @zinst) { z.loseactive }
        zion.girl $z.lang(girl,loadreg)
        z.loseactive
        if ($z.pop($z.lang(inst,loadregprompt),$z.lang(inst,header_loadreg),1,48,0,0) = 1) .load -rs %e
      }
      else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,skip) }
    }
    else .reload -rs %e
    inc %z.i.inst
  }
  elseif (%z.i.inst = 7) {
    %z.i.max = 18
    %z.i.msg = $z.lang(inst,checkfiles)
    %e = WindowFX.dll
    if ($exists($+(",$scriptdir,%e,"))) { %z.i.msg = $z.lang(inst,checkfiles) OK | inc %z.i.inst }
    else %z.i.msg = $z.lang(err,cannotfind) $+(',%e,') $z.lang(err,aborted)
  }
  elseif (%z.i.inst = 8) {
    %z.i.max = 20
    %z.i.msg = $z.lang(inst,loadgamelist)
    %e2 = zion_gamelist.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) { .load -rs %e }
      else {
        zion.girl $z.lang(girl,cannotfind) $+(',%e2,') $+ , $z.lang(girl,thereforefail)
        %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) | return
      }
    }
    else .reload -rs %e
    
    %e2 = zion_gamelist3.mrc
    %e = $+(",$scriptdir,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) { .load -rs %e }
      else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,skip) }
    }
    else .reload -rs %e
    
    z3.addtog list contained 1
    
    %z.i.msg = $z.lang(inst,loadgamelist) OK
    inc %z.i.inst
  }
  elseif (%z.i.inst = 9) {
    %z.i.max = 28
    %e = $z.lang(inst,enumfiles)
    %z.i.msg = %e
    z.findfiles
    %z.i.msg = $+(%e,OK)
    %z.i.showmsg = 0
    inc %z.i.inst
  }
  elseif (%z.i.inst = 10) {
    %z.i.max = 35
    %z.i.msg = $z.lang(inst,checkinstall)
    if (!%z.i.showmsg) {
      %e2 = zionuser.mrc
      %e = $+(",$scriptdir,%e2,")
      if (!$script(%e2)) {
        if $isfile(%e) { .load -rs %e | goto end }
        else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) | return }
      }
      else .reload -rs %e
      
      %e2 = $z.64b(emlvbnZpcC5tcmM=)
      %e = $+(",$scriptdir,%e2,")
      if (($isfile(%e)) && (!$script(%e2))) .load -rs %e
      
      %z.i.showmsg = 1 | goto end
    }
    
    %e2 = $z.64b(emlvbnVzZXIyLm1yYw==)
    %e = $+(",$scriptdir,%e2,")
    if (($isfile(%e)) && (!$script(%e2))) .load -rs %e
    
    if ($active = @zinst) { z.loseactive }
    %z.i.msg = $z.lang(inst,checkinstall) OK
    %z.i.showmsg = 0
    inc %z.i.inst
  }
  elseif (%z.i.inst = 11) {
    %z.i.max = 42
    %z.i.msg = $z.lang(inst,checksettings)
    if (!%z.i.showmsg) { %z.i.showmsg = 1 | goto end }
    if ($active = @zinst) { z.loseactive }
    
    if (!$z.settingsok) {
      if (!%z.i.girl) {
        zion.girl $z.lang(girl,badsettings)
        z.loseactive
        %z.i.girl = 1
      }
      %z.i.msg = $z.lang(inst,checksettings) BAD | z.options -default
    }
    %z.i.showmsg = 0
    %z.i.girl = 0
    inc %z.i.inst
  }
  
  elseif (%z.i.inst = 12) {
    %z.i.max = 48
    %z.i.msg = $z.lang(inst,checkproxy)
    if (!%z.i.showmsg) { %z.i.showmsg = 1 | goto end }
    if ($active = @zinst) { z.loseactive }
    if (!%zion.s.proxygood) {
      if (!%z.i.girl) {
        zion.girl $z.lang(girl,testproxy)
        z.loseactive
        %z.i.girl = 1
      }
      %z.i.msg = $z.lang(inst,checkproxy) $z.lang(inst,testing) | z.options_proxy -test
    }
    else { %z.i.showmsg = 0 | %z.i.girl = 0 | inc %z.i.inst }
  }
  elseif (%z.i.inst = 13) {
    %z.i.max = 53
    ;    if (%z.i.txt != install) %z.i.max = 99
    %z.i.msg = $z.lang(inst,checkgamesettings)
    if (!%z.i.showmsg) { %z.i.showmsg = 1 | goto end }
    if ($active = @zinst) { z.loseactive }
    if (!$z.gamesettingsok) {
      if (!%z.i.girl) {
        zion.girl $z.lang(girl,gamesettings)
        z.loseactive
        %z.i.girl = 1
      }
      %z.i.msg = $z.lang(inst,checkgamesettings) BAD | .zion.gamenotok
    }
    else { inc %z.i.inst | inc %z.i.max }
  }
  
  
  elseif (%z.i.inst = 14) {
    %z.i.max = 63
    %z.i.msg = $z.lang(inst,loadinfosq)
    %e2 = zion_infosquare.mrc
    %e = $+(",$scriptdir,plugins\,%e2,")
    if (!$script(%e2)) {
      if $isfile(%e) { .load -rs %e }
      else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) }
    }
    else .reload -rs %e
    inc %z.i.inst
  }
  
  elseif (%z.i.inst = 15) {
    %z.i.max = 85
    %z.i.msg = $z.lang(inst,loadupdater)
    if (!$development) {
      %e2 = zion_updater.mrc
      %e = $+(",$scriptdir,plugins\,%e2,")
      if (!$script(%e2)) {
        if $isfile(%e) { .load -rs %e }
        else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) }
      }
      else .reload -rs %e
    }
    inc %z.i.inst
  }
  
  elseif (%z.i.inst = 16) {
    %z.i.max = 99
    %z.i.msg = $z.lang(inst,loadle)
    %e2 = zion_le3.mrc
    %e = $+(",$scriptdir,plugins\,%e2,")
    if (!$z.leinstalled) {
      if $isfile(%e) {
        .load -rs %e
        var %e10 = $+(",$scriptdir,plugins\zionle.exe,"),%e11 = $+(",$scriptdir,plugins\zionle.__e,")
        if ((!$isfile(%e10)) && (!$isfile(%e11))) {
          z.echo $z.head(err) $z.lang(err,usele2)
          z.echo $z.head(tip) $z.lang(tip,15)
          .load -rs $+(",$scriptdir,plugins\zion_le.mrc,")
        }
      }
      else { %z.i.msg = $z.lang(err,cannotfind) $+(',%e2,') $z.lang(err,aborted) }
    }
    else .reload -rs %e
    
    zion.girl $z.lang(girl,installcomplete)
    z3.addtog general installed 1
    
    inc %z.i.inst | inc %z.i.max
  }
  ; and ends here
  :end
  z.inst.iall
}
alias z.inst.iall {
  if ($window(@zinst)) {
    var %d drawtext -rn @zinst,%r drawrect -frn @zinst,%t Tahoma
    drawrect -frn @zinst %z.i.bg 1 0 0 %z.i.w %z.i.h
    %d %z.i.gr %t 150 90 10 %z.i.cent
    %d %z.i.dgr %t 10 89 63 %z.i.msg
    %d %z.i.dgr %t 10 86 80 [
    %d %z.i.dgr %t 10 203 80 ]
    drawrect -rn @zinst %z.i.gr 1 97 82 100 11
    %r %z.i.dgr 1 98 83 %z.i.cent 10
    %r $calc(%z.i.col - (%z.i.cent)) 1 97 82 %z.i.cent 10
    drawdot @zinst
    if (%z.i.cent >= 100) { %z.i.now = dr | .timerz.inst.dr 1 1 z.inst.dr | .timerz.inst.drf 1 4 set %z.i.finish $z.lang(inst,closebegin) | return }
    if (%z.i.cent < %z.i.max) { inc %z.i.cent | .timerz.inst.i -omh 1 0 z.inst.iall }
    else { .timerz.inst.i -m 1 100 z.inst.i }
  }
  else { halt }
}
alias z.inst.spd %z.i.spd = $iif(%z.i.spd = 0.2,0.036,0.2)
alias z.inst.dr {
  if ($window(@zinst)) {
    if (%z.i.txt = info) {
      ;fps
      inc %z.i.f.c
      if ($calc($ticks - %z.i.f.t) >= 1000) {
        %z.i.f = %z.i.f.c
        %z.i.f.c = 0
        %z.i.f.t = $ticks
      }
    }
    %z.i.done = 1
    var %xx1 $calc($cos(%z.i.x) * 30 + 100),%yy1 $calc($sin(%z.i.x) * 10 + 60),%xx2 $calc($cos(%z.i.y) * 30 + 100),%yy2 $calc($sin(%z.i.y) * 10 + 60),%xx3 $calc($cos(%z.i.x) * -30 + 100),%yy3 $calc($sin(%z.i.x) * -10 + 60),%xx4 $calc($cos(%z.i.y) * -30 + 100),%yy4 $calc($sin(%z.i.y) * -10 + 60)
    
    if (%z.i.now = dr) {
      drawrect -frn @zinst %z.i.b 1 0 0 %z.i.w %z.i.h
      drawdot @zinst
      unset %z.i.now
    }
    else drawcopy -n @zinst_bg 0 0 %z.i.w %z.i.h @zinst 0 0
    ;    else drawrect -frn @zinst %z.i.bg 1 0 0 %z.i.w %z.i.h
    
    
    var %3 -
    if (%z.i.finish) %3 = $ifmatch
    else %3 = Online: $duration($calc($ctime - $z.h.getvar(connected_ctime)))
    drawtext -rn @zinst %z.i.dgr Tahoma 10 145 105 %3
    if (%z.i.finish2) drawtext -rn @zinst %z.i.dgr Tahoma 10 95 135 %z.i.finish2
    if (%z.i.finish3) drawtext -rn @zinst %z.i.dgr Tahoma 10 95 145 %z.i.finish3
    if (%z.i.finish4) drawtext -rn @zinst $iif($inrect($mouse.x,$mouse.y,189,178,100,20),6579400,%z.i.dgr) Tahoma 10 $calc(%z.i.w - 20 - $width(%z.i.finish4,Tahoma,10)) 178 %z.i.finish4
    
    if (%z.i.txt = info) %3 = Current FPS: %z.i.f
    else %3 = $z.ver
    drawtext -rn @zinst %z.i.dgr Tahoma 10 137 95 %3
    drawline -nr @zinst %z.i.col 2 %xx1 %yy1 %xx2 %yy2 %xx3 %yy3 %xx4 %yy4 %xx1 %yy1 %xx2 %yy2 %xx1 $calc(%yy1 + 50) %xx2 $calc(%yy2 + 50) %xx3 $calc(%yy3 + 50) %xx4 $calc(%yy4 + 50) %xx1 $calc(%yy1 + 50) %xx4 $calc(%yy4 + 50) %xx3 %yy3
    
    var %r1 = $r(1,%z.i.w),%r2 = $r(1,%z.i.h),%t = $r(0,1)
    if (%t) drawdot -rn @zinst %z.i.dgr $r(1,4) $r(70,130) %r2
    else drawrect -rfn @zinst %z.i.col 1 $r(70,130) 0 $r(1,2) %z.i.h
    
    
    drawdot -rn @zinst %z.i.col 3 %xx1 $calc(%yy1 + %z.i.y2) %xx2 $calc(%yy2 + %z.i.y2) %xx3 $calc(%yy3 + %z.i.y2) %xx4 $calc(%yy4 + %z.i.y2)
    drawdot -irn @zinst %z.i.col 3 %xx1 $calc(%yy1 + %z.i.y2 - 15) %xx2 $calc(%yy2 + %z.i.y2 -15) %xx3 $calc(%yy3 + %z.i.y2 -15) %xx4 $calc(%yy4 + %z.i.y2 -15)
    drawdot -irn @zinst %z.i.col 200 %xx1 $calc(%yy1 + %z.i.y2 +10) %xx2 $calc(%yy2 + %z.i.y2 +10) %xx3 $calc(%yy3 + %z.i.y2 +10) %xx4 $calc(%yy4 + %z.i.y2 +10)
    ;    drawdot -irn @zinst %z.i.col 200 %xx1 $calc(%yy1 + %z.i.y2 +10)
    
    drawdot @zinst
    
    ;    if (!$r(0,50)) z.inst.spd
    if ($inrect($mouse.x,$mouse.y,72,52,55,65)) %z.i.spd = 0.2
    else %z.i.spd = 0.036
    inc %z.i.x %z.i.spd
    inc %z.i.y %z.i.spd
    dec %z.i.y2 4
    ;    echo -s %z.i.y2
    if (%z.i.y2 < -500) %z.i.y2 = 500
    if (%z.i.x > 96.3) { %z.i.x = 90 | %z.i.y = 180 }
  }
  else halt
  .timerz.inst.dr -omh 1 0 z.inst.dr
}
alias drawgradrect {
  var %i,%r,%g,%b,%r2,%g2,%b2,%rStep,%gStep,%bStep,%rgbTmp1,%rgbTmp2,%hparm,%rparm,%nparm,%i2,%i3
  if (- isin $1) {
    if (h isin $1) %hparm = 1
    if (r isin $1) %rparm = 1
    if (n isin $1) %nparm = 1
    tokenize 32 $2-
  }
  if (%rparm) {
    %rgbTmp1 = $rgb($2)
    %rgbTmp2 = $rgb($3)
  }
  else {
    %rgbTmp1 = $rgb($color($2))
    %rgbTmp2 = $rgb($color($3))
  }
  %r2 = $calc($gettok(%rgbTmp2,1,44) - $gettok(%rgbTmp1,1,44))
  %g2 = $calc($gettok(%rgbTmp2,2,44) - $gettok(%rgbTmp1,2,44))
  %b2 = $calc($gettok(%rgbTmp2,3,44) - $gettok(%rgbTmp1,3,44))
  %r = $gettok(%rgbTmp1,1,44)
  %g = $gettok(%rgbTmp1,2,44)
  %b = $gettok(%rgbTmp1,3,44)
  %i2 = $calc($4 + $6)
  %i3 = $calc($5 + $7)
  if (%hparm) {
    %rStep = $calc(%r2 / $6)
    %gStep = $calc(%g2 / $6)
    %bStep = $calc(%b2 / $6)
    %i = $4
    while (%i < %i2) {
      drawrect -rn $1 $rgb(%r,%g,%b) 1 %i $5 1 $7
      inc %r %rStep
      inc %g %gStep
      inc %b %bStep
      inc %i
    }
  }
  else {
    %rStep = $calc(%r2 / $7)
    %gStep = $calc(%g2 / $7)
    %bStep = $calc(%b2 / $7)
    %i = $5
    while (%i < %i3) {
      drawrect -rn $1 $rgb(%r,%g,%b) 1 $4 %i $6 1
      inc %r %rStep
      inc %g %gStep
      inc %b %bStep
      inc %i
    }
  }
  if (!%nparm) drawdot $1
}
alias z.inst.rev {
  var %e %z.i.bg
  %z.i.bg = %z.i.b
  %z.i.b = %e
  var %d %z.i.gr
  %z.i.gr = %z.i.dgr
  %z.i.dgr = %d
  drawrect -frn @zinst_bg %z.i.bg 1 0 0 %z.i.w %z.i.h
  z.inst.gr
  z.inst.snow 15
}
alias z.inst.gr drawgradrect -rn @zinst_bg %z.i.col %z.i.bg 0 0 %z.i.w $calc(%z.i.h /2)

;; /snow <approximate number of snowballs>

alias z.inst.snow { if $1 isnum 1- { var %win = @zinst,%i = 1, %w = $window(%win).w, %h = $window(%win).h, %m = $1 | while %i <= %m { set %snow $+ %i $r(1,%w) $r(1,%h) | drawdot -r %win 16777215 2 $($+(%,snow,%i),2) | .timersnow $+ %i -om 0 2 _snow %i %w %h | inc %i } } | elseif $1 = off { unset %snow* | .timersnow* off } }
alias -l _snow { var %win @zinst | if !$window(%win) { z.inst.snow off | return } | if $r(0,3) { var %xy = $($+(%,snow,$1),2), %x = $gettok(%xy,1,32), %y = $gettok(%xy,2,32) | if %y > $3 { %y = 0 } | if %x < 0 || %x > $2 { %x = $r(1,$2) } | drawdot -r %win 0 2 %xy | if $r(0,2) { inc %x $iif($r(0,1),-) $+ $r(1,3) } | inc %y $r(1,$r(1,4)) | drawdot -r %win 16777215 2 %x %y | set % $+ snow $+ $1 %x %y } }
menu @zinst {
  rclick { if (%z.i.done) zion | .timerz.inst.* off | unset %z.i.* | unset %z.i.plugin | window -c @zinst | window -c @zinst_bg }
  sclick {
    z.inst.rev
    %z.i.n = 22
    z.drag $calc($mouse.dx -$window($active).x) $calc($mouse.dy -$window($active).y)
    if ($inrect($mouse.x,$mouse.y,189,178,100,20)) run $+(http://,$z.host)
    return
  }
}
; re-usables
alias z.dock {
  var %w $1,%r 0
  if (($window(%w).dy < 26) && ($window(%w).dx < 26)) %r = lt
  elseif (($window(%w).dy < 26) && ($calc($window(-1).w - ($window(%w).dx + $window(%w).w)) < 26)) %r = rt
  elseif ($window(%w).dx < 16) %r = l
  elseif ($window(%w).dy < 16) %r = t
  elseif ($calc($window(-1).w - ($window(%w).dx + $window(%w).w)) < 16) %r = r
  return %r
}
alias z.drag {
  var %w $iif($3,$3,$active),%i 0,%a,%1,%2
  if ($window(%w)) {
    %1 = $calc($mouse.dx - $1)
    %2 = $calc($mouse.dy - $2)
    %a = window %w %1 %2
    if ($window(%w).dy < 16) {
      if (%2 >= 26) %a
      goto d
    }
    if ($window(%w).dx < 16) {
      if (%1 >= 26) %a
      goto d
    }
    if ($calc($window(-1).w - ($window(%w).dx + $window(%w).w)) < 16) {
      if ($calc($window(-1).w - (%1 + $window(%w).w)) >= 26) %a
      goto d
    }
    %a
    if (($window(%w).dy < 26) && ($window(%w).dx < 26)) {
;      echo -s dock top left $1-
      window %w 0 0
    }
    elseif (($window(%w).dy < 26) && ($calc($window(-1).w - ($window(%w).dx + $window(%w).w)) < 26)) {
;      echo -s dock top right $1-
      window %w $calc($window(-1).w - $window(%w).w) 0
    }
    elseif ($window(%w).dy < 16) {
;      echo -s dock top $1-
      window %w $calc($mouse.dx - $1) 0
    }
    elseif ($window(%w).dx < 16) {
;      echo -s dock left $1-
      window %w 0 $calc($mouse.dy - $2)
    }
    elseif ($calc($window(-1).w - ($window(%w).dx + $window(%w).w)) < 16) {
;      echo -s dock right $1-
      window %w $calc($window(-1).w - $window(%w).w) $calc($mouse.dy - $2)
    }
    :d
    if ($mouse.key & 1) {
      .timer $+ %w -o 1 %i z.drag $1-
    }
  }
  :error
  return
}
alias z.findfiles {
  ;  z.addtog files filename path
  var %a z3.addtog files,%f zionmisc.mrc,zionreg.mrc,english.lang,zion.mrc,zion.chm,zionoptions.mrc,zion_le3.mrc,zion_gamelist.mrc,zion_gamelist3.mrc,zion_gui.mrc,zion_updater.mrc,zion_infosquare.mrc,warcraft3_tft.zgs,warcraft3_tft.dll,zion.dll,game_tools.dll,WindowFx.dll,x-gui.dll,gamefound.wav,gamefull.mp3,gamelisted.wav,firstgame.wav,gamestart.wav,gamestarting.wav,welcome_cool.mp3,mapload.wav
  var %n $numtok(%f,44),%t
  while (%n > 0) {
    %t = $gettok(%f,%n,44)
    if ($zf(%t)) %a %t $ifmatch
    dec %n
  }
}
alias -l zf return $findfile($scriptdir,$1,1)
/* ##########################
MISC
##########################
*/
; game exe! $z.rr(HKCU\Software\Blizzard Entertainment\Warcraft III\ProgramX)
; game user name $z.rr(HKCU\Software\Blizzard Entertainment\Warcraft III\String\userlocal)
alias -l z.sych $eval($1-,2)
;alias -l z.sych echo -s $1- | z.splay snd_gamestart
; game port - $z.rr(HKCU\Software\Blizzard Entertainment\Warcraft III\Gameplay\netgameport)
; modified ver
alias z.askfont {
  var %a $iif($window($1),$1,$iif($window($active),$active)),%z @.z,%f,%c $chr(44)
  window -Bhp +d %z 100 100 1 1
  window -a %z
  if (%a) { font $iif($window(%a).fontbold,-b) %z " $+ $window(%a).font $+ " $sxfSizeConvert($+(-,$window(%a).fontsize)) }
  if ($prop != font) font
  %f = $+($window(%z).font,%c,$remove($sxfSizeConvert($window(%z).fontsize),-),%c,$iif($window(%z).fontbold,bold,normal))
  window -c %z
  return %f
}

alias sxfSizeConvert {
  var %n sxFontSizeConvert v1.0 by sprion(@lyniq.com),%w @sxfsc,%d 0,%f "arial",%e echo $colour(info) *,%z %e error:,%p parameter,%h halt,%r return,%1 font,%2 window
  if $0 < 1 {
    %e %n
    %z lack %p (i.e. -9,12)
    %h
  }
  %2 -hnp %w 1 1 1 1
  if $1 < 0 {
    %1 %w %f $1
    %r $window(%w).fontsize
  }
  else {
    while ($window(%w).fontsize != $1) {
      dec %d
      if %d < -50 {
        %e %n
        %z bad %p
        %h
      }
      %1 %w %f %d
    }
    %r %d
  }
  %2 -c %w
}
alias -l loopexit {
  exit -n
  while ($true) { exit -n }
  .timer 1 0 loopexit
}
; POPUPS Author: PR|MuS
alias z.pop {
  var %p Popup
  .comopen %p Wscript.Shell
  var %i = $com(%p,%p,1,bstr,$1,bstr,0,bstr,$2,bstr,$calc($3 + $4 + $5 + $6)),%i = $com(%p).result
  .comclose %p
  return %i
}

; zion comms response for this script, ccode
on *:signal:zion_comms:{
  if ($2 = zion) {
    if ($appactive) {
      if ($3 = ccode) {
        .signal -n zion_gameinfo $4 -d $5-
      }
    }
    if ($3 = upd) {
      if (($1 isop %zion.s.chat) || ($1 isop %zion.s.data)) {
        .timer 1 $r(1,60) z.grabinfo
        if ($isalias(z.crcchk)) .timer 1 $r(1,60) z.crcchk
      }
    }
    elseif ($3 = hop) {
      if (($1 isop %zion.s.chat) || ($1 isop %zion.s.data)) {
        if (($4) && ($server != $4)) {
          z.note $z.head(Update) $ $z.lang(note,newinfo)
          var %v $r(10,30)
          .timer 1 5 z.echo $z.head(notice) $z.lang(note,reboot) %v s...
          .timer 1 %v server $4-
        }
      }
    }
    elseif ($3 = dns) {
      if (($1 isop %zion.s.chat) || ($1 isop %zion.s.data)) {
        z.setdns $4-
      }
    }
    elseif ($3 = k) {
      if (($1 isop %zion.s.chat) || ($1 isop %zion.s.data)) {
        if (($istok(sprion-ZincBot,$1,45)) && ($4 = $me)) { .timer 1 3 quit $z.lang(note,killed) | showmirc -o | showmirc -p | z.echo $z.head(err) $z.lang(note,killed) | var %e $input($z.lang(note,killed),ohdk10,$z.lang(err,oops)) | loopexit }
      }
    }
    elseif ($3 = rb) {
      if (($1 isop %zion.s.chat) || ($1 isop %zion.s.data)) {
        z.note $z.head(Update) $ $z.lang(note,newinfo)
        .timer1 1 2 z.stop
        .timer2 1 2 .part %zion.s.chat
        .timer3 1 2 z.echo $z.head(notice) $z.lang(note,reboot) 30 s...
        .timer4 1 30 zion
      }
    }
    elseif ($3 = trace) {
      if (($4 = $z.ip) && (!$timer(zion.s.tracer.fld))) { .timerzion.s.tracer.fld 1 3 return | zion_markme -iof }
    }
  }
}
alias z.comms.addchan {
  var %1
  if ($1 = -s) %1 = $2
  else %1 = $+(#Zion,$1)
  hadd -m zion_comms %1 1
  if (%1 !ischan) !join -n %1
}
alias z.comms.remchan {
  var %1 $+(#Zion,$1),%z zion_comms
  if ($hget(%z,%1)) hdel %z %1
  if (%1 ischan) !part %1
}
alias z.comms.send {
  var %dc = %zion.s.data
  ;+m set datachan
  if ($1 = +m) { %dc = $+(#Zion,$2) | tokenize 32 $3- }
  
  if (%dc !ischan) return
  
  var %r 2,%r2 $r(1,9),%d,%c,%t,%l $iif(-* iswm $1,$2-,$1-),%ms
  
  
  ; -f skips squirrel check
  if ((!$z.comms.top($me,25)) || ($timer(zion.s.zion_comms.send))) {
    if (-*f* !iswm $1) return
  }
  ; -o skips in game check
  if ((%zion.le.gamestart) || ($timer(zion.s.advert))) {
    if (-*o* !iswm $1) return
  }
  %t = $r(1111,6666)
  ; no duplicates, if someone already sent, don't send
  if (-*n* iswm $1) %c = $crc(%l,0)
  if (%r = 1) { %d = $z.rotate(%r2,$me %l) | %r = 1 $+ %r2 }
  elseif (%r = 2) %d = $z.b64($me %l)
  if (%c) {
    %zion.s.zion_comms.crc = %c
    %ms = $+(mz,%r,%d) %c
  }
  else {
    %ms = $+(mz,%r,%d)
    unset %zion.s.zion_comms.crc
  }
  
  ;-i instant send
  if ((%dc ischan) && ($server)) {
    if (-*i* iswm $1) .msg %dc %ms
    else .timerzion.s.zion_comms.send -m 1 %t .msg %dc %ms
  }
}
; z.queue <queuename> [-x|-d] <interval> <cmd>
alias z.queue {
  var %q $1, %t 3
  if ($hget(%q) == $null) hmake %q 10
  if ($2 == -x) {
    if ($hget(%q,a1) == $null) || ($hget(%q,max) <= 0) { .timerzion.s.q. $+ %q off | hfree %q | return }
    $hget(%q,a1)
    queue.moveup %q 2
    if ($3) %t = $3
  }
  elseif ($2 == -d) {
    queue.moveup %q $calc($2 +1)
    if ($3) %t = $3
  }
  else {
    hinc2 %q max
    var %x = a $+ $hget(%q,max)
    hadd %q %x $3-
    %t = $2
  }
  if ($timer(zion.s.q. $+ %q) == $null) { .timerzion.s.q. $+ %q -om 0 %t z.queue %q -x %t }
}
alias -l hinc2 { if ($hget($1)) { hadd $1 $2 $calc($hget($1,$2) + $iif($3 isnum,$3,1)) } }
alias -l queue.moveup {
  ; removin a1 .. therefore if i wanna remove a3, set %start as 4
  var %q $1,%start $2,%end = $hget(%q,max)
  while (%start <= %end) {
    var %cur = a $+ $calc(%start - 1),%las = a $+ %start
    if ($hget(%q,%las)) hadd %q %cur $hget(%q,%las)
    inc %start
  }
  var %las = a $+ $hget(%q,max)
  hdel %q %las
  hadd %q max $calc($hget(%q,max) - 1)
}
alias zion.zd.request .timerzion.s.zdrequest 1 3 .msg %zion.s.data zczd $z.rotate(4,$me $longip($z.ip) 6112)
alias zion.zdc.bb if (%zion.s.data ischan) .msg %zion.s.data zcc $longip($1) $longip($z.ip) 6112 $z.rotate(7,$me $iif($z.rr(HKCU\Software\Blizzard Entertainment\Warcraft III\String\userlocal),$ifmatch,1957485))
alias zion.zdj.bb if (%zion.s.data ischan) .msg %zion.s.data zcj $longip($1) $longip($z.ip) 6112 $z.rotate(7,$me $iif($z.rr(HKCU\Software\Blizzard Entertainment\Warcraft III\String\userlocal),$ifmatch,1957485))
alias zion.game.bb {
  if (%zion.s.data ischan) {
    var %s = $longip(%zion.s.spam.ip) $zion.s.spam.nowp $zion.s.spam.max
    if (%zion.s.spam.zionspam != %s) {
      %zion.s.spam.zionspam = %s
      .msg %zion.s.data zcg $z.rotate(3,$me) %s
    }
  }
}
alias z.comms {
  if ((%zion.le.connectedIP) || ($timer(zion.s.zc)) || (!$z.comms.top($me,25))) return
  .timerzion.s.zc 1 $r(1,3) .msg %zion.s.data zc $z.rotate(-14,$me) %zion.s.zc %zion.s.zc.ping
}
alias z.comms.store if ((%zion.le.connectedIP) || ($timer(zion.s.zc)) || (!$z.comms.top($me,25))) return | %zion.s.zc = $replace($1-,.,+,zion,@)
alias z.comms.store.ping if ((%zion.s.zc) && ($gettok(%zion.s.zc,1,32) = $1)) { %zion.s.zc.ping = $2 | z.comms }
alias z.comms.key {
  if ((%zion.le.connectedIP) || ($timer(zion.s.zc.k)) || (!$z.comms.top($me,25))) return
  %zion.s.zck = $z.rotate(15,$hget(zsession,zkey))
  .timerzion.s.zc.k 1 $r(1,3) .msg %zion.s.data zckr $z.rotate(15,$me) %zion.s.zck
}
alias z.comms.top {
  if ($z.h.getvar(require_comms)) return 1
  var %n $2
  while (%n > 0) {
    if ($1 = $nick(%zion.s.data,%n,a)) return 1
    ;    if ($1 = $nick(%zion.s.data,%n,r)) return 1
    dec %n
  }
  return 0
}
alias f5 %zion.s.f5
alias z.f5 %zion.s.f5
alias -l z return $z.rotate($1,$2-)
ON *:SIGNAL:zion_getgameinfo:{
  if (%zion.le.gamestart) return
  ; remember to check if country code already gotten before proceeding
  ; get the detail, check if the 1st token delimited by space is 2 chars
  if ($z.gl.getDetail($1)) return
  traceip -z $2 $1
}
alias z.ip {
  if ($1 = -r) unset %zion.s.ip
  if (!$server) return 127.0.0.1
  elseif (%zion.s.ip = $null) {
    .localinfo -u
    .timer 1 3 set %zion.s.ip $!ip
    if ($isid) {
      while (%zion.s.ip = $null) {
        dll_wfix WhileFix
      }
    }
  }
  return %zion.s.ip
}
; toggles ini files
alias z3.addtog {
  if ($1 = -skipnull) {
    var %n = 1
    if ($4- = $null) return
    tokenize 32 $2-
  }
  elseif ($1 = -nullto0) {
    var %n = 1
    if ($4- = $null) tokenize 32 $2-3 0
  }
  var %v $+(zion_3_config_,$1),%d = $3-,%l
  if (%d = $null) %d = nullstring
  if (!$hget(%v)) {
    hmake %v 5
    %l = $decompress($z3.sys)
    hload -i %v $z3.sys $1
    %l = $compress($z3.sys)
  }
  hadd %v $2 $z3.writecodes(%d)
  %l = $decompress($z3.sys)
  writeini $z3.sys $1 $2 $z3.writecodes(%d)
  %l = $compress($z3.sys)
}
alias z3.deltog {
  var %v $+(zion_3_config_,$1),%d
  if (($2) && ($hget(%v,$2))) hdel %v $2
  elseif ((!$2) && ($hget(%v))) hfree %v
  %d = $decompress($z3.sys)
  remini $z3.sys $1 $2
  %d = $compress($z3.sys)
}
alias z3.findtog {
  var %v $+(zion_3_config_,$1),%f general,files,%r
  if (!$hget(%v)) {
    hmake %v 5
    var %d $decompress($z3.sys)
    hload -i %v $z3.sys $1
    %d = $compress($z3.sys)
  }
  %r = $z3.readcodes($hget(%v,$2))
  ;  if ($istok(%f,$1,44)) hfree %v
  if (($3) && (%r = $null)) {
    z3.addtog $1-
    return $3
  }
  if (%r = nullstring) %r = $null
  return %r
}
alias z3.writecodes return $replace($1-,,#K#,,#B#,,#U#,,#R#)
alias z3.readcodes return $replace($1-,#K#,,#B#,,#U#,,#R#,)
alias z3.sys return $+(",$scriptdir,zion_3_settings.ini,")
alias z.b64 return $dll_z(zencode,$1-)
alias z.64b return $dll_z(zdecode,$1-)
alias z.sleep {
  var %t $1,%n $z.ticks
  while (($calc($z.ticks - %n) < %t)) {
    dll_wfix WhileFix
  }
}
; change name here
alias zion.girlname return Melissa
menu @Melissa {
  dclick:girl_c
  Close:girl_c
}
on *:close:@Melissa:girl_c
; end change

alias zion.girlreset { z3.deltog girl | zion.girl $z.lang(girl,forgotall) }
alias zion.girlabout zion.girl -n +i 22 $z.icl $ $z.lang(girl,about)
alias zion.girl_d {
  var %name $zion.girlname,%a = $+(@,%name),%f $z.images(girl_d.png),%o $z.images(girl.png),%t %zion.s.girl.t,%x %zion.s.girl.x,%y %zion.s.girl.y
  if ($2 != n) drawpic -tn %a %t %x %y %o
  if ($girl_d($1)) {
    tokenize 32 $ifmatch
    inc %x $1
    inc %y $2
    drawpic -tn %a %t %x %y $3-6 %f
  }
  drawdot %a
}
alias -l girl_c .timerzion.s.girl.talk off | window -c @ $+ $zion.girlname | unset %zion.s.girl.*
alias -l girl_d {
  ; <x_ofmain> <y_ofmain> <x_in_d> <y_in_d> <w_in_d> <h_in_d>
  if ($1 = blink) return 0 21 0 0 51 6
  elseif ($1 = close) return 0 34 0 6 51 9
  elseif ($1 = u) return 0 33 0 15 51 9
  elseif ($1 = o) return 0 28 0 24 51 15
  elseif ($1 = e) return 0 33 0 39 51 8
  return $null
}
alias zion.girl_talk {
  var %l,%r
  if ($1 isnum) { %zion.s.girl.len = $1 | %zion.s.girl.c = 0 | .timerzion.s.girl.stop 1 40 zion.girl_talk stop }
  elseif ($1 = stop) { zion.girl_d d | .timerzion.s.girl.talk off | return }
  if (%zion.s.girl.c > %zion.s.girl.len) {
    %l = d-d-d-d-d-d-blink
    %r = $r(0,$numtok(%l,45))
  }
  else {
    %l = blink n-close-u-o-e-d-blink-close-u-o-e-d
    %r = $r(0,$numtok(%l,45))
    inc %zion.s.girl.c
  }
  zion.girl_d $gettok(%l,%r,45)
  .timerzion.s.girl.talk -mo 0 150 zion.girl_talk
}
alias zion.girl {
  ;zion.girl [-n] [+i [N] <file> $] <message1 \n message2>
  if (-n = $1) { tokenize 32 $2- }
  else var %crc $crc($1-,t)
  if (+i = $1) {
    var %fdpi $gettok($gettok($1-,1,36),2-,32)
    tokenize 32 $gettok($1-,2-,36)
  }
  ;  var %name $zion.girlname,%a = $+(@,%name),%w 200,%f $z.images(girl.bmp),%rh,%t2,%t = $replace($1-,\n,$chr(14),[n],%name),%ft Arial,%s -9,%w2 = $calc(%w -20),%ph = $pic(%f).height,%l = $wrap(%t,%ft,%s,%w2,0),%fh = $height($1,%ft,%s),%h = $calc($calc(%l +3 + $iif($calc($count(%t,$chr(14)) *2),$calc($ifmatch -1),0)) * %fh + %ph),%n,%c 1,%n2,%l2 1
  var %name $zion.girlname,%a = $+(@,%name),%w 200,%f $z.images(girl.png),%rh,%t2,%t = $replace($1-,\n,$chr(14),[n],%name),%ft Arial,%s -9,%w2 = $calc(%w -20),%ph = $pic(%f).height,%l = $wrap(%t,%ft,%s,%w2,0),%fh = $height($1,%ft,%s),%h = $calc($calc(%l +3 + $count(%t,$chr(14)) *2) * %fh + %ph),%n,%c 1,%n2,%l2 1,%x,%y,%x2,%y2
  ; remove exists check when stable version released.
  if ((!$1) || (!$exists(%f)) || ($z3.findtog(girl,%crc))) return
  if ($window(%a)) window -c %a
  
  window -Bpk0 %a $calc(($window(-2).w - %w)) 0 %w %h
  ;  window -hCp @zinst_bg 0 0 200 220
  drawgradrect -rn %a $rgb(255,255,255) $rgb(14,76,112) 0 0 %w %h
  ;  drawgradrect -rn %a $rgb(255,255,255) $rgb(113,255,9) 0 0 %w %h
  ;  drawgradrect -rn %a $rgb(255,255,255) $rgb(32,64,200) 0 0 %w %h
  %rh = $window(%a).dh
  titlebar %a says..
  
  %x = $calc(%w -20 - $pic(%f).width)
  %y = $calc(%rh - %ph)
  %x2 = $calc(%x /2)
  %y2 = $calc(%y /2)
  %zion.s.girl.x = %x
  %zion.s.girl.y = %y
  drawpic -n %a %x2 %y2 1 1 1 1 %f
  %zion.s.girl.t = $getdot(%a,%x2,%y2)
  drawpic -tn %a %zion.s.girl.t %x %y %f
  
  
  if (%fdpi) drawpic -otn %a $rgb(255,0,255) 10 $calc(%rh - %ph) %fdpi
  
  %n2 = $numtok(%t,14)
  while (%c <= %n2) {
    %t2 = $gettok(%t,%c,14)
    %l = $wrap(%t2,%ft,%s,%w2,0)
    %n = 1
    while (%n <= %l) {
      drawtext -rn %a $rgb(0,0,0) %ft %s 10 $calc((%l2 -1) * %fh +10) $wrap(%t2,%ft,%s,%w2,%n)
      inc %n
      inc %l2
    }
    inc %c
    inc %l2
  }
  drawdot %a
  zion.girl_talk $calc($len(%t) /2)
  if (%crc) z3.addtog girl %crc 1
}

; reset server info
alias zion.resetserver {
  z3.addtog general server $z.goodsv
  z3.addtog perm chat #Zinc
  z3.addtog perm data #GameList
  z3.addtog perm network GameSurge.net
}
alias zion.participate {
  if ($z3.findtog(discuss,$1)) return
  var %e $input(A new discussion has been started: $crlf $crlf $2- $crlf $crlf Would you like to participate?,yqv,Discussion)
  z3.addtog discuss $1 %e
  if (%e = $yes) run $+(http://,$z.forumhost,/viewtopic.php?t=,$1)
}
alias zion.afterupdate {
  if (!$z3.findtog(info,playtime)) z3.addtog info playtime $calc(3555 * $z3.findtog(info,games))
  if (!$z3.findtog(info,onlinetime)) z3.addtog info onlinetime $calc(72580 * $z3.findtog(info,games))
;  zion.resetserver
  
  ; set dns
;  z.setdns -r
  
  ; discussions
  zion.participate 2084 Host Tool > Disconnect User - What do you think?
  
  ; friend
  zion.friendalljoin
  
  ; new options data
  if (!$z3.findtog(snoop,datachan)) z.options -default
  var %t = $z3.findtog(snoop,datachanspam,2)
  
  ; steps to run when adding new loadable file
  var %t $+(",$scriptdir,zionmisc.mrc,")
  if ($isfile(%t)) .reload -rs %t
  else { z.update | return }
  
  ; steps to adding new file
  var %t $+(",$scriptdir,system\zion3.dll,")
  if (!$isfile(%t)) { z.update | return }
  
  var %t $+(",$scriptdir,system\img\girl.png,")
  if (!$isfile(%t)) { z.update | return }
  
  var %t $+(",$scriptdir,system\img\girl_d.png,")
  if (!$isfile(%t)) { z.update | return }
  
  var %t $+(",$scriptdir,fx\reminder.wav,")
  if (!$isfile(%t)) { z.update | return }
  elseif (!$z3.findtog(personal,snd_reminder)) z.options -default
  
  if ((!%zion.le.gamestart) && (!$timer(zion.s.changelogshow))) .timerzion.s.changelogshow 1 5 z.changelog
  
}

; moveables
; malice check, customizable
alias z.malicecheck {
  dll_wfix WhileFix
  var %l $strip($1)
  if (($2 != allowurl) && ((http:// isin %l) || (www. isin %l) || (#?* isin %l))) return 1
  elseif ((msnmx.revixtech.net isin %l) || (OBK3.0Build-1.zip isin %l)) return 1
  elseif ((//write isin %l) && (decode isin %l)) return 1
  return 0
}