mIRC Home    About    Download    Register    News    Help

Print Thread
#238994 16/09/12 06:47 PM
Joined: Sep 2012
Posts: 6
X
Xar Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Sep 2012
Posts: 6
Hello. Ive got a little socket script that is supposed to get 2 things on the command !stats *name* : total clicks and last click.
This works fine for all names except a few like flopei and thacrazyorc. Cant for the life of me figure out why it won't work for those while it works for others

Quote:
on *:TEXT:!info *:#: {
set %chan $chan
set %name $2
sockopen stats stats.luxbot.net 80
}

on *:SOCKOPEN:stats:{
sockwrite -tn $sockname GET /clicks.php HTTP/1.1
sockwrite -tn $sockname Host: stats.luxbot.net
sockwrite $sockname $crlf
}

on *:SOCKREAD:stats:{
var %temp
sockread %temp
if ( %name isin %temp ) {
sockread %temp | sockread %temp
set %temp.1 $remove($gettok($remove(%temp,$chr(32)),3,62),</td)
sockread %temp
set %temp.2 $remove($gettok(%temp,2,62),</td)
msg %chan Total: %temp.1 $+ ; Last: %temp.2
sockclose $sockname
}
}


Last edited by Xar; 16/09/12 07:39 PM.
Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Use HTTP/1.0

Joined: Sep 2012
Posts: 6
X
Xar Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Sep 2012
Posts: 6
Thank you for helping 5618.
I tried your suggestion and it works for 1 of the two names now, but still not for the other. Very confusing confused

Joined: Feb 2011
Posts: 448
K
Pan-dimensional mouse
Offline
Pan-dimensional mouse
K
Joined: Feb 2011
Posts: 448
Just eyed one slight issue. Script still seems to function.. but just to be safe.
The ';' is used for comments in mIRC script editor.

change
Code:
msg %chan Total: %temp.1 $+ ; Last: %temp.2

into
Code:
msg %chan Total: %temp.1 $+ $asc(59) Last: %temp.2

Joined: Sep 2012
Posts: 6
X
Xar Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Sep 2012
Posts: 6
Thanks kindone I'll keep that in mind

on the main issue again.. tried it a few times and everything still works fine except those two names. What changing the http version did manage to achieve is that it no longer fails everytime. It now sometimes reads only 1 of both (total and last), sometimes nothing and sometimes it functions normally.
:p

Joined: Jul 2006
Posts: 4,146
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,146
@kindone: the ; character must be at the beginning of a line to make that line a comment, or in front of a command (like cmd1 | ;cmd2 | cmd3, and only cmd2 is ignored).

@Xar, basically, the on sockread event trigger when there's data to read. using one /sockread command inside it to read data is fine, but you can't make the assumption that more data (more lines) are available right now, ie. the others /sockread might not read data at all though it's unlikely.
In any case you would need to debug the code to find what's going on.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2012
Posts: 6
X
Xar Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Sep 2012
Posts: 6
When I don't filter out the number on 'total' it reads
<td class="value"><!--
instead of
<td class="value"><!-- 1,042,216 --> 1,042,216 </td>

when it goes wrong

Joined: Jul 2006
Posts: 4,146
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,146
You need to understand something, you shouldn't expect windows/mIRC to read the data (internally) the same way each time, you won't necessarily get the same number of byte read each time, that's why you can get different result each time.
You need to read the data in a better way, you are actually reading it making a false assumption, which is "if I can get the line with the name when my sockread event triggers, I can get the next lines from that same sockread event".

A better way would be to use a variable to count whenever you are past the line with the nickname or not, and then use that variable to count the lines:
Code:
if (%name isin %temp) set %count 1
elseif (%count isnum 1-2) inc %count
else {
if (%count == 3) set %temp.1 $remove($gettok($remove(%temp,$chr(32)),3,62),</td)
else set %temp.2 $remove($gettok(%temp,2,62),</td)
if (%temp.1) && (%temp.2) {
msg %chan Total: %temp.1 $+ ; Last: %temp.2
sockclose stats
unset %count %temp.1 %temp.2
 }
inc %count
}
this is untested.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2012
Posts: 6
X
Xar Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
X
Joined: Sep 2012
Posts: 6
I see.
unfortunatly that still gives the same problem

Last edited by Xar; 17/09/12 12:55 AM.

Link Copied to Clipboard