mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 15
X
Xklark Offline OP
Pikka bird
OP Offline
Pikka bird
X
Joined: Oct 2005
Posts: 15
Well im trying to make a IdleRPG stat lookup with sockets. I read tutorials and everything and cant get it to work. Could someone help me?

Code:
 alias -l htmlfree {
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  return %x
}

on *:sockopen:idlelevel:{ 
  sockwrite -n $sockname GET /~idlerpg/playerview.php?player= $+ %statnick HTTP/1.1 
  sockwrite -n $sockname Host: wrathirc.cjb.net $+ $crlf $+ $crlf
}

on *:sockread:idlelevel:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    %temptext = $htmlfree(%temptext)
    if (Class: * iswm %temptext) {
      set %class %temptext
    }
    if (Alignment: * iswm %temptext) {
      set %alignment %temptext
    }
    if (Level: * iswm %temptext) {
      set %level %temptext
    }
  }
}

on *:text:!level*:#: {
  set %statnick $2-
  sockopen idlelevel wrathirc.cjb.net 80
  sockclose idlelevel
  notice $nick 14[2 $+ %statnick $+ 14] %class | %alignment | %level
  unset %statnick
} 


Thanks

Last edited by Xklark; 11/12/05 09:12 PM.
Joined: Oct 2005
Posts: 15
X
Xklark Offline OP
Pikka bird
OP Offline
Pikka bird
X
Joined: Oct 2005
Posts: 15
Can anyone help please?

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
This is the calling code
Quote:
set %statnick $1-
sockopen idlelevel wrathirc.cjb.net 80
sockclose idlelevel
notice $nick 14[2 $+ %statnick $+ 14] %class | %alignment | %level
unset %statnick


What does it do: set %statnick to $nick, open and immediately close a socket, notice someone a %level that isn't set and unset %statnick.

What you need to realize is that connecting to a website can take seconds or even days. That is a lot longer than the time between the /sockopen and the /sockclose. Once you understand how the whole socket opening writing and reading works, then you can start doing stuff.

You can only send the notice once all required info from that website is transferred. The easiers way is in the on SOCKCLOSE event, since that means the entire web page is sent. You could also parse the web site and once you have all (3) levels you notice the user and /sockclose immediately.

The website sends HTML and in packets. This means that one line gotten is not guaranteed to be a complete line. On some websites one line might be a lot longer than what mIRC can handle too. Not on this website afaics.

Make sure to do read up some mIRC socket tutorials to understand what is going on. Socket scripting is not that easy, so be prepared to read a lot of documentation and spend a lot of time in debugging.

Joined: Oct 2005
Posts: 15
X
Xklark Offline OP
Pikka bird
OP Offline
Pikka bird
X
Joined: Oct 2005
Posts: 15
Thank you for all your help. This is my first time learning about sockets and am starting to understand it more clearly. Thanks again for all your help.

Joined: Oct 2005
Posts: 15
X
Xklark Offline OP
Pikka bird
OP Offline
Pikka bird
X
Joined: Oct 2005
Posts: 15
Its working now!! Thanks for all your help! smile


Link Copied to Clipboard