mIRC Home    About    Download    Register    News    Help

Print Thread
Sockopen/Sockwrite/Sockread/Sockclose #193546 21/01/08 03:15 AM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
I've been working with mIRC script for a while now, and I am interested in trying to learn how to use sockets to fetch information from the web. In particular, I have a project: The script needs to go to a colony page and grab the military units.

Every colony url ends with numbers, IE http://www.lunarwars.net/profile.php?lookup=833

So, say, I typed !units 833

and the script would open http://www.lunarwars.net/profile.php?lookup= $+ $$2

Then it would go down to the military units, get them, and read them off to the channel, IE:

Military Strength 68,523
Soldiers 12,528
Ground Assault 500
Orbital Fighters 403
Long Range Missiles 0
Nuclear Arsenal 0


I would like to learn how to do this myself, and I would appreciate it if ;documentation could be included.

Re: Sockopen/Sockwrite/Sockread/Sockclose [Re: Mpot] #193550 21/01/08 05:31 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
You need to /sockopen a connection to the server (www.lunarwars.net) on port 80. Once the connection opens (on sockopen) you need to request the webpage with /sockwrite. You need to GET /profile.php?lookup= $+ $2 HTTP/1.0 . Then you need to parse the on sockread data using /sockread.

-genius_at_work

Re: Sockopen/Sockwrite/Sockread/Sockclose [Re: genius_at_work] #193572 21/01/08 05:31 PM
Joined: Apr 2007
Posts: 228
M
Mpot Offline OP
Fjord artisan
OP Offline
Fjord artisan
M
Joined: Apr 2007
Posts: 228
Would you be able to write that? And what is the HTTP 1.0 business?

Last edited by Mpot; 21/01/08 05:33 PM.
Re: Sockopen/Sockwrite/Sockread/Sockclose [Re: Mpot] #193592 22/01/08 05:11 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
This bit of code would get information from a regular non-passworded webpage. Unfortunately, the page you want to read is password protected. Therefore, you will need a more complex code (to return cookies) in order to read the site. You can search this site for 'cookies'.

Code:

alias units {
  if ($1 == $null) return
  var %sockname = $+(units.,$r(000,999))
  sockmark %sockname $1
  sockopen %sockname www.lunarwars.net 80
}

on *:SOCKOPEN:units.*:{
  sockwrite -n $sockname GET /profile.php?lookup= $sock($sockname).mark http/1.0
  sockwrite -n $sockname host: www.lunarwars.net
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:units.*:{
  var %s
  sockread %s
  echo -s > %s
}




-genius_at_work