mIRC Homepage
Posted By: adamb53 need some help plz - 29/03/06 02:32 AM
well i am the kind of person that needs guidding through something so can some1 tell me if this is even close to being right so far, i dont want some1 to give me the script but to tell me if what i am doing is right:

/sockopen hpcomp runescape.com 80

on *:sockopen:hpcomp:{
sockwrite -n $sockname GET /lang/en/aff/runescape/hiscorepersonal.ws?user1= HTTP/1.1
sockwrite -n $sockname Host: runescape.com $+ $crlf $+ $crlf
}
on *:sockread:hpcomp:{
if ($sockerr) {
echo -a Error.
halt
}
else {
var %temptext
sockread %temptext
; handling here
}
}

i forgot to add that this is going to call the hp stats from runescape.com
Posted By: genius_at_work Re: need some help plz - 29/03/06 04:27 AM
That code looks like it should work. A couple things though:

You should use HTTP/1.0 in mIRC sockets, otherwise the server will send in bursts, and you will get strange numbers in your data.

To test if the connection is working, add an echo where you have:
; handling here.

Something like this:
echo 5 -s > %temptext

That should echo the entire contents of the website to the status window.

-genius_at_work
Posted By: adamb53 Re: need some help plz - 29/03/06 04:33 AM
hmmm ok, i attempted to add some more and im starting to get confused and i think there is something wrong but ill post it:

Code:
/sockopen hpcomp runescape.com 80

on *:sockopen:hpcomp:{
  sockwrite -n $sockname GET /lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %user HTTP/1.0
  sockwrite -n $sockname Host: runescape.com $+ $crlf $+ $crlf
}
on *:sockread:hpcomp:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    echo 5 -s > %temptext
    if <span class="small text">Hitpoint stats: Starting Level: * , Current Level: * , Difference: *{
    echo -a -
    echo -a $htmlfree(%temptext)
  }
}
}
alias -l htmlfree {
; It's local because it won't be used by the command line, only this file.
; Local aliases avoid conflicting names.
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}

alias hpcomp {
if ($2-) {
  set %user $2

  ; Variables to be used in the future URL are being set here!
  sockopen hpcomp runescape.com 80
}
else {
  echo -a You didn't specify a user and the info.
}
}
Posted By: RusselB Re: need some help plz - 29/03/06 05:20 AM
You have an extra } at the end of your ON SOCKREAD event.
Posted By: adamb53 Re: need some help plz - 29/03/06 11:50 AM
ok i fixed that, anything else wrong?

Code:
/sockopen hpcomp runescape.com 80

on *:sockopen:hpcomp:{
  sockwrite -n $sockname GET /lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %user HTTP/1.0
  sockwrite -n $sockname Host: runescape.com $+ $crlf $+ $crlf
}
on *:sockread:hpcomp:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    echo 5 -s > %temptext
    if <span class="small text">Hitpoint stats: Starting Level: * , Current Level: * , Difference: *{
    echo -a -
    echo -a $htmlfree(%temptext)
  }
}
alias -l htmlfree {
  ; It's local because it won't be used by the command line, only this file.
  ; Local aliases avoid conflicting names.
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  return %x
}

alias hpcomp {
  if ($2-) {
    set %user $2

    ; Variables to be used in the future URL are being set here!
    sockopen hpcomp runescape.com 80
  }
  else {
    echo -a You didn't specify a user and the info.
  }
}
Posted By: genius_at_work Re: need some help plz - 29/03/06 03:05 PM
Your /sockopen command should be within an alias, like this:

Code:
alias rune {
  if ($sock(hpcomp)) sockclose hpcomp
  sockopen hpcomp runescape.com 80
  .timer 1 5 sockclose hpcomp
  echo -at Connecting to runescape
}


To start the connection, you would type /rune

-genius_at_work
Posted By: adamb53 Re: need some help plz - 30/03/06 02:35 AM
my finaly code is:

Code:
on *:sockopen:hpcomp:{
  sockwrite -n $sockname GET /lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %user HTTP/1.0
  sockwrite -n $sockname Host: runescape.com $+ $crlf $+ $crlf
}
on *:sockread:hpcomp:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    echo 5 -s > %temptext
    if <span class="small text"> Hitpoint stats: Starting Level: * , Current Level: * , Difference: *{
    echo -a -
    echo -a $htmlfree(%temptext)
  }
}
alias -l htmlfree {
  ; It's local because it won't be used by the command line, only this file.
  ; Local aliases avoid conflicting names.
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  return %x
}

alias hpcomp {
  if ($2-) {
    set %user $2

    ; Variables to be used in the future URL are being set here!
    sockopen hpcomp runescape.com 80
  }
  else {
    echo -a You didn't specify a user and the info.
  }
}

alias rune {
  if ($sock(hpcomp)) sockclose hpcomp
  sockopen hpcomp runescape.com 80
  .timer 1 5 sockclose hpcomp
  echo -at Connecting to runescape
}

but when i try to use it, it says:

[21:34:21] Connecting to runescape <--- in the active window
* /if: 'class="small' unknown operator (line 16, script13.ini) <--- in status window
Posted By: RusselB Re: need some help plz - 30/03/06 03:30 AM
simply put a space on either side of the equals sign in that line. I don't know if it makes a difference or not, but in most of the coding for a comparison, a == is used, rather than =

Just make sure you have a space on either side of the == or the =
Posted By: genius_at_work Re: need some help plz - 30/03/06 03:51 AM
I don't see any actual comparison in that if-statement. Your code is like this:

if (SOMETHING) {

Which always evaluates to true. It should have a comparison in it like this:

if (SOMETHING == SOMETHING) {

Or in your case,

if (*wild*string* iswm %variable) {

Code:
if (&lt;span class="small text"&gt; Hitpoint stats: Starting Level: * , Current Level: * , Difference: * iswm %temptext) {


-genius_at_work
Posted By: adamb53 Re: need some help plz - 30/03/06 04:24 AM
ok my code:

Code:
/sockopen hpcomp runescape.com 80

on *:sockopen:hpcomp:{
  sockwrite -n $sockname GET runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %user HTTP/1.0
  sockwrite -n $sockname Host: runescape.com $+ $crlf $+ $crlf
}
on *:sockread:hpcomp:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    echo 5 -s &gt; %temptext
    if (&lt;span+class == "small text"&gt;Hitpoint stats: Starting Level: * , Current Level: * , Difference: * iswm %temptext){
    echo -a -
    echo -a $htmlfree(%temptext)
  }
}
alias -l htmlfree {
  ; It's local because it won't be used by the command line, only this file.
  ; Local aliases avoid conflicting names.
  var %x, %i = $regsub($1-,/(^[^&lt;]*&gt;|&lt;[^&gt;]*&gt;|&lt;[^&gt;]*$)/g,$null,%x), %x = $remove(%x,&amp;nbsp;)
  return %x
}

alias hpcomp {
  if ($2-) {
    set %user $2

    ; Variables to be used in the future URL are being set here!
    sockopen hpcomp runescape.com 80
  }
  else {
    echo -a You didn't specify a user and the info.
  }
}

alias rune {
  if ($sock(hpcomp)) sockclose hpcomp
  sockopen hpcomp runescape.com 80
  .timer 1 5 sockclose hpcomp
  echo -at Connecting to runescape
}


and it says:

[23:25:05] Connecting to runescape
-
HTTP/1.1 404 Not found
-
Content-type: text/html
-
Cache-control: no-cache
-
Pragma: no-cache
-
Expires: 0
-
Connection: Close
-
Content-length: 549
-
404 - Page not found404 - Page not foundSorry, the page you were looking for was not found.
Posted By: genius_at_work Re: need some help plz - 30/03/06 04:36 AM
Obviously, that result means that the page you are trying to view doesn't exist. Find the correct URL, and change it in your code.

Also, your sockwrite GET line is incorrect. It should be something like this:

sockwrite -n $sockname GET lang/en/aff/runescape/hiscorepersonal.ws?user1= $+ %user HTTP/1.0

That is assuming that you have set %user as a global variable somewhere else before you opened the socket.

Your if iswm line also has a problem. At the end of the line, there should be a space between the ) and {, like this:

if (<span...%temptext) {

When you fix that, you will have a } bracket mismatch. Add another } after the second /echo command.

-genius_at_work
© mIRC Discussion Forums