comparison Ikariam.pm @ 1:f9eac5385dc0

added viewWorldMap
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 07 Oct 2008 22:56:12 +0800
parents abaee7064429
children 0fb73a7a0b94
comparison
equal deleted inserted replaced
0:abaee7064429 1:f9eac5385dc0
1 #!/usr/bin/env perl 1 #!/usr/bin/env perl
2 package Ikariam; 2 package Ikariam;
3 3
4 use Data::Dumper; 4 use Data::Dumper;
5 use LWP; 5 use LWP;
6 use LWP::Debug qw(+ -conns); 6 # use LWP::Debug qw(+ -conns);
7 use HTTP::Cookies; 7 use HTTP::Cookies;
8 use WWW::Mechanize; 8 use WWW::Mechanize;
9 use HTML::TagParser; 9 use HTML::TagParser;
10 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; 10 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
11 11
31 { 31 {
32 my $self = shift; 32 my $self = shift;
33 my $x = shift; 33 my $x = shift;
34 my $y = shift; 34 my $y = shift;
35 35
36 my $res; 36 if(!defined($x) && !defined($y))
37 if(defined($x) && defined($y)) 37 {
38 { 38 die('location required');
39 $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ 39 }
40
41 my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [
40 xajax => 'getMapData', 42 xajax => 'getMapData',
41 'xajaxargs[]' => $x, 43 'xajaxargs[]' => $x,
42 'xajaxargs[]' => $y, 44 'xajaxargs[]' => $y,
43 xajaxr => time, 45 xajaxr => time,
44 ]); 46 ]);
45 } else { 47
46 $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); 48 my $c;
47 } 49 my $status = gunzip \$res->content => \$c
50 or die "gunzip failed: $GunzipError\n";
51
52 my @islands;
53 # parsing xjxobj
54 while($c =~ /<cmd n="jc" t="addToMap"><xjxobj><e><k>0<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>1<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>2<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>3<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>4<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>5<\/k><v><!\[CDATA\[(\w+)\]\]><\/v><\/e><e><k>6<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>7<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><\/xjxobj><\/cmd>/g)
55 {
56 my %island;
57 $island{id} = $3;
58 $island{x} = $1;
59 $island{y} = $2;
60 $island{name} = $6;
61 $island{tradegood} = $4;
62 $island{wonder} = $5;
63 # $7 ?
64 $island{people} = $8;
65 push @islands, \%island;
66 }
67 return @islands;
68 }
69
70 sub viewHomedMap
71 {
72 my $self = shift;
73
74 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}));
48 75
49 my $c; 76 my $c;
50 my $status = gunzip \$res->content => \$c 77 my $status = gunzip \$res->content => \$c
51 or die "gunzip failed: $GunzipError\n"; 78 or die "gunzip failed: $GunzipError\n";
52 79