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.24 by root, Thu Apr 8 17:36:53 2010 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 $pl->ob->kv_set (schmorplog_client => $pl->ns->{who_version});
52
53 $pl->ob->set_ob_key_value (schmorplog_client => $client);
54 54
55 ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); 55 ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name);
56 56
57 $UPDATE_LOGINS->start; 57 $UPDATE_LOGINS->start;
58 58
59 warn "LOGIN: ", $pl->ob->name, " from ", $pl->ns->host; 59 warn "LOGIN: ", $pl->ob->name, " from ", $pl->ns->host;
60 }, 60 },
61 on_logout => sub { 61 on_logout => sub {
62 my ($pl, $cleanly) = @_; 62 my ($pl, $cleanly) = @_;
63 $pl->ob->set_ob_key_value (schmorplog_last_logout => time); 63 $pl->ob->kv_set (schmorplog_last_logout => time);
64 ext::irc::do_notice (sprintf "%s left", $pl->ob->name); 64 ext::irc::do_notice (sprintf "%s left", $pl->ob->name);
65 65
66 $UPDATE_LOGINS->start; 66 $UPDATE_LOGINS->start;
67 67
68 warn "LOGOUT: ", $pl->ob->name, " from ", $pl->ns->host, " ($cleanly)"; 68 warn "LOGOUT: ", $pl->ob->name, " from ", $pl->ns->host, " ($cleanly)";
69 }, 69 },
70 on_birth => sub { 70 on_birth => sub {
71 my ($pl) = @_; 71 my ($pl) = @_;
72 ext::irc::do_notice (sprintf "%s was just born", $pl->ob->name); 72 ext::irc::do_notice (sprintf "%s was just born", $pl->ob->name);
73 $pl->ob->set_ob_key_value (schmorplog_birthdate => time); 73 $pl->ob->kv_set (schmorplog_birthdate => time);
74 74
75 warn "BIRTH: ", $pl->ob->name, " from ", $pl->ns->host; 75 warn "BIRTH: ", $pl->ob->name, " from ", $pl->ns->host;
76 }, 76 },
77 on_quit => sub { 77 on_quit => sub {
78 my ($pl) = @_; 78 my ($pl) = @_;
80 80
81 warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host; 81 warn "QUIT: ", $pl->ob->name, " from ", $pl->ns->host;
82 }, 82 },
83 on_death => sub { 83 on_death => sub {
84 my ($pl) = @_; 84 my ($pl) = @_;
85
85 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);
86 88
87 ++$pl->ob->{stats_death}{$pl->killer_name}; 89 ++$pl->ob->{stats_death}{$pl->killer_name};
88 90
89 $pl->ob->set_ob_key_value (schmorplog_death_count => 91 $pl->ob->kv_set (schmorplog_death_count =>
90 1 + $pl->ob->get_ob_key_value ("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;
91 }, 96 },
92 on_load => sub { 97 on_load => sub {
93 my ($pl, $path) = @_; 98 my ($pl, $path) = @_;
94 $pl->ob->set_ob_key_value (schmorplog_last_load => time); 99 $pl->ob->kv_set (schmorplog_last_load => time);
95 }, 100 },
96 on_save => sub { 101 on_save => sub {
97 my ($pl, $path) = @_; 102 my ($pl, $path) = @_;
98 $pl->ob->set_ob_key_value (schmorplog_last_save => time); 103 $pl->ob->kv_set (schmorplog_last_save => time);
99 }, 104 },
100); 105);
101 106
107cf::register_script_function "statistician::talk" => sub {
108 my ($who, $msg, $npc) = @_;
109
110 my ($cmd, $args) = split /\s+/, $msg, 2;
111
112 $args ||= $who->name;
113
114 if ($cmd eq "deaths") {
115 cf::async {
116 my $pl = cf::player::find $args
117 or return $who->reply ($npc, "I don't know any person named '$args'.");
118
119 my $s = $pl->ob->{stats_death}
120 or return $who->reply ($npc, "$args didn't die even once.");
121
122 my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n";
123
124 for (sort { $s->{$b} <=> $s->{$a} } keys %$s) {
125 $rep .= sprintf " C<%4d> time(s) due to %s.\n", $s->{$_}, $_;
126 }
127
128 $who->reply ($npc, $rep);
129 };
130 } elsif ($cmd eq "kills") {
131 cf::async {
132 my $pl = cf::player::find $args
133 or return $who->reply ($npc, "I don't know any person named '$args'.");
134
135 my $s = $pl->ob->{stats_kill}
136 or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far.");
137
138 my $rep = sprintf "Here is a list of all the kills I know about:\n\n";
139 for (sort { $s->{$b} <=> $s->{$a} } keys %$s) {
140 $rep .= sprintf " C<%6s> %s\n", $s->{$_}, $_;
141 }
142
143 $who->reply ($npc, $rep);
144 };
145 } elsif ($cmd eq "hi") {
146 $who->reply ($npc, "Hello!\n\n"
147 . "I am a statistician, I keep statistics about all people here.\n\n"
148 . " - To know how often somebody died, ask C<deaths> I<playername>\n"
149 . " - To know how many kills somebody scored, ask C<kills> I<playername>");
150 } else {
151 $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?");
152 }
153
154 $cmd = lc $cmd;
155};
156
157# log "crash" messages, i.e. client exit reasons
158cf::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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines