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.105 by root, Wed Apr 28 11:28:21 2010 UTC vs.
Revision 1.106 by elmex, Thu Apr 29 06:33:04 2010 UTC

124 ); 124 );
125 } 125 }
126 } 126 }
127 127
128 $ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
129}
130
131sub encode_password {
132 crypt $_[0],
133 join '',
134 ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
129} 135}
130 136
131# delete a player directory, be non-blocking AND synchronous... 137# delete a player directory, be non-blocking AND synchronous...
132# (that's hard, so we crap out and fork). 138# (that's hard, so we crap out and fork).
133sub nuke_playerdir { 139sub nuke_playerdir {
303 } 309 }
304 310
305 nuke_str $pass2; 311 nuke_str $pass2;
306 312
307 my $pl = cf::player::new $user; 313 my $pl = cf::player::new $user;
308 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]); 314 $pl->password (encode_password $pass);
309 nuke_str $pass; 315 nuke_str $pass;
310 $pl->connect ($ns); 316 $pl->connect ($ns);
311 my $ob = $pl->ob; 317 my $ob = $pl->ob;
312 318
313 $ob->goto ($pl->maplevel, $ob->x, $ob->y); 319 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
384 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { 390 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
385 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); 391 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
386 } 392 }
387 }); 393 });
388}); 394});
395
396cf::register_command password => sub {
397 my ($pl, $arg) = @_;
398
399 my (@args) = split /\s+/, $arg;
400
401 my ($new_pw, $player);
402
403 if ($pl->flag (cf::FLAG_WIZ)) {
404 ($player, $new_pw) = @args;
405 } else {
406 $new_pw = $args[0];
407 }
408
409 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
410 $pl->message (
411 "Usage: password <player> [<new password>]",
412 cf::NDI_UNIQUE | cf::NDI_REPLY);
413 return;
414 } elsif (!$pl->flag (cf::FLAG_WIZ) && $new_pw eq '') {
415 $pl->message (
416 "Usage: password <new password>",
417 cf::NDI_UNIQUE | cf::NDI_REPLY);
418 return;
419 }
420
421 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
422 unless ($new_pw ne '') {
423 $new_pw =
424 join '',
425 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
426 1..9;
427 }
428
429 cf::async {
430 my $plc = cf::player::find $player;
431 if ($plc) {
432 $plc->password (encode_password $new_pw);
433 $pl->message (
434 "Ok, changed password of '$player' to '$new_pw'!",
435 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
436 } else {
437 $pl->message (
438 "Fail! Couldn't set password for '$player', "
439 . "he doesn't seem to exist!",
440 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
441 }
442 };
443 } else {
444 my $change = delete $pl->{password_change};
445 warn "CHECK: @$change | $pl->{password_change} <<<<<\n";
446
447 if ($change && (time - $change->[0]) < 60) {
448 $pl->message (
449 "Ok, changed your password!",
450 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
451 $pl->contr->password (encode_password $new_pw);
452
453 } else {
454 $pl->message (
455 "Ok, please confirm your new password by sending "
456 . "the command again within one minute!",
457 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
458 $pl->{password_change} = [time, $new_pw];
459 }
460 }
461};
389 462
390cf::register_command quit => sub { 463cf::register_command quit => sub {
391 my ($ob, $arg) = @_; 464 my ($ob, $arg) = @_;
392 465
393 $ob->send_msg (undef, 466 $ob->send_msg (undef,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines