annotate scan.pl @ 199:b33c8dbe9b04

fixed is_any_corruption
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 03 Nov 2008 12:00:54 +0800
parents 0da6658697df
children b7af307a222d
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;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
7
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
8 sub saveCities
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
9 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
10 my ($island, @cities) = @_;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11
48
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
12 if ($#cities == -1) {
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
13 warn ("empty cities list.\n");
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
14 return;
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
15 }
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
16
121
0bab14dddf60 fixed the timestamp for scanning
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 99
diff changeset
17 foreach my $h_city (@cities) {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
18 $h_city->{island} = $island;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
19 $h_city->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
20 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
21 if(defined($c)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
22 foreach (keys(%$h_city)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
23 $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
24 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
25 } else {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
26 $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
27 }
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
28 $c->update();
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
29
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
30 my $user = Ikariam::User->retrieve($h_city->{'user'});
123
6043e9bfdeef revert to earier versoin which is easier to read.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 121
diff changeset
31 next if (defined($user) && defined($user->time) && $user->time le (time - 60*60*1));
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
32
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
33 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
34 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
35 }
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 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
38 {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
39 my $userName = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
40 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
41
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
42 foreach my $x (qw/score army_score_main trader_score_secondary/) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
43 $users = $::i->viewScore($x, $userName, 0);
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
44
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
45 foreach my $h_user (values(%{$users})) {
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
46 printf("Saving user %s\n", $h_user->{'name'});
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
47 $h_user->{'time'} = time;
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
48
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
49 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
50 if(defined($user)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
51 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
52 } else {
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
53 $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
54 }
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
55 $user->update();
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
56 saveAlly($h_user->{allyId});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
57 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
58 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
59 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
60
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
61 sub saveAlly
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
62 {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
63 my $allyId = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
64 return unless (defined($allyId) && $allyId ne '0');
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
65
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
66 # Save for member of ally
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
67 my $ally = Ikariam::Ally->retrieve($allyId);
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
68 if(!defined($ally) || $ally->time le (time - 60*60*1)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
69 my $h_ally = $::i->viewAlly($allyId);
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
70 $h_ally->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
71 if(defined($ally)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
72 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
73 } else {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
74 $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
75 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
76 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
77 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
78
41
5849b6fdc76c removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 36
diff changeset
79 our $i = new Ikariam($::server, $::user, $::pass);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
80
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
81 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
82 $i->login;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
83 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
84 saveIslands(@islands);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
85 $i->logout;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
86 } 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
87 $i->login;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
88 my $island = $ARGV[0];
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
89 my @cities = $i->viewIsland($island);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
90 saveCities($island, @cities);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
91 $i->logout;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
92 } 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
93 $i->login;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
94 my $cities = $i->check;
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
95 foreach my $cityId (keys(%$cities)) {
141
0da6658697df fixed the param of islands
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 140
diff changeset
96 printf("%s %s\n", $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
97 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
98 saveIslands(@islands);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
99 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
100 $i->logout;
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
101 } else {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
102 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
103 }
121
0bab14dddf60 fixed the timestamp for scanning
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 99
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 {
141
0da6658697df fixed the param of islands
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 140
diff changeset
106 my @islands = @_;
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
107
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
108 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
109 {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
110 printf("checking island %d\n", $h_island->{id});
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
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 my $island;
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
113 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
114 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
115 $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
116 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
117 } else {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
118 $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
119 }
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
120
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
121 # scanning the island
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
122 if($island->time le (time - 60*60*6))
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
123 {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
124 my @cities = $i->viewIsland($h_island->{id});
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
125 saveCities($h_island->{id}, @cities);
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
126
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
127 $island->set('time', time);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
128 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
129 $island->update();
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
130
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
131 }
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
132 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
133 # $i->getCityInfo();