… | |
… | |
219 | |
219 | |
220 | ############################################################################# |
220 | ############################################################################# |
221 | # export recentlog |
221 | # export recentlog |
222 | |
222 | |
223 | our %RECENT; |
223 | our %RECENT; |
|
|
224 | our $EXPORT_RECENTLOG_GRACE = 120; |
224 | |
225 | |
225 | our $update_w; |
226 | our $update_w; |
226 | our %need_update; |
227 | our %need_update; |
227 | |
228 | |
228 | sub _update_login { |
229 | sub _update_login { |
… | |
… | |
242 | my $last_login = /^schmorplog_last_login (\S+)$/m ? $1 : undef; |
243 | my $last_login = /^schmorplog_last_login (\S+)$/m ? $1 : undef; |
243 | my $last_logout = /^schmorplog_last_logout (\S+)$/m ? $1 : undef; |
244 | my $last_logout = /^schmorplog_last_logout (\S+)$/m ? $1 : undef; |
244 | my $client = /^schmorplog_client (.*)$/m ? $1 : "?"; |
245 | my $client = /^schmorplog_client (.*)$/m ? $1 : "?"; |
245 | my $map = /^map (.*)$/m ? $1 : "?"; |
246 | my $map = /^map (.*)$/m ? $1 : "?"; |
246 | |
247 | |
247 | return unless $last_login; |
248 | return delete $RECENT{$login} unless $last_login; |
248 | |
249 | |
249 | $last_logout = $last_save if $last_save > $last_logout && $last_login > $last_logout && $last_save < $NOW - 10 * 60; |
250 | $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 | $last_logout = undef if $last_logout < $last_login; |
251 | |
252 | |
252 | return unless $last_login > $NOW - 86400 * ($login_count * 7 + 10); |
253 | return delete $RECENT{$login} unless $last_login > $NOW - 86400 * ($login_count * 7 + 10); |
253 | |
254 | |
254 | # next if $count < 3 && $login < $NOW - 86400*2; |
255 | # next if $count < 3 && $login < $NOW - 86400*2; |
255 | $RECENT{$login} = [$login, $birthdate, $last_login, $login_count, $last_logout, $client, $death_count, $map]; |
256 | $RECENT{$login} = [$login, $birthdate, $last_login, $login_count, $last_logout, $client, $death_count, $map]; |
256 | } |
257 | } |
257 | } |
258 | } |
… | |
… | |
259 | sub _update { |
260 | sub _update { |
260 | cf::async_ext { |
261 | cf::async_ext { |
261 | $Coro::current->nice (1); |
262 | $Coro::current->nice (1); |
262 | $Coro::current->{desc} = "recentlog updater"; |
263 | $Coro::current->{desc} = "recentlog updater"; |
263 | |
264 | |
264 | Coro::AnyEvent::sleep 5; # grace time to allow file-saves |
|
|
265 | |
|
|
266 | my $lock = cf::lock_acquire "export_recentlog"; |
265 | my $lock = cf::lock_acquire "export_recentlog"; |
267 | |
266 | |
|
|
267 | my @logins = keys %need_update; %need_update = (); |
|
|
268 | undef $update_w; |
|
|
269 | |
|
|
270 | Coro::AnyEvent::sleep $EXPORT_RECENTLOG_GRACE; # grace time to allow file-saves |
|
|
271 | |
268 | my $t0 = EV::now; |
272 | my $t0 = EV::now; |
269 | |
273 | |
270 | while (%need_update) { |
|
|
271 | for (keys %need_update) { |
|
|
272 | delete $need_update{$_}; |
|
|
273 | |
|
|
274 | _update_login $_; |
274 | _update_login $_ |
275 | } |
275 | for @logins; |
276 | } |
|
|
277 | |
|
|
278 | undef $update_w; |
|
|
279 | |
276 | |
280 | cf::get_slot 0.1, 0, "recentlog serialise"; |
277 | cf::get_slot 0.1, 0, "recentlog serialise"; |
281 | |
278 | |
282 | my $NOW = $cf::NOW; |
279 | my $NOW = $cf::NOW; |
283 | |
280 | |
… | |
… | |
295 | } |
292 | } |
296 | |
293 | |
297 | sub update { |
294 | sub update { |
298 | return unless defined $EXPORT_RECENTLOG; |
295 | return unless defined $EXPORT_RECENTLOG; |
299 | |
296 | |
300 | $update_w ||= AE::timer $EXPORT_RECENTLOG_INTERVAL, 0, \&_update; |
297 | $update_w ||= AE::timer $EXPORT_RECENTLOG_INTERVAL - $EXPORT_RECENTLOG_GRACE, 0, \&_update; |
301 | } |
298 | } |
302 | |
299 | |
303 | sub reload { |
300 | sub reload { |
304 | return unless defined $EXPORT_RECENTLOG; |
301 | return unless defined $EXPORT_RECENTLOG; |
305 | |
302 | |
… | |
… | |
321 | on_login => sub { undef $need_update{$_[0]->ob->name}; update }, |
318 | on_login => sub { undef $need_update{$_[0]->ob->name}; update }, |
322 | on_logout => sub { undef $need_update{$_[0]->ob->name}; update }, |
319 | on_logout => sub { undef $need_update{$_[0]->ob->name}; update }, |
323 | on_birth => sub { undef $need_update{$_[0]->ob->name}; update }, |
320 | on_birth => sub { undef $need_update{$_[0]->ob->name}; update }, |
324 | on_death => sub { undef $need_update{$_[0]->ob->name}; update }, |
321 | on_death => sub { undef $need_update{$_[0]->ob->name}; update }, |
325 | # on_load => sub { undef $need_update{$_[0]->ob->name}; update }, |
322 | # on_load => sub { undef $need_update{$_[0]->ob->name}; update }, |
326 | # on_save => sub { undef $need_update{$_[0]->ob->name}; update }, |
323 | on_save => sub { undef $need_update{$_[0]->ob->name}; update }, |
327 | ); |
324 | ); |
328 | |
325 | |
329 | cf::post_init { |
326 | cf::post_init { |
330 | reload; |
327 | reload; |
331 | }; |
328 | }; |