# HG changeset patch # User "Rex Tsai " # Date 1223523227 -28800 # Node ID 54ab0becd73096182e6428376713992f54adb6d6 # Parent 552528bb491758209ac840902d8d0ff9a39a27f2 implemented a prototype for collecting account status. diff -r 552528bb4917 -r 54ab0becd730 Ikariam.pm --- a/Ikariam.pm Wed Oct 08 19:27:54 2008 +0800 +++ b/Ikariam.pm Thu Oct 09 11:33:47 2008 +0800 @@ -235,6 +235,66 @@ return @cities; } +sub check +{ + my $self = shift; + + my $aaaa = $self->{'cities'}; + + # 運輸船 + # CargoShip + foreach my $i (keys(%{$self->{'cities'}})) + { + + # search for goods + my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ + action => 'header', + cityId => $i, + function => 'changeCurrentCity', + id => $i, + oldView => 'city', + ]); + my $c; + my $status = gunzip \$res->content => \$c + or die "gunzip failed: $GunzipError\n"; + + my $html = HTML::TagParser->new($c); + my @elems; + + foreach my $j (qw/value_wood value_wine value_marble value_crystal value_sulfur/) { + my ($elem) = $html->getElementsByAttribute("id", $j); + $self->{'cities'}->{$i}->{$j} = $elem->innerText(); + $self->{'cities'}->{$i}->{$j} =~ s/,//g; + } + + my %types; + $types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; + $types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; + + foreach my $x (qw/army fleet/) + { + $self->{'cities'}->{$i}->{$x} = {}; + # search army + $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $i)); + $status = gunzip \$res->content => \$c + or die "gunzip failed: $GunzipError\n"; + + $html = HTML::TagParser->new($c); + @elems = $html->getElementsByTagName('td'); + + foreach my $j (0..$#{$types{$x}}) { + next if($types{$x}[$j] eq 'undef'); + if($elems[$j]->innerText() == '-') { + $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = 0; + } else { + $self->{'cities'}->{$i}->{$x}->{$types{$x}[$j]} = $elems[$j]->innerText(); + } + } + } + } + print Dumper($self->{'cities'}); +} + sub logout { my $self = shift; @@ -256,6 +316,15 @@ if($c =~ /錯誤!/) { die ("password error\n"); + } else { + my $html = HTML::TagParser->new($c); + my @elems; + + @elems = $html->getElementsByAttribute("class", "avatarCities coords"); + foreach my $elem (@elems) { + # my cities + $self->{'cities'}->{$elem->getAttribute('value')} = {}; + } } } diff -r 552528bb4917 -r 54ab0becd730 ally.pl --- a/ally.pl Wed Oct 08 19:27:54 2008 +0800 +++ b/ally.pl Thu Oct 09 11:33:47 2008 +0800 @@ -6,6 +6,8 @@ package main; +# my $users = Ikariam::User->search(ally => 'WMeMe'); + Ikariam::Cities->set_sql(ally => qq { SELECT cities.id FROM island, cities diff -r 552528bb4917 -r 54ab0becd730 sheep.pl --- a/sheep.pl Wed Oct 08 19:27:54 2008 +0800 +++ b/sheep.pl Thu Oct 09 11:33:47 2008 +0800 @@ -34,6 +34,7 @@ } ); + if($#ARGV != 1) { die("Usage: $0 x y\n"); }