… | |
… | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; |
8 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | |
9 | |
10 | # paranoia function to overwrite a string-in-place |
10 | # paranoia function to overwrite a string-in-place |
11 | sub nuke_str { |
11 | sub 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; |
… | |
… | |
284 | ); |
288 | ); |
285 | next; |
289 | next; |
286 | } |
290 | } |
287 | } else { |
291 | } else { |
288 | # unable to load the playerfile: |
292 | # unable to load the playerfile: |
289 | # 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 |
290 | # something very similar. |
294 | # something very similar. |
291 | if (!aio_stat cf::player::playerdir $user) { |
295 | if (!aio_stat cf::player::playerdir $user) { |
292 | $ns->send_drawinfo ( |
296 | $ns->send_drawinfo ( |
293 | "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. " |
294 | . "If this is your account, ask a dungeon master for assistance. " |
298 | . "If this is your account, ask a dungeon master for assistance. " |
… | |
… | |
405 | }); |
409 | }); |
406 | |
410 | |
407 | cf::register_command password => sub { |
411 | cf::register_command password => sub { |
408 | my ($pl, $arg) = @_; |
412 | my ($pl, $arg) = @_; |
409 | |
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 | |
410 | my (@args) = split /\s+/, $arg; |
421 | my (@args) = split /\s+/, $arg; |
411 | |
|
|
412 | my ($new_pw, $player); |
|
|
413 | |
|
|
414 | if ($pl->flag (cf::FLAG_WIZ)) { |
|
|
415 | ($player, $new_pw) = @args; |
422 | my ($player, $new_pw) = @args; |
416 | } else { |
|
|
417 | $new_pw = $args[0]; |
|
|
418 | } |
|
|
419 | |
423 | |
420 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
424 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
421 | $pl->message ( |
425 | $pl->message ( |
422 | "Usage: password <player> [<new password>]", |
426 | "Usage: password <player> [<new password>]", |
423 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
427 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
424 | return; |
428 | return; |
425 | } elsif (!$pl->flag (cf::FLAG_WIZ) && $new_pw eq '') { |
|
|
426 | $pl->message ( |
|
|
427 | "Usage: password <new password>", |
|
|
428 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
|
|
429 | return; |
|
|
430 | } |
429 | } |
431 | |
430 | |
432 | if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) { |
|
|
433 | unless ($new_pw ne '') { |
431 | if ($new_pw eq '') { |
434 | $new_pw = |
432 | $new_pw = |
435 | join '', |
433 | join '', |
436 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
434 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
437 | 1..9; |
435 | 1..9; |
438 | } |
436 | } |
439 | |
437 | |
440 | cf::async { |
438 | cf::async { |
441 | my $plc = cf::player::find $player; |
439 | my $plc = cf::player::find $player; |
442 | if ($plc) { |
440 | if ($plc) { |
443 | $plc->password (encode_password $new_pw); |
441 | $plc->password (encode_password $new_pw); |
444 | $pl->message ( |
|
|
445 | "Ok, changed password of '$player' to '$new_pw'!", |
|
|
446 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
447 | } else { |
|
|
448 | $pl->message ( |
|
|
449 | "Fail! Couldn't set password for '$player', " |
|
|
450 | . "he doesn't seem to exist!", |
|
|
451 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
452 | } |
|
|
453 | }; |
|
|
454 | } else { |
|
|
455 | my $change = delete $pl->{password_change}; |
|
|
456 | |
|
|
457 | if ($change && (time - $change->[0]) < 60) { |
|
|
458 | $pl->message ( |
442 | $pl->message ( |
459 | "Ok, changed your password!", |
443 | "Ok, changed password of '$player' to '$new_pw'!", |
460 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
444 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
461 | $pl->contr->password (encode_password $new_pw); |
|
|
462 | |
|
|
463 | } else { |
445 | } else { |
464 | $pl->message ( |
446 | $pl->message ( |
465 | "Ok, please confirm your new password by sending " |
447 | "Fail! Couldn't set password for '$player', " |
466 | . "the command again within one minute!", |
448 | . "he doesn't seem to exist!", |
467 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
449 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
468 | $pl->{password_change} = [time, $new_pw]; |
|
|
469 | } |
450 | } |
470 | } |
451 | }; |
471 | }; |
452 | }; |
472 | |
453 | |
473 | cf::register_command quit => sub { |
454 | cf::register_command quit => sub { |
474 | my ($ob, $arg) = @_; |
455 | my ($ob, $arg) = @_; |
475 | |
456 | |
… | |
… | |
514 | |
495 | |
515 | $pl->save; |
496 | $pl->save; |
516 | |
497 | |
517 | $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); |
518 | |
499 | |
|
|
500 | my $ns = $pl->ns |
|
|
501 | or return; |
|
|
502 | |
519 | $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 { |
520 | if ($_[0] !~ /^[yY]/) { |
504 | if ($_[0] !~ /^[yY]/) { |
521 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
505 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
522 | $pl->deactivate; |
506 | $pl->deactivate; |
523 | $pl->ns->destroy; |
507 | $pl->ns->destroy; |
524 | } |
508 | } |