annotate scores.pl @ 12:0aeb0fe59257

added update owner of cities
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 11:53:43 +0800
parents f590b5ea5e55
children bb6eebd349fc
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 {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
24
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
25 printf("Saving %s\n", $user->{'name'});
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
26 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
27 {
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 foreach my $i (keys(%$user)) {
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 eval($c->$i($user->{$i}));
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 }
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 $c->autoupdate(1);
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 $c->update();
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 } else {
8
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 7
diff changeset
34 Ikariam::User->insert($user);
5
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 }
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d");
12
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
40 $i->login;
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
41
5
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 if($#ARGV == 0) {
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 my $users;
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 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
45 {
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 $users = $i->viewScore($x, $ARGV[0], 0);
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 saveUser($users);
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 }
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
49 } elsif ($#ARGV == 1) {
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
50 # search the islands and cities nearby
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
51 my ($x, $y) = @ARGV;
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
52 my $offset = 5;
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
53
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
54 Ikariam::Island->has_many(cities => 'Ikariam::Cities');
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
55
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
56 my @islands = Ikariam::Island->retrieve_from_sql(
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
57 "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) .
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
58 " AND " .
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
59 "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset)
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
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
62 my %owners;
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
63 foreach my $island (@islands)
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
64 {
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
65 my @cities = $island->cities;
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
66 foreach my $city (@cities)
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
67 {
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
68 $owners{$city->owner} += 1;
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
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
72 foreach my $o (keys(%owners))
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
73 {
9
ae412d1f7761 added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
74 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
75 {
9
ae412d1f7761 added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
76 my $users = $i->viewScore($type, $o, 0);
7
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
77 saveUser($users);
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
78 }
2040ccc95670 implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 5
diff changeset
79 }
5
dbb97c4265ba implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
80 } else {
12
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
81 if(0) {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
82 # Update all the users
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
83 my @users = Ikariam::User->retrieve_all();
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
84 foreach my $user (@users)
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
85 {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
86 printf("%s\n", $user->name);
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
87 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
88 {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
89 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
90 saveUser($users);
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 }
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
93 } else {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
94 # Update owner of cities
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
95 my @cities = Ikariam::Cities->retrieve_all();
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
96 foreach my $city (@cities)
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
97 {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
98 printf("%s\n", $city->owner);
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
99 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
100 {
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
101 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
102 saveUser($users);
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 }
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
106 # 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
107 }
12
0aeb0fe59257 added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
108 $i->logout;