Mercurial > eagle-eye
annotate scores.pl @ 46:9466964ae5bb
added url of debian packags.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 17 Oct 2008 14:06:31 +0800 |
parents | 5849b6fdc76c |
children | 53c87400183f |
rev | line source |
---|---|
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
6 # highscoreType |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
7 # <option value="score">總積分</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
8 # <option value="building_score_main">建築大師</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
9 # <option value="building_score_secondary">建築等級</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
10 # <option value="research_score_main">科學巨人</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
11 # <option value="research_score_secondary">研究等級</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
12 # <option value="army_score_main" selected="selected">戰爭將軍</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
13 # <option value="trader_score_secondary">黃金存量</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
14 # my $users = $i->viewScore('score', 'chihchun', '0'); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
15 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 package main; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 sub saveUser |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
19 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
20 my $users = shift; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
21 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
22 foreach my $user (values(%{$users})) |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
23 { |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
24 printf("Saving %s\n", $user->{'name'}); |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
25 if(my $c = Ikariam::User->retrieve($user->{id})) |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 foreach my $i (keys(%$user)) { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 eval($c->$i($user->{$i})); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
30 $c->autoupdate(1); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 $c->update(); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
32 } else { |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
33 Ikariam::User->insert($user); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
34 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
35 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
37 |
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
13
diff
changeset
|
38 my $i = new Ikariam($::server, $::user, $::pass); |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
39 $i->login; |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
40 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 if($#ARGV == 0) { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 my $users; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 foreach my $x (qw/score army_score_main trader_score_secondary/) |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
45 $users = $i->viewScore($x, $ARGV[0], 0); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 saveUser($users); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
47 } |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
48 } elsif ($#ARGV == 1) { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
49 # search the islands and cities nearby |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
50 my ($x, $y) = @ARGV; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
51 my $offset = 5; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
52 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
53 Ikariam::Island->has_many(cities => 'Ikariam::Cities'); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
54 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
55 my @islands = Ikariam::Island->retrieve_from_sql( |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
56 "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) . |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
57 " AND " . |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
58 "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
59 ); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
60 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
61 my %owners; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
62 foreach my $island (@islands) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
63 { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
64 my @cities = $island->cities; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
65 foreach my $city (@cities) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
66 { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
67 $owners{$city->owner} += 1; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
68 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
69 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
70 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
71 foreach my $o (keys(%owners)) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
72 { |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
73 foreach my $type (qw/score army_score_main trader_score_secondary/) |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
74 { |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
75 my $users = $i->viewScore($type, $o, 0); |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
76 saveUser($users); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
77 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
78 } |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
79 } else { |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
80 if(0) { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
81 # Update all the users |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
82 my @users = Ikariam::User->retrieve_all(); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
83 foreach my $user (@users) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
84 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
85 printf("%s\n", $user->name); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
86 foreach my $type (qw/score army_score_main trader_score_secondary/) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
87 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
88 my $users = $i->viewScore($type, $user->name, 0); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
89 saveUser($users); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
90 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
91 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
92 } else { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
93 # Update owner of cities |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
94 my @cities = Ikariam::Cities->retrieve_all(); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
95 foreach my $city (@cities) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
96 { |
13
bb6eebd349fc
removed debug message
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
12
diff
changeset
|
97 # printf("%s\n", $city->owner); |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
98 foreach my $type (qw/score army_score_main trader_score_secondary/) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
99 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
100 my $users = $i->viewScore($type, $city->owner, 0); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
101 saveUser($users); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
102 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
103 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
104 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
105 # die("Usage: $0 nickname\nUsage: $0 x y"); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
106 } |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
107 $i->logout; |