TheImrac commented on a Page, mIRC Servers List Update - 1.0  -  Oct 24, 2011

This is such a great concept I decided I would tackle it in my own way. I just used the ETag HTTP header to check if the file has changed.

on *:START:{ svini_update }
ON: *:UNLOAD:{
  unset %svini.etag
}

on *:SOCKOPEN:svini:{
  if ($sockerr) { 
    echo -s 14[4*14] 1Unable to Connect to mIRC.COM
    .sockclose svini
    halt
  }
  sockwrite -n $sockname GET /servers.ini HTTP/1.1
  sockwrite -n $sockname Host: www.mirc.com
  if (%svini.etag) { sockwrite -n $sockname If-None-Match: $qt($v1) }
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:svini:{
  if ($sockerr) { 
    echo -s 14[4*14] 1Unable to Download Latest servers.ini File (read error)
    if ($2) { unset %svini.etag }
    .sockclose svini
    halt
  }
  tokenize 32 $sock($sockname).mark 
  if (!$2) {
    var %read
    sockread %read
    while (%read) {
      if ($regex(%read,/^HTTP/1.1 304  Not Modified$/)) {
        echo -s 14[9*14] 1You Have the Latest servers.ini ( $+ $calc(($ticks - $1) / 1000) $+ s)
        .sockclose svini
        halt      
      }
      elseif ($regex(%read,/^Content-Length: (\d+)$/)) { sockmark $sockname $1 $regml(1) }
      elseif ($regex(%read,/^ETag: "(.*)"$/)) { set %svini.etag.new $regml(1) }
      sockread %read
    }
  }
  else {

    sockread &read 
    while ($sockbr) {
      bwrite $+($mircdir,servers.ini.tmp) -1 -1 &read
      if ($file($+($mircdir,servers.ini.tmp)).size == $2) {
        svini_finish $1
        halt
      }
      sockread &read  
    }
  }
}

ON *:SOCKCLOSE:svini:{
  tokenize 32 $sock($sockname).mark 
  echo -s 14[4*14] 1Unable to Download Latest servers.ini File (socket closed)
  if ($2) { unset %svini.etag.new }
  .sockclose svini
  halt
}
alias svini_update {
  echo -s 14[8*14] 1Checking for new servers.ini File...
  .remove $+($mircdir,servers.ini.tmp)
  if ($1 == -force) { unset %svini.etag }
  sockopen svini www.mirc.com 80
  sockmark svini $ticks
}
alias -l svini_finish {
  .copy -o $+($mircdir,servers.ini) $+($mircdir,servers.ini.old)
  .copy -o $+($mircdir,servers.ini.tmp) $+($mircdir,servers.ini)
  set %svini.etag %svini.etag.new
  unset %svini.etag.new
  echo -s 14[9*14] 1Successfully Downloaded Latest servers.ini ( $+ $calc(($ticks - $1) / 1000) $+ s)
  .sockclose svini
}

Quick ninja Edit: Changed it so the etag doesn't get update until it finishes copying over the new server list.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.