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.30 by root, Sun Aug 14 13:19:30 2011 UTC vs.
Revision 1.31 by root, Sat Feb 4 00:14:41 2012 UTC

3# statistics-package 3# statistics-package
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7 7
8CONF EXPORT_RECENTLOG = undef
9CONF EXPORT_RECENTLOG_INTERVAL = 0.5
10
11#############################################################################
12# stuffs
13
8our %PLAYERSEEN; 14our %PLAYERSEEN;
9 15
16# EV, because we call ->start
10our $UPDATE_LOGINS = EV::idle sub { 17our $UPDATE_LOGINS = EV::idle sub {
11 $_[0]->stop; 18 $_[0]->stop;
12 19
13 cf::async { 20 cf::async {
14 my ($status, @pl) = ext::commands::who_listing; 21 my ($status, @pl) = ext::commands::who_listing;
172 cf::error sprintf "clientlog [%s/%s]: %s\n", $ns->host, $name, $msg; 179 cf::error sprintf "clientlog [%s/%s]: %s\n", $ns->host, $name, $msg;
173 180
174 () 181 ()
175}; 182};
176 183
184#############################################################################
177# log max playercount every minute 185# log max playercount every minute
178#############################################################################
179 186
180our $STATSDIR = "$LOCALDIR/maxplayers"; 187our $STATSDIR = "$LOCALDIR/maxplayers";
181 188
182mkdir $STATSDIR; 189mkdir $STATSDIR;
183 190
208 }; 215 };
209 }; 216 };
210 }; 217 };
211}; 218};
212 219
220#############################################################################
221# export recentlog
222
223our %RECENT;
224
225our $update_w;
226our %need_update;
227
228sub _update_login {
229 my ($login) = @_;
230
231 my $path = (cf::player::playerdir $login) . "/playerdata";
232
233 if (0 >= aio_load $path, my $data) {
234 delete $RECENT{$login};
235 } else {
236 local $_ = $data;
237
238 my $birthdate = /^schmorplog_birthdate (\S+)$/m ? $1 : undef;
239 my $login_count = /^schmorplog_login_count (\S+)$/m ? $1 : 0;
240 my $death_count = /^schmorplog_death_count (\S+)$/m ? $1 : 0;
241 my $last_save = /^schmorplog_last_save (\S+)$/m ? $1 : undef;
242 my $last_login = /^schmorplog_last_login (\S+)$/m ? $1 : undef;
243 my $last_logout = /^schmorplog_last_logout (\S+)$/m ? $1 : undef;
244 my $client = /^schmorplog_client (.*)$/m ? $1 : "?";
245 my $map = /^map (.*)$/m ? $1 : "?";
246
247 return unless $last_login;
248
249 $last_logout = $last_save if $last_save > $last_logout && $last_login > $last_logout && $last_save < $NOW - 10 * 60;
250 $last_logout = undef if $last_logout < $last_login;
251
252 return unless $last_login > $NOW - 86400 * ($login_count * 7 + 10);
253
254# next if $count < 3 && $login < $NOW - 86400*2;
255 $RECENT{$login} = [$login, $birthdate, $last_login, $login_count, $last_logout, $client, $death_count, $map];
256 }
257}
258
259sub _update {
260 cf::async_ext {
261 my $t0 = EV::now;
262
263 $Coro::current->nice (1);
264 $Coro::current->{desc} = "recentlog updater";
265
266 my $lock = cf::lock_acquire "export_recentlog";
267
268 while (%need_update) {
269 for (keys %need_update) {
270 delete $need_update{$_};
271
272 _update_login $_;
273 }
274 }
275
276 cf::get_slot 0.1, 0, "recentlog serialise";
277
278 my $NOW = $cf::NOW;
279
280 cf::replace_file $EXPORT_RECENTLOG, cf::encode_json {
281 version => 1,
282 date => $NOW,
283 data => [
284 sort { ($b->[4] || $NOW) <=> ($a->[4] || $NOW) }
285 values %RECENT
286 ],
287 };
288
289 cf::trace "recentlog updated (", EV::now - $t0, "s).\n";
290 };
291}
292
293sub update {
294 return unless defined $EXPORT_RECENTLOG;
295
296 $update_w ||= AE::timer $EXPORT_RECENTLOG_INTERVAL, 0, \&_update;
297}
298
299sub reload {
300 return unless defined $EXPORT_RECENTLOG;
301
302 my $lock = cf::lock_acquire "export_recentlog";
303
304 cf::async_ext {
305 $lock;
306
307 $Coro::current->{desc} = "recentlog reloader";
308
309 undef $need_update{$_}
310 for @{ +cf::player::list_logins };
311
312 _update;
313 };
314}
315
316cf::player->attach (
317 on_login => sub { undef $need_update{$_[0]->ob->name}; _update },
318 on_logout => sub { undef $need_update{$_[0]->ob->name}; _update },
319 on_birth => sub { undef $need_update{$_[0]->ob->name}; _update },
320 on_death => sub { undef $need_update{$_[0]->ob->name}; _update },
321 on_load => sub { undef $need_update{$_[0]->ob->name}; _update },
322 on_save => sub { undef $need_update{$_[0]->ob->name}; _update },
323);
324
325cf::post_init {
326 reload;
327};
328

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines