Mercurial > eagle-eye
comparison Ikariam.pm @ 23:54ab0becd730
implemented a prototype for collecting account status.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 09 Oct 2008 11:33:47 +0800 |
parents | 9c52ae71c1cb |
children | d8117792c6f5 |
comparison
equal
deleted
inserted
replaced
22:552528bb4917 | 23:54ab0becd730 |
---|---|
233 } | 233 } |
234 | 234 |
235 return @cities; | 235 return @cities; |
236 } | 236 } |
237 | 237 |
238 sub check | |
239 { | |
240 my $self = shift; | |
241 | |
242 my $aaaa = $self->{'cities'}; | |
243 | |
244 # 運輸船 | |
245 # CargoShip | |
246 foreach my $i (keys(%{$self->{'cities'}})) | |
247 { | |
248 | |
249 # search for goods | |
250 my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ | |
251 action => 'header', | |
252 cityId => $i, | |
253 function => 'changeCurrentCity', | |
254 id => $i, | |
255 oldView => 'city', | |
256 ]); | |
257 my $c; | |
258 my $status = gunzip \$res->content => \$c | |
259 or die "gunzip failed: $GunzipError\n"; | |
260 | |
261 my $html = HTML::TagParser->new($c); | |
262 my @elems; | |
263 | |
264 foreach my $j (qw/value_wood value_wine value_marble value_crystal value_sulfur/) { | |
265 my ($elem) = $html->getElementsByAttribute("id", $j); | |
266 $self->{'cities'}->{$i}->{$j} = $elem->innerText(); | |
267 $self->{'cities'}->{$i}->{$j} =~ s/,//g; | |
268 } | |
269 | |
270 my %types; | |
271 $types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; | |
272 $types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; | |
273 | |
274 foreach my $x (qw/army fleet/) | |
275 { | |
276 $self->{'cities'}->{$i}->{$x} = {}; | |
277 # search army | |
278 $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $i)); | |
279 $status = gunzip \$res->content => \$c | |
280 or die "gunzip failed: $GunzipError\n"; | |
281 | |
282 $html = HTML::TagParser->new($c); | |
283 @elems = $html->getElementsByTagName('td'); | |
284 | |
285 foreach my $j (0..$#{$types{$x}}) { | |
286 next if($types{$x}[$j] eq 'undef'); | |
287 if($elems[$j]->innerText() == '-') { | |
288 $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = 0; | |
289 } else { | |
290 $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = $elems[$j]->innerText(); | |
291 } | |
292 } | |
293 } | |
294 } | |
295 print Dumper($self->{'cities'}); | |
296 } | |
297 | |
238 sub logout | 298 sub logout |
239 { | 299 { |
240 my $self = shift; | 300 my $self = shift; |
241 $self->{mech}->get(sprintf('http://%s/index.php?action=loginAvatar&function=logout', $self->{server})); | 301 $self->{mech}->get(sprintf('http://%s/index.php?action=loginAvatar&function=logout', $self->{server})); |
242 } | 302 } |
254 or die "gunzip failed: $GunzipError\n"; | 314 or die "gunzip failed: $GunzipError\n"; |
255 | 315 |
256 if($c =~ /錯誤!/) | 316 if($c =~ /錯誤!/) |
257 { | 317 { |
258 die ("password error\n"); | 318 die ("password error\n"); |
319 } else { | |
320 my $html = HTML::TagParser->new($c); | |
321 my @elems; | |
322 | |
323 @elems = $html->getElementsByAttribute("class", "avatarCities coords"); | |
324 foreach my $elem (@elems) { | |
325 # my cities | |
326 $self->{'cities'}->{$elem->getAttribute('value')} = {}; | |
327 } | |
259 } | 328 } |
260 } | 329 } |
261 | 330 |
262 sub getElementsByTagName { | 331 sub getElementsByTagName { |
263 my $element = shift; | 332 my $element = shift; |