annotate scan.pl @ 18:fd44e3a1f800

fixed the cache. show tradegoodText of sheeps. refined enemy.pl
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 16:10:01 +0800
parents 59f2c435760c
children 5635e75c92d0
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;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Ikariam;
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 package main;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
7 sub saveCities
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
8 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
9 my ($island, @cities) = @_;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
11 foreach my $city (@cities)
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
12 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
13 $city->{island} = $island;
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
14 $city->{'time'} = time;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
15 if(my $c = Ikariam::Cities->retrieve($city->{cityId}))
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
16 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
17 foreach my $i (keys(%$city)) {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
18 eval($c->$i($city->{$i}));
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
19 # printf("%s %s ", $i, $city->{$i});
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
20 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
21 # print ("\n");
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
22
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
23 $c->autoupdate(1);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
24 $c->update();
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
25 } else {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
26 Ikariam::Cities->insert($city);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
27 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
28
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
29 printf("city %d %s saved\n", $city->{cityId}, $city->{cityname});
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
30
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
31 # Download user profile.
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
32 foreach my $x (qw/score army_score_main trader_score_secondary/)
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
33 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
34 my $users = $::i->viewScore($x, $city->{owner}, 0);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
35 saveUser($users);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
36 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
37 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
38 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
39
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
40 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
41 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
42 my $users = shift;
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
43
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
44 foreach my $user (values(%{$users}))
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 # print(Dumper($user));
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
47 printf("Saving user %s\n", $user->{'name'});
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
48 $user->{'time'} = time;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
49 if(my $c = Ikariam::User->retrieve($user->{id}))
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
50 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
51 foreach my $i (keys(%$user)) {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
52 eval($c->$i($user->{$i}));
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
53 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
54 $c->autoupdate(1);
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
55 $c->update();
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
56 } else {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
57 Ikariam::User->insert($user);
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 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
61
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
62 our $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
63
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
64 my @islands;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
65 if($#ARGV == 1) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
66 $i->login;
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
67 @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
68 } elsif($#ARGV == 0) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
69 $i->login;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
70 my $island = $ARGV[0];
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
71
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
72 my @cities = $i->viewIsland($island);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
73 saveCities($island, @cities);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
74 $i->logout;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
75 return;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
76 } elsif($#ARGV == -1) {
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
77 $i->login;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
78 @islands = $i->viewHomeMap();
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
79 } else {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
80 die("Usage: $0\nUsage: $0 x y\n");
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
81 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
82
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
83 foreach my $h_island (@islands)
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
84 {
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
85 printf("checking island %d\n", $h_island->{id});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
86
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
87 my $island;
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
88 if($island = Ikariam::Island->retrieve($h_island->{id})) {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
89 foreach my $i (keys(%$h_island)) {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
90 $island->set($i => $h_island->{$i});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
91 }
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
92 } else {
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
93 $island = Ikariam::Island->insert($h_island);
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
94 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
95
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
96 # scanning the island
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
97 if($island->time le (time - 60*60*12 ))
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
98 {
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
99 my @cities = $i->viewIsland($h_island->{id});
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
100 saveCities($h_island->{id}, @cities);
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
101 }
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
102
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
103 $island->set('time', time);
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
104 $island->update();
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
105 }
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
106 $i->logout;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
107 # $i->getCityInfo();