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.110 by root, Sat May 8 10:49:44 2010 UTC vs.
Revision 1.112 by elmex, Mon May 10 15:54:40 2010 UTC

143 } else { 143 } else {
144 return $token eq crypt $pass, $token; 144 return $token eq crypt $pass, $token;
145 } 145 }
146} 146}
147 147
148# delete a player directory, be non-blocking AND synchronous... 148# delete a player directory
149# (that's hard, so we crap out and fork).
150sub nuke_playerdir { 149sub nuke_playerdir {
151 my ($user) = @_; 150 my ($user) = @_;
152 151
152 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
153
153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 154 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
154
155 cf::fork_call {
156 rename "$PLAYERDIR/$user", $temp; 155 aio_rename "$PLAYERDIR/$user", $temp;
157 system "rm", "-rf", $temp; 156 IO::AIO::aio_rmtree $temp;
158 };
159} 157}
160 158
161cf::client->attach (on_addme => sub { 159cf::client->attach (on_addme => sub {
162 my ($ns) = @_; 160 my ($ns) = @_;
163 161
303 301
304 # the rest of this function is character creation 302 # the rest of this function is character creation
305 $Coro::current->{desc} = "addme($user) chargen"; 303 $Coro::current->{desc} = "addme($user) chargen";
306 304
307 # just to make sure nothing is left over 305 # just to make sure nothing is left over
306 # normally, nothing is there.
308 nuke_playerdir $user; 307 nuke_playerdir $user;
309 308
310 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 309 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
311 310
312 if ($pass2 ne $pass) { 311 if ($pass2 ne $pass) {
406}); 405});
407 406
408cf::register_command password => sub { 407cf::register_command password => sub {
409 my ($pl, $arg) = @_; 408 my ($pl, $arg) = @_;
410 409
410 unless ($pl->flag (cf::FLAG_WIZ)) {
411 $pl->message (
412 "The password can currently only changed by a DM.",
413 cf::NDI_UNIQUE | cf::NDI_REPLY);
414 return;
415 }
416
411 my (@args) = split /\s+/, $arg; 417 my (@args) = split /\s+/, $arg;
412
413 my ($new_pw, $player);
414
415 if ($pl->flag (cf::FLAG_WIZ)) {
416 ($player, $new_pw) = @args; 418 my ($player, $new_pw) = @args;
417 } else {
418 $new_pw = $args[0];
419 }
420 419
421 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 420 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
422 $pl->message ( 421 $pl->message (
423 "Usage: password <player> [<new password>]", 422 "Usage: password <player> [<new password>]",
424 cf::NDI_UNIQUE | cf::NDI_REPLY); 423 cf::NDI_UNIQUE | cf::NDI_REPLY);
425 return; 424 return;
426 } elsif (!$pl->flag (cf::FLAG_WIZ) && $new_pw eq '') {
427 $pl->message (
428 "Usage: password <new password>",
429 cf::NDI_UNIQUE | cf::NDI_REPLY);
430 return;
431 } 425 }
432 426
433 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
434 unless ($new_pw ne '') { 427 if ($new_pw eq '') {
435 $new_pw = 428 $new_pw =
436 join '', 429 join '',
437 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 430 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
438 1..9; 431 1..9;
439 } 432 }
440 433
441 cf::async { 434 cf::async {
442 my $plc = cf::player::find $player; 435 my $plc = cf::player::find $player;
443 if ($plc) { 436 if ($plc) {
444 $plc->password (encode_password $new_pw); 437 $plc->password (encode_password $new_pw);
445 $pl->message (
446 "Ok, changed password of '$player' to '$new_pw'!",
447 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
448 } else {
449 $pl->message (
450 "Fail! Couldn't set password for '$player', "
451 . "he doesn't seem to exist!",
452 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
453 }
454 };
455 } else {
456 my $change = delete $pl->{password_change};
457
458 if ($change && (time - $change->[0]) < 60) {
459 $pl->message ( 438 $pl->message (
460 "Ok, changed your password!", 439 "Ok, changed password of '$player' to '$new_pw'!",
461 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 440 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 $pl->contr->password (encode_password $new_pw);
463
464 } else { 441 } else {
465 $pl->message ( 442 $pl->message (
466 "Ok, please confirm your new password by sending " 443 "Fail! Couldn't set password for '$player', "
467 . "the command again within one minute!", 444 . "he doesn't seem to exist!",
468 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 445 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
469 $pl->{password_change} = [time, $new_pw];
470 } 446 }
471 } 447 };
472}; 448};
473 449
474cf::register_command quit => sub { 450cf::register_command quit => sub {
475 my ($ob, $arg) = @_; 451 my ($ob, $arg) = @_;
476 452
488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 464 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub {
489 if ($_[0] !~ /^[yY]/) { 465 if ($_[0] !~ /^[yY]/) {
490 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 466 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
491 } else { 467 } else {
492 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 468 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
493 $pl->ns->flush;
494 cf::async { 469 cf::async {
495 ext::highscore::check $pl->ob;
496 $pl->quit_character; 470 $pl->quit_character;
497 }; 471 };
498 } 472 }
499 }); 473 });
500}; 474};
508 482
509 my $pl = $ob->contr; 483 my $pl = $ob->contr;
510 484
511 # update respawn position 485 # update respawn position
512 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 486 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
513 cf::async { $pl->save };
514 487
488 cf::async {
515 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 489 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
516 ext::highscore::check $ob; 490 ext::highscore::check $ob;
517 491
492 $pl->save;
493
518 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 494 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
519 495
520 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 496 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
521 if ($_[0] !~ /^[yY]/) { 497 if ($_[0] !~ /^[yY]/) {
522 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 498 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
523 $pl->deactivate; 499 $pl->deactivate;
524 $pl->ns->destroy; 500 $pl->ns->destroy;
525 } else { 501 }
526 cf::async { $pl->save };
527 } 502 });
528 }); 503 };
529 }, 504 },
530); 505);
531 506
532cf::player->attach ( 507cf::player->attach (
533 on_login => sub { 508 on_login => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines