# HG changeset patch # User "Rex Tsai " # Date 1223391372 -28800 # Node ID f9eac5385dc0d97e9bd5f8767988282409b9f36b # Parent abaee70644290715a05d1f08fbb5fd93096db894 added viewWorldMap diff -r abaee7064429 -r f9eac5385dc0 Ikariam.pm --- a/Ikariam.pm Tue Oct 07 22:24:46 2008 +0800 +++ b/Ikariam.pm Tue Oct 07 22:56:12 2008 +0800 @@ -3,7 +3,7 @@ use Data::Dumper; use LWP; -use LWP::Debug qw(+ -conns); +# use LWP::Debug qw(+ -conns); use HTTP::Cookies; use WWW::Mechanize; use HTML::TagParser; @@ -33,18 +33,45 @@ my $x = shift; my $y = shift; - my $res; - if(defined($x) && defined($y)) + if(!defined($x) && !defined($y)) { - $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ + die('location required'); + } + + my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ xajax => 'getMapData', 'xajaxargs[]' => $x, 'xajaxargs[]' => $y, xajaxr => time, ]); - } else { - $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); + + my $c; + my $status = gunzip \$res->content => \$c + or die "gunzip failed: $GunzipError\n"; + + my @islands; + # parsing xjxobj + while($c =~ /0<\/k><\/v><\/e>1<\/k><\/v><\/e>2<\/k><\/v><\/e>3<\/k><\/v><\/e>4<\/k><\/v><\/e>5<\/k><\/v><\/e>6<\/k><\/v><\/e>7<\/k><\/v><\/e><\/xjxobj><\/cmd>/g) + { + my %island; + $island{id} = $3; + $island{x} = $1; + $island{y} = $2; + $island{name} = $6; + $island{tradegood} = $4; + $island{wonder} = $5; + # $7 ? + $island{people} = $8; + push @islands, \%island; } + return @islands; +} + +sub viewHomedMap +{ + my $self = shift; + + my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); my $c; my $status = gunzip \$res->content => \$c diff -r abaee7064429 -r f9eac5385dc0 scan.pl --- a/scan.pl Tue Oct 07 22:24:46 2008 +0800 +++ b/scan.pl Tue Oct 07 22:56:12 2008 +0800 @@ -14,7 +14,9 @@ my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); $i->login; -my @islands = $i->viewWorldMap(89, 60); +# my @islands = $i->viewHomeMap(); +# my @islands = $i->viewWorldMap(89, 60); +my @islands = $i->viewWorldMap(50, 34); foreach my $island (@islands) {