#!/usr/bin/perl -w use LWP 5.64; use LWP::ConnCache; # Alloscomp GoldGetter v1.0 # contact: webmaster@alloscomp.com # Feel free to use this IF you credit the Alloscomp GoldGetter in your code and in any public release # Set to 0 if you run this on your own system my $logging = 0; # cache often looked up users my %users = ( 'lanzer' => '3', 'enigma ghost' => '109467', 'desna' => '756', 'cyrene' => '102924', 'chevrolet silverado 1500' => '6730424', 'vo' => '4', 'l0cke' => '21', 'iflight' => '10856315' ); my $browser = LWP::UserAgent->new(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6'); $browser -> protocols_allowed(['http']); $browser -> conn_cache(LWP::ConnCache->new()); # Proxy using Tor... I don't like bans #$browser -> proxy('http', 'http://localhost:8118/'); $| = 1; my $gold = -1; my $userid = -1; my $name = shift; # Get name from command line my $google = 0; $google = 1 if(($google = shift) && $google eq 'google'); if($name =~ /^\d*$/) { # If the 'name' is all numbers, assume it's the user-id $userid = $name; } else { $userid = getIdForUser($name); # Get the userid for the name -- do a search with the find user function } if($userid == -1) { if($google) { print "$name|-1"; } else { print "Non-existant user.\n"; } exit(1); } else { $gold = getGoldForId($userid); # Get gold by querying the game server if($google) { # handle google gadget output format print "$name|$gold"; } else { print "$name ($userid) has: $gold"."g\n"; } } if($logging) { open CSV,">>/tmp/getgold.csv"; # Log time,name,id,gold -- just for optimising my cache print CSV '"'.time().'","'.$name.'","'.$userid.'","'.$gold.'"'."\n"; close CSV; } exit(0); sub getGoldForId { my($userid) = @_; my $url = 'http://www.gaiaonline.com/chat/gsi/gateway.php'; # games and town interface PHP script my $response = $browser -> post($url,[ 'X' => time().'1319', # Need time plus milliseconds, so I'm making it up :D 'v' => 'sushi', # sushi, aka raw, encoding 'm' => '113'.chr(01).$userid.chr(04) # method 113, chr(01), userid, chr(04) ]); unless ($response->is_success && $response->content_type eq 'text/html') { sleep 1; return getGoldForId($userid); } return $1 if($response->decoded_content =~ /113\%01\%05\%01([0-9]+)/); return -1; } sub getIdForUser { my($un) = @_; $un =~ tr/A-Z/a-z/; return $users{$un} if($users{$un}); my $url = "http://www.gaiaonline.com/search/?type=&val=$un&x=0&y=0"; my $response = $browser -> get($url); unless ($response->is_success && $response->content_type eq 'text/html') { sleep 1; return getIdForUser($un); } return $1 if($response->decoded_content =~ //); return -1; }