diff scan.pl @ 232:978a949602e5

Auto-update Scientists numbers for Academy. Refined the rules for safehouse, the safe house must be same or higher level then Town Hall. Make people very happy, when the townHall is less then 16. Build museum first then tavern THG: changed warfare.pl
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 06 Nov 2008 20:31:05 +0800
parents 541bc1fba446
children 1a7b2d42fcbf
line wrap: on
line diff
--- a/scan.pl	Wed Nov 05 03:08:16 2008 +0800
+++ b/scan.pl	Thu Nov 06 20:31:05 2008 +0800
@@ -76,32 +76,6 @@
     }
 }
 
-our $i = new Ikariam($::server, $::user, $::pass);
-
-if($#ARGV == 1) {
-    $i->login;
-    my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
-    saveIslands(@islands);
-    $i->logout;
-} elsif($#ARGV == 0) {
-    $i->login;
-    my $island = $ARGV[0];
-    my @cities = $i->viewIsland($island);
-    saveCities($island, @cities);
-    $i->logout;
-} elsif($#ARGV == -1) {
-    $i->login;
-    my $cities = $i->check;
-    foreach my $cityId (keys(%$cities)) {
-        printf("%s %s\n", $cities->{$cityId}->{island}->{x},  $cities->{$cityId}->{island}->{y});
-        my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x},  $cities->{$cityId}->{island}->{y});
-        saveIslands(@islands);
-    }
-    $i->logout;
-} else {
-    die("Usage: $0\nUsage: $0 x y\n");
-}
-
 sub saveIslands {
     my @islands = @_;
 
@@ -121,7 +95,7 @@
         # scanning the island
         if($island->time le (time - 30*60*6))
         {
-            my @cities = $i->viewIsland($h_island->{id});
+            my @cities = $::i->viewIsland($h_island->{id});
             saveCities($h_island->{id}, @cities);
 
             $island->set('time', time);
@@ -130,4 +104,33 @@
 
     }
 }
-# $i->getCityInfo();
+
+
+local $SIG{ALRM} = sub { die "timeout\n" };
+alarm 3;
+our $i = new Ikariam($::server, $::user, $::pass);
+
+if($#ARGV == 1) {
+    $i->login;
+    my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
+    saveIslands(@islands);
+    $i->logout;
+} elsif($#ARGV == 0) {
+    $i->login;
+    my $island = $ARGV[0];
+    my @cities = $i->viewIsland($island);
+    saveCities($island, @cities);
+    $i->logout;
+} elsif($#ARGV == -1) {
+    $i->login;
+    my $cities = $i->check;
+    # random
+    foreach my $cityId (keys(%$cities)) {
+        printf("%s %s\n", $cities->{$cityId}->{island}->{x},  $cities->{$cityId}->{island}->{y});
+        my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x},  $cities->{$cityId}->{island}->{y});
+        saveIslands(@islands);
+    }
+    $i->logout;
+} else {
+    die("Usage: $0\nUsage: $0 x y\n");
+}