/*
Usage: /dejatoons <player>
If you don't specify a player, you will be prompted to enter one. If you still don't, the script halts. Note that the player's name is case sensitive, so if you specify "goldarrow111" the server will not give you the statistics, instead they will be empty. You must specify "GoldArrow111" exactly.
Once the script has downloaded the player statistics, all of it is stored in a hash table named after the player, in our example "Goldarrow111".
You can retrieve all of his stats with the identifier $dejatoons.get(player,category,property)
* Player = the nickname of the player, in our case GoldArrow111
* Category = player, penalties, or items
* Property = an attribute from a certain category, like "weapon" from the category "items"
Examples:
//echo -a $dejatoons.get(goldarrow111,player,level)
//echo -a $dejatoons.get(goldarrow111,penalties,kick)
//echo -a $dejatoons.get(goldarrow111,items,shield)
IMPORTANT: Once you've issued /dejatoons <player>, and the statistics are stored in the hash table, you need not issue the /dejatoons <player> command the whole time, since you can just get the stats from the hash table. This will decrease the load on the server, and gets results faster for you. It's your choice of course, though I would update the stats only once in a while.
The last person that you looked up statistics for is stored in the global variable %dejatoons.player
Normally I'd clean up this variable, but I think you might need it.
*/
alias dejatoons {
var %player = $iif($0,$1,$input(Please specifiy a nickname (case-sensitive),eo))
if (!$regex(%player,/[a-z]/)) {
echo -ac info * /dejatoons: bad/missing playername
return
}
if ($hget(%player)) hfree %player
set %dejatoons.player %player
sockclose dejatoons
sockopen dejatoons betamaxstat.dejatoons.net 80
}
[color:red] [/color]
on *:sockopen:dejatoons:{
if ($sockerr) { echo -ac info * /dejatoons: error opening socket | return }
var %s = sockwrite -tn $sockname
%s GET /irpg/xml.php?player= $+ %dejatoons.player HTTP/1.0
%s Host: betamaxstat.dejatoons.net
%s
}
[color:red] [/color]
on *:sockread:dejatoons:{
if ($sockerr) return
var %tmp, %sock = $sockname
sockread %tmp
tokenize 32 %tmp
if ($regex(djt,$$1-,/^<([a-z]+)>$/)) set %dejatoons.category $regml(djt,1)
elseif ($regex(djt,$1-,/^<(.+?)>(.*?)<\/.+?>$/)) {
tokenize 32 $regml(djt,1) $regml(djt,2)
; $1 = tag, $2 = value
if ($1- == username) {
sockclose dejatoons
echo -ac info * /dejatoons: incorrect username specified ( %dejatoons.player )
unset %dejatoons.*
return
}
dejatoons.add %dejatoons.player %dejatoons.category $1-
}
}
[color:red] [/color]
on *:sockclose:dejatoons:{
echo -ac info * /dejatoons: finished retrieving player info for %dejatoons.player
unset %dejatoons.category
}
[color:red] [/color]
alias dejatoons.add {
; 1 = hash table (player), 2 = category, 3 = tag, 4- = data
hadd -m $1 $2 $addtok($hget($1,$2),$3:: $+ $4-,127)
}
[color:red] [/color]
alias dejatoons.get {
; $dejatoons.get(player,category,property)
return $gettok($wildtok($hget($1,$2),$3::*,1,127),2,58)
}