mIRC Home    About    Download    Register    News    Help

Print Thread
#128173 21/08/05 03:54 PM
Joined: Jan 2003
Posts: 36
S
s0tt0 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2003
Posts: 36
I need help to fix this script. It should get data from the web if someone writes specific things in channel, but it cant get the data from the web. Please help me to fix it!

Code:
on *:text:@skills:#: msg $chan Next skills are available: $replace($rune_skills,|,$chr(44)) 
on *:text:@%skills:#: msg $chan  
on *:text:@*:#: { 
  var %skills = overall attack defence strength ranged hitpoints magic fletching thieving crafting cooking firemaking fishing smithing mining prayer runecrafting herblore agility slayer farming
  var %query = $remove($1,@) 
  if ($istok(%skills,%query,32)) { 
    if ($2) runescape $chan %query $2- 
    else msg $chan 14you have to specify a name - $1 $nick 
  } 
  else msg $chan 14Wrong skill, write @skills to see all available skills 
} 

alias runescape { 
  var %sock = runescape. $+ $ticks 
  hadd -m %sock target $1 
  hadd %sock query $2 
  hadd %sock name $3- 
  sockopen %sock hiscore-web.runescape.com 80 
} 

alias rune.add { writeini $shortfn($scriptdirrunedb.ini) $1 $2 $$3 } 

alias rune_skills { return overall|attack|defence|strength|range|hitpoints|magic|fletching|thieving|crafting|cooking|firemaking|fishing|smithing|mining|prayer|runecrafting|herblore|agility|slayer|farming } 

alias delimit { 
  var %regex = (^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d)) 
  .echo -q $regsub($1,m~ %regex ~xg,\1 $+ $chr($2),%regex) 
  return %regex 
} 

alias lvlxp { 
  var %A, %B, %C, %i = 1 
  while (%i <= $1) { 
    %A = $floor($calc(%C / 4)) 
    %B = $floor($calc(%i + 300 * 2^(%i / 7))) 
    %C = $calc(%C + %B) 
    inc %i 
  } 
  return %A 
} 

on *:sockopen:runescape.*: { 
  var %name = $replace($hget($sockname,name),$chr(32),+) 
  sockwrite -n $sockname GET http://hiscore-web.runescape.com/aff/runescape/hiscorepersonal.cgi?username=username$+ 
  sockwrite -n $sockname Host: http://hiscore-web.runescape.com/aff/runescape/hiscores.html
  sockwrite -n $sockname Connection: close 
} 

on *:sockread:runescape.*: { 
  var %temp 
  sockread %temp 

  if (*class=c>*</a></td>* iswm %temp) { 
    hadd $sockname subject $nohtml(%temp) 
    hinc $sockname capture 
  } 
  elseif ($nohtml(%temp)) && ($hget($sockname,capture)) { 
    var %cap = $ifmatch, %subject = $hget($sockname,subject) 
    hadd $sockname %subject $+ $gettok(_rank _level _xp,%cap,32) $nohtml(%temp) 
    if (%cap >= 3) hdel $sockname capture 
    else hinc $sockname capture 
  } 
} 

on *:sockclose:runescape.*: {  
  var %query = $hget($sockname,query), %results 
  if (%query == overall) { 
    var %i = 1 
    while ($hfind($sockname,*_level,%i,w)) { 
      var %type = $gettok($ifmatch,1,95), %value = $hget($sockname,$ifmatch) 
      %results = %results $+([^B],%type,[^B] %value : 
      inc %i 
    } 
  } 
  else { 
    var %level = $hget($sockname,%query $+ _level) 
    var %lvlXP = $lvlxp($calc(%level + 1)) 
    var %currentXP = $hget($sockname,%query $+ _xp) 
    var %needXP = $calc(%lvlXP - $remove(%currentXP,$chr(44))) 

    var %stats = [^B]Rank:[^B] $hget($sockname,%query $+ _rank) : [^B]Level:[^B] $hget($sockname,%query $+ _level) : [^B]XP:[^B] %currentXP : [^B]XP for next lvl:[^B] $delimit(%needXP,44) 

    var %i = 1, %objects, %file = $shortfn($scriptdirrunedb.ini) 
    while ($ini(%file,%query,%i)) { 
      var %object = $ifmatch, %xp = $readini(%file,%query,$ifmatch) 
      if (%xp) %objects = %objects $+([^B],%object,[^B] $floor($calc(%needxp / %xp)) 
      inc %i 
      if (%query == smithing) && (%i > $ini(%file,%query,0)) var %objects = [^B][Smelt][^B] %objects [^B][Smith + Smelt][^B], %query = smelt, %i = 1 
    } 
    if (%query == smelt) %query = smithing 
    var %results = %stats :: %objects 
  } 
  var %jun = $hget($sockname,%query $+ _level)  
  if (%jun) { var %code2 = %results } 
  else { var %code2 = Couldnt get data} 
  msg $hget($sockname,target) 14Nami: 14[7 $hget($sockname,name) 14] Skill: [7 %query 14] :: %code2 
}
 

Joined: Jan 2003
Posts: 36
S
s0tt0 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2003
Posts: 36
please help me! frown

Joined: Jan 2003
Posts: 36
S
s0tt0 Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Jan 2003
Posts: 36
comoon people please, someone has to know whats wrong with it

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
No one is really interested in investing 1 hour to read the entire script, try to understand it, debug it by trying all kinds of changes, ... That, and the added problem that I don't even really know what you really want or how to get it. I don't even know a username to test it on the actual site.

My suggestion: get a program that sniffs your internet traffic (ethereal is a free one) and then use that to sniff both your script's request and reply and a request from your normal browser. Then you can look for differences and see what causes them and if they are crucial to get correct data. Also find the needed documentation: HTTP RFC, some socket script tutorials, mIRC help file, a saved copy of the returned page, ...

To start I'll just give the first problems your script fails. Most likely there are others, like sockread giving too long lines, or chopped ones, both resulting in the following tests to fail.

Code:
on *:sockopen:runescape.*: { 
  var %name = $replace($hget($sockname,name),$chr(32),+)
  [color:orange]; this %name isn't even used??[/color]
  sockwrite -n $sockname GET [color:orange]http://hiscore-web.runescape.com[/color]/aff/runescape/hiscorepersonal.cgi?username=[color:red]username$+[/color]
  sockwrite -n $sockname Host: [color:red]http://[/color]hiscore-web.runescape.com[color:red]/aff/runescape/hiscores.html[/color]
  sockwrite -n $sockname Connection: close [color:green]$+ $crlf $+ $crlf[/color]
}


Link Copied to Clipboard