annotate scan.pl @ 261:2488d31240b7

next to CITY tag.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 19 Nov 2008 12:24:14 +0800
parents b01560b95779
children 3b3f1306255a
rev   line source
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
3 use Data::Dumper;
238
1a7b2d42fcbf fixed the stupid timeout and cache timing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
4 use Carp;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use Ikariam;
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
6 use Parallel::ForkManager;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 package main;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
9
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
10 package Ikariam::Scanner;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
11 use strict;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
12 use Carp;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
13 use Ikariam;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
14 use Data::Dumper;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
15 use Parallel::ForkManager;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
16
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
17 sub new {
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
18 my($class, $i) = @_;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
19 warn("new scanner");
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
20 my $self = {
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
21 ikariam => $i,
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
22 };
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
23
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
24 return bless $self, $class;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
25 }
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
26
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
27 sub saveCities
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
28 {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
29 my ($self, $island, @cities) = @_;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30
48
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
31 if ($#cities == -1) {
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
32 warn ("empty cities list.\n");
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
33 return;
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
34 }
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
35
121
0bab14dddf60 fixed the timestamp for scanning
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 99
diff changeset
36 foreach my $h_city (@cities) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
37 # Carp::carp(sprintf("checking %s\n", $h_city->{'cityname'}));
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
38 print(STDERR sprintf("checking cityname %s\n", $h_city->{'cityname'}));
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
39 $h_city->{island} = $island;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
40 $h_city->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
41 my $c = Ikariam::Cities->retrieve($h_city->{cityId});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
42 if(defined($c)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
43 foreach (keys(%$h_city)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
44 $c->set($_ => $h_city->{$_});
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
45 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
46 } else {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
47 $c = Ikariam::Cities->insert($h_city);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
48 }
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
49 $c->update();
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
50
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
51 my $user = Ikariam::User->retrieve($h_city->{'user'});
238
1a7b2d42fcbf fixed the stupid timeout and cache timing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
52 next if (defined($user) && defined($user->time) && $user->time gt (time - 30*60));
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
53
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
54 $self->saveUser($h_city->{owner});
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
55 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
56 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
57
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
58 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
59 {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
60 my $self = shift;
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
61 my $userName = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
62 my $users;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
63
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
64 foreach my $x (qw/score army_score_main trader_score_secondary/) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
65 my $i = $self->{ikariam}->clone();
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
66 $users = $i->viewScore($x, $userName, 0);
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
67
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
68 foreach my $h_user (values(%{$users})) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
69 # Carp::carp(sprintf("Saving user %s\n", $h_user->{'name'}));
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
70 $h_user->{'time'} = time;
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
71 my $user = Ikariam::User->retrieve($h_user->{'id'});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
72 if(defined($user)) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
73 # check if the arm score is down
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
74 foreach (keys(%$h_user)) { $user->set($_ => $h_user->{$_}); }
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
75 } else {
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
76 $user = Ikariam::User->insert($h_user);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
77 }
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
78 $user->update();
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
79 $self->saveAlly($h_user->{allyId});
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
80 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
81 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
82 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
83
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
84 sub saveAlly
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
85 {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
86 my $self = shift;
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
87 my $allyId = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
88 return unless (defined($allyId) && $allyId ne '0');
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
89
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
90 # Save for member of ally
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
91 my $ally = Ikariam::Ally->retrieve($allyId);
211
541bc1fba446 update very 30 minutes.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 206
diff changeset
92 if(!defined($ally) || $ally->time le (time - 30*60*1)) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
93 my $i = $self->{ikariam}->clone();
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
94 my $h_ally = $i->viewAlly($allyId);
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
95 $h_ally->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
96 if(defined($ally)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
97 foreach (keys(%$h_ally)) { $ally->set($_ => $h_ally->{$_}); }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
98 } else {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
99 $ally = Ikariam::Ally->insert($h_ally);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
100 }
252
d75f26fc1c69 fixed saving ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 250
diff changeset
101 $ally->update();
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
102 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
103 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
104
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
105 sub saveIslands {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
106 my ($self, @islands) = @_;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
107
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
108 my $pm = new Parallel::ForkManager(10);
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
109
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
110 foreach my $h_island (@islands)
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
111 {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
112 my $pid = $pm->start and next;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
113
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
114 printf("checking island %d\n", $h_island->{id});
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
115 my $island;
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
116 if($island = Ikariam::Island->retrieve($h_island->{id})) {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
117 foreach my $i (keys(%$h_island)) {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
118 $island->set($i => $h_island->{$i});
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
119 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
120 } else {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
121 $island = Ikariam::Island->insert($h_island);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
122 }
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
123
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
124 # scanning the island
255
b01560b95779 fixed cache time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 254
diff changeset
125 # 30 minutes cache.
b01560b95779 fixed cache time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 254
diff changeset
126 if($island->time le (time - 60*30)) {
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
127 my $i = $self->{ikariam}->clone();
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
128 my @cities =
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
129 $i->viewIsland($h_island->{id});
255
b01560b95779 fixed cache time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 254
diff changeset
130 $self->saveCities($h_island->{id}, @cities);
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
131 $island->set('time', time);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
132 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
133 $island->update();
254
1e4922d9a671 fixed for saving island data.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 252
diff changeset
134
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
135 $pm->finish;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
136 }
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
137 $pm->wait_all_children;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
138 }
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
139
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
140 1;
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
141
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
142 package main;
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
143
238
1a7b2d42fcbf fixed the stupid timeout and cache timing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
144 # local $SIG{ALRM} = sub { die "timeout\n" };
1a7b2d42fcbf fixed the stupid timeout and cache timing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
145 # alarm 3;
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
146 our $i = new Ikariam($::server, $::user, $::pass);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
147
252
d75f26fc1c69 fixed saving ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 250
diff changeset
148 $i->login;
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
149 if($#ARGV == 1) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
150 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
151 # my $s = new Ikariam::Scanner($i);
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
152 # $s->saveIslands(@islands);
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
153 new Ikariam::Scanner($i)->saveIslands(@islands);
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
154 } elsif($#ARGV == 0) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
155 my $island = $ARGV[0];
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
156 my @cities = $i->viewIsland($island);
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
157 new Ikariam::Scanner($i)->saveCities($island, @cities);
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
158 } elsif($#ARGV == -1) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
159 my $cities = $i->check;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
160 # random
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
161 foreach my $cityId (keys(%$cities)) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
162 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
163 new Ikariam::Scanner($i)->saveIslands(@islands);
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
164 }
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
165 } else {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
166 die("Usage: $0\nUsage: $0 x y\n");
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
167 }
250
a654d43731f0 implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 239
diff changeset
168 $i->logout;