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.89 by root, Sat Aug 30 05:19:03 2008 UTC vs.
Revision 1.93 by elmex, Fri Oct 31 16:13:41 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 }
292 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) {
293 nuke_str $pass; 293 nuke_str $pass;
294 # password matches, wonderful 294 # password matches, wonderful
295 my $pl = cf::player::find $user or next; 295 my $pl = cf::player::find $user or next;
296 $pl->connect ($ns); 296 $pl->connect ($ns);
297 $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp
297 enter_map $pl; 298 enter_map $pl;
298 last; 299 last;
299 } elsif (can_cleanup $pl, $mtime) { 300 } elsif (can_cleanup $pl, $mtime) {
300 Coro::Timer::sleep 1; 301 Coro::Timer::sleep 1;
301 302
432 Coro::Timer::sleep 0.2; 433 Coro::Timer::sleep 0.2;
433 } 434 }
434 435
435 $ob->reply (undef, "Welcome to Deliantra!"); 436 $ob->reply (undef, "Welcome to Deliantra!");
436 437
438 # XXX: Workaround for delayed client ext protocol handshake
439 $pl->esrv_new_player;
440
437 delete $pl->{deny_save}; 441 delete $pl->{deny_save};
438 442
439 last; 443 last;
440 } 444 }
441 }); 445 });
519 unless safe_spot $pl; 523 unless safe_spot $pl;
520 } 524 }
521 }, 525 },
522); 526);
523 527
524#############################################################################
525 528
526our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs
527our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
528
529our $SCHEDULER = cf::async_ext {
530 $Coro::current->{desc} = "player scheduler";
531
532 while () {
533 Coro::EV::timer_once $SCHEDULE_INTERVAL;
534
535 # this weird form of iteration over values is used because
536 # the hash changes underneath us frequently, and for
537 # keeps a direct reference to the value without (in 5.8 perls)
538 # keeping a reference, so this is prone to crashes or worse.
539 my @players = keys %cf::PLAYER;
540 for (@players) {
541 my $pl = $cf::PLAYER{$_}
542 or next;
543 $pl->valid or next;
544
545 eval {
546 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
547 $pl->save;
548
549 unless ($pl->active || $pl->ns) {
550 # check refcounts, this is tricky and needs to be adjusted to fit server internals
551 my $ob = $pl->ob;
552
553 my $pl_ref = $pl->refcnt_cnt;
554 my $ob_ref = $ob->refcnt_cnt;
555
556 ## pl_ref == $pl + ob->contr + %cf::PLAYER
557 ## ob_ref == $ob + pl->observe + simply being an object
558 if ($pl_ref == 3 && $ob_ref == 3) {
559 warn "player-scheduler destroy ", $ob->name;#d#
560
561 # remove from sight and get fresh "copies"
562 $pl = delete $cf::PLAYER{$ob->name};
563 $ob = $pl->ob;
564
565 $pl->destroy; # destroys $ob
566 } else {
567 my $a_ = $pl->refcnt;#d#
568 my $b_ = $ob->refcnt;#d#
569
570 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d#
571 }
572 }
573 }
574 };
575 warn $@ if $@;
576 cf::cede_to_tick;
577 };
578 }
579};
580
581$SCHEDULER->prio (1);
582

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines