… | |
… | |
405 | }); |
405 | }); |
406 | |
406 | |
407 | cf::register_command password => sub { |
407 | cf::register_command password => sub { |
408 | my ($pl, $arg) = @_; |
408 | my ($pl, $arg) = @_; |
409 | |
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 | |
410 | my (@args) = split /\s+/, $arg; |
417 | my (@args) = split /\s+/, $arg; |
411 | |
|
|
412 | my ($new_pw, $player); |
|
|
413 | |
|
|
414 | if ($pl->flag (cf::FLAG_WIZ)) { |
|
|
415 | ($player, $new_pw) = @args; |
418 | my ($player, $new_pw) = @args; |
416 | } else { |
|
|
417 | $new_pw = $args[0]; |
|
|
418 | } |
|
|
419 | |
419 | |
420 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
420 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
421 | $pl->message ( |
421 | $pl->message ( |
422 | "Usage: password <player> [<new password>]", |
422 | "Usage: password <player> [<new password>]", |
423 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
423 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
424 | return; |
424 | 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 | } |
425 | } |
431 | |
426 | |
432 | if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) { |
|
|
433 | unless ($new_pw ne '') { |
427 | if ($new_pw eq '') { |
434 | $new_pw = |
428 | $new_pw = |
435 | join '', |
429 | join '', |
436 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
430 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
437 | 1..9; |
431 | 1..9; |
438 | } |
432 | } |
439 | |
433 | |
440 | cf::async { |
434 | cf::async { |
441 | my $plc = cf::player::find $player; |
435 | my $plc = cf::player::find $player; |
442 | if ($plc) { |
436 | if ($plc) { |
443 | $plc->password (encode_password $new_pw); |
437 | $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 ( |
438 | $pl->message ( |
459 | "Ok, changed your password!", |
439 | "Ok, changed password of '$player' to '$new_pw'!", |
460 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
440 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
461 | $pl->contr->password (encode_password $new_pw); |
|
|
462 | |
|
|
463 | } else { |
441 | } else { |
464 | $pl->message ( |
442 | $pl->message ( |
465 | "Ok, please confirm your new password by sending " |
443 | "Fail! Couldn't set password for '$player', " |
466 | . "the command again within one minute!", |
444 | . "he doesn't seem to exist!", |
467 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
445 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
468 | $pl->{password_change} = [time, $new_pw]; |
|
|
469 | } |
446 | } |
470 | } |
447 | }; |
471 | }; |
448 | }; |
472 | |
449 | |
473 | cf::register_command quit => sub { |
450 | cf::register_command quit => sub { |
474 | my ($ob, $arg) = @_; |
451 | my ($ob, $arg) = @_; |
475 | |
452 | |