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.117 by root, Fri Feb 3 03:01:44 2012 UTC

3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7 7
8our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; 8CONF MAX_DISCONNECT_TIME = 3600;
9 9
10# paranoia function to overwrite a string-in-place 10# paranoia function to overwrite a string-in-place
11sub nuke_str { 11sub nuke_str {
12 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 12 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
13} 13}
58 58
59 my $m = $ob->map 59 my $m = $ob->map
60 or return; 60 or return;
61 my $x = $ob->x; 61 my $x = $ob->x;
62 my $y = $ob->y; 62 my $y = $ob->y;
63
64 # never happens normally, but helps when shell users make mistakes
65 $m->linkable
66 or return 1;
63 67
64# return 0;#d# 68# return 0;#d#
65# warn join ":", $m->at ($x, $y);#d# 69# warn join ":", $m->at ($x, $y);#d#
66# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; 70# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n";
67# return 0; 71# return 0;
143 } else { 147 } else {
144 return $token eq crypt $pass, $token; 148 return $token eq crypt $pass, $token;
145 } 149 }
146} 150}
147 151
148# delete a player directory, be non-blocking AND synchronous... 152# delete a player directory
149# (that's hard, so we crap out and fork).
150sub nuke_playerdir { 153sub nuke_playerdir {
151 my ($user) = @_; 154 my ($user) = @_;
152 155
156 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
157
153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 158 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
154
155 cf::fork_call {
156 rename "$PLAYERDIR/$user", $temp; 159 aio_rename "$PLAYERDIR/$user", $temp;
157 system "rm", "-rf", $temp; 160 IO::AIO::aio_rmtree $temp;
158 };
159} 161}
160 162
161cf::client->attach (on_addme => sub { 163cf::client->attach (on_addme => sub {
162 my ($ns) = @_; 164 my ($ns) = @_;
163 165
286 ); 288 );
287 next; 289 next;
288 } 290 }
289 } else { 291 } else {
290 # unable to load the playerfile: 292 # unable to load the playerfile:
291 # check wether the player dir exists, which means the file is corrupted or 293 # check whether the player dir exists, which means the file is corrupted or
292 # something very similar. 294 # something very similar.
293 if (!aio_stat cf::player::playerdir $user) { 295 if (!aio_stat cf::player::playerdir $user) {
294 $ns->send_drawinfo ( 296 $ns->send_drawinfo (
295 "Unable to retrieve this player. It might be a locked or broken account. " 297 "Unable to retrieve this player. It might be a locked or broken account. "
296 . "If this is your account, ask a dungeon master for assistance. " 298 . "If this is your account, ask a dungeon master for assistance. "
303 305
304 # the rest of this function is character creation 306 # the rest of this function is character creation
305 $Coro::current->{desc} = "addme($user) chargen"; 307 $Coro::current->{desc} = "addme($user) chargen";
306 308
307 # just to make sure nothing is left over 309 # just to make sure nothing is left over
310 # normally, nothing is there.
308 nuke_playerdir $user; 311 nuke_playerdir $user;
309 312
310 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 313 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
311 314
312 if ($pass2 ne $pass) { 315 if ($pass2 ne $pass) {
406}); 409});
407 410
408cf::register_command password => sub { 411cf::register_command password => sub {
409 my ($pl, $arg) = @_; 412 my ($pl, $arg) = @_;
410 413
414 unless ($pl->flag (cf::FLAG_WIZ)) {
415 $pl->message (
416 "The password can currently only changed by a DM.",
417 cf::NDI_UNIQUE | cf::NDI_REPLY);
418 return;
419 }
420
411 my (@args) = split /\s+/, $arg; 421 my (@args) = split /\s+/, $arg;
412
413 my ($new_pw, $player);
414
415 if ($pl->flag (cf::FLAG_WIZ)) {
416 ($player, $new_pw) = @args; 422 my ($player, $new_pw) = @args;
417 } else {
418 $new_pw = $args[0];
419 }
420 423
421 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 424 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
422 $pl->message ( 425 $pl->message (
423 "Usage: password <player> [<new password>]", 426 "Usage: password <player> [<new password>]",
424 cf::NDI_UNIQUE | cf::NDI_REPLY); 427 cf::NDI_UNIQUE | cf::NDI_REPLY);
425 return; 428 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 } 429 }
432 430
433 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
434 unless ($new_pw ne '') { 431 if ($new_pw eq '') {
435 $new_pw = 432 $new_pw =
436 join '', 433 join '',
437 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 434 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
438 1..9; 435 1..9;
439 } 436 }
440 437
441 cf::async { 438 cf::async {
442 my $plc = cf::player::find $player; 439 my $plc = cf::player::find $player;
443 if ($plc) { 440 if ($plc) {
444 $plc->password (encode_password $new_pw); 441 $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 ( 442 $pl->message (
460 "Ok, changed your password!", 443 "Ok, changed password of '$player' to '$new_pw'!",
461 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 444 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 $pl->contr->password (encode_password $new_pw);
463
464 } else { 445 } else {
465 $pl->message ( 446 $pl->message (
466 "Ok, please confirm your new password by sending " 447 "Fail! Couldn't set password for '$player', "
467 . "the command again within one minute!", 448 . "he doesn't seem to exist!",
468 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 449 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
469 $pl->{password_change} = [time, $new_pw];
470 } 450 }
471 } 451 };
472}; 452};
473 453
474cf::register_command quit => sub { 454cf::register_command quit => sub {
475 my ($ob, $arg) = @_; 455 my ($ob, $arg) = @_;
476 456
488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 468 $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]/) { 469 if ($_[0] !~ /^[yY]/) {
490 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 470 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
491 } else { 471 } else {
492 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 472 $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 { 473 cf::async {
495 ext::highscore::check $pl->ob;
496 $pl->quit_character; 474 $pl->quit_character;
497 }; 475 };
498 } 476 }
499 }); 477 });
500}; 478};
508 486
509 my $pl = $ob->contr; 487 my $pl = $ob->contr;
510 488
511 # update respawn position 489 # update respawn position
512 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 490 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
513 cf::async { $pl->save };
514 491
492 cf::async {
515 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 493 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
516 ext::highscore::check $ob; 494 ext::highscore::check $ob;
517 495
496 $pl->save;
497
518 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 498 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
519 499
500 my $ns = $pl->ns
501 or return;
502
520 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 503 $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
521 if ($_[0] !~ /^[yY]/) { 504 if ($_[0] !~ /^[yY]/) {
522 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 505 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
523 $pl->deactivate; 506 $pl->deactivate;
524 $pl->ns->destroy; 507 $pl->ns->destroy;
525 } else { 508 }
526 cf::async { $pl->save };
527 } 509 });
528 }); 510 };
529 }, 511 },
530); 512);
531 513
532cf::player->attach ( 514cf::player->attach (
533 on_login => sub { 515 on_login => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines