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