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.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;
126 } 130 }
127 131
128 $ob->goto ($map, $x, $y); 132 $ob->goto ($map, $x, $y);
129} 133}
130 134
131sub encode_password { 135sub encode_password($) {
132 crypt $_[0], 136# crypt $_[0],
133 join '', 137# join '',
134 ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] 138# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
139 "!" . unpack "H*", $_[0]
135} 140}
136 141
137# delete a player directory, be non-blocking AND synchronous... 142sub compare_password($$) {
138# (that's hard, so we crap out and fork). 143 my ($pass, $token) = @_;
144
145 if ($token =~ /!!(.*)/) {
146 return +(substr $pass, 0, 8) eq pack "H*", $1;
147 } elsif ($token =~ /!(.*)/) {
148 return $pass eq pack "H*", $1;
149 } else {
150 return $token eq crypt $pass, $token;
151 }
152}
153
154# delete a player directory
139sub nuke_playerdir { 155sub nuke_playerdir {
140 my ($user) = @_; 156 my ($user) = @_;
141 157
158 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
159
142 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 160 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
143
144 cf::fork_call {
145 rename "$PLAYERDIR/$user", $temp; 161 aio_rename "$PLAYERDIR/$user", $temp;
146 system "rm", "-rf", $temp; 162 IO::AIO::aio_rmtree $temp;
147 };
148} 163}
149 164
150cf::client->attach (on_addme => sub { 165cf::client->attach (on_addme => sub {
151 my ($ns) = @_; 166 my ($ns) = @_;
152 167
230 245
231 # try to read the user file and check the password 246 # try to read the user file and check the password
232 if (my $pl = cf::player::find $user) { 247 if (my $pl = cf::player::find $user) {
233 aio_stat $pl->path and next; 248 aio_stat $pl->path and next;
234 my $mtime = (stat _)[9]; 249 my $mtime = (stat _)[9];
235 my $hash = $pl->password; 250 my $token = $pl->password;
236 251
237 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 252 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
253 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
238 nuke_str $pass; 254 nuke_str $pass;
239 # password matches, wonderful 255 # password matches, wonderful
240 my $pl = cf::player::find $user or next; 256 my $pl = cf::player::find $user or next;
241 $pl->connect ($ns); 257 $pl->connect ($ns);
242 enter_map $pl; 258 enter_map $pl;
274 ); 290 );
275 next; 291 next;
276 } 292 }
277 } else { 293 } else {
278 # unable to load the playerfile: 294 # unable to load the playerfile:
279 # 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
280 # something very similar. 296 # something very similar.
281 if (!aio_stat cf::player::playerdir $user) { 297 if (!aio_stat cf::player::playerdir $user) {
282 $ns->send_drawinfo ( 298 $ns->send_drawinfo (
283 "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. "
284 . "If this is your account, ask a dungeon master for assistance. " 300 . "If this is your account, ask a dungeon master for assistance. "
291 307
292 # the rest of this function is character creation 308 # the rest of this function is character creation
293 $Coro::current->{desc} = "addme($user) chargen"; 309 $Coro::current->{desc} = "addme($user) chargen";
294 310
295 # just to make sure nothing is left over 311 # just to make sure nothing is left over
312 # normally, nothing is there.
296 nuke_playerdir $user; 313 nuke_playerdir $user;
297 314
298 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.";
299 316
300 if ($pass2 ne $pass) { 317 if ($pass2 ne $pass) {
394}); 411});
395 412
396cf::register_command password => sub { 413cf::register_command password => sub {
397 my ($pl, $arg) = @_; 414 my ($pl, $arg) = @_;
398 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
399 my (@args) = split /\s+/, $arg; 423 my (@args) = split /\s+/, $arg;
400
401 my ($new_pw, $player);
402
403 if ($pl->flag (cf::FLAG_WIZ)) {
404 ($player, $new_pw) = @args; 424 my ($player, $new_pw) = @args;
405 } else {
406 $new_pw = $args[0];
407 }
408 425
409 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { 426 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
410 $pl->message ( 427 $pl->message (
411 "Usage: password <player> [<new password>]", 428 "Usage: password <player> [<new password>]",
412 cf::NDI_UNIQUE | cf::NDI_REPLY); 429 cf::NDI_UNIQUE | cf::NDI_REPLY);
413 return; 430 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 } 431 }
420 432
421 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
422 unless ($new_pw ne '') { 433 if ($new_pw eq '') {
423 $new_pw = 434 $new_pw =
424 join '', 435 join '',
425 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } 436 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
426 1..9; 437 1..9;
427 } 438 }
428 439
429 cf::async { 440 cf::async {
430 my $plc = cf::player::find $player; 441 my $plc = cf::player::find $player;
431 if ($plc) { 442 if ($plc) {
432 $plc->password (encode_password $new_pw); 443 $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 ( 444 $pl->message (
448 "Ok, changed your password!", 445 "Ok, changed password of '$player' to '$new_pw'!",
449 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 446 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
450 $pl->contr->password (encode_password $new_pw);
451
452 } else { 447 } else {
453 $pl->message ( 448 $pl->message (
454 "Ok, please confirm your new password by sending " 449 "Fail! Couldn't set password for '$player', "
455 . "the command again within one minute!", 450 . "he doesn't seem to exist!",
456 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 451 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
457 $pl->{password_change} = [time, $new_pw];
458 } 452 }
459 } 453 };
460}; 454};
461 455
462cf::register_command quit => sub { 456cf::register_command quit => sub {
463 my ($ob, $arg) = @_; 457 my ($ob, $arg) = @_;
464 458
476 $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 {
477 if ($_[0] !~ /^[yY]/) { 471 if ($_[0] !~ /^[yY]/) {
478 $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);
479 } else { 473 } else {
480 $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);
481 $pl->ns->flush;
482 cf::async { 475 cf::async {
483 ext::highscore::check $pl->ob;
484 $pl->quit_character; 476 $pl->quit_character;
485 }; 477 };
486 } 478 }
487 }); 479 });
488}; 480};
496 488
497 my $pl = $ob->contr; 489 my $pl = $ob->contr;
498 490
499 # update respawn position 491 # update respawn position
500 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 492 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
501 cf::async { $pl->save };
502 493
494 cf::async {
503 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;
504 ext::highscore::check $ob; 496 ext::highscore::check $ob;
505 497
498 $pl->save;
499
506 $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);
507 501
502 my $ns = $pl->ns
503 or return;
504
508 $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 {
509 if ($_[0] !~ /^[yY]/) { 506 if ($_[0] !~ /^[yY]/) {
510 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 507 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
511 $pl->deactivate; 508 $pl->deactivate;
512 $pl->ns->destroy; 509 $pl->ns->destroy;
513 } else { 510 }
514 cf::async { $pl->save };
515 } 511 });
516 }); 512 };
517 }, 513 },
518); 514);
519 515
520cf::player->attach ( 516cf::player->attach (
521 on_login => sub { 517 on_login => sub {
536 unless safe_spot $pl; 532 unless safe_spot $pl;
537 } 533 }
538 }, 534 },
539); 535);
540 536
541

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines