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.108 by elmex, Thu Apr 29 10:08:26 2010 UTC vs.
Revision 1.112 by elmex, Mon May 10 15:54:40 2010 UTC

126 } 126 }
127 127
128 $ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
129} 129}
130 130
131sub encode_password { 131sub encode_password($) {
132 crypt $_[0], 132# crypt $_[0],
133 join '', 133# join '',
134 ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] 134# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
135 "!" . unpack "H*", $_[0]
135} 136}
136 137
137# delete a player directory, be non-blocking AND synchronous... 138sub compare_password($$) {
138# (that's hard, so we crap out and fork). 139 my ($pass, $token) = @_;
140
141 if ($token =~ /\!(.*)/) {
142 return $pass eq pack "H*", $1;
143 } else {
144 return $token eq crypt $pass, $token;
145 }
146}
147
148# delete a player directory
139sub nuke_playerdir { 149sub nuke_playerdir {
140 my ($user) = @_; 150 my ($user) = @_;
141 151
152 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
153
142 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 154 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
143
144 cf::fork_call {
145 rename "$PLAYERDIR/$user", $temp; 155 aio_rename "$PLAYERDIR/$user", $temp;
146 system "rm", "-rf", $temp; 156 IO::AIO::aio_rmtree $temp;
147 };
148} 157}
149 158
150cf::client->attach (on_addme => sub { 159cf::client->attach (on_addme => sub {
151 my ($ns) = @_; 160 my ($ns) = @_;
152 161
230 239
231 # try to read the user file and check the password 240 # try to read the user file and check the password
232 if (my $pl = cf::player::find $user) { 241 if (my $pl = cf::player::find $user) {
233 aio_stat $pl->path and next; 242 aio_stat $pl->path and next;
234 my $mtime = (stat _)[9]; 243 my $mtime = (stat _)[9];
235 my $hash = $pl->password; 244 my $token = $pl->password;
236 245
237 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 246 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
247 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
238 nuke_str $pass; 248 nuke_str $pass;
239 # password matches, wonderful 249 # password matches, wonderful
240 my $pl = cf::player::find $user or next; 250 my $pl = cf::player::find $user or next;
241 $pl->connect ($ns); 251 $pl->connect ($ns);
242 enter_map $pl; 252 enter_map $pl;
291 301
292 # the rest of this function is character creation 302 # the rest of this function is character creation
293 $Coro::current->{desc} = "addme($user) chargen"; 303 $Coro::current->{desc} = "addme($user) chargen";
294 304
295 # just to make sure nothing is left over 305 # just to make sure nothing is left over
306 # normally, nothing is there.
296 nuke_playerdir $user; 307 nuke_playerdir $user;
297 308
298 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 309 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
299 310
300 if ($pass2 ne $pass) { 311 if ($pass2 ne $pass) {
394}); 405});
395 406
396cf::register_command password => sub { 407cf::register_command password => sub {
397 my ($pl, $arg) = @_; 408 my ($pl, $arg) = @_;
398 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
399 my (@args) = split /\s+/, $arg; 417 my (@args) = split /\s+/, $arg;
400
401 my ($new_pw, $player);
402
403 if ($pl->flag (cf::FLAG_WIZ)) {
404 ($player, $new_pw) = @args; 418 my ($player, $new_pw) = @args;
405 } else {
406 $new_pw = $args[0];
407 }
408 419
409 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 420 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
410 $pl->message ( 421 $pl->message (
411 "Usage: password <player> [<new password>]", 422 "Usage: password <player> [<new password>]",
412 cf::NDI_UNIQUE | cf::NDI_REPLY); 423 cf::NDI_UNIQUE | cf::NDI_REPLY);
413 return; 424 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 } 425 }
420 426
421 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
422 unless ($new_pw ne '') { 427 if ($new_pw eq '') {
423 $new_pw = 428 $new_pw =
424 join '', 429 join '',
425 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 430 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
426 1..9; 431 1..9;
427 } 432 }
428 433
429 cf::async { 434 cf::async {
430 my $plc = cf::player::find $player; 435 my $plc = cf::player::find $player;
431 if ($plc) { 436 if ($plc) {
432 $plc->password (encode_password $new_pw); 437 $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
446 if ($change && (time - $change->[0]) < 60) {
447 $pl->message ( 438 $pl->message (
448 "Ok, changed your password!", 439 "Ok, changed password of '$player' to '$new_pw'!",
449 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 440 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
450 $pl->contr->password (encode_password $new_pw);
451
452 } else { 441 } else {
453 $pl->message ( 442 $pl->message (
454 "Ok, please confirm your new password by sending " 443 "Fail! Couldn't set password for '$player', "
455 . "the command again within one minute!", 444 . "he doesn't seem to exist!",
456 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 445 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
457 $pl->{password_change} = [time, $new_pw];
458 } 446 }
459 } 447 };
460}; 448};
461 449
462cf::register_command quit => sub { 450cf::register_command quit => sub {
463 my ($ob, $arg) = @_; 451 my ($ob, $arg) = @_;
464 452
476 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 464 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub {
477 if ($_[0] !~ /^[yY]/) { 465 if ($_[0] !~ /^[yY]/) {
478 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 466 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
479 } else { 467 } else {
480 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 468 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
481 $pl->ns->flush;
482 cf::async { 469 cf::async {
483 ext::highscore::check $pl->ob;
484 $pl->quit_character; 470 $pl->quit_character;
485 }; 471 };
486 } 472 }
487 }); 473 });
488}; 474};
496 482
497 my $pl = $ob->contr; 483 my $pl = $ob->contr;
498 484
499 # update respawn position 485 # update respawn position
500 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 486 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
501 cf::async { $pl->save };
502 487
488 cf::async {
503 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 489 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
504 ext::highscore::check $ob; 490 ext::highscore::check $ob;
505 491
492 $pl->save;
493
506 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 494 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
507 495
508 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 496 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
509 if ($_[0] !~ /^[yY]/) { 497 if ($_[0] !~ /^[yY]/) {
510 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 498 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
511 $pl->deactivate; 499 $pl->deactivate;
512 $pl->ns->destroy; 500 $pl->ns->destroy;
513 } else { 501 }
514 cf::async { $pl->save };
515 } 502 });
516 }); 503 };
517 }, 504 },
518); 505);
519 506
520cf::player->attach ( 507cf::player->attach (
521 on_login => sub { 508 on_login => sub {
536 unless safe_spot $pl; 523 unless safe_spot $pl;
537 } 524 }
538 }, 525 },
539); 526);
540 527
541

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines