diff scores.pl @ 8:e4b3168d0319

implemented sheep and enemy scripts.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 04:23:01 +0800
parents 2040ccc95670
children ae412d1f7761
line wrap: on
line diff
--- a/scores.pl	Wed Oct 08 02:50:19 2008 +0800
+++ b/scores.pl	Wed Oct 08 04:23:01 2008 +0800
@@ -8,10 +8,14 @@
 sub saveUser
 {
     my $users = shift;
+
+    my $u;
     foreach my $user (values(%{$users}))
     {
+        next if($u == $user->{'id'}); $u = $user->{'id'};
+        
         printf("Saving %s\n", $user->{'name'});
-        if(my $c = Ikariam::Users->retrieve($user->{id}))
+        if(my $c = Ikariam::User->retrieve($user->{id}))
         {
             foreach my $i (keys(%$user)) {
                 eval($c->$i($user->{$i}));
@@ -19,15 +23,16 @@
             $c->autoupdate(1);
             $c->update();
         } else {
-            Ikariam::Users->insert($user);
+            Ikariam::User->insert($user);
         }
     }
 }
 
 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
-$i->login;
 
 if($#ARGV == 0) {
+    $i->login;
+
     my $users;
     foreach my $x (qw/score army_score_main trader_score_secondary/)
     {
@@ -35,6 +40,8 @@
         saveUser($users);
     }
 } elsif ($#ARGV == 1) {
+    $i->login;
+
     # search the islands and cities nearby
     my ($x, $y) = @ARGV;
     my $offset = 5;
@@ -69,7 +76,7 @@
 } else {
     # my $users = $i->viewScore('army_score_main');
     # saveUser($users);
-    die("Usage: $0 nickname\n");
+    die("Usage: $0 nickname\nUsage: $0 x y");
 }
 
 # highscoreType