changeset 119:755e5f5434e4

merged for fixed inactive-map.pl and hacks for highscore search.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 30 Oct 2008 15:08:56 +0800
parents d7a17dc6dc27 (current diff) 5a66fea952fe (diff)
children bdf025bc50ea
files
diffstat 2 files changed, 43 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Thu Oct 30 15:08:20 2008 +0800
+++ b/Ikariam.pm	Thu Oct 30 15:08:56 2008 +0800
@@ -50,7 +50,10 @@
         $string = $content;
     }
 
-    $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'utf-8' });
+    # dirty hack for stupid highScore search function.
+    $string =~ s/name="searchUser" value=".*?"/name="searchUser" value=""/;
+
+    $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'UTF-8' });
     return;
 }
 
@@ -90,14 +93,11 @@
 use strict;
 use Data::Dumper;
 use LWP;
-# use LWP::Debug qw(+ -conns -trace -debug);
-# use LWP::Debug qw(+trace);
 use HTTP::Cookies;
 use WWW::Mechanize;
 use HTML::TagParser;
 use XML::LibXML qw(:encoding);
 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
-# use Time::ParseDate;
 use POSIX;
 use utf8;
 
@@ -114,6 +114,7 @@
         server => $server,
         user => $user,
         pass => $pass,
+        debug => undef,
         buildingIDs => {
             townHall =>  0,
             townhall =>  0,
@@ -139,6 +140,9 @@
     };
 
 
+    # if debug
+    # LWP::Debug::level('+conns');
+
     $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1));
     $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate');
  
@@ -171,25 +175,30 @@
     my $offset = shift || 0;
     my %users;
 
-    my $res = $self->{mech}->post(sprintf("http://%s/index.php", $self->{server}), [
-        highscoreType => $type,
-        offset => $offset,
-        searchUser => $user,
-        view => 'highscore'
-        ]);
+    $self->{mech}->get(sprintf("http://%s/index.php?view=highscore&showMe=1", $self->{server}));
+    my $res = $self->{mech}->submit_form(
+        form_number => 1,
+        fields      => {
+            highscoreType => $type,
+            offset => $offset,
+            searchUser => $user,
+        }
+   );
+
     my $extractor = new Ikariam::Extractor(content => $res->content);
     my $result = $extractor->{doc}->find('//table[@class="table01"][2]//tr');
 
     foreach my $tr ( @$result ) {
         my %user;
-        my $extractor = new Ikariam::Extractor(content => $tr->toString(1));
+        my $extractor = new Ikariam::Extractor(content => $tr->toString(0));
 
         my $href = $extractor->find('//td[@class="action"]/a/@href');
         if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) {
             $user{'id'} = $1;
-            $user{'name'} = $user;
+            # $user{'name'} = $user;
             # encoding issue.
             $user{'name'} = $extractor->find('//td[@class="name"]/text()');
+            next if($user{'name'} eq '');
 
             $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()');
             my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href');
@@ -298,7 +307,17 @@
             $info{'owner'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="owner"]/text()', $i));
             $info{'owner'} =~ s/\s+//g;
             $info{'ally'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/text()', $i));
-            delete($info{'ally'}) if($info{'ally'} eq '-');
+            if($info{'ally'} eq '-') {
+                delete($info{'ally'}) 
+            } else {
+                my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/@href', $i));
+                # http://s2.ikariam.tw/index.php?view=allyPage&allyId=264&oldView=island&id=569
+                if($href =~ /&allyId=(\d+)&/) {
+                    $info{'allyId'} = $1;
+                }
+            }
+
+            # Ally Id
 
             my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//a[@class="messageSend"]/@href', $i));
             # ?view=sendMessage&type=0&with=20204&destinationCityId=64165&oldView=island
--- a/inactive-map.pl	Thu Oct 30 15:08:20 2008 +0800
+++ b/inactive-map.pl	Thu Oct 30 15:08:56 2008 +0800
@@ -10,13 +10,13 @@
 Ikariam::User->set_sql(inactivity => qq {
     SELECT user.id 
       FROM user, cities, island
-      WHERE user.id == cities.user
-        AND cities.island == island.id
+      WHERE user.id = cities.user
+        AND cities.island = island.id
         AND island.x <= ?
         AND island.x >= ?
         AND island.y <= ?
         AND island.y >= ?
-        AND cities.status == 'i'
+        AND cities.status = 'i'
     }
 );
 #Ikariam::User->set_sql(sheeps => qq {
@@ -36,9 +36,9 @@
 Ikariam::User->set_sql(sheeps => qq {
         SELECT user.id 
           FROM user, cities 
-         WHERE user.id == cities.user 
-           AND cities.status == 'i'
-           AND user.trader_score_secondary >= 50000 
+         WHERE user.id = cities.user 
+           AND cities.status = 'i'
+           AND user.trader_score_secondary >= 50000
            AND user.army_score_main <= 40
     }
 );
@@ -69,7 +69,7 @@
             # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000
             my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000;
 
-            next if($robbery < 2000);
+            next if($robbery < 1000);
 
             $maps{$island->x}{$island->y}{'id'} = $island->id;
             $maps{$island->x}{$island->y}{'density'} += 1;
@@ -95,16 +95,16 @@
         }
         </style></head><body><table border=1>");
 
-    foreach my $x ($x1..$x2)
+    foreach my $y($y1..$y2)
     {
         print(OUT "<tr>");
-        foreach my $y($y1..$y2)
+        foreach my $x ($x1..$x2)
         {
             # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>");
             if(defined($maps{$x}{$y}{'density'})) {
                 my $c = 255 - (15 * $maps{$x}{$y}{'density'});
-                printf(OUT "<td style=\"background-color: rgb(255,%d,%d);\"><a href=\"http://s2.ikariam.tw/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>",
-                    $c, $c, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
+                printf(OUT "<td style=\"background-color: rgb(255,%d,%d);\"><a href=\"http://%s/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>",
+                    $c, $c, $::server, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
             } else {
                 printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y);
             }