ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/schmorplog.ext
Revision: 1.20
Committed: Sat May 3 13:29:14 2008 UTC (16 years ago) by root
Branch: MAIN
CVS Tags: rel-2_6, rel-2_54, rel-2_55, rel-2_56, rel-2_53, rel-2_61
Changes since 1.19: +1 -1 lines
Log Message:
shit

File Contents

# Content
1 #! perl # depends=irc
2
3 # statistics-package
4
5 use Fcntl;
6 use Coro::AIO;
7
8 our $UPDATE_LOGINS = EV::idle sub {
9 $_[0]->stop;
10
11 cf::async {
12 my ($status, @pl) = ext::commands::who_listing;
13
14 my $fh = aio_open "$LOCALDIR/usercount", O_WRONLY | O_CREAT | O_TRUNC, 0644
15 or return;
16 aio_write $fh, 0, undef, scalar @pl, 0;
17 aio_close $fh;
18
19 my $who;
20 for ($status, @pl) {
21 s/[<&]//g;
22 $who .= "$_<br />\n";
23 }
24
25 my $fh = aio_open "$LOCALDIR/userlisting.html", O_WRONLY | O_CREAT | O_TRUNC, 0644
26 or return;
27 aio_write $fh, 0, undef, $who, 0;
28 aio_close $fh;
29 };
30 };
31
32 cf::object->attach (
33 on_kill => sub {
34 my ($ob, $hitter) = @_;
35
36 return unless $hitter;
37 $hitter = $hitter->outer_owner;
38 my $pl = $hitter->contr
39 or return;
40
41 ++$hitter->{stats_kill}{$ob->name};
42 },
43 );
44
45 cf::player->attach (
46 on_login => sub {
47 my ($pl) = @_;
48 $pl->ob->kv_set (schmorplog_last_login => time);
49
50 $pl->ob->kv_set (schmorplog_login_count =>
51 1 + $pl->ob->kv_get ("schmorplog_login_count"));
52
53 (my $client = $pl->ns->version) =~ s/\n/\\n/g;
54
55 $pl->ob->kv_set (schmorplog_client => $client);
56
57 ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name);
58
59 $UPDATE_LOGINS->start;
60
61 warn "LOGIN: ", $pl->ob->name, " from ", $pl->ns->host;
62 },
63 on_logout => sub {
64 my ($pl, $cleanly) = @_;
65 $pl->ob->kv_set (schmorplog_last_logout => time);
66 ext::irc::do_notice (sprintf "%s left", $pl->ob->name);
67
68 $UPDATE_LOGINS->start;
69
70 warn "LOGOUT: ", $pl->ob->name, " from ", $pl->ns->host, " ($cleanly)";
71 },
72 on_birth => sub {
73 my ($pl) = @_;
74 ext::irc::do_notice (sprintf "%s was just born", $pl->ob->name);
75 $pl->ob->kv_set (schmorplog_birthdate => time);
76
77 warn "BIRTH: ", $pl->ob->name, " from ", $pl->ns->host;
78 },
79 on_quit => sub {
80 my ($pl) = @_;
81 ext::irc::do_notice (sprintf "%s quit the game", $pl->ob->name);
82
83 warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host;
84 },
85 on_death => sub {
86 my ($pl) = @_;
87 ext::irc::do_notice (sprintf "%s was killed by %s", $pl->ob->name, $pl->killer_name);
88
89 ++$pl->ob->{stats_death}{$pl->killer_name};
90
91 $pl->ob->kv_set (schmorplog_death_count =>
92 1 + $pl->ob->kv_get ("schmorplog_death_count"));
93 },
94 on_load => sub {
95 my ($pl, $path) = @_;
96 $pl->ob->kv_set (schmorplog_last_load => time);
97 },
98 on_save => sub {
99 my ($pl, $path) = @_;
100 $pl->ob->kv_set (schmorplog_last_save => time);
101 },
102 );
103
104 cf::register_script_function "statistician::talk" => sub {
105 my ($who, $msg, $npc) = @_;
106
107 my ($cmd, $args) = split /\s+/, $msg, 2;
108
109 $args ||= $who->name;
110
111 if ($cmd eq "deaths") {
112 cf::async {
113 my $pl = cf::player::find $args
114 or return $who->reply ($npc, "I don't know any person named '$args'.");
115
116 my $s = $pl->ob->{stats_death}
117 or return $who->reply ($npc, "$args didn't die even once.");
118
119 my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n\n\n";
120
121 for (sort { $s->{$b} <=> $s->{$a} } keys %$s) {
122 $rep .= "$s->{$_} time(s) due to $_.\n\n";
123 }
124
125 $who->reply ($npc, $rep);
126 };
127 } elsif ($cmd eq "kills") {
128 cf::async {
129 my $pl = cf::player::find $args
130 or return $who->reply ($npc, "I don't know any person named '$args'.");
131
132 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.");
134
135 my $rep = sprintf "\n\nC<%6s> %s\n\n", "Kills", "Name";
136 for (sort { $s->{$a} <=> $s->{$b} } keys %$s) {
137 $rep .= sprintf "C<%6s> %s\n\n", $s->{$_}, $_;
138 }
139
140 $who->reply ($npc, $rep);
141 };
142 } elsif ($cmd eq "hi") {
143 $who->reply ($npc, "Hello!\n\n"
144 . "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"
146 . "To know how many kills somebody scored, ask C<kills> I<playername>");
147 } else {
148 $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?");
149 }
150
151 $cmd = lc $cmd;
152 };
153