… | |
… | |
51 | ); |
51 | ); |
52 | |
52 | |
53 | 1 |
53 | 1 |
54 | } |
54 | } |
55 | |
55 | |
56 | sub check_clean_save { |
56 | sub enter_map { |
57 | my ($pl) = @_; |
57 | my ($pl) = @_; |
58 | |
58 | |
|
|
59 | my ($map, $x, $y) |
|
|
60 | = $pl->ob->{_link_pos} |
|
|
61 | ? @{delete $pl->ob->{_link_pos}} |
|
|
62 | : ($pl->maplevel, $pl->ob->x, $pl->ob->y); |
|
|
63 | |
|
|
64 | $pl->ob->enter_link; |
|
|
65 | |
59 | if (my $time = delete $pl->{unclean_save}) { |
66 | if (my $time = delete $pl->{unclean_save}) { |
|
|
67 | if (my $m = cf::map::find $map) { |
|
|
68 | if ($time < $m->{instantiate_time}) { |
|
|
69 | # the map was reset in the meantime |
|
|
70 | my $age = $cf::RUNTIME - $time; |
|
|
71 | warn $pl->ob->name, " map reset after logout, logout age $age\n";#d# |
|
|
72 | |
|
|
73 | # for now, just go back to savebed |
|
|
74 | ($map, $x, $y) = $pl->savebed; |
|
|
75 | |
60 | $pl->ns->send_drawinfo ( |
76 | $pl->ns->send_drawinfo ( |
|
|
77 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
|
|
78 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
|
|
79 | . "Better use a savebed next time, much worse things could have happened...", |
|
|
80 | cf::NDI_RED |
|
|
81 | ); |
|
|
82 | } else { |
|
|
83 | $pl->ns->send_drawinfo ( |
61 | "You didn't use a savebed to leave this realm. This is very dangerous, " |
84 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
62 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
85 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
63 | . "or monsters suddenly snapping your body. Better use a savebed next time.", |
86 | . "or monsters suddenly snapping your body. Better use a savebed next time.", |
64 | cf::NDI_RED |
87 | cf::NDI_RED |
|
|
88 | ); |
|
|
89 | } |
65 | ); |
90 | } |
66 | #d#TODO |
|
|
67 | } |
91 | } |
|
|
92 | |
|
|
93 | $pl->ob->goto ($map, $x, $y); |
68 | } |
94 | } |
69 | |
95 | |
70 | # delete a player directory, be non-blocking AND synchronous... |
96 | # delete a player directory, be non-blocking AND synchronous... |
71 | # (thats hard, so we crap out and fork). |
97 | # (thats hard, so we crap out and fork). |
72 | sub nuke_playerdir { |
98 | sub nuke_playerdir { |
… | |
… | |
332 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
358 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
333 | nuke_str $pass; |
359 | nuke_str $pass; |
334 | # password matches, wonderful |
360 | # password matches, wonderful |
335 | my $pl = cf::player::find $user or next; |
361 | my $pl = cf::player::find $user or next; |
336 | $pl->connect ($ns); |
362 | $pl->connect ($ns); |
337 | check_clean_save $pl; |
363 | enter_map $pl; |
338 | last; |
364 | last; |
339 | } elsif (can_cleanup $pl, $mtime) { |
365 | } elsif (can_cleanup $pl, $mtime) { |
340 | Coro::Timer::sleep 1; |
366 | Coro::Timer::sleep 1; |
341 | |
367 | |
342 | $ns->send_drawinfo ( |
368 | $ns->send_drawinfo ( |
… | |
… | |
405 | |
431 | |
406 | my $pl = cf::player::new $user; |
432 | my $pl = cf::player::new $user; |
407 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); |
433 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); |
408 | nuke_str $pass; |
434 | nuke_str $pass; |
409 | $pl->connect ($ns); |
435 | $pl->connect ($ns); |
410 | |
|
|
411 | my $ob = $pl->ob; |
436 | my $ob = $pl->ob; |
|
|
437 | |
|
|
438 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
412 | |
439 | |
413 | while () { |
440 | while () { |
414 | $ob->update_stats; |
441 | $ob->update_stats; |
415 | $pl->save_stats; |
442 | $pl->save_stats; |
416 | |
443 | |
… | |
… | |
563 | eval { |
590 | eval { |
564 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
591 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
565 | cf::wait_for_tick_begin; |
592 | cf::wait_for_tick_begin; |
566 | $pl->save; |
593 | $pl->save; |
567 | |
594 | |
568 | unless ($pl->active) { |
595 | unless ($pl->active || $pl->ns) { |
569 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
596 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
570 | my $ob = $pl->ob; |
597 | my $ob = $pl->ob; |
571 | Scalar::Util::weaken $pl; |
598 | |
572 | Scalar::Util::weaken $ob; |
|
|
573 | my $a_ = $pl->refcnt;#d# |
|
|
574 | my $b_ = $ob->refcnt;#d# |
|
|
575 | my $pl_ref = $pl->refcnt_cnt; |
599 | my $pl_ref = $pl->refcnt_cnt; |
576 | my $ob_ref = $ob->refcnt_cnt; |
600 | my $ob_ref = $ob->refcnt_cnt; |
577 | |
601 | |
578 | ## pl_ref == one from object + one from cf::PLAYER |
602 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
579 | ## ob_ref == one from simply being an object |
603 | ## ob_ref == $ob + pl->observe + simply being an object |
580 | if ($pl_ref == 2 && $ob_ref == 1) { |
604 | if ($pl_ref == 3 && $ob_ref == 3) { |
581 | warn "player-scheduler destroy ", $ob->name;#d# |
605 | warn "player-scheduler destroy ", $ob->name;#d# |
582 | |
606 | |
583 | # remove from sight and get fresh "copies" |
607 | # remove from sight and get fresh "copies" |
584 | $pl = delete $cf::PLAYER{$ob->name}; |
608 | $pl = delete $cf::PLAYER{$ob->name}; |
585 | $ob = $pl->ob; |
609 | $ob = $pl->ob; |
586 | |
610 | |
587 | $ob->destroy; |
611 | $ob->destroy; |
588 | $pl->destroy; |
612 | $pl->destroy; |
589 | } else { |
613 | } else { |
|
|
614 | my $a_ = $pl->refcnt;#d# |
|
|
615 | my $b_ = $ob->refcnt;#d# |
|
|
616 | |
590 | warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# |
617 | warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# |
591 | } |
618 | } |
592 | } |
619 | } |
593 | } |
620 | } |
594 | }; |
621 | }; |