Advertisement
Guest User

Untitled

a guest
Jun 17th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. alias Update {
  2.   var %filepath Hermes.txt
  3.   if ($exists(%filepath)) {
  4.     remove %filepath
  5.   }
  6.   elseif ($remote !& 2) {
  7.     var %error Remote is off
  8.   }
  9.   if (%error) {
  10.     echo $color(info) -as * /Update $+ : %error
  11.     halt
  12.   }
  13.   var %id HermesUpdate.1
  14.   if ($sock(%id)) {
  15.     echo 4 -s Updater is already running!
  16.     return
  17.   }
  18.   if ($hget(%id)) {
  19.     hfree %id
  20.   }
  21.   var %host beardbot.net84.net,%path /update.text
  22.   hmake %id 5
  23.   hadd %id DownloadPath %filepath
  24.   hadd %id Host %host
  25.   hadd %id Path %path
  26.   hadd %id ReceivedAllHeaders $false
  27.   sockopen %id %host 80
  28. }
  29. on *:sockopen:HermesUpdate.*: {
  30.   if ($sockerr) {
  31.     echo 4 -s sockopen error: $sock($sockname).wsmsg
  32.     return
  33.   }
  34.   sockwrite -nt $sockname GET $hget($sockname,Path) HTTP/1.1
  35.   sockwrite -nt $sockname Host: $hget($sockname,Host)
  36.   sockwrite -nt $sockname User-agent: Secret
  37.   sockwrite -nt $sockname $crlf
  38. }
  39. on *:sockread:HermesUpdate.*: {
  40.   if ($sockerr) {
  41.     echo 4 -s sockread error: $sock($sockname).wsmsg
  42.     HttpGetEvent $sockname ERROR SOCKREAD Error: $sock($sockname).wsmsg
  43.     return
  44.   }
  45.   TryRead
  46.   while ($sockbr) {
  47.     TryRead
  48.   }
  49. }
  50. alias TryRead {
  51.   if ($hget($sockname,ReceivedAllHeaders)) {
  52.     sockread &data
  53.     var %file $hget($sockname,DownloadPath)
  54.     bwrite $qt(%file) -1 -1 &data
  55.     hinc $sockname ContentReceivedLength $sockbr
  56.     if ($hget($sockname,ContentLength) == $hget($sockname,ContentReceivedLength)) {
  57.       DownloadSuccess $sockname
  58.       load -rs Hermes.txt
  59.       DownloadCleanup $sockname
  60.     }
  61.   }
  62.   else {
  63.     var %data
  64.     sockread %data
  65.     if (%data == $null) {
  66.       hadd $sockname ReceivedAllHeaders $true
  67.     }
  68.     elseif ($regex(%data,/^Content-Length: (\d+)$/i)) {
  69.       hadd $sockname ContentLength $regml(1)
  70.     }
  71.   }
  72. }
  73. on *:sockclose:HermesUpdate.*: {
  74.   DownloadFailed $sockname
  75.   DownloadCleanup $sockname
  76. }
  77. alias DownloadCleanup {
  78.   if ($sock($1)) {
  79.     sockclose $1
  80.   }
  81.   if ($hget($1)) {
  82.     hfree $1
  83.   }
  84. }
  85. alias DownloadSuccess {
  86.   echo Download success!
  87. }
  88. alias DownloadFailed {
  89.   echo Download failed
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement