ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/schmorplog.ext
(Generate patch)

Comparing deliantra/server/ext/schmorplog.ext (file contents):
Revision 1.15 by root, Wed Apr 30 10:36:01 2008 UTC vs.
Revision 1.23 by root, Sun Sep 21 23:21:49 2008 UTC

1#! perl # depends=irc 1#! perl # depends=irc mandatory
2
3# statistics-package
2 4
3use Fcntl; 5use Fcntl;
4use Coro::AIO; 6use Coro::AIO;
5 7
6our $UPDATE_LOGINS = EV::idle sub { 8our $UPDATE_LOGINS = EV::idle sub {
34 return unless $hitter; 36 return unless $hitter;
35 $hitter = $hitter->outer_owner; 37 $hitter = $hitter->outer_owner;
36 my $pl = $hitter->contr 38 my $pl = $hitter->contr
37 or return; 39 or return;
38 40
39 ++$hitter->{stats_kill}{$ob->name_pl}; 41 ++$hitter->{stats_kill}{$ob->name};
40 }, 42 },
41); 43);
42 44
43cf::player->attach ( 45cf::player->attach (
44 on_login => sub { 46 on_login => sub {
45 my ($pl) = @_; 47 my ($pl) = @_;
46 $pl->ob->set_ob_key_value (schmorplog_last_login => time); 48 $pl->ob->kv_set (schmorplog_last_login => time);
47 49
48 $pl->ob->set_ob_key_value (schmorplog_login_count => 50 $pl->ob->kv_set (schmorplog_login_count =>
49 1 + $pl->ob->get_ob_key_value ("schmorplog_login_count")); 51 1 + $pl->ob->kv_get ("schmorplog_login_count"));
50 52
51 (my $client = $pl->ns->version) =~ s/\n/\\n/g; 53 (my $client = $pl->ns->version) =~ s/\n/\\n/g;
52 54
53 $pl->ob->set_ob_key_value (schmorplog_client => $client); 55 $pl->ob->kv_set (schmorplog_client => $client);
54 56
55 ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); 57 ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name);
56 58
57 $UPDATE_LOGINS->start; 59 $UPDATE_LOGINS->start;
58 60
59 warn "LOGIN: ", $pl->ob->name, " from ", $pl->ns->host; 61 warn "LOGIN: ", $pl->ob->name, " from ", $pl->ns->host;
60 }, 62 },
61 on_logout => sub { 63 on_logout => sub {
62 my ($pl, $cleanly) = @_; 64 my ($pl, $cleanly) = @_;
63 $pl->ob->set_ob_key_value (schmorplog_last_logout => time); 65 $pl->ob->kv_set (schmorplog_last_logout => time);
64 ext::irc::do_notice (sprintf "%s left", $pl->ob->name); 66 ext::irc::do_notice (sprintf "%s left", $pl->ob->name);
65 67
66 $UPDATE_LOGINS->start; 68 $UPDATE_LOGINS->start;
67 69
68 warn "LOGOUT: ", $pl->ob->name, " from ", $pl->ns->host, " ($cleanly)"; 70 warn "LOGOUT: ", $pl->ob->name, " from ", $pl->ns->host, " ($cleanly)";
69 }, 71 },
70 on_birth => sub { 72 on_birth => sub {
71 my ($pl) = @_; 73 my ($pl) = @_;
72 ext::irc::do_notice (sprintf "%s was just born", $pl->ob->name); 74 ext::irc::do_notice (sprintf "%s was just born", $pl->ob->name);
73 $pl->ob->set_ob_key_value (schmorplog_birthdate => time); 75 $pl->ob->kv_set (schmorplog_birthdate => time);
74 76
75 warn "BIRTH: ", $pl->ob->name, " from ", $pl->ns->host; 77 warn "BIRTH: ", $pl->ob->name, " from ", $pl->ns->host;
76 }, 78 },
77 on_quit => sub { 79 on_quit => sub {
78 my ($pl) = @_; 80 my ($pl) = @_;
80 82
81 warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host; 83 warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host;
82 }, 84 },
83 on_death => sub { 85 on_death => sub {
84 my ($pl) = @_; 86 my ($pl) = @_;
87
85 ext::irc::do_notice (sprintf "%s was killed by %s", $pl->ob->name, $pl->killer_name); 88 my $msg = $pl->expand_cfpod (sprintf "%s was killed by %s.", $pl->ob->name, $pl->killer_name);
89 ext::irc::do_notice ($msg);
86 90
87 ++$pl->ob->{stats_death}{$pl->killer_name}; 91 ++$pl->ob->{stats_death}{$pl->killer_name};
88 92
89 $pl->ob->set_ob_key_value (schmorplog_death_count => 93 $pl->ob->kv_set (schmorplog_death_count =>
90 1 + $pl->ob->get_ob_key_value ("schmorplog_death_count")); 94 1 + $pl->ob->kv_get ("schmorplog_death_count"));
95
96 $_->send_msg ("" => $msg, cf::NDI_VERBATIM)
97 for cf::player::list;
91 }, 98 },
92 on_load => sub { 99 on_load => sub {
93 my ($pl, $path) = @_; 100 my ($pl, $path) = @_;
94 $pl->ob->set_ob_key_value (schmorplog_last_load => time); 101 $pl->ob->kv_set (schmorplog_last_load => time);
95 }, 102 },
96 on_save => sub { 103 on_save => sub {
97 my ($pl, $path) = @_; 104 my ($pl, $path) = @_;
98 $pl->ob->set_ob_key_value (schmorplog_last_save => time); 105 $pl->ob->kv_set (schmorplog_last_save => time);
99 }, 106 },
100); 107);
101 108
109cf::register_script_function "statistician::talk" => sub {
110 my ($who, $msg, $npc) = @_;
111
112 my ($cmd, $args) = split /\s+/, $msg, 2;
113
114 $args ||= $who->name;
115
116 if ($cmd eq "deaths") {
117 cf::async {
118 my $pl = cf::player::find $args
119 or return $who->reply ($npc, "I don't know any person named '$args'.");
120
121 my $s = $pl->ob->{stats_death}
122 or return $who->reply ($npc, "$args didn't die even once.");
123
124 my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n";
125
126 for (sort { $s->{$b} <=> $s->{$a} } keys %$s) {
127 $rep .= sprintf " C<%4d> time(s) due to %s.\n", $s->{$_}, $_;
128 }
129
130 $who->reply ($npc, $rep);
131 };
132 } elsif ($cmd eq "kills") {
133 cf::async {
134 my $pl = cf::player::find $args
135 or return $who->reply ($npc, "I don't know any person named '$args'.");
136
137 my $s = $pl->ob->{stats_kill}
138 or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far.");
139
140 my $rep = sprintf "Here is a list of all the kills I know about:\n\n";
141 for (sort { $s->{$b} <=> $s->{$a} } keys %$s) {
142 $rep .= sprintf " C<%6s> %s\n", $s->{$_}, $_;
143 }
144
145 $who->reply ($npc, $rep);
146 };
147 } elsif ($cmd eq "hi") {
148 $who->reply ($npc, "Hello!\n\n"
149 . "I am a statistician, I keep statistics about all people here.\n\n"
150 . " - To know how often somebody died, ask C<deaths> I<playername>\n"
151 . " - To know how many kills somebody scored, ask C<kills> I<playername>");
152 } else {
153 $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?");
154 }
155
156 $cmd = lc $cmd;
157};
158
159# log "crash" messages, i.e. client exit reasons
160cf::register_exticmd clientlog => sub {
161 my ($ns, $msg) = @_;
162
163 my $name = $ns->pl && $ns->pl->ob ? $ns->pl->ob->name : "<unknown>";
164
165 $msg =~ y/\x0a\x20-\x7f//cd;
166 $msg =~ s/\s+$//;
167
168 warn sprintf "clientlog [%s/%s]: %s\n", $ns->host, $name, $msg;
169
170 ()
171};
172

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines