ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/util/guilds.pl
Revision: 1.9
Committed: Fri Jan 5 23:59:06 2007 UTC (17 years, 4 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +0 -0 lines
State: FILE REMOVED
Log Message:
moved file

File Contents

# Content
1 #!/usr/bin/env perl
2
3 # Script to help drawing conclusions on guild activity
4 # Usage is at the bottom
5
6 use strict;
7 use List::Util qw(max);
8
9 my $PLAYERDIR = "/var/crossfire/players";
10
11 my $NOW = time;
12
13 my %slaying = (
14 bs => "black_shield",
15 dh => "damned_heretics",
16 ds => "dreaming_sage",
17 db => "drunken_barbarian",
18 ls => "laughing_skull",
19 mf => "mailed_fist",
20 pd => "poisoned_dagger",
21 pb => "purple_butterfly",
22 sc => "smoking_cauldron",
23 ki => "ketsueki_itsuryuu",
24 ny => "nenshou_youso",
25 zdr => "zaseki_dzuki_ryoku"
26 );
27
28 my %members;
29 my %count;
30
31 sub init {
32 chdir $PLAYERDIR;
33
34 for my $pl (<*>) {
35 my $pldata = do { local $/; open my $fh, "<$pl/$pl.pl" or die "$pl/$pl.pl: $!"; <$fh> };
36
37 for my $guild (keys %slaying) {
38 $pldata =~ /^slaying $slaying{$guild}$/m && push @{ $members{$guild} }, $pl;
39 }
40 }
41
42 for my $guild (keys %slaying) {
43 $count{$guild} = @{ $members{$guild} };
44 }
45 }
46
47 sub init_with_age {
48 my ($age) = @_;
49 chdir $PLAYERDIR;
50
51 for my $pl (<*>) {
52 my $mtime = (stat $pl)[9];
53 my $pldata = do { local $/; open my $fh, "<$pl/$pl.pl" or die "$pl/$pl.pl: $!"; <$fh> };
54
55 for my $guild (keys %slaying) {
56 $pldata =~ /^slaying $slaying{$guild}$/m && push @{ $members{$guild} }, $pl
57 if ($NOW - $mtime < $age * 24 * 3600);
58 }
59 }
60
61 for my $guild (keys %slaying) {
62 $count{$guild} = @{ $members{$guild} } if $members{$guild};
63 }
64 }
65
66 sub in_days {
67 my ($secs) = @_;
68 ($NOW - $secs) / 3600 / 24;
69 }
70
71 sub guild_list {
72 print STDERR "short name full name\n";
73 print STDERR "-" x 27 . "\n";
74 print "$_" . (length $_ == 3 ? "" : " ") . " " x 15 . $slaying{$_} . "\n" for keys %slaying;
75 }
76
77 sub members_mtime_avg {
78 my %mtime;
79 init;
80
81 print STDERR "Guild: mtime:\n";
82 print STDERR "-" x 26 . "\n";
83 for my $guild (keys %slaying) {
84 for my $member (@{ $members{$guild} }) {
85 $mtime{$guild} += (stat "$member")[9];
86 }
87 $mtime{$guild} /= $count{$guild};
88 print $slaying{$guild} . " " x (20 - length $slaying{$guild}) . in_days($mtime{$guild}) . "\n";
89 }
90 }
91
92 sub members_mtime_max {
93 my %mtime;
94 init;
95
96 print STDERR "Guild: mtime:\n";
97 print STDERR "-" x 26 . "\n";
98 for my $guild (keys %slaying) {
99 for my $member (@{ $members{$guild} }) {
100 $mtime{$guild} = max +(stat $member)[9], $mtime{$guild};
101 }
102 print $slaying{$guild} . " " x (20 - length $slaying{$guild}) . in_days($mtime{$guild}) . "\n";
103 }
104 }
105
106 sub members_cnt {
107 my ($age) = @_;
108 if ($age) {
109 init_with_age $age;
110 print STDERR "Guild member count for members with mtime < $age days\n";
111 } else {
112 init;
113 print STDERR "Guild member count\n";
114 }
115
116 print STDERR "Guild: members:\n";
117 print STDERR "-" x 28 . "\n";
118 print $slaying{$_} . " " x (20 - length $slaying{$_}) . ($count{$_} or 0) . "\n"
119 for keys %slaying;
120 }
121
122 sub members_list {
123 my ($guild, $age) = @_;
124 init;
125
126 if ($guild) {
127 print STDERR "Members for guild " . $slaying{$guild} . ($age ? " with mtime < $age" : "") . ":\n";
128 print STDERR "-" x 31 . "\n";
129
130 if ($age) {
131 for my $member (@{ $members{$guild} }) {
132 if ($NOW - (stat $member)[9] < $age * 24 * 3600) {
133 print "$member\n";
134 }
135 }
136 } else {
137 print "$_\n" for @{ $members{$guild} };
138 }
139 } else {
140 guild_list;
141 return;
142 }
143 }
144
145 sub usage {
146 print <<USAGE;
147 \033[1mUsage: perl guilds.pl max|avg|cnt|lst <guild> [<max age>]\033[0m
148
149 max: max(mtime of all guild members) for each guild
150 avg: average mtime of all guild members for each guild
151 cnt: member count (number of players owning a key)
152 lst: list members for \033[1m<guild>\033[0m. lst without \033[1m<guild>\033[0m lists all guild names
153
154 The optional <max age> is the maximum time in days a player can be
155 logged out and still appear on the list. \033[1m<max age>\033[0m only applies
156 to \033[1mcnt\033[0m and \033[1mlst\033[0m.
157
158 Copyright (C) 2006 The Crossfire+ Development Team
159 USAGE
160 }
161
162 if ($ARGV[0] eq "max") {
163 members_mtime_max;
164 } elsif ($ARGV[0] eq "avg") {
165 members_mtime_avg;
166 } elsif ($ARGV[0] eq "cnt") {
167 members_cnt $ARGV[1];
168 } elsif ($ARGV[0] eq "lst") {
169 members_list $ARGV[1], $ARGV[2];
170 } else {
171 usage;
172 }