Advertisement
glacier_rat

Untitled

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