ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.19 by root, Mon Jan 8 19:25:53 2007 UTC vs.
Revision 1.23 by root, Tue Jan 9 15:36:18 2007 UTC

294 294
295 my $pl = $ob->contr; 295 my $pl = $ob->contr;
296 296
297 # update respawn position 297 # update respawn position
298 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 298 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
299 cf::async { $pl->save };
299 300
300 $pl->killer ("left"); 301 $pl->killer ("left");
301 $ob->check_score; 302 $ob->check_score;
302 303
303 $ob->reply (undef, "In the future, you will wake up here when you die."); 304 $ob->reply (undef, "In the future, you will wake up here when you die.");
338 on_addme => \&addme, 339 on_addme => \&addme,
339); 340);
340 341
341############################################################################# 342#############################################################################
342 343
343our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 344our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs
344our $SAVE_TIMEOUT = 200; # save players every n seconds 345our $SAVE_TIMEOUT = 20; # save players every n seconds
345our $SAVE_INTERVAL = 0.1; # save at max. one player every $SAVE_INTERVAL 346our $SAVE_INTERVAL = 0.5; # save at max. one player every $SAVE_INTERVAL
346 347
347our $SCHEDULER = cf::async_ext { 348our $SCHEDULER = cf::async_ext {
348 while () { 349 while () {
349 Coro::Timer::sleep $SCHEDULE_INTERVAL; 350 Coro::Timer::sleep $SCHEDULE_INTERVAL;
350 351
359 $pl->valid or next; 360 $pl->valid or next;
360 361
361 eval { 362 eval {
362 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 363 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
363 $pl->save; 364 $pl->save;
365
366 unless ($pl->active) {
367 # check refcounts, this is tricky and needs to be adjusted to fit server internals
368 my $ob = $pl->ob;
369 Scalar::Util::weaken $pl;
370 Scalar::Util::weaken $ob;
371 my $a_ = $pl->refcnt;#d#
372 my $b_ = $ob->refcnt;#d#
373 my $pl_ref = $pl->refcnt_cnt;
374 my $ob_ref = $ob->refcnt_cnt;
375
376 ## pl_ref == one from object + one from cf::PLAYER
377 ## ob_ref == one from simply being an object
378 if ($pl_ref == 2 && $ob_ref == 1) {
379 warn "player-scheduler destroy ", $ob->name;#d#
380
381 # remove from sight and get fresh "copies"
382 $pl = delete $cf::PLAYER{$ob->name};
383 $ob = $pl->ob;
384
385 $ob->destroy;
386 $pl->destroy;
387 } else {
388 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d#
389 }
390 }
364 Coro::Timer::sleep $SAVE_INTERVAL; 391 Coro::Timer::sleep $SAVE_INTERVAL;
365 }
366
367 unless ($pl->active) {
368 # check refcounts, this is tricky and needs to be adjusted to fit server internals
369 my $ob = $pl->ob;
370 Scalar::Util::weaken $pl;
371 Scalar::Util::weaken $ob;
372 my $a_ = $pl->refcnt;
373 my $b_ = $ob->refcnt;
374 my $pl_ref = $pl->refcnt_cnt;
375 my $ob_ref = $ob->refcnt_cnt;
376
377 if ($pl_ref == 2 && $ob_ref == 1) {
378 warn "player-scheduler destroy ", $ob->name;#d#
379 delete $cf::PLAYER{$ob->name};
380 # pl_ref == one from object + one from cf::PLAYER
381 # ob_ref == one from simply being an object
382 $ob->destroy;
383 $pl->destroy;
384 } else {
385 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d#
386 }
387 } 392 }
388 }; 393 };
389 warn $@ if $@; 394 warn $@ if $@;
390 Coro::cede; 395 Coro::cede;
391 }; 396 };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines