Mercurial > eagle-eye
comparison Ikariam.pm @ 326:58b36b18809f
new scanning tool
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 11 Feb 2009 21:59:51 +0800 |
parents | b3b845d30d4b |
children | 484aaddeef66 |
comparison
equal
deleted
inserted
replaced
325:1f5cd5c4f6b6 | 326:58b36b18809f |
---|---|
114 use WWW::Mechanize; | 114 use WWW::Mechanize; |
115 use XML::LibXML qw(:encoding); | 115 use XML::LibXML qw(:encoding); |
116 use YAML qw/LoadFile Dump DumpFile/; | 116 use YAML qw/LoadFile Dump DumpFile/; |
117 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; | 117 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
118 use POSIX; | 118 use POSIX; |
119 use JSON;; | |
119 use utf8; | 120 use utf8; |
120 | 121 |
121 sub new | 122 sub new |
122 { | 123 { |
123 my ($class, $server, $user, $pass) = @_; | 124 my ($class, $server, $user, $pass) = @_; |
229 | 230 |
230 if(!defined($x) && !defined($y)) { | 231 if(!defined($x) && !defined($y)) { |
231 die('location required'); | 232 die('location required'); |
232 } | 233 } |
233 | 234 |
234 my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ | 235 my $res = $self->{mech}->post(sprintf("http://%s/index.php?action=WorldMap&function=getJSONArea&x_min=%d&x_max=%d&y_min=%d&y_max=%d", |
235 xajax => 'getMapData', | 236 $self->{server}, $x - 14, $x + 12, $y - 17, $y + 9), []); |
236 'xajaxargs[]' => $x, | |
237 'xajaxargs[]' => $y, | |
238 xajaxr => time, | |
239 ]); | |
240 | 237 |
241 my $c; | 238 my $c; |
242 my $status = gunzip \$res->content => \$c | 239 my $status = gunzip \$res->content => \$c |
243 or die "gunzip failed: $GunzipError\n"; | 240 or die "gunzip failed: $GunzipError\n"; |
244 | 241 |
242 my $nodes = jsonToObj($c); | |
245 my @islands; | 243 my @islands; |
246 # parsing xjxobj | 244 |
247 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) | 245 print $nodes->{'data'}; |
248 { | 246 foreach my $x (keys %{$nodes->{'data'}}) { |
249 my %island; | 247 foreach my $y (keys(%{$nodes->{data}->{$x}})) { |
250 $island{id} = $3; | 248 my %island; |
251 $island{x} = $1; | 249 $island{id} = $nodes->{data}->{$x}->{$y}[0]; |
252 $island{y} = $2; | 250 $island{x} = $x; |
253 $island{name} = $6; | 251 $island{y} = $y; |
254 $island{tradegood} = $4; | 252 $island{name} = $nodes->{data}->{$x}->{$y}[1]; |
255 $island{wonder} = $5; | 253 |
256 # $7 ? | 254 # $island{tradegood} = $4; |
257 $island{people} = $8; | 255 # $island{wonder} = $5; |
258 push @islands, \%island; | 256 # $island{people} = $8; |
259 } | 257 push @islands, \%island; |
260 return @islands; | 258 } |
261 } | |
262 | |
263 sub viewHomeMap | |
264 { | |
265 my $self = shift; | |
266 | |
267 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); | |
268 | |
269 my $c; | |
270 my $status = gunzip \$res->content => \$c | |
271 or die "gunzip failed: $GunzipError\n"; | |
272 | |
273 # m[50][36]=new Array(564,1,5,'Risietia', '5', 13); | |
274 # x = 43-57 = 6 | |
275 # y = 27-41 = 6 | |
276 my @islands; | |
277 while($c =~ /m\[(\d+)\]\[(\d+)\]=new Array\((\d+),(\d+),(\d+),'(\w+)', '(\d+)', (\d+)\);/g) | |
278 { | |
279 my %island; | |
280 $island{id} = $3; | |
281 $island{x} = $1; | |
282 $island{y} = $2; | |
283 $island{name} = $6; | |
284 $island{tradegood} = $4; | |
285 $island{wonder} = $5; | |
286 # $7 ? | |
287 $island{people} = $8; | |
288 | |
289 #foreach my $i (sort(keys(%island))) | |
290 #{ | |
291 # printf ("%s %s\n", $i, $island{$i}); | |
292 #} | |
293 #print("\n"); | |
294 push @islands, \%island; | |
295 } | 259 } |
296 return @islands; | 260 return @islands; |
297 } | 261 } |
298 | 262 |
299 sub viewIsland | 263 sub viewIsland |