mIRC Home    About    Download    Register    News    Help

Print Thread
#204101 08/09/08 12:23 PM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
I've been trying to fix, re-fix, re-write, re-re-write and re-fix this script for some days now and i can not figure out why i can't get the name out of the HTML:
Php Code:

alias somealias {
  sockopen somealias some.com 80
  set %playerid $1-
  set %host_url /host.php?id= $+ %playerid
}

on *:SOCKOPEN:somealias: {
  sockwrite -n $sockname GET %host_url HTTP/1.1
  sockwrite -n $sockname Host: somehost.com  
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname $crlf
}

on *:sockread:somealias:{
  if ($sockerr > 0) return
  var %temptext |  sockread %temptext
  if (<img src="hlstatsimg/flags/.*\.gif" style="border:0px;" alt=".*" title=".*">\&nbsp;<b>.*</b> iswm %temptext) { echo -a %temptext }
}
on *:sockread:somealias:{
  if ($sockerr > o) return
  sockread %temptext
  var %tmpexp <img src="hlstatsimg/flags/.*\.gif" style="border:0px;" alt=".*" title=".*">&nbsp;<b>(.*)<\/b>
  if ($regex(%temptext, %tmpexp)) { echo -a $regml(1)
  }

  unset %playerid
  unset %host_url
  sockclose somealias
} 


I've edited out the alis names, web host and stuff.

What i am trying to do is:
Get Player ID from input (ex: /somealias 528 for id 528)
Add it to the host url as page.php?playerid=528
That works fine.

Then I am taking all the HTML from the page, looking for the line that includes <img .. flag/(flag_name_here).gif> alt="country name" title="country name">
<b>My name(in this case z4nd)</b>

that seems to be in %temptex, but i can not get the reg-ex functions to work and find the data i need to echo out (doesn't have to spam the channel, but can change that later on)

How do i remove the html, get the name and echo it all out?
I've been reading up on reg-ex and mirc reg-ex functions, looking at other scripts and all kind of suff, but can't seem to get it right.
Sockets really is my nemesis.

Side question (can look into that later, doesn't have to be answered): Would it be possible to make it into a small function, so i can take whatever data i need?
like Name, rank, points, as long it's on the site.

Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
I still hope someone can help just tiny bit here, got it changed alot now, using a £gettok parser to find whatever i need.
Php Code:

alias parser { 
return $gettok($gettok($1,-3,$asc(<)),2,$asc(>)) }

alias mpuktf2 {
  if ($sock(mpuktf2)) { sockclose mpuktf2 }
  sockopen mpuktf2 tf2.multiplay.co.uk 80
  set %chan $chan
  set %playerid $1-
  set %host_url /hlstats/hlstats.php?mode=playerinfo&player= $+ %playerid
}

on *:SOCKOPEN:mpuktf2: {
  sockwrite -n $sockname GET %host_url HTTP/1.1
  sockwrite -n $sockname Host: tf2.multiplay.co.uk
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname $crlf
}

on *:sockread:mpuktf2: {
  if ($sockerr > 0) return
  :nextread
  var %x
  sockread %x
  if ($sockbr == 0) return
  if (%x == $null) return
  goto nextread
  if (*Rank:* iswm %x) {
	echo -a %chan Rank: $parser(%x)
  }
  sockclose mpuktf2
} 


But this still doesn't seem to work as intented.
If i put the if before the goto nextread, i echoes:
Rank: Rank:
Rank:
But no rank what so ever, it just wont get that number for me.
Any hints?

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
Ok 1st of all your parser alias is picking the wrong token, it should be $gettok($gettok($1,-4,60),2,62)

Secondly the rank is actually on the line AFTER the matched "Rank:" text. Just set a variable when the match is made, allowing triggering the parser on the next line.
Code:
alias parser { return $gettok($gettok($1,-4,60),2,62) }

alias mpuktf2 {
  if ($sock(mpuktf2)) { sockclose mpuktf2 }
  set %mpuktf2.chan $chan
  set %mpuktf2.playerid $1
  set %mpuktf2.host_url /hlstats/hlstats.php?mode=playerinfo&player= $+ %mpuktf2.playerid
  sockopen mpuktf2 tf2.multiplay.co.uk 80
}

on *:SOCKOPEN:mpuktf2: {
  sockwrite -n $sockname GET %mpuktf2.host_url HTTP/1.1
  sockwrite $sockname Host: tf2.multiplay.co.uk $+ $str($lf,2)
}

on *:sockread:mpuktf2: {
  if ($sockerr > 0) return
  var %x
  sockread %x
  if (%mpukt.rank) { echo -a %mpuktf2.chan Rank: $parser(%x) | sockclose mpuktf2 | unset %mpukt.* }
  if (*Rank:* iswm %x) { inc -u3 %mpukt.rank }
}

P.S. Don't send a "Keep-Alive" header if you do not want to keep the connection alive. wink


Link Copied to Clipboard