1 | #! perl # MANDATORY |
1 | #! perl # mandatory |
2 | |
2 | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | use List::Util qw(min max); |
7 | use List::Util qw(min max); |
|
|
8 | |
|
|
9 | our %EXT_SETUP; |
8 | |
10 | |
9 | # paranoia function to overwrite a string-in-place |
11 | # paranoia function to overwrite a string-in-place |
10 | sub nuke_str { |
12 | sub nuke_str { |
11 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
13 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
12 | } |
14 | } |
… | |
… | |
590 | eval { |
592 | eval { |
591 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
593 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
592 | cf::wait_for_tick_begin; |
594 | cf::wait_for_tick_begin; |
593 | $pl->save; |
595 | $pl->save; |
594 | |
596 | |
595 | unless ($pl->active) { |
597 | unless ($pl->active || $pl->ns) { |
596 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
598 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
597 | my $ob = $pl->ob; |
599 | my $ob = $pl->ob; |
598 | Scalar::Util::weaken $pl; |
600 | |
599 | Scalar::Util::weaken $ob; |
|
|
600 | my $a_ = $pl->refcnt;#d# |
|
|
601 | my $b_ = $ob->refcnt;#d# |
|
|
602 | my $pl_ref = $pl->refcnt_cnt; |
601 | my $pl_ref = $pl->refcnt_cnt; |
603 | my $ob_ref = $ob->refcnt_cnt; |
602 | my $ob_ref = $ob->refcnt_cnt; |
604 | |
603 | |
605 | ## pl_ref == one from object + one from cf::PLAYER |
604 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
606 | ## ob_ref == one from simply being an object |
605 | ## ob_ref == $ob + pl->observe + simply being an object |
607 | if ($pl_ref == 2 && $ob_ref == 1) { |
606 | if ($pl_ref == 3 && $ob_ref == 3) { |
608 | warn "player-scheduler destroy ", $ob->name;#d# |
607 | warn "player-scheduler destroy ", $ob->name;#d# |
609 | |
608 | |
610 | # remove from sight and get fresh "copies" |
609 | # remove from sight and get fresh "copies" |
611 | $pl = delete $cf::PLAYER{$ob->name}; |
610 | $pl = delete $cf::PLAYER{$ob->name}; |
612 | $ob = $pl->ob; |
611 | $ob = $pl->ob; |
613 | |
612 | |
614 | $ob->destroy; |
613 | $ob->destroy; |
615 | $pl->destroy; |
614 | $pl->destroy; |
616 | } else { |
615 | } else { |
|
|
616 | my $a_ = $pl->refcnt;#d# |
|
|
617 | my $b_ = $ob->refcnt;#d# |
|
|
618 | |
617 | warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# |
619 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d# |
618 | } |
620 | } |
619 | } |
621 | } |
620 | } |
622 | } |
621 | }; |
623 | }; |
622 | warn $@ if $@; |
624 | warn $@ if $@; |