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