1 | #! perl # depends=irc |
1 | #! perl # depends=irc mandatory |
2 | |
2 | |
3 | # statistics-package |
3 | # statistics-package |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | our $UPDATE_LOGINS = EV::idle sub { |
8 | our $UPDATE_LOGINS = AE::idle sub { |
9 | $_[0]->stop; |
9 | $_[0]->stop; |
10 | |
10 | |
11 | cf::async { |
11 | cf::async { |
12 | my ($status, @pl) = ext::commands::who_listing; |
12 | my ($status, @pl) = ext::commands::who_listing; |
13 | |
13 | |
… | |
… | |
48 | $pl->ob->kv_set (schmorplog_last_login => time); |
48 | $pl->ob->kv_set (schmorplog_last_login => time); |
49 | |
49 | |
50 | $pl->ob->kv_set (schmorplog_login_count => |
50 | $pl->ob->kv_set (schmorplog_login_count => |
51 | 1 + $pl->ob->kv_get ("schmorplog_login_count")); |
51 | 1 + $pl->ob->kv_get ("schmorplog_login_count")); |
52 | |
52 | |
53 | (my $client = $pl->ns->version) =~ s/\n/\\n/g; |
|
|
54 | |
|
|
55 | $pl->ob->kv_set (schmorplog_client => $client); |
53 | $pl->ob->kv_set (schmorplog_client => $pl->ns->{who_version}); |
56 | |
54 | |
57 | ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); |
55 | ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); |
58 | |
56 | |
59 | $UPDATE_LOGINS->start; |
57 | $UPDATE_LOGINS->start; |
60 | |
58 | |
… | |
… | |
82 | |
80 | |
83 | warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host; |
81 | warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host; |
84 | }, |
82 | }, |
85 | on_death => sub { |
83 | on_death => sub { |
86 | my ($pl) = @_; |
84 | my ($pl) = @_; |
|
|
85 | |
87 | ext::irc::do_notice (sprintf "%s was killed by %s", $pl->ob->name, $pl->killer_name); |
86 | my $msg = $pl->expand_cfpod (sprintf "%s was killed by %s.", $pl->ob->name, $pl->killer_name); |
|
|
87 | ext::irc::do_notice ($msg); |
88 | |
88 | |
89 | ++$pl->ob->{stats_death}{$pl->killer_name}; |
89 | ++$pl->ob->{stats_death}{$pl->killer_name}; |
90 | |
90 | |
91 | $pl->ob->kv_set (schmorplog_death_count => |
91 | $pl->ob->kv_set (schmorplog_death_count => |
92 | 1 + $pl->ob->kv_get ("schmorplog_death_count")); |
92 | 1 + $pl->ob->kv_get ("schmorplog_death_count")); |
|
|
93 | |
|
|
94 | $_->send_msg ("" => $msg, cf::NDI_VERBATIM) |
|
|
95 | for cf::player::list; |
93 | }, |
96 | }, |
94 | on_load => sub { |
97 | on_load => sub { |
95 | my ($pl, $path) = @_; |
98 | my ($pl, $path) = @_; |
96 | $pl->ob->kv_set (schmorplog_last_load => time); |
99 | $pl->ob->kv_set (schmorplog_last_load => time); |
97 | }, |
100 | }, |
… | |
… | |
114 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
117 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
115 | |
118 | |
116 | my $s = $pl->ob->{stats_death} |
119 | my $s = $pl->ob->{stats_death} |
117 | or return $who->reply ($npc, "$args didn't die even once."); |
120 | or return $who->reply ($npc, "$args didn't die even once."); |
118 | |
121 | |
119 | my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n\n\n"; |
122 | my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n"; |
120 | |
123 | |
121 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
124 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
122 | $rep .= "$s->{$_} time(s) due to $_.\n\n"; |
125 | $rep .= sprintf " C<%4d> time(s) due to %s.\n", $s->{$_}, $_; |
123 | } |
126 | } |
124 | |
127 | |
125 | $who->reply ($npc, $rep); |
128 | $who->reply ($npc, $rep); |
126 | }; |
129 | }; |
127 | } elsif ($cmd eq "kills") { |
130 | } elsif ($cmd eq "kills") { |
… | |
… | |
130 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
133 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
131 | |
134 | |
132 | my $s = $pl->ob->{stats_kill} |
135 | my $s = $pl->ob->{stats_kill} |
133 | or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far."); |
136 | or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far."); |
134 | |
137 | |
135 | my $rep = sprintf "\n\nC<%6s> %s\n\n", "Kills", "Name"; |
138 | my $rep = sprintf "Here is a list of all the kills I know about:\n\n"; |
136 | for (sort { $s->{$a} <=> $s->{$b} } keys %$s) { |
139 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
137 | $rep .= sprintf "C<%6s> %s\n\n", $s->{$_}, $_; |
140 | $rep .= sprintf " C<%6s> %s\n", $s->{$_}, $_; |
138 | } |
141 | } |
139 | |
142 | |
140 | $who->reply ($npc, $rep); |
143 | $who->reply ($npc, $rep); |
141 | }; |
144 | }; |
142 | } elsif ($cmd eq "hi") { |
145 | } elsif ($cmd eq "hi") { |
143 | $who->reply ($npc, "Hello!\n\n" |
146 | $who->reply ($npc, "Hello!\n\n" |
144 | . "I am a statistician, I keep statistics about all people here.\n\n" |
147 | . "I am a statistician, I keep statistics about all people here.\n\n" |
145 | . "To know how often somebody died, ask C<deaths> I<playername>\n\n" |
148 | . " - To know how often somebody died, ask C<deaths> I<playername>\n" |
146 | . "To know how many kills somebody scored, ask C<kills> I<playername>"); |
149 | . " - To know how many kills somebody scored, ask C<kills> I<playername>"); |
147 | } else { |
150 | } else { |
148 | $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); |
151 | $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); |
149 | } |
152 | } |
150 | |
153 | |
151 | $cmd = lc $cmd; |
154 | $cmd = lc $cmd; |
152 | }; |
155 | }; |
153 | |
156 | |
|
|
157 | # log "crash" messages, i.e. client exit reasons |
|
|
158 | cf::register_exticmd clientlog => sub { |
|
|
159 | my ($ns, $msg) = @_; |
|
|
160 | |
|
|
161 | my $name = $ns->pl && $ns->pl->ob ? $ns->pl->ob->name : "<unknown>"; |
|
|
162 | |
|
|
163 | $msg =~ y/\x0a\x20-\x7f//cd; |
|
|
164 | $msg =~ s/\s+$//; |
|
|
165 | |
|
|
166 | warn sprintf "clientlog [%s/%s]: %s\n", $ns->host, $name, $msg; |
|
|
167 | |
|
|
168 | () |
|
|
169 | }; |
|
|
170 | |