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.92 by root, Mon Sep 22 01:33:09 2008 UTC

230 $ns->send_drawinfo ( 230 $ns->send_drawinfo (
231 "That username is currently used in another login session. " 231 "That username is currently used in another login session. "
232 . "Chose another, or wait till the other session has ended.", 232 . "Chose another, or wait till the other session has ended.",
233 cf::NDI_RED 233 cf::NDI_RED
234 ); 234 );
235 } 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/) {
236 last; 236 last;
237 } else { 237 } else {
238 $ns->send_drawinfo ( 238 $ns->send_drawinfo (
239 "Your username contains illegal characters " 239 "Your username contains illegal characters "
240 . "(only a-z, A-Z and 0-9 are allowed), " 240 . "(only a-z, A-Z and 0-9 are allowed), "
241 . "or is not between 3 and 18 characters in length.", 241 . "or is not between 3 and 20 characters in length.",
242 cf::NDI_RED 242 cf::NDI_RED
243 ); 243 );
244 } 244 }
245 Coro::Timer::sleep 0.4; 245 Coro::Timer::sleep 0.4;
246 } 246 }
520 unless safe_spot $pl; 520 unless safe_spot $pl;
521 } 521 }
522 }, 522 },
523); 523);
524 524
525#############################################################################
526 525
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