mIRC Home    About    Download    Register    News    Help

Print Thread
#76098 22/03/04 03:15 AM
Joined: Feb 2003
Posts: 13
A
Arrow Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 13
In the last week or so, a script that I've had no problem whatsoever with started giving some odd errors for anybody that used it.

It's a RPG battle script, but the part that's messing up is the section of code that uses sockets to connect to my webpage and download a character's stats. Here's the code:

Code:
alias wave-grabstats {
  :name
  set -n %wavestorm-name $input(Please enter your player name,eoi,Wavestorm,%wavename)
  set -n %wavename %wavestorm-name
  if (!%wavestorm-name) { goto name }
  :password
  set -n %wavestorm-password $input(Please enter your password,poi,Wavestorm,%wavepassword)
  set -n %wavepassword %wavestorm-password
  if (!%wavestorm-password) { goto password }
  if ($sock(wavestormgrab)) { sockclose wavestormgrab }
  sockopen wavestormgrab www.wavestorm.info 80
  display3 %wavechat Retrieving stats for %wavestorm-name $+ ...
  set %wavestorm-sockettime 1
  .timerwavestorm-sockettime 0 1 inc %wavestorm-sockettime 1
}

on *:sockopen:wavestormgrab: {
  sockwrite -tn $sockname GET /Player2.php?data=get&player= $+ $replace(%wavestorm-name,$chr(32),$chr(37) $+ 20) 
     $+ &password= $+ $replace(%wavestorm-password,$chr(32),$chr(37) $+ 20) HTTP/1.1
  sockwrite -tn $sockname Host: www.wavestorm.info $+ $crlf $+ $crlf
  sockwrite -tn $sockname Connection: Keep-Alive 
  sockwrite -tn $sockname $crlf
}

on *:sockread:wavestormgrab: {
  if ($sockerr) {
    echo -a Error: Stats not retrieved!  $sockerr
    unset %wavestorm-name
    unset %wavestorm-password
    return
  }
  var %temptext
  sockread %temptext
  if ($left(%temptext,9) == $+(stats,$chr(61),yes)) { 
    set %wavestorm-grabstats 1
    if ($hget(Player)) { hfree Player }
    wavewindowreset
    hmake Player 100
    var %socktemp = 2
    :socktemp
    hadd -m Player $gettok($gettok(%temptext,%socktemp,126),1,61) $gettok($gettok(%temptext,%socktemp,126),2,61)
    inc %socktemp 1
    if (%socktemp <= $numtok(%temptext,126)) { goto socktemp }
  }
  elseif ($left(%temptext,9) == $+(stats,$chr(61),no1)) { set %wavestorm-grabstats 2 }
  elseif ($left(%temptext,9) == $+(stats,$chr(61),no2)) { set %wavestorm-grabstats 3 }
  elseif ($left(%temptext,9) == $+(stats,$chr(61),no3)) { set %wavestorm-grabstats 4 }
  if (!%wavestorm-grabstats) { set %wavestorm-grabstats 5 }
}

on *:sockclose:wavestormgrab: {
  .timerwavestorm-sockettime off
  if (%wavestorm-sockettime == 1) { var %wavestorm-dummysocket = 1 second }
  else { var %wavestorm-dummysocket = %wavestorm-sockettime seconds }
  if (%wavestorm-grabstats == 1) {
    display3 %wavechat Stats successfully retrieved! ( $+ %wavestorm-dummysocket $+ )
    if (!window(@Wavestorm)) { wavewindow }
    else { wavewindowreset }
    if ($dialog(options)) { optionsrefresh }
  }
  elseif (%wavestorm-grabstats == 2) { display3 %wavechat Error: 
     The character %wavestorm-name does not exist.  Stats not retrieved! ( $+ %wavestorm-dummysocket $+ ) }
  elseif (%wavestorm-grabstats == 3) { display3 %wavechat Error: 
     Incorrect password.  Stats not retrieved! ( $+ %wavestorm-dummysocket $+ ) }
  elseif (%wavestorm-grabstats == 4) { display3 %wavechat Error: 
     Database down.  Stats not retrieved! ( $+ %wavestorm-dummysocket $+ ) }
  elseif (%wavestorm-grabstats == 5) { display3 %wavechat Error: 
     Incorrect webpage syntax.  Stats not retrieved! ( $+ %wavestorm-dummysocket $+ ) }
  unset %wavestorm-name
  unset %wavestorm-password
  unset %wavestorm-grabstats
  unset %wavestorm-sockettime
}


I've manually split several of those lines (the GET statement, the error messages) so people reading this don't have to scroll right indefinitely, but they're all one line apiece. There's various aliases in there that I won't bother to explain in detail; they basically have to do with clearing and regenerating the associated custom window attached to this script after purging/getting stats. As you can see above, the script basically uses a socket to connect to the following link:

http://www.wavestorm.info/Player2.php?data=get&player=YOURNAME&password=YOURPASSWORD

I'd give you a name and password to let you all test, but... you know. Anyways, what comes up on the page if you look at it in a web browser is something similar to the following:

Code:
PlayerStats
stats=yes~Gender=Male~Level=57~HealthPoints=5698~MagicPoints=564~AbilityPoints=15~CurrentExperience=384~
NeededExperience=29683~Credits=50039~Wavelength=4~Color=Blue~Weapon=2~Weaponname=Staff~Modifier=j~
Modifiera=1~Modifierb=1~Modifierc=1~Modifierd=1~Modifiere=1~Modifierf=1~Modifierg=1~Modifierh=1~Modifieri=1~
Modifierj=1~Wins=1~Losses=2~Item1=0~Item2=0~Item3=0~Item4=0~Item5=0~Item6=0~Item7=0~Item8=0~Item9=0~
Item10=0~Item11=0~Item12=0~Item13=0~Item14=0~Item15=0~Item16=0~Item17=0~Item18=0~Item19=0~Item20=0~
Item21=0~Item22=0~Item23=0~Item24=0~Item25=0~Item26=0~Item27=0~Item28=0~Item29=0~Item30=0~Item31=0~
Item32=0~Item33=0~Item34=0~Item35=0~Item36=0~Item37=0~Item38=0~Item39=0~Item40=0~Item41=0~Item42=0~
Item43=0~Item44=0~Item45=0~Item46=0~Item47=0~Item48=0~Item49=0~Item50=0~Item51=0~Item52=0~Item53=0~
Item54=0~Item55=0~Item56=0~Spell1=1~Spell2=1~Spell3=1~Spell4=1~Spell5=0~Spell6=0~Spell7=0


Once again, from "stats=yes" to "Spell7=1" is one line; I've just split it manually so as not to make everyone who views this page have to scroll right forever while reading. The script just uses tokens to seperate that entire bit into a hash table. Normally. And other sites, such as this HTTP Request Viewer, also show a similarly fine layout, like this:

Code:
<HTML><HEAD><TITLE>Player·Stats</TITLE></HEAD><BODY><H1>Player·Stats</H1>(LF)
(LF)
stats=yes~Gender=Male~Level=57~HealthPoints=5698~MagicPoints=564~AbilityPoints=15~CurrentExperience=384~etc.(LF)
</BODY></HTML>


Now, the problem is mIRC. When you use the socket to connect, the information read is basically what's in the following text file.

http://www.wavestorm.info/Extra/socket.txt

Where did all those random letters and numbers come from? Is it a problem with mIRC or my code? I can't see it being a problem with the webpage, not when seperate viewers and browsers show it just fine.

#76099 22/03/04 09:19 PM
Joined: Dec 2002
Posts: 208
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 208
i didnt look though all of your code in detail but the first thing i noticed off the bat is this line:

.timerwavestorm-sockettime 0 1 inc %wavestorm-sockettime 1

mIRC evaluates each item in a string before it sets the timer so the time rwill preform /inc VALUE_OF_%wavestorm...

to prevent this use the ! prefix .. for example if you type

//set %blah 2 | timer 1 1 inc %blah
mIRC will try to do 'inc 2'
but if you do
//set %blah 2 | timer 1 1 inc %!blah
mIRC will do 'inc %blah'

notice the '!' .. this will also work with $identifers .. if you do $!identifer mIRC will not evaluate the identifer.. that awy it gets evaluated each time the timer executes.

so you want to add a ! to your var like this

.timerwavestorm-sockettime 0 1 inc %!wavestorm-sockettime 1


now, withough going though all your code line by line i figured if that .txt was the output u were geting, that it had to be the loops in your sockread event .. so i ran this test:

Code:
alias test01 {
  var %temptext = stats=yes~Gender=Male~Level=57~HealthPoints=5698~MagicPoints=564~AbilityPoints=15~CurrentExperience=384~NeededExperience=29683~Credits=50039~Wavelength=4~Color=Blue~Weapon=2~Weaponname=Staff~Modifier=j~Modifiera=1~Modifierb=1~Modifierc=1~Modifierd=1~Modifiere=1~Modifierf=1~Modifierg=1~Modifierh=1~Modifieri=1~Modifierj=1~Wins=1~Losses=2~Item1=0~Item2=0~Item3=0~Item4=0~Item5=0~Item6=0~Item7=0~Item8=0~Item9=0~Item10=0~Item11=0~Item12=0~Item13=0~Item14=0~Item15=0~Item16=0~Item17=0~Item18=0~Item19=0~Item20=0~Item21=0~Item22=0~Item23=0~Item24=0~Item25=0~Item26=0~Item27=0~Item28=0~Item29=0~Item30=0~Item31=0~Item32=0~Item33=0~Item34=0~Item35=0~Item36=0~Item37=0~Item38=0~Item39=0~Item40=0~Item41=0~Item42=0~Item43=0~Item44=0~Item45=0~Item46=0~Item47=0~Item48=0~Item49=0~Item50=0~Item51=0~Item52=0~Item53=0~Item54=0~Item55=0~Item56=0~Spell1=1~Spell2=1~Spell3=1~Spell4=1~Spell5=0~Spell6=0~Spell7=0
  if ($left(%temptext,9) == $+(stats,$chr(61),yes)) {
    if ($window(@test01)) { clear @test01 } | else { window @test01 }
    set %wavestorm-grabstats 1
    if ($hget(Player)) { hfree Player }
    ; wavewindowreset
    hmake Player 100
    var %socktemp = 2
    :socktemp
    echo @test01 hadd -m Player $gettok($gettok(%temptext,%socktemp,126),1,61) $gettok($gettok(%temptext,%socktemp,126),2,61)
    inc %socktemp 1
    if (%socktemp <= $numtok(%temptext,126)) { goto socktemp }
  }
}


typed /test01

everything apears fine to me .. with that test, except for the alias that i remarked out with ';' .. is it at all posible that alias is the alis writeing extra lines ?

hope this was remotly helpful.

Cobra^

#76100 22/03/04 10:53 PM
Joined: Feb 2003
Posts: 13
A
Arrow Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 13
The ! timer thing actually has never given me any problems, but I'll look into adding it; it'll probably be useful (and politically correct so to speak) to use regardless.

As for the alias writing extra lines, I doubt it. All those artifacts are streaming straight out the socket; the code literally does a sockread into %temptext, and then to create that socket.txt file, I stuck "write C:\socket.txt %temptext" immediately after the sockread to see what was happening. So something's gotta be wrong in the socket code itself if anywhere.

#76101 23/03/04 01:22 AM
Joined: Dec 2002
Posts: 208
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 208
if you changed your code to the following:

Code:
on *:sockread:wavestormgrab: {
  if ($sockerr > 0) { return }
  :read.next | sockread %temp.read
  if ($sockbr == 0) { return }
  write socklog.txt %temp.read
  goto read.next
}


what you see in the .txt is exactly wahts being sent .. there is no problems with the above code ..

so please run that test and show me what you get

Cobra^

#76102 26/03/04 03:08 AM
Joined: Feb 2003
Posts: 13
A
Arrow Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Feb 2003
Posts: 13
Still getting the artifacts. Here's my socklog.txt so you can see. A 400 Bad Request wasn't attached to the bottom this time though, at least.


Link Copied to Clipboard