mIRC Home    About    Download    Register    News    Help

Print Thread
$sockread problem #228095 06/12/10 08:55 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
I am trying to put to $sockread on one sockread event but an error is appear, The error is when the file trying to complete the download it stucks (halts) on the half progress, any ideas?

Code:
alias banlist_download {
  sockclose banlist_download
  echo -s banlist_download Connecting to www.westor.ucoz.com ...
  set %BL_DOWNLOAD_START_TIME $ctime
  sockopen banlist_download www.westor.ucoz.com 80
}

ON *:SOCKOPEN:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  echo -s $sockname Connected to westor.ucoz.com
  sockwrite -n $sockname GET /remotes/banlist.rar HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
  sockwrite -n $sockname Host: westor.ucoz.com
  sockwrite -n $sockname $crlf
}

ON *:SOCKREAD:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  var %s
  sockread %s
  sockread &temp
  if (content-length:* iswm %s) { echo -s $sockname $gettok(%s,2-,32) [SIZE] ! }
  if ($sockbr == 0) return
  bwrite " $+ $mircdirdownloads\banlist.rar $+ " -1 -1 &temp
  echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs
}


- Thanks!


Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-
Re: $sockread problem [Re: westor] #228107 07/12/10 11:59 AM
Joined: Apr 2010
Posts: 30
M
m0viefreak Offline
Ameglian cow
Offline
Ameglian cow
M
Joined: Apr 2010
Posts: 30
There are several mistakes:
1) you read TWICE on every sockread call, this results in half the data going to %s, and the other half to &temp
2) you don't distinguish between header data and user data, this results in some of the headers being written to your target file, thus making it invalid
3) echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs is called multiple times during the process

try something like this:
Code:
alias banlist_download {
  sockclose banlist_download
  echo -s banlist_download Connecting to www.westor.ucoz.com ...
  set %BL_DOWNLOAD_START_TIME $ctime
  sockopen banlist_download www.westor.ucoz.com 80
}

ON *:SOCKOPEN:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }
  echo -s $sockname Connected to westor.ucoz.com
  sockwrite -n $sockname GET /remotes/banlist.rar HTTP/1.0
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10
  sockwrite -n $sockname Host: westor.ucoz.com
  sockwrite -n $sockname $crlf
}

ON *:SOCKREAD:banlist_download: {
  if ($sockerr > 0) { echo -s $sockname Error: Connection problem check your connection and try again later! | return }

  ;; interpret as header data until we reach a null byte
  if (!$sock($sockname).mark) {
    var %s | sockread %s
    if (content-length:* iswm %s) { echo -s $sockname $gettok(%s,2-,32) [SIZE] ! }
    if (%s == $null) { sockmark $sockname 1 }
  }

  ;; null byte found, everything that comes next, is data
  else { sockread &temp | bwrite " $+ $mircdirdownloads\banlist.rar $+ " -1 -1 &temp }
}

on *:SOCKCLOSE:banlist_download: {
  echo -s banlist_download TOOK : $calc($ctime - %BL_DOWNLOAD_START_TIME) $+ secs
}


also make sure you delete the .rar file each time before you start downloading, else it will just append to the end of the file! i.e. use something like
Code:
remove " $+ $mircdirdownloads\banlist.rar $+ "

at first line in your alias

Last edited by m0viefreak; 07/12/10 12:02 PM.
Re: $sockread problem [Re: m0viefreak] #228112 07/12/10 03:53 PM
Joined: Dec 2008
Posts: 1,511
westor Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,511
Thank you very much my friend!


Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-