diff Ikariam.pm @ 5:dbb97c4265ba

implemented the scores search tool
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 01:51:28 +0800
parents b72786cdccbb
children 2975a94aa7a2
line wrap: on
line diff
--- a/Ikariam.pm	Wed Oct 08 01:51:08 2008 +0800
+++ b/Ikariam.pm	Wed Oct 08 01:51:28 2008 +0800
@@ -3,7 +3,7 @@
 use Class::DBI::AutoLoader (
     dsn       => 'dbi:SQLite:dbname=ikariam.sqlite',
     options   => { RaiseError => 1 },
-    tables    => ['cities', 'islands'],
+    tables    => ['cities', 'islands', 'users'],
     use_base  => 'Class::DBI::SQLite',
     namespace => 'Ikariam',
 );
@@ -36,6 +36,70 @@
     return bless $self, $class;
 }
 
+sub viewScore
+{
+    my $self = shift;
+    my $type = shift || 'score';
+    my $user = shift || '';
+    my $offset = shift || 0;
+
+#    my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [
+#        highscoreType => $type,
+#        offset => $offset,
+#        searchUser => $user,
+#        view => 'highscore'
+#        ]);
+#
+#    my $c;
+#    my $status = gunzip \$res->content => \$c 
+#        or die "gunzip failed: $GunzipError\n";
+
+    my $c;
+    open(IN, "f");
+    while(<IN>) { $c .= $_;}
+    close(IN);
+    my $html = HTML::TagParser->new($c);
+
+    my ($table) = $html->getElementsByAttribute("class", "table01");
+    my @elems = getElementsByTagName($table, "tr");
+
+    my %users;
+    foreach my $elem (@elems) {
+        my $e;
+        my %user;
+
+        $e = getElementsByAttribute($elem, "class", "action");
+        $e = getElementsByTagName($e, "a");
+
+        if($e->getAttribute('href') =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/)
+        {
+            $user{'id'} = $1;
+
+            $e = getElementsByAttribute($elem, "class", "name");
+            $user{'name'} = $e->innerText();
+
+            $e = getElementsByAttribute($elem, "class", "allytag");
+            $user{'ally'} = $e->innerText();
+
+            $e  = getElementsByTagName($e, "a");
+            if($e->getAttribute('href') =~ /\?view=allyPage&allyId=(\d+)/)
+            {
+                $user{'allyId'} = $1;
+            }
+
+            $e = getElementsByAttribute($elem, "class", "score");
+            $user{$type} = $e->innerText();
+            $user{$type} =~ s/,//;
+
+            $users{$user{'id'}} = \%user;
+        } else {
+            next;
+        }
+    }
+
+    return \%users;
+}
+
 sub viewWorldMap
 {
     my $self = shift;
@@ -134,6 +198,8 @@
         $info{'citylevel'} = substr($e[1]->innerText(), 14);
         $info{'owner'} = substr($e[2]->innerText(), 8);
         $info{'ally'} = substr($e[3]->innerText(), 8);
+        delete($info{'ally'}) if($info{'ally'} eq '-');
+
         @e = getElementsByAttribute($elem, "class", "messageSend");
         if ( $e[0]->getAttribute("href") =~ /with=(\d+)&destinationCityId=(\d+)/)
         {