Originally Posted By: sparta
i solved the problem with tell if it's a new update on the site, but i cant make it to download and install it.


:P

Code:
alias -l rm.host { return HOST }
alias -l rm.path { return /PATH/ }
alias -l rm.hash { return rmlist }
alias -l rm.hfile { return system\hash\rmlist.hsh }

alias -l rm.save {
  if ($hget($rm.hash)) {
    var %t = 1, %dir = $nofile($rm.hfile), %tok = $iif($pos(%dir,/),47,92), %n = $numtok(%dir,%tok)
    while (%t < %n) {
      var %path = $gettok(%dir,$iif(%t == 1,%t,$+(1-,%t)),%tok), %t = %t + 1
      if (!$isdir(%path)) /mkdir %path
    }
    /hsave $rm.hash $rm.hfile
  }
}

on *:START: {
  var %dir_list = system\hash system\backup system\scripts, %d = 1
  while ($gettok(%dir_list,%d,32)) {
    var %t = 1, %dir = $v1, %n = $numtok(%dir,92), %d = %d + 1
    while (%t < %n) {
      var %path = $gettok(%dir,$iif(%t == 1,%t,$+(1-,%t)),92), %t = %t + 1
      if (!$isdir(%path)) /mkdir %path
    }
  }

  if (!$hget($rm.hash)) /hmake $rm.hash 10
  if ($isFile($rm.hfile)) /hload $rm.hash $rm.hfile
  if ($version == 6.3) {
    if (%stswitch) { 
      if (%stswitch == on) {
        server irc.fcirc.net
        .timer 1 1 /join #scripts
      }
      elseif (%stswitch == off) { echo -a Auto Connect is halted }
    }
    else { $startup }
  }
}

on *:EXIT: {
  /rm.save
}

alias -l rm.cmd {
  if ($1 == echo) return /echo -s *
  return /msg $1
}

alias -l rm.chk_update {
  var %cmd = $rm.cmd($1), %file = $replace($2-,$chr(32),$+(%,20)), %lupdate = $hget($rm.hash,%file)

  if (%lupdate) {
    /sockopen rm.update $rm.host 80
    /sockmark rm.update CHKUPDATE $1 %file
    [ %cmd ] Checking for update of %file $+ ...
  }
  else [ %cmd ] Could not update file: Previous record not found.
}

alias -l rm.update {
  var %cmd = $rm.cmd($1), %file = $replace($2-,$chr(32),$+(%,20)), %lupdate = $hget($rm.hash,%file)

  /sockopen rm.update $rm.host 80
  /sockmark rm.update UPDATE $1 %file
  [ %cmd ] Downloading update of %file $+ ...
}

on *:SOCKOPEN:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)

  /set %rm.update.header 1

  if ($right($rm.path,1) == /) var %gfile = $rm.path $+ %file
  else var %gfile = $rm.path $+ / $+ %file

  if ($sockerr) [ %cmd ] Could not check for update: $sock(%sock).wsmsg
  else if (%what == CHKUPDATE) {
    /sockwrite -n %sock HEAD %gfile HTTP/1.0
    /sockwrite -n %sock Host: $rm.host
    /sockwrite -n %sock User-Agent: Mozilla/4.0 (mIRC Remote)
    /sockwrite -n %sock Accept: */*
    /sockwrite -n %sock If-Modified-Since: $hget($rm.hash,%file)
    /sockwrite -n %sock $crlf
  }
  else if (%what == UPDATE) {
    /sockwrite -n %sock GET %gfile HTTP/1.0
    /sockwrite -n %sock Host: $rm.host
    /sockwrite -n %sock User-Agent: Mozilla/4.0 (mIRC Remote)
    /sockwrite -n %sock Accept: */*
    /sockwrite -n %sock $crlf
  }
  else {
    [ %cmd ] Unknown action %what
    /sockclose %sock
  }
}

on *:SOCKREAD:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark, %read
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)

  if (%rm.update.header) {
    /sockread %read
    if ($len(%read) == 0) {
      /unset %rm.update.header
      return
    }
  }
  else {
    /sockread &data
  }

  ; HEADERS
  if (%rm.update.header) {
    var %reg_http = /HTTP[\/0-9\.]+ ([0-9]+) .*/i
    var %reg_lmod = /Last-Modified: (.*)/i
    if (%what == CHKUPDATE) {
      if ($regex(%read,%reg_http)) {
        var %code = $regml(1)
        if (%code == 304) [ %cmd ] %file has not been updated
        else if (%code == 200) /set %rm.update.modified 1
        else if (%code == 404) [ %cmd ] File could not be found. Check the file name, and try again.
      }
      else if (($regex(%read,%reg_lmod)) && (%rm.update.modified)) {
        var %date = $gettok(%read,2-,32)
        [ %cmd ] %file was last modified %date $+ .
        /unset %rm.update.modified
      }
    }
    else if (%what == UPDATE) {
      if ($regex(%read,%reg_http)) {
        var %code = $regml(1)
        if (%code == 200) {
          /set %rm.update.download 1
          [ %cmd ] Found %file $+ , downloading...
        }
        else if (%code == 404) [ %cmd ] File could not be found. Check the file name, and try again. | halt
      }
      else if ($regex(%read,%reg_lmod)) {
        var %date = $regml(1)
        if (!$hget($rm.hash,%file)) /set %rm.upload.newfile 1
        /hadd $rm.hash %file %date
        /rm.save
      }
    }
    else if ($regex(%read,%reg_http)) {
      var %code = $regml(1)
      if (%code == 400) [ %cmd ] Could not retrieve file: bad request
      else [ %cmd ] Unknown error: %read
    }
  }
  else if (%rm.update.modified || %rm.update.download) {
    var %savefile = $replace(%file,$+(%,20),$chr(32))
    /bwrite $+(",%savefile,") -1 -1 &data
    /set %rm.update.file %savefile
  }
}

on *:SOCKCLOSE:rm.update: {
  var %sock = $sockname, %mark = $sock(%sock).mark
  var %what = $gettok(%mark,1,32), %cmd = $rm.cmd($gettok(%mark,2,32)), %file = $gettok(%mark,3-,32)
  if ((%what == UPDATE) && (%rm.update.file)) {
    [ %cmd ] Download complete. Loading script...

    var %savefile = %rm.update.file
    if ($isFile($+("system\scripts\,%savefile,"))) .copy -o $+("system\scripts\,%savefile,") $+("system\backup\,%savefile,")

    .copy -o $+(",%savefile,") $+("system\scripts\,%savefile,")
    .remove $+(",%savefile,")

    if ($script($+("system\scripts\,%savefile,"))) /reload -rs $+("system\scripts\,%savefile,")
    else /load -rs $+("system\scripts\,%savefile,")

    if (*Loaded* !isin $line(Status Window,$calc($line(Status Window,0) - 1))) {
      [ %cmd ] $line(Status Window,$calc($line(Status Window,0) - 1))
    }
    else [ %cmd ] %file loaded successfully.

    /unset %rm.update.*
    clear -s
  }
}

on *:INPUT:#: {
  if (/ == $left($1-,1)) { return }
  elseif ($1 == @download) {
    var %target = $iif($target == $me,$nick,$chan)
    %stswitch = on
    if ($2) {
      var %file = $2-
      if ($exists($+($mircdir,/system/scripts/,%file)) == $true) { unload -rs ./system/scripts/ $+ %file | /.remove ./system/scripts/ $+ %file | goto xscript }
      else { goto xscript }
      :xscript 
      /msg %target Downloading $+(,%file,...)
      /rm.update %target %file
    }
    else /msg %target Insufficient parameters: @download <file>
  }
  else if ($1 == @update) {
    var %target = $iif($target == $me,$nick,$chan)
    if ($2) {
      var %file = $2-
      /msg %target Checking $+(,%file,) for update...
      /rm.chk_update %target %file
    }
    else /msg %target Insufficient parameters: @update <file>
  }
  elseif ($1 ison #) { echo -t $+(:[,$me,]:) $+(15,$1,7:) $2-
    .msg # $+(15,$1,7:) $2-
    /halt
  } 
  else { 
    if ($me isop $chan) { echo -t $+(%co1,%brl,%co2,@,$me,%co1,%brr,) $1- | /.msg # $1- | halt }
    elseif ($me ishop $chan) { echo -t $+(%co1,%brl,%co2,%,$me,%co1,%brr,) $1- | /.msg # $1- | halt }
    elseif ($me isvoice $chan) { echo -t $+(%co1,%brl,%co2,+,$me,%co1,%brr,) $1- | /.msg # $1- | halt }
    else { echo -t $+(%co1,%brl,%co2,$me,%co1,%brr,) $1- | /.msg # $1- | halt }
  }
}


NOTE if you have a ON INPUT script it might clash with this on input event @download,@update are the triggers :P you can work on the rest you can remove me %co1,%brr vars, its for my color theme. Sue me... I put those months ago.

Of course include your own HOST and PATH at the very top of page.

Also I fixed the script to reflect mIRC 6.3 and yes it checks for the matching version, :P

Also note my original server i connected too is in script irc.fcirc.net, and finally if the script doesnt work you will have to make your own dirs /system/hash system/etc... << youll see at the top of the script, I can't remember if the MKDIR routine was added.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }