annotate scan.pl @ 14:8b7bc598ba06

we now also save user's profile when scanning islands.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 12:18:50 +0800
parents f590b5ea5e55
children 59f2c435760c
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;
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
14 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
15 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
16 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
17 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
18 # 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
19 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
20 # print ("\n");
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
21
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
22 $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
23 $c->update();
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
24 } else {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
25 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
26 }
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 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
29
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
30 # 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
31 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
32 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
33 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
34 saveUser($users);
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 }
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 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
40 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
41 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
42
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
43 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
44 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
45 # 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
46 printf("Saving user %s\n", $user->{'name'});
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
47 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
48 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
49 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
50 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
51 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
52 $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
53 $c->update();
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
54 } else {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
55 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
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
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
60 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
61
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
62 my @islands;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
63 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
64 $i->login;
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
65 @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
66 } 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
67 $i->login;
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
68 my $island = $ARGV[0];
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
69
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
70 my @cities = $i->viewIsland($island);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
71 saveCities($island, @cities);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
72 $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
73 return;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
74 } 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
75 $i->login;
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
76 @islands = $i->viewHomeMap();
2
0fb73a7a0b94 ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 1
diff changeset
77 } else {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
78 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
79 }
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
80
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
81 foreach my $island (@islands)
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
82 {
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
83 printf("checking island %d\n", $island->{id});
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
84 if(my $c = Ikariam::Island->retrieve($island->{id})) {
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
85 foreach my $i (keys(%$island)) {
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
86 eval($c->$i($island->{$i}));
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
87 }
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
88 } else {
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
89 Ikariam::Island->insert($island);
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
90 }
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
91
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
92 # scanning the island
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
93 my @cities = $i->viewIsland($island->{id});
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
94 saveCities($island->{id}, @cities);
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
95 }
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
96 $i->logout;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
97 # $i->getCityInfo();