Mercurial > eagle-eye
annotate scan.pl @ 359:4bea7db828eb
fixed scanner
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Mon, 23 Feb 2009 16:24:35 +0800 |
parents | 15c288dd7dc5 |
children | 6ca0677a361e |
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 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 } |
295
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
265
diff
changeset
|
49 |
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
265
diff
changeset
|
50 $c->set(risk => $self->{ikariam}->viewSendSpy($h_city->{cityId})); |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
51 $c->update(); |
36
704d76b67670
fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
25
diff
changeset
|
52 |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
53 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
|
54 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
|
55 |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
56 $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
|
57 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
58 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
59 |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
60 sub saveUser |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
61 { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
62 my $self = shift; |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
63 my $userName = shift; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
64 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
|
65 |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
66 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
|
67 my $i = $self->{ikariam}->clone(); |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
68 $users = $i->viewScore($x, $userName, 0); |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
69 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
70 foreach my $h_user (values(%{$users})) { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
71 # 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
|
72 $h_user->{'time'} = time; |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
73 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
|
74 if(defined($user)) { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
75 # 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
|
76 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
|
77 } else { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
78 $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
|
79 } |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
80 $user->update(); |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
81 $self->saveAlly($h_user->{allyId}); |
98
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 } |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
85 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
86 sub saveAlly |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
87 { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
88 my $self = shift; |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
89 my $allyId = shift; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
90 return unless (defined($allyId) && $allyId ne '0'); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
91 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
92 # Save for member of ally |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
93 my $ally = Ikariam::Ally->retrieve($allyId); |
211
541bc1fba446
update very 30 minutes.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
206
diff
changeset
|
94 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
|
95 my $i = $self->{ikariam}->clone(); |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
96 my $h_ally = $i->viewAlly($allyId); |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
97 $h_ally->{'time'} = time; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
98 if(defined($ally)) { |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
99 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
|
100 } else { |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
89
diff
changeset
|
101 $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
|
102 } |
252 | 103 $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
|
104 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
105 } |
8b7bc598ba06
we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
106 |
140
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
107 sub saveIslands { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
108 my ($self, @islands) = @_; |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
109 |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
110 my $pm = new Parallel::ForkManager(10); |
18 | 111 |
140
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
112 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
|
113 { |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
114 my $pid = $pm->start and next; |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
115 |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
116 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
|
117 my $island; |
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
118 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
|
119 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
|
120 $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
|
121 } |
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
122 } else { |
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
123 $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
|
124 } |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
14
diff
changeset
|
125 |
140
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
126 # scanning the island |
255 | 127 # 30 minutes cache. |
128 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
|
129 my $i = $self->{ikariam}->clone(); |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
130 my @cities = |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
131 $i->viewIsland($h_island->{id}); |
255 | 132 $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
|
133 $island->set('time', time); |
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
134 } |
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
135 $island->update(); |
254
1e4922d9a671
fixed for saving island data.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
252
diff
changeset
|
136 |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
137 $pm->finish; |
140
124fc7abda39
scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
123
diff
changeset
|
138 } |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
139 $pm->wait_all_children; |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
140 } |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
141 |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
142 1; |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
143 |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
144 package main; |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
145 |
238
1a7b2d42fcbf
fixed the stupid timeout and cache timing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
232
diff
changeset
|
146 # 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
|
147 # alarm 3; |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
148 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
|
149 |
252 | 150 $i->login; |
232
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
151 if($#ARGV == 1) { |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
152 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
|
153 # my $s = new Ikariam::Scanner($i); |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
154 # $s->saveIslands(@islands); |
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
155 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
|
156 } elsif($#ARGV == 0) { |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
157 my $island = $ARGV[0]; |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
158 my @cities = $i->viewIsland($island); |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
159 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
|
160 } elsif($#ARGV == -1) { |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
161 my $cities = $i->check; |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
162 # random |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
163 foreach my $cityId (keys(%$cities)) { |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
164 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
|
165 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
|
166 } |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
167 } else { |
978a949602e5
Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
211
diff
changeset
|
168 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
|
169 } |
250
a654d43731f0
implement multi-thread Ikariam::Scanner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
239
diff
changeset
|
170 $i->logout; |