# HG changeset patch # User "Rex Tsai " # Date 1224868340 -28800 # Node ID 82acbba33b97a18123b66557b73f9c344b3ac876 # Parent d57920014cb4a30744003f13223f08aa6218a6c5 fixed the build function. diff -r d57920014cb4 -r 82acbba33b97 Ikariam.pm --- a/Ikariam.pm Sat Oct 25 00:42:59 2008 +0800 +++ b/Ikariam.pm Sat Oct 25 01:12:20 2008 +0800 @@ -91,7 +91,7 @@ use Data::Dumper; use LWP; # use LWP::Debug qw(+ -conns -trace -debug); -# use LWP::Debug qw(+trace); +use LWP::Debug qw(+trace); use HTTP::Cookies; use WWW::Mechanize; use HTML::TagParser; @@ -372,9 +372,9 @@ $position = $_ if($locations[$_] eq $type); } - if($position == -1) - { + if($position == -1) { foreach (0..$#locations) { + # XXX next if($_ <= 2 && ($self->{buildingIDs}->{$type} ne "workshop-fleet" && $self->{buildingIDs}->{$type} ne "shipyard")); if($locations[$_] eq undef) { @@ -384,20 +384,9 @@ } } } else { - $self->{mech}->add_header( Referer => - sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); - my $res = $self->{mech}->post(sprintf('http://%s/index.php', $self->{server}), [ - action => 'CityScreen', - 'function' => 'upgradeBuilding', - id => $cityId, - position => $position, - level => $self->{'cities'}->{$cityId}->{buildings}->{$type}, - oldView => $type, - ]); -# my $content; -# gunzip \$res->content => \$content -# or die "gunzip failed: $GunzipError\n"; -# print ($content); + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + my $url = Ikariam::Extractor->new(content => $res->content)->find('//a[@title="升級建築物"/@href'); + $self->{mech}->get($url); } } @@ -700,23 +689,13 @@ password => $self->{pass}, ]); - my $c; - my $status = gunzip \$res->content => \$c - or die "gunzip failed: $GunzipError\n"; + my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); - if($c =~ /錯誤!/) - { - die ("password error\n"); - } else { - my $result = XML::LibXML->new('1.0','utf-8') - ->parse_html_string ($c, { suppress_errors => 1 }) - ->find( '//option[@class="avatarCities coords"]' ); - - if ( $result->isa( 'XML::LibXML::NodeList' ) ) { - foreach ( @$result ) { - $self->{'cities'}->{$_->getAttribute('value')} = {}; - } - } + if($#cities<0) { + die ("login failed\n"); + } + foreach(@cities) { + $self->{'cities'}->{$_} = {}; } } diff -r d57920014cb4 -r 82acbba33b97 agent.pl --- a/agent.pl Sat Oct 25 00:42:59 2008 +0800 +++ b/agent.pl Sat Oct 25 01:12:20 2008 +0800 @@ -226,7 +226,6 @@ $i->logout; - sub triggerAction { my ($action, $cityId) = @_;