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.111 by root, Sun May 9 22:51:13 2010 UTC vs.
Revision 1.118 by root, Thu Nov 8 00:16:07 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;
136} 140}
137 141
138sub compare_password($$) { 142sub compare_password($$) {
139 my ($pass, $token) = @_; 143 my ($pass, $token) = @_;
140 144
141 if ($token =~ /\!(.*)/) { 145 if ($token =~ /!!(.*)/) {
146 return +(substr $pass, 0, 8) eq pack "H*", $1;
147 } elsif ($token =~ /!(.*)/) {
142 return $pass eq pack "H*", $1; 148 return $pass eq pack "H*", $1;
143 } else { 149 } else {
144 return $token eq crypt $pass, $token; 150 return $token eq crypt $pass, $token;
145 } 151 }
146} 152}
284 ); 290 );
285 next; 291 next;
286 } 292 }
287 } else { 293 } else {
288 # unable to load the playerfile: 294 # unable to load the playerfile:
289 # check wether the player dir exists, which means the file is corrupted or 295 # check whether the player dir exists, which means the file is corrupted or
290 # something very similar. 296 # something very similar.
291 if (!aio_stat cf::player::playerdir $user) { 297 if (!aio_stat cf::player::playerdir $user) {
292 $ns->send_drawinfo ( 298 $ns->send_drawinfo (
293 "Unable to retrieve this player. It might be a locked or broken account. " 299 "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. " 300 . "If this is your account, ask a dungeon master for assistance. "
405}); 411});
406 412
407cf::register_command password => sub { 413cf::register_command password => sub {
408 my ($pl, $arg) = @_; 414 my ($pl, $arg) = @_;
409 415
416 unless ($pl->flag (cf::FLAG_WIZ)) {
417 $pl->message (
418 "The password can currently only changed by a DM.",
419 cf::NDI_UNIQUE | cf::NDI_REPLY);
420 return;
421 }
422
410 my (@args) = split /\s+/, $arg; 423 my (@args) = split /\s+/, $arg;
411
412 my ($new_pw, $player);
413
414 if ($pl->flag (cf::FLAG_WIZ)) {
415 ($player, $new_pw) = @args; 424 my ($player, $new_pw) = @args;
416 } else {
417 $new_pw = $args[0];
418 }
419 425
420 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 426 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
421 $pl->message ( 427 $pl->message (
422 "Usage: password <player> [<new password>]", 428 "Usage: password <player> [<new password>]",
423 cf::NDI_UNIQUE | cf::NDI_REPLY); 429 cf::NDI_UNIQUE | cf::NDI_REPLY);
424 return; 430 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 } 431 }
431 432
432 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
433 unless ($new_pw ne '') { 433 if ($new_pw eq '') {
434 $new_pw = 434 $new_pw =
435 join '', 435 join '',
436 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 436 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
437 1..9; 437 1..9;
438 } 438 }
439 439
440 cf::async { 440 cf::async {
441 my $plc = cf::player::find $player; 441 my $plc = cf::player::find $player;
442 if ($plc) { 442 if ($plc) {
443 $plc->password (encode_password $new_pw); 443 $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 ( 444 $pl->message (
459 "Ok, changed your password!", 445 "Ok, changed password of '$player' to '$new_pw'!",
460 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 446 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
461 $pl->contr->password (encode_password $new_pw);
462
463 } else { 447 } else {
464 $pl->message ( 448 $pl->message (
465 "Ok, please confirm your new password by sending " 449 "Fail! Couldn't set password for '$player', "
466 . "the command again within one minute!", 450 . "he doesn't seem to exist!",
467 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 451 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
468 $pl->{password_change} = [time, $new_pw];
469 } 452 }
470 } 453 };
471}; 454};
472 455
473cf::register_command quit => sub { 456cf::register_command quit => sub {
474 my ($ob, $arg) = @_; 457 my ($ob, $arg) = @_;
475 458
514 497
515 $pl->save; 498 $pl->save;
516 499
517 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 500 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
518 501
502 my $ns = $pl->ns
503 or return;
504
519 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 505 $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
520 if ($_[0] !~ /^[yY]/) { 506 if ($_[0] !~ /^[yY]/) {
521 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 507 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
522 $pl->deactivate; 508 $pl->deactivate;
523 $pl->ns->destroy; 509 $pl->ns->destroy;
524 } 510 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines