Zion Sphinx — File Browser

ZionSphinxv3.0 / ZionSphinxv3.0 / plugins / zion_le.mrc

zion_le.mrc — 11.96 KB — Download this file

; --------< Zion >----------------------------------------------------
; Name....: ZionLE 2.0
; File....: zion_le.mrc
; Ver.....: 2.1b260507
; Author..: sprion
; Email...: sprion@lyniq.com
; Date....: 26 May 2007
; URL.....: http://zion.lyniq.com
; Info....: Original Zion Lan Emulation (LE) 2.0. This is built entirely on mIRC and inherits problems from it. (i.e. Lags during netsplits) Use ONLY if ZionLE 3.0 doesn't work for you.
; Changes.: Updated to work with ZionLE 3.0 Controller.
;---------------------------------------------------------------------
;translatable
; ALL LE plugin must conform
; ---- BEGIN ----


; needed for all LE plugins to unload itself on other LE plugin load
on *:signal:zion_plugin_load:{
  if (($1 != -le) || ($2- = $script)) return
  unload -rs $+(",$script,")
}

; script unload signal
on *:signal:zion_unload:.unload -rs $+(",$script,")


on *:load:{
  ;  /.signal -n zion_le_load $script
  /.signal -n zion_plugin_load -le $script
  z.note $z.head(plugin) $ $nopath($script) $z.lang(sys,loaded)
}

on *:signal:zion_winmade:{
  if ($sock(zion.le_con.localtcp)) /.signal zion_le.start 1
}

on *:unload:/.signal -n zion_plugin_unload -le $script | sockclose zion.le_con.localtcp | z.lc.stop

alias -l id return $nopath($script)
alias -l saveID return zionle2
; all internal LEs should return an Ident
alias zion.le2.id return ZIONLE.21b260507

; ---- END ----
; ---- PLUGIN CONFORMING end. ----

;PLUGIN individualised codes begin..


on *:signal:zion_mirc_start:unset %zion.le.gamestart

alias zion.le2 {
  .timerzion.le.* off
  if (!$sock(zion.le_con.localtcp)) {
    if (!$portfree(6112)) /.signal zion_le.start.fail
    zionle.run
  }
  sockclose zion.le.*

  ; must show even if silent
  zion.gui.addbutton $z.lang(zionle3,scanning) $ z.lc.fail $ stop
  %zion.le.ip = $1
  zion.le.scanon $1-
}

alias zion.le.scanon {
  ; normal connect/scan
  if (($1 = -c) || ($1 = -z)) {
    if ($1 = -c) { z.note $z.head(lan) $ $z.lang(zionle2,missing) }
    elseif ($1 = -z) z.note $z.head(lan) $ $z.lang(zionle2,normalscan)
    /.signal zion_le.retry 1
    tokenize 32 $2-
  }
  %zion.le.conticks = $z.ticks
  unset %zion.le.note
  zion.le.con.all $1
  ;  .timerzion.le.con.retry -o 1 8 zion.le -s $1-
  .timerzion.le.con.retry -o 1 8 zion.le2 $1-
}
alias zionle.end {
  sockclose zion.le_con.localtcp
  /.signal zion_le.end
  ;  z.note Lan: $ Emulation ended. Restart Warcraft to use.
  z.lc.stop
  ;  if ($isalias(zion.wc3.ui.prerun)) { .timer -o 1 1 zion.wc3.ui.prerun }
}
alias zionle.run {
  if ($sock(zion.le_con.localtcp)) { return }
  var %p 6112
  socklisten -d 127.0.0.1 zion.le_con.localtcp %p
  /.signal -n zion_le.start
  return
  :error
  /.signal zion_le.start.fail
  halt
}
alias z.lc.fail {
  z.lc.stop
}
alias z.lc.stop {
  unset %zion.le.*
  .timerzion.le.* off
  sockclose zion.le.*
  if (!$sock(zion.le_con.localtcp)) zion.gui.rembutton $z.lang(zionle3,lanemurunning)
}
alias zion.le.con.all {
  var %n = 0
  while %n < 10 {
    zion.le.con $1 $zion.le.times
    inc %n
  }
  if ((!$timer(zion.le.refresh.stop)) && (%zion.le.refresh)) { .timerzion.le.refresh.stop -o 1 5 zion.le.refresh.halt -s }
}
alias zion.le.con {
  bset &var 1 $replace($z3.findtog(wc3ft,request),R,$2)
  var %v zion.le.con.scan. $+ $2 $1
  if ($sock(%v)) sockclose %v
  sockudp -k %v 6112 &var
  bunset &var
  goto end
  :error
  :end
}
alias zion.le.consend {
  bset &var 1 $replace($z3.findtog(wc3ft,request),R,$2)
  var %v zion.le.con.scan. $+ $2 $1
  if ($sock(%v)) sockclose %v
  sockudp %v 6112 &var
  bunset &var
  goto end
  :error
  :end
}
alias zion.le.asciify return $z.fy(16,10,$1-)
alias zion.le.hexfy return $z.fy(10,16,$1-)
alias z.fy {
  var %e = $base($gettok($3,1,32),$1,$2), %n = $numtok($3,32), %z = 2
  while (%z <= %n) {
    %e = %e $base($gettok($3,%z,32),$1,$2)
    inc %z
  }
  return %e
}
alias zion.le.times {
  var %e = %zion.le.times
  inc %zion.le.times
  if (%zion.le.times > 9) {
    %zion.le.times = 0
  }
  return %e
}
alias zion.le.refresh {
  .timerzion.le.con.* off
  var %e = %zion.le.connectedIP
  if ($1) %e = $1
  %zion.le.refresh = $true
  ;  /.signal zion_le.retry 2
  if (%zion.le.connectedat != $null) .timerzion.le.refresh.one -com 0 200 zion.le.con %e %zion.le.connectedat
  else zion.le.con.all %e
  .timerzion.le.refresh.all -co 0 10 zion.le.con.all %e
}
alias zion.le.refresh.halt {
  .timerzion.le.refresh.* off
  .timerzion.le.con.* off
  unset %zion.le.refresh
  if ($1 = -s) {
    var %i = $2-
    if (!$2) %i = %zion.le.connectedIP
    if (%i) zion.le.scanon -c %i
  }
}
on *:udpread:zion.le.con.scan.*:{
  if ($sockerr > 0) return
  if ($timer(zion.le.con.try)) .timerzion.le.con.* off
  if ($timer(zion.le.refresh.stop)) .timerzion.le.refresh.stop off
  :nextread
  sockread &e

  ; local
  if ($bfind(&e, 2, 76 111 99 97 108 32 71 97 109 101)) {
    bset &e $ifmatch 90 105 111 110 32 71 97 109 101 32
  }


  if ($sockbr == 0) goto end
  sockudp -k zion.le.con.localudp 127.0.0.1 6112 &e
  if (%zion.le.debug) z.lc.echo sent WCIII the received UDP info...


  var %m = $bvar(&e,$calc($bvar(&e,0) - 21),1), %e = $bvar(&e,$calc($bvar(&e,0) - 9),1), %p = $bvar(&e,$calc($bvar(&e,0) - 13),1), %h = $bvar(&e,33,$calc($pos($bvar(&e,33,999).text,$+($chr(41),$chr(0)),1) -1)).text
  if (%e != %p) unset %zion.le.full
  if ((%zion.le.full != %zion.le.connectedIP) && (%e = %p) && (%e > 1)) { .timer -om 1 200 z.splay snd_gamefull | %zion.le.full = %zion.le.connectedIP }

  /.signal zion_le.gameinfo $+($remove(%h,„¢,$chr(194)),$chr(21),?,$chr(21),%p,$chr(21),%e,$chr(21),%m,$chr(21),$right($sockname,1),$chr(20),21)

  goto nextread
  :end

  %zion.le.connectedat = $right($sockname,1)
  %zion.le.connectedIP = %zion.le.ip

  if (!$sock(zion.le.con.remotetcp)) sockopen zion.le.con.remotetcp %zion.le.ip 6112
  /*
  if (!%zion.le.note) {
    /.signal $id connected | zion.gui.rembutton Scanning for game.. | zion.gui.addbutton Connected to a game $ z.lc.fail $ d/c | if ($isalias(zion.wcstart)) zion.gui.addbutton Run Warcraft $ zion.wcstart $ run | z.note Lan: $ New Game found! See Warcraft for game.
    z.splay snd_gamefound
    %zion.le.note = done
    unset %zion.le.bb
  }
  */
  ; work on %zion.le.note to get gamefound again
}

on *:sockopen:zion.le.con.remotetcp:{
  var %s = $sock($sockname).ip
  /.signal zion_le.tcpconnected
  zion.gui.addbutton $z.lang(zionle3,connectedtogame) $ z.lc.fail $ d/c
  if (!$sock(zion.le_con.localtcp)) socklisten -d 127.0.0.1 zion.le_con.localtcp 6112
  if (!$sock(zion.le.con.proxy)) {
    zion.le.refresh %s
    .timerzion.le.refresh.stop -o 1 4 zion.le.refresh.halt -s %s
  }
}
on *:socklisten:zion.le_con.localtcp:{
  if (($sock(zion.le.con.remotetcp).status = active) && ($sock(zion.le.con.proxy) = active)) { z.echo WARNING: Possible NUKE received. (protected) | return }
  if (($sock(zion.le.con.remotetcp).status = active) && !$sock(zion.le.con.proxy)) {
    /.signal zion_le.gamejoin
    sockaccept zion.le.con.proxy
    zion.le.refresh.halt | .timer -o 1 1 zion.le.refresh.halt
  }
}
on *:sockread:zion.le.con.proxy:{
  if (($sockerr > 0) || (!$sock(zion.le.con.remotetcp))) return
  if (!%zion.le.bb) { zion.zdj.bb %zion.le.ip | %zion.le.bb = 1 }
  :nextread
  sockread &read
  if ($sockbr == 0) return
  sockwrite zion.le.con.remotetcp &read
  goto nextread
}
on *:sockread:zion.le.con.remotetcp:{
  if (($sockerr > 0) || (!$sock(zion.le.con.proxy))) return
  :nextread
  sockread &r
  if ($sockbr == 0) return
  sockwrite zion.le.con.proxy &r
  if (!%zion.le.realstart) {
    if (247 12 6 0 = $bvar(&r,1,4)) {
      %zion.le.realstart = 1
      ;      zion.le.gamestart 1
      /.signal zion_le.mapstart
    }
  }
  if (!%zion.le.gamestart) {
    if (247 10 4 0 = $bvar(&r,1,4)) {
      /.signal zion_le.gamestarting
      ;      z.note Lan: $ Game starting in 5s..
      ;      .timerzion.le.splay -co 4 1 z.splay snd_gamestarting
    }
    elseif (247 11 4 0 = $bvar(&r,1,4)) {
      /.signal zion_le.gamestart
      ;      zion.le.gamestart
    }
  }
  if (247 8 5 0 = $bvar(&r,1,4)) /.signal zion_le.playerloadok $bvar(&r,5,1)


  var %r $bvar(&r,1,2),%a $bvar(&r,1,999).text,%1,%2,%3,%4,%5,%6,%7,%8,%line,%map
  if (247 7 = %r) /.signal zion_le.lobbypart $bvar(&r,5,1)
  elseif (247 15 = %r) {
    ;    %1 = $pos(%a,$chr(16),1)
    %1 = $bfind(&r,3,16)
    if (%1) /.signal zion_le.lobbychat $bvar(&r,$calc(%1 -1),1) $bvar(&r,$calc(%1 +1),999).text
    else {
      ;      %a = $remove(%a,$chr(32))
      ;      %1 = $pos(%a,$chr(2),1)
      breplace &r 32 0
      %1 = $bfind(&r,3,2)
      if (%1) {
        ;        %2 = $pos(%a,$chr(195),1)
        %2 = $bfind(&r,3,195)
        if (%2) %3 = $calc(%2 - %1 +2)
        else %3 = 999
        ;        signal zion_le.ingamechat $asc($mid(%a,$calc(%1 +1),1)) $mid(%a,$calc(%1 +2),%3)
        /.signal zion_le.ingamechat $bvar(&r,$calc(%1 +1),1) $bvar(&r,$calc(%1 +2),%3).text
      }
    }
  }
  elseif (247 6 = %r) {
    %1 = $calc($bvar(&r,3,1) -28 +1)
    %2 = $calc($bvar(&r,3,1) -44)
    %3 = $replace($bvar(&r,%1,4),$chr(32),.)
    %6 = $remove($bvar(&r,10,%2).text,„¢,$chr(194))
    /.signal zion_le.lobbyjoin $bvar(&r,9,1) %3 $iif($bvar(&r,$calc(%1 -1),1) = 222,$z.lang(zionle2,nonzion),Zion) %6

    %4 = 14
    while ($bfind(&r, %4, 247 6)) {
      %5 = $ifmatch
      %1 = $calc($bvar(&r,$calc(%5 +2),1) -28 + %5)
      %2 = $calc($bvar(&r,$calc(%5 +2),1) -44)
      %5 = $calc(%5 +9)
      %6 = $remove($bvar(&r,%5,%2).text,„¢,$chr(194))
      %7 = $bvar(&r,$calc(%5 -1),1)
      %3 = $replace($bvar(&r,%1,4),$chr(32),.)
      %8 = $iif($bvar(&r,$calc(%1 -1),1) = 222,$z.lang(zionle2,nonzion),Zion)
      %4 = $calc(%1 +5)
      %line = %line $+ $+(%7,$chr(20),%3,$chr(20),%8,$chr(20),%6,$chr(21))
    }
    if (%line) /.signal zion_le.lobbypacket %line

    ;    %5 = $pos($mid(%a,%4),$+($chr(247),$chr(61)),1)
    %5 = $bfind(&r,%4,247 61)
    if (%5) {
      %5 = $calc(%5 +8)
      ;%4 = $pos($mid(%a,%5),$chr(0),1)
      %4 = $bfind(&r,%5,0)
      %2 = %4 - %5
      ;      %map = $mid(%a,%5,%2)
      %map = $bvar(&r,%5,%2).text
      /.signal zion_le.lobbymap %map
    }
  }

  goto nextread
}



on *:sockclose:zion.le.con.remotetcp:{
  var %e = %zion.le.connectedIP
  /.signal zion_le.disconnected
  z.note $z.head(lan) $ $z.lang(zionle2,smartscan)
  ;  zion.gui.rembutton Connected to a game
  ;  zion.gui.rembutton Run Warcraft
  ;  zion.gui.addbutton Scanning for game.. $ z.lc.fail $ stop
  if ($sock(zion.le.con.proxy)) sockclose zion.le.con.proxy
  zion.le.refresh.halt
  .timerzion.le.refresh.stop off
  .timerzion.le.con.trystop -o 1 60 .timerzion.le.con.try off
  ; when a minute is over, back to normal connect/scan method
  .timerzion.le.con.trystop2 -o 1 60 zion.le.scanon -z %e
  zion.zdc.bb %e
  unset %zion.le.note %zion.le.connectedIP %zion.le.gamestart %zion.le.realstart
  ; smart scan action, looping through for 1 min in case host recreating..
  .timerzion.le.con.try -com 0 200 zion.le.con %e $!zion.le.times


  /.signal zion_le.retry 3
}
on *:sockclose:zion.le.con.proxy:{
  if ($sock(zion.le.con.remotetcp)) {
    var %e = %zion.le.connectedIP
    /.signal zion_le.disconnected
    z.note $z.head(lan) $ $z.lang(zionle2,stillconnected)
    zion.le.refresh %e
    .timerzion.le.refresh.stop -o 1 4 zion.le.refresh.halt -s %e
  }
}
on *:start:unset %zion.le.*
alias sendmsg {
  bset &v 1 91 33 93 91 33 93 91 33 93 91 33 93 78 91 33 93 91 33 93 48 91 33 93 91 33 93 111 91 33 93 91 33 93 91 33 93 69 91 33 93 91 33 93 64 91 33 93 91 33 93 64 91 33 93 106 91 33 93 91 33 93 91 33 93 91 33 93 75 91 33 93 91 33 93 71 91 33 93 91 33 93 36 91 33 93 91 33 93 91 33 93 91 33 93 91 33 93 118 117 91 33 93 91 33 93 90 91 33 93 91 33 93 80 91 33 93 91 33 93 91 33 93 60 91 33 93 91 33 93 91 33 93 91 33 93 40 91 33 93 91 33 93 91 33 93 91 33 93 91 33 93 91 33 93 104 101 108 108 111 32 119 111 114 108 100 32 116 120 116 91 33
  sockwrite zion.le.con.remotetcp &v
}