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.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}
147 153
148# delete a player directory, be non-blocking AND synchronous... 154# delete a player directory
149# (that's hard, so we crap out and fork).
150sub nuke_playerdir { 155sub nuke_playerdir {
151 my ($user) = @_; 156 my ($user) = @_;
152 157
158 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
159
153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 160 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
154
155 cf::fork_call {
156 rename "$PLAYERDIR/$user", $temp; 161 aio_rename "$PLAYERDIR/$user", $temp;
157 system "rm", "-rf", $temp; 162 IO::AIO::aio_rmtree $temp;
158 };
159} 163}
160 164
161cf::client->attach (on_addme => sub { 165cf::client->attach (on_addme => sub {
162 my ($ns) = @_; 166 my ($ns) = @_;
163 167
286 ); 290 );
287 next; 291 next;
288 } 292 }
289 } else { 293 } else {
290 # unable to load the playerfile: 294 # unable to load the playerfile:
291 # 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
292 # something very similar. 296 # something very similar.
293 if (!aio_stat cf::player::playerdir $user) { 297 if (!aio_stat cf::player::playerdir $user) {
294 $ns->send_drawinfo ( 298 $ns->send_drawinfo (
295 "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. "
296 . "If this is your account, ask a dungeon master for assistance. " 300 . "If this is your account, ask a dungeon master for assistance. "
303 307
304 # the rest of this function is character creation 308 # the rest of this function is character creation
305 $Coro::current->{desc} = "addme($user) chargen"; 309 $Coro::current->{desc} = "addme($user) chargen";
306 310
307 # just to make sure nothing is left over 311 # just to make sure nothing is left over
312 # normally, nothing is there.
308 nuke_playerdir $user; 313 nuke_playerdir $user;
309 314
310 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 315 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
311 316
312 if ($pass2 ne $pass) { 317 if ($pass2 ne $pass) {
406}); 411});
407 412
408cf::register_command password => sub { 413cf::register_command password => sub {
409 my ($pl, $arg) = @_; 414 my ($pl, $arg) = @_;
410 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
411 my (@args) = split /\s+/, $arg; 423 my (@args) = split /\s+/, $arg;
412
413 my ($new_pw, $player);
414
415 if ($pl->flag (cf::FLAG_WIZ)) {
416 ($player, $new_pw) = @args; 424 my ($player, $new_pw) = @args;
417 } else {
418 $new_pw = $args[0];
419 }
420 425
421 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 426 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
422 $pl->message ( 427 $pl->message (
423 "Usage: password <player> [<new password>]", 428 "Usage: password <player> [<new password>]",
424 cf::NDI_UNIQUE | cf::NDI_REPLY); 429 cf::NDI_UNIQUE | cf::NDI_REPLY);
425 return; 430 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 } 431 }
432 432
433 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
434 unless ($new_pw ne '') { 433 if ($new_pw eq '') {
435 $new_pw = 434 $new_pw =
436 join '', 435 join '',
437 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 436 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
438 1..9; 437 1..9;
439 } 438 }
440 439
441 cf::async { 440 cf::async {
442 my $plc = cf::player::find $player; 441 my $plc = cf::player::find $player;
443 if ($plc) { 442 if ($plc) {
444 $plc->password (encode_password $new_pw); 443 $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 ( 444 $pl->message (
460 "Ok, changed your password!", 445 "Ok, changed password of '$player' to '$new_pw'!",
461 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 446 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 $pl->contr->password (encode_password $new_pw);
463
464 } else { 447 } else {
465 $pl->message ( 448 $pl->message (
466 "Ok, please confirm your new password by sending " 449 "Fail! Couldn't set password for '$player', "
467 . "the command again within one minute!", 450 . "he doesn't seem to exist!",
468 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 451 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
469 $pl->{password_change} = [time, $new_pw];
470 } 452 }
471 } 453 };
472}; 454};
473 455
474cf::register_command quit => sub { 456cf::register_command quit => sub {
475 my ($ob, $arg) = @_; 457 my ($ob, $arg) = @_;
476 458
488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 470 $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]/) { 471 if ($_[0] !~ /^[yY]/) {
490 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 472 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
491 } else { 473 } else {
492 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 474 $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 { 475 cf::async {
495 ext::highscore::check $pl->ob;
496 $pl->quit_character; 476 $pl->quit_character;
497 }; 477 };
498 } 478 }
499 }); 479 });
500}; 480};
508 488
509 my $pl = $ob->contr; 489 my $pl = $ob->contr;
510 490
511 # update respawn position 491 # update respawn position
512 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 492 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
513 cf::async { $pl->save };
514 493
494 cf::async {
515 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 495 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
516 ext::highscore::check $ob; 496 ext::highscore::check $ob;
517 497
498 $pl->save;
499
518 $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);
519 501
502 my $ns = $pl->ns
503 or return;
504
520 $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 {
521 if ($_[0] !~ /^[yY]/) { 506 if ($_[0] !~ /^[yY]/) {
522 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 507 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
523 $pl->deactivate; 508 $pl->deactivate;
524 $pl->ns->destroy; 509 $pl->ns->destroy;
525 } else { 510 }
526 cf::async { $pl->save };
527 } 511 });
528 }); 512 };
529 }, 513 },
530); 514);
531 515
532cf::player->attach ( 516cf::player->attach (
533 on_login => sub { 517 on_login => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines