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.90 by root, Tue Sep 16 16:03:02 2008 UTC vs.
Revision 1.95 by root, Wed Dec 17 16:43:38 2008 UTC

13} 13}
14 14
15sub query { 15sub query {
16 my ($ns, $flags, $text) = @_; 16 my ($ns, $flags, $text) = @_;
17 17
18 my $current = $Coro::current; 18 $ns->query ($flags, $text, Coro::rouse_cb);
19 $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); 19 Coro::rouse_wait
20 Coro::schedule while ref $current;
21
22 $current
23} 20}
24 21
25sub can_cleanup { 22sub can_cleanup {
26 my ($pl, $mtime) = @_; 23 my ($pl, $mtime) = @_;
27 24
230 $ns->send_drawinfo ( 227 $ns->send_drawinfo (
231 "That username is currently used in another login session. " 228 "That username is currently used in another login session. "
232 . "Chose another, or wait till the other session has ended.", 229 . "Chose another, or wait till the other session has ended.",
233 cf::NDI_RED 230 cf::NDI_RED
234 ); 231 );
235 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { 232 } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) {
236 last; 233 last;
237 } else { 234 } else {
238 $ns->send_drawinfo ( 235 $ns->send_drawinfo (
239 "Your username contains illegal characters " 236 "Your username contains illegal characters "
240 . "(only a-z, A-Z and 0-9 are allowed), " 237 . "(only a-z, A-Z and 0-9 are allowed), "
241 . "or is not between 3 and 18 characters in length.", 238 . "or is not between 3 and 20 characters in length.",
242 cf::NDI_RED 239 cf::NDI_RED
243 ); 240 );
244 } 241 }
245 Coro::Timer::sleep 0.4; 242 Coro::Timer::sleep 0.4;
246 } 243 }
433 Coro::Timer::sleep 0.2; 430 Coro::Timer::sleep 0.2;
434 } 431 }
435 432
436 $ob->reply (undef, "Welcome to Deliantra!"); 433 $ob->reply (undef, "Welcome to Deliantra!");
437 434
435 # XXX: Workaround for delayed client ext protocol handshake
436 $pl->esrv_new_player;
437
438 delete $pl->{deny_save}; 438 delete $pl->{deny_save};
439 439
440 last; 440 last;
441 } 441 }
442 }); 442 });
443}); 443});
444 444
445cf::register_command quit => sub { 445cf::register_command quit => sub {
446 my ($ob, $arg) = @_; 446 my ($ob, $arg) = @_;
447 447
448 $ob->reply (undef, 448 $ob->send_msg (undef,
449 "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " 449 "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. "
450 . "If you are sure you want to do this, then use the quit_character command instead of quit.", 450 . "If you are sure you want to do this, then use the quit_character command instead of quit.",
451 cf::NDI_UNIQUE | cf::NDI_RED); 451 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
452}; 452};
453 453
454cf::register_command quit_character => sub { 454cf::register_command quit_character => sub {
455 my ($ob, $arg) = @_; 455 my ($ob, $arg) = @_;
456 456
457 my $pl = $ob->contr; 457 my $pl = $ob->contr;
458 458
459 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 459 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub {
460 if ($_[0] !~ /^[yY]/) { 460 if ($_[0] !~ /^[yY]/) {
461 $ob->reply (undef, 461 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 "Ok, not not quitting then.",
463 cf::NDI_UNIQUE | cf::NDI_RED);
464 } else { 462 } else {
465 $ob->reply (undef, 463 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
466 "Ok, quitting, hope to see you again.",
467 cf::NDI_UNIQUE | cf::NDI_RED);
468 $pl->ns->flush; 464 $pl->ns->flush;
469 cf::async { $pl->quit_character }; 465 cf::async { $pl->quit_character };
470 } 466 }
471 }); 467 });
472}; 468};
485 cf::async { $pl->save }; 481 cf::async { $pl->save };
486 482
487 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 483 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
488 $ob->check_score; 484 $ob->check_score;
489 485
490 $ob->reply (undef, "In the future, you will wake up here when you die."); 486 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
491 487
492 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
493 if ($_[0] !~ /^[yY]/) { 489 if ($_[0] !~ /^[yY]/) {
494 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 490 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
495 $pl->deactivate; 491 $pl->deactivate;
520 unless safe_spot $pl; 516 unless safe_spot $pl;
521 } 517 }
522 }, 518 },
523); 519);
524 520
525#############################################################################
526 521
527our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs
528our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
529
530our $SCHEDULER = cf::async_ext {
531 $Coro::current->{desc} = "player scheduler";
532
533 while () {
534 Coro::EV::timer_once $SCHEDULE_INTERVAL;
535
536 # this weird form of iteration over values is used because
537 # the hash changes underneath us frequently, and for
538 # keeps a direct reference to the value without (in 5.8 perls)
539 # keeping a reference, so this is prone to crashes or worse.
540 my @players = keys %cf::PLAYER;
541 for (@players) {
542 my $pl = $cf::PLAYER{$_}
543 or next;
544 $pl->valid or next;
545
546 eval {
547 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
548 $pl->save;
549
550 unless ($pl->active || $pl->ns) {
551 # check refcounts, this is tricky and needs to be adjusted to fit server internals
552 my $ob = $pl->ob;
553
554 my $pl_ref = $pl->refcnt_cnt;
555 my $ob_ref = $ob->refcnt_cnt;
556
557 ## pl_ref == $pl + ob->contr + %cf::PLAYER
558 ## ob_ref == $ob + pl->observe + simply being an object
559 if ($pl_ref == 3 && $ob_ref == 3) {
560 warn "player-scheduler destroy ", $ob->name;#d#
561
562 # remove from sight and get fresh "copies"
563 $pl = delete $cf::PLAYER{$ob->name};
564 $ob = $pl->ob;
565
566 $pl->destroy; # destroys $ob
567 } else {
568 my $a_ = $pl->refcnt;#d#
569 my $b_ = $ob->refcnt;#d#
570
571 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d#
572 }
573 }
574 }
575 };
576 warn $@ if $@;
577 cf::cede_to_tick;
578 };
579 }
580};
581
582$SCHEDULER->prio (1);
583

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines