… | |
… | |
73 | } |
73 | } |
74 | |
74 | |
75 | sub enter_map { |
75 | sub enter_map { |
76 | my ($pl) = @_; |
76 | my ($pl) = @_; |
77 | |
77 | |
|
|
78 | warn $pl->ob->name, ": enter map 1\n";#d# |
78 | my $ob = $pl->ob; |
79 | my $ob = $pl->ob; |
79 | |
80 | |
80 | my ($map, $x, $y) |
81 | my ($map, $x, $y) |
81 | = $ob->{_link_pos} |
82 | = $ob->{_link_pos} |
82 | ? @{delete $ob->{_link_pos}} |
83 | ? @{delete $ob->{_link_pos}} |
83 | : ($pl->maplevel, $ob->x, $ob->y); |
84 | : ($pl->maplevel, $ob->x, $ob->y); |
84 | |
85 | |
|
|
86 | warn $pl->ob->name, ": enter map 2\n";#d# |
85 | $ob->enter_link; |
87 | $ob->enter_link; |
|
|
88 | warn $pl->ob->name, ": enter map 3\n";#d# |
86 | |
89 | |
87 | my $m = cf::map::find $map; |
90 | my $m = cf::map::find $map; |
88 | my $time = delete $pl->{unclean_save}; |
91 | my $time = delete $pl->{unclean_save}; |
|
|
92 | warn $pl->ob->name, ": enter map 4\n";#d# |
89 | |
93 | |
90 | if ($time && $m) { |
94 | if ($time && $m) { |
91 | if ($time < $m->{instantiate_time}) { |
95 | if ($time < $m->{instantiate_time}) { |
92 | # the map was reset in the meantime |
96 | # the map was reset in the meantime |
93 | my $age = $cf::RUNTIME - $time; |
97 | my $age = $cf::RUNTIME - $time; |
… | |
… | |
126 | cf::NDI_RED |
130 | cf::NDI_RED |
127 | ); |
131 | ); |
128 | } |
132 | } |
129 | } |
133 | } |
130 | |
134 | |
|
|
135 | warn $pl->ob->name, ": enter map 5\n";#d# |
131 | $ob->goto ($map, $x, $y); |
136 | #$ob->goto ($map, $x, $y); |
|
|
137 | $ob->goto ($map, $x, $y, sub { |
|
|
138 | warn $pl->ob->name, ": enter map check\n";#d# |
|
|
139 | $_[0] |
|
|
140 | }, sub { |
|
|
141 | warn $pl->ob->name, ": enter map done\n";#d# |
|
|
142 | }); |
|
|
143 | warn $pl->ob->name, ": enter map 6\n";#d# |
|
|
144 | |
132 | } |
145 | } |
133 | |
146 | |
134 | # delete a player directory, be non-blocking AND synchronous... |
147 | # delete a player directory, be non-blocking AND synchronous... |
135 | # (thats hard, so we crap out and fork). |
148 | # (thats hard, so we crap out and fork). |
136 | sub nuke_playerdir { |
149 | sub nuke_playerdir { |
… | |
… | |
209 | cf::NDI_BLUE |
222 | cf::NDI_BLUE |
210 | ); |
223 | ); |
211 | |
224 | |
212 | # read username |
225 | # read username |
213 | while () { |
226 | while () { |
214 | $user = query $ns, 0, "What is your name?\n:"; |
227 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
215 | |
228 | |
216 | if ($cf::LOGIN_LOCK{$user}) { |
229 | if ($cf::LOGIN_LOCK{$user}) { |
217 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
218 | "That username is currently used in another login session. " |
231 | "That username is currently used in another login session. " |
219 | . "Chose another, or wait till the other session has ended.", |
232 | . "Chose another, or wait till the other session has ended.", |
… | |
… | |
279 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
292 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
280 | nuke_str $pass; |
293 | nuke_str $pass; |
281 | # password matches, wonderful |
294 | # password matches, wonderful |
282 | my $pl = cf::player::find $user or next; |
295 | my $pl = cf::player::find $user or next; |
283 | $pl->connect ($ns); |
296 | $pl->connect ($ns); |
|
|
297 | $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp |
284 | enter_map $pl; |
298 | enter_map $pl; |
285 | last; |
299 | last; |
286 | } elsif (can_cleanup $pl, $mtime) { |
300 | } elsif (can_cleanup $pl, $mtime) { |
287 | Coro::Timer::sleep 1; |
301 | Coro::Timer::sleep 1; |
288 | |
302 | |
… | |
… | |
506 | unless safe_spot $pl; |
520 | unless safe_spot $pl; |
507 | } |
521 | } |
508 | }, |
522 | }, |
509 | ); |
523 | ); |
510 | |
524 | |
511 | ############################################################################# |
|
|
512 | |
525 | |
513 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
|
|
514 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
|
|
515 | |
|
|
516 | our $SCHEDULER = cf::async_ext { |
|
|
517 | $Coro::current->{desc} = "player scheduler"; |
|
|
518 | |
|
|
519 | while () { |
|
|
520 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
|
|
521 | |
|
|
522 | # this weird form of iteration over values is used because |
|
|
523 | # the hash changes underneath us frequently, and for |
|
|
524 | # keeps a direct reference to the value without (in 5.8 perls) |
|
|
525 | # keeping a reference, so this is prone to crashes or worse. |
|
|
526 | my @players = keys %cf::PLAYER; |
|
|
527 | for (@players) { |
|
|
528 | my $pl = $cf::PLAYER{$_} |
|
|
529 | or next; |
|
|
530 | $pl->valid or next; |
|
|
531 | |
|
|
532 | eval { |
|
|
533 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
534 | $pl->save; |
|
|
535 | |
|
|
536 | unless ($pl->active || $pl->ns) { |
|
|
537 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
|
|
538 | my $ob = $pl->ob; |
|
|
539 | |
|
|
540 | my $pl_ref = $pl->refcnt_cnt; |
|
|
541 | my $ob_ref = $ob->refcnt_cnt; |
|
|
542 | |
|
|
543 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
|
|
544 | ## ob_ref == $ob + pl->observe + simply being an object |
|
|
545 | if ($pl_ref == 3 && $ob_ref == 3) { |
|
|
546 | warn "player-scheduler destroy ", $ob->name;#d# |
|
|
547 | |
|
|
548 | # remove from sight and get fresh "copies" |
|
|
549 | $pl = delete $cf::PLAYER{$ob->name}; |
|
|
550 | $ob = $pl->ob; |
|
|
551 | |
|
|
552 | $pl->destroy; # destroys $ob |
|
|
553 | } else { |
|
|
554 | my $a_ = $pl->refcnt;#d# |
|
|
555 | my $b_ = $ob->refcnt;#d# |
|
|
556 | |
|
|
557 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d# |
|
|
558 | } |
|
|
559 | } |
|
|
560 | } |
|
|
561 | }; |
|
|
562 | warn $@ if $@; |
|
|
563 | cf::cede_to_tick; |
|
|
564 | }; |
|
|
565 | } |
|
|
566 | }; |
|
|
567 | |
|
|
568 | $SCHEDULER->prio (1); |
|
|
569 | |
|
|