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.31 by root, Sat Feb 4 00:14:41 2012 UTC vs.
Revision 1.34 by root, Sat Feb 4 01:12:33 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines