… | |
… | |
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; |
… | |
… | |
103 | cf::NDI_RED |
107 | cf::NDI_RED |
104 | ); |
108 | ); |
105 | # kill them. |
109 | # kill them. |
106 | # reminds me of the famous badness 10000 syndrome... |
110 | # reminds me of the famous badness 10000 syndrome... |
107 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
111 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
108 | my $killer = cf::arch::get "killer_login"; |
112 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
109 | $pl->killer ($killer); |
|
|
110 | $killer->destroy; |
|
|
111 | } else { |
113 | } else { |
112 | ($map, $x, $y) = $pl->savebed; |
114 | ($map, $x, $y) = $pl->savebed; |
113 | |
115 | |
114 | $ob->message ( |
116 | $ob->message ( |
115 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
117 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
… | |
… | |
128 | cf::NDI_RED |
130 | cf::NDI_RED |
129 | ); |
131 | ); |
130 | } |
132 | } |
131 | } |
133 | } |
132 | |
134 | |
|
|
135 | warn $pl->ob->name, ": enter map 5\n";#d# |
133 | $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 | |
134 | } |
145 | } |
135 | |
146 | |
136 | # delete a player directory, be non-blocking AND synchronous... |
147 | # delete a player directory, be non-blocking AND synchronous... |
137 | # (thats hard, so we crap out and fork). |
148 | # (thats hard, so we crap out and fork). |
138 | sub nuke_playerdir { |
149 | sub nuke_playerdir { |
… | |
… | |
211 | cf::NDI_BLUE |
222 | cf::NDI_BLUE |
212 | ); |
223 | ); |
213 | |
224 | |
214 | # read username |
225 | # read username |
215 | while () { |
226 | while () { |
216 | $user = query $ns, 0, "What is your name?\n:"; |
227 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
217 | |
228 | |
218 | if ($cf::LOGIN_LOCK{$user}) { |
229 | if ($cf::LOGIN_LOCK{$user}) { |
219 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
220 | "That username is currently used in another login session. " |
231 | "That username is currently used in another login session. " |
221 | . "Chose another, or wait till the other session has ended.", |
232 | . "Chose another, or wait till the other session has ended.", |
222 | cf::NDI_RED |
233 | cf::NDI_RED |
223 | ); |
234 | ); |
224 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { |
235 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) { |
225 | last; |
236 | last; |
226 | } else { |
237 | } else { |
227 | $ns->send_drawinfo ( |
238 | $ns->send_drawinfo ( |
228 | "Your username contains illegal characters " |
239 | "Your username contains illegal characters " |
229 | . "(only a-z, A-Z and 0-9 are allowed), " |
240 | . "(only a-z, A-Z and 0-9 are allowed), " |
230 | . "or is not between 3 and 18 characters in length.", |
241 | . "or is not between 3 and 20 characters in length.", |
231 | cf::NDI_RED |
242 | cf::NDI_RED |
232 | ); |
243 | ); |
233 | } |
244 | } |
234 | Coro::Timer::sleep 0.4; |
245 | Coro::Timer::sleep 0.4; |
235 | } |
246 | } |
… | |
… | |
281 | 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) { |
282 | nuke_str $pass; |
293 | nuke_str $pass; |
283 | # password matches, wonderful |
294 | # password matches, wonderful |
284 | my $pl = cf::player::find $user or next; |
295 | my $pl = cf::player::find $user or next; |
285 | $pl->connect ($ns); |
296 | $pl->connect ($ns); |
|
|
297 | $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp |
286 | enter_map $pl; |
298 | enter_map $pl; |
287 | last; |
299 | last; |
288 | } elsif (can_cleanup $pl, $mtime) { |
300 | } elsif (can_cleanup $pl, $mtime) { |
289 | Coro::Timer::sleep 1; |
301 | Coro::Timer::sleep 1; |
290 | |
302 | |
… | |
… | |
379 | } |
391 | } |
380 | } else { |
392 | } else { |
381 | $ob->roll_stats; |
393 | $ob->roll_stats; |
382 | } |
394 | } |
383 | |
395 | |
384 | Coro::Timer::sleep 0.2; |
396 | Coro::Timer::sleep 0.05; |
385 | } |
397 | } |
386 | |
398 | |
387 | $ob->set_animation (2); |
399 | $ob->set_animation (2); |
388 | $ob->add_statbonus; |
400 | $ob->add_statbonus; |
389 | |
401 | |
… | |
… | |
420 | } |
432 | } |
421 | Coro::Timer::sleep 0.2; |
433 | Coro::Timer::sleep 0.2; |
422 | } |
434 | } |
423 | |
435 | |
424 | $ob->reply (undef, "Welcome to Deliantra!"); |
436 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
437 | |
|
|
438 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
439 | $pl->esrv_new_player; |
425 | |
440 | |
426 | delete $pl->{deny_save}; |
441 | delete $pl->{deny_save}; |
427 | |
442 | |
428 | last; |
443 | last; |
429 | } |
444 | } |
… | |
… | |
470 | |
485 | |
471 | # update respawn position |
486 | # update respawn position |
472 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
487 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
473 | cf::async { $pl->save }; |
488 | cf::async { $pl->save }; |
474 | |
489 | |
475 | my $killer = cf::arch::get "killer_logout"; |
490 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
476 | $pl->killer ($killer); |
|
|
477 | $killer->destroy; |
|
|
478 | $ob->check_score; |
491 | $ob->check_score; |
479 | |
492 | |
480 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
493 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
481 | |
494 | |
482 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
495 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
… | |
… | |
510 | unless safe_spot $pl; |
523 | unless safe_spot $pl; |
511 | } |
524 | } |
512 | }, |
525 | }, |
513 | ); |
526 | ); |
514 | |
527 | |
515 | ############################################################################# |
|
|
516 | |
528 | |
517 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
|
|
518 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
|
|
519 | |
|
|
520 | our $SCHEDULER = cf::async_ext { |
|
|
521 | $Coro::current->{desc} = "player scheduler"; |
|
|
522 | |
|
|
523 | while () { |
|
|
524 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
|
|
525 | |
|
|
526 | # this weird form of iteration over values is used because |
|
|
527 | # the hash changes underneath us frequently, and for |
|
|
528 | # keeps a direct reference to the value without (in 5.8 perls) |
|
|
529 | # keeping a reference, so this is prone to crashes or worse. |
|
|
530 | my @players = keys %cf::PLAYER; |
|
|
531 | for (@players) { |
|
|
532 | my $pl = $cf::PLAYER{$_} |
|
|
533 | or next; |
|
|
534 | $pl->valid or next; |
|
|
535 | |
|
|
536 | eval { |
|
|
537 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
538 | $pl->save; |
|
|
539 | |
|
|
540 | unless ($pl->active || $pl->ns) { |
|
|
541 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
|
|
542 | my $ob = $pl->ob; |
|
|
543 | |
|
|
544 | my $pl_ref = $pl->refcnt_cnt; |
|
|
545 | my $ob_ref = $ob->refcnt_cnt; |
|
|
546 | |
|
|
547 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
|
|
548 | ## ob_ref == $ob + pl->observe + simply being an object |
|
|
549 | if ($pl_ref == 3 && $ob_ref == 3) { |
|
|
550 | warn "player-scheduler destroy ", $ob->name;#d# |
|
|
551 | |
|
|
552 | # remove from sight and get fresh "copies" |
|
|
553 | $pl = delete $cf::PLAYER{$ob->name}; |
|
|
554 | $ob = $pl->ob; |
|
|
555 | |
|
|
556 | $pl->destroy; # destroys $ob |
|
|
557 | } else { |
|
|
558 | my $a_ = $pl->refcnt;#d# |
|
|
559 | my $b_ = $ob->refcnt;#d# |
|
|
560 | |
|
|
561 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d# |
|
|
562 | } |
|
|
563 | } |
|
|
564 | } |
|
|
565 | }; |
|
|
566 | warn $@ if $@; |
|
|
567 | cf::cede_to_tick; |
|
|
568 | }; |
|
|
569 | } |
|
|
570 | }; |
|
|
571 | |
|
|
572 | $SCHEDULER->prio (1); |
|
|
573 | |
|
|