… | |
… | |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | CONF EXPORT_RECENTLOG = undef |
8 | CONF EXPORT_RECENTLOG = undef |
9 | CONF EXPORT_RECENTLOG_INTERVAL = 0.5 |
9 | CONF EXPORT_RECENTLOG_INTERVAL = 300 |
10 | |
10 | |
11 | ############################################################################# |
11 | ############################################################################# |
12 | # stuffs |
12 | # stuffs |
13 | |
13 | |
14 | our %PLAYERSEEN; |
14 | our %PLAYERSEEN; |
… | |
… | |
261 | my $t0 = EV::now; |
261 | my $t0 = EV::now; |
262 | |
262 | |
263 | $Coro::current->nice (1); |
263 | $Coro::current->nice (1); |
264 | $Coro::current->{desc} = "recentlog updater"; |
264 | $Coro::current->{desc} = "recentlog updater"; |
265 | |
265 | |
|
|
266 | Coro::AnyEvent::sleep 5; # grace time to allow file-saves |
|
|
267 | |
266 | my $lock = cf::lock_acquire "export_recentlog"; |
268 | my $lock = cf::lock_acquire "export_recentlog"; |
267 | |
269 | |
268 | while (%need_update) { |
270 | while (%need_update) { |
269 | for (keys %need_update) { |
271 | for (keys %need_update) { |
270 | delete $need_update{$_}; |
272 | delete $need_update{$_}; |
271 | |
273 | |
272 | _update_login $_; |
274 | _update_login $_; |
273 | } |
275 | } |
274 | } |
276 | } |
|
|
277 | |
|
|
278 | undef $update_w; |
275 | |
279 | |
276 | cf::get_slot 0.1, 0, "recentlog serialise"; |
280 | cf::get_slot 0.1, 0, "recentlog serialise"; |
277 | |
281 | |
278 | my $NOW = $cf::NOW; |
282 | my $NOW = $cf::NOW; |
279 | |
283 | |
… | |
… | |
282 | date => $NOW, |
286 | date => $NOW, |
283 | data => [ |
287 | data => [ |
284 | sort { ($b->[4] || $NOW) <=> ($a->[4] || $NOW) } |
288 | sort { ($b->[4] || $NOW) <=> ($a->[4] || $NOW) } |
285 | values %RECENT |
289 | values %RECENT |
286 | ], |
290 | ], |
287 | }; |
291 | } or warn "$EXPORT_RECENTLOG: $!"; |
288 | |
292 | |
289 | cf::trace "recentlog updated (", EV::now - $t0, "s).\n"; |
293 | cf::trace "recentlog updated (", EV::now - $t0, "s).\n"; |
290 | }; |
294 | }; |
291 | } |
295 | } |
292 | |
296 | |
… | |
… | |
312 | _update; |
316 | _update; |
313 | }; |
317 | }; |
314 | } |
318 | } |
315 | |
319 | |
316 | cf::player->attach ( |
320 | cf::player->attach ( |
317 | on_login => sub { undef $need_update{$_[0]->ob->name}; _update }, |
321 | on_login => sub { undef $need_update{$_[0]->ob->name}; update }, |
318 | on_logout => sub { undef $need_update{$_[0]->ob->name}; _update }, |
322 | on_logout => sub { undef $need_update{$_[0]->ob->name}; update }, |
319 | on_birth => sub { undef $need_update{$_[0]->ob->name}; _update }, |
323 | on_birth => sub { undef $need_update{$_[0]->ob->name}; update }, |
320 | on_death => sub { undef $need_update{$_[0]->ob->name}; _update }, |
324 | on_death => sub { undef $need_update{$_[0]->ob->name}; update }, |
321 | on_load => sub { undef $need_update{$_[0]->ob->name}; _update }, |
325 | # on_load => sub { undef $need_update{$_[0]->ob->name}; update }, |
322 | on_save => sub { undef $need_update{$_[0]->ob->name}; _update }, |
326 | # on_save => sub { undef $need_update{$_[0]->ob->name}; update }, |
323 | ); |
327 | ); |
324 | |
328 | |
325 | cf::post_init { |
329 | cf::post_init { |
326 | reload; |
330 | reload; |
327 | }; |
331 | }; |