mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
Okay, my friend asked me to help him with a website socket problem, which I did for the most part, but now we're having problems returning the last peice of data. (BannedMACs[3].)

(I edited some of the code, since that's what I do most of the time. - Original here if you're interested.)

Code:
on *:sockopen:rebsite:{ 
  sockwrite -nt $sockname GET /*removed*.txt HTTP/1.1
  sockwrite -nt $sockname Host: rebellion.net.au $+ $str($crlf,2)
}

on *:sockread:rebsite:{
  var %x = $null
  sockread %x
  if (!$sockerr) {
    if (BannedMACs[*]=* iswm %x) { echo $active $v2 }
  }
}

alias riscban { sockopen rebsite rebellion.net.au 80 }


Quote:

*removed*


Any ideas?


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This is happening because the last line of text is not CRLF-terminated, so using /sockread without -f will not read any bytes. In your case, this will do:
Code:
on *:sockread:rebsite:{
  if $sockerr { 
    echo 4 -a Error $v1 on $sockname : $sock($sockname).wserr ( $sock($sockname).wsmsg ) 
    return 
  }
  var %x
  sockread %x
  while $sockbr {
    if (BannedMACs[*]=* iswm %x) { echo -a %x }
    sockread %x
  }
  sockread -f %x
  if (BannedMACs[*]=* iswm %x) { echo -a %x }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2007
Posts: 37
C
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 37
Your problem is that the last line does not contain a crlf, so when the /sockread command is used, no data will be read into the variable. You can use binary variables to solve this, or alternatively edit the source of the page (presuming you have access to) to add a crlf on the end.

Code:
on *:sockread:rebsite:{
  sockread -fn &b
  if (!$sockerr) {
    if (BannedMACs[*]=* iswm $bvar(&b,1-).text) { echo -a $v2 }
  }
}


Should work.

Edit: qwerty beat me frown

Last edited by Chessnut; 18/04/08 01:18 PM.
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
Thanks guys, he fixed it. :P


What do you do at the end of the world? Are you busy? Will you save us?

Link Copied to Clipboard