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.103 by root, Sun Apr 11 21:26:36 2010 UTC vs.
Revision 1.111 by root, Sun May 9 22:51:13 2010 UTC

87 if ($time && $m) { 87 if ($time && $m) {
88 if ($time < $m->{instantiate_time}) { 88 if ($time < $m->{instantiate_time}) {
89 # the map was reset in the meantime 89 # the map was reset in the meantime
90 my $age = $cf::RUNTIME - $time; 90 my $age = $cf::RUNTIME - $time;
91 91
92 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 92 cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
93 93
94 if ($age >= $MAX_DISCONNECT_TIME) { 94 if ($age >= $MAX_DISCONNECT_TIME) {
95 $ob->message ( 95 $ob->message (
96 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 96 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
97 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " 97 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
126 } 126 }
127 127
128 $ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
129} 129}
130 130
131# delete a player directory, be non-blocking AND synchronous... 131sub encode_password($) {
132# (that's hard, so we crap out and fork). 132# crypt $_[0],
133# join '',
134# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
135 "!" . unpack "H*", $_[0]
136}
137
138sub compare_password($$) {
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
133sub nuke_playerdir { 149sub nuke_playerdir {
134 my ($user) = @_; 150 my ($user) = @_;
135 151
152 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
153
136 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 154 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
137
138 cf::fork_call {
139 rename "$PLAYERDIR/$user", $temp; 155 aio_rename "$PLAYERDIR/$user", $temp;
140 system "rm", "-rf", $temp; 156 IO::AIO::aio_rmtree $temp;
141 };
142} 157}
143 158
144cf::client->attach (on_addme => sub { 159cf::client->attach (on_addme => sub {
145 my ($ns) = @_; 160 my ($ns) = @_;
146 161
224 239
225 # try to read the user file and check the password 240 # try to read the user file and check the password
226 if (my $pl = cf::player::find $user) { 241 if (my $pl = cf::player::find $user) {
227 aio_stat $pl->path and next; 242 aio_stat $pl->path and next;
228 my $mtime = (stat _)[9]; 243 my $mtime = (stat _)[9];
229 my $hash = $pl->password; 244 my $token = $pl->password;
230 245
231 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#
232 nuke_str $pass; 248 nuke_str $pass;
233 # password matches, wonderful 249 # password matches, wonderful
234 my $pl = cf::player::find $user or next; 250 my $pl = cf::player::find $user or next;
235 $pl->connect ($ns); 251 $pl->connect ($ns);
236 enter_map $pl; 252 enter_map $pl;
285 301
286 # the rest of this function is character creation 302 # the rest of this function is character creation
287 $Coro::current->{desc} = "addme($user) chargen"; 303 $Coro::current->{desc} = "addme($user) chargen";
288 304
289 # just to make sure nothing is left over 305 # just to make sure nothing is left over
306 # normally, nothing is there.
290 nuke_playerdir $user; 307 nuke_playerdir $user;
291 308
292 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.";
293 310
294 if ($pass2 ne $pass) { 311 if ($pass2 ne $pass) {
303 } 320 }
304 321
305 nuke_str $pass2; 322 nuke_str $pass2;
306 323
307 my $pl = cf::player::new $user; 324 my $pl = cf::player::new $user;
308 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 325 $pl->password (encode_password $pass);
309 nuke_str $pass; 326 nuke_str $pass;
310 $pl->connect ($ns); 327 $pl->connect ($ns);
311 my $ob = $pl->ob; 328 my $ob = $pl->ob;
312 329
313 $ob->goto ($pl->maplevel, $ob->x, $ob->y); 330 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
385 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); 402 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
386 } 403 }
387 }); 404 });
388}); 405});
389 406
407cf::register_command password => sub {
408 my ($pl, $arg) = @_;
409
410 my (@args) = split /\s+/, $arg;
411
412 my ($new_pw, $player);
413
414 if ($pl->flag (cf::FLAG_WIZ)) {
415 ($player, $new_pw) = @args;
416 } else {
417 $new_pw = $args[0];
418 }
419
420 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
421 $pl->message (
422 "Usage: password <player> [<new password>]",
423 cf::NDI_UNIQUE | cf::NDI_REPLY);
424 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
432 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
433 unless ($new_pw ne '') {
434 $new_pw =
435 join '',
436 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
437 1..9;
438 }
439
440 cf::async {
441 my $plc = cf::player::find $player;
442 if ($plc) {
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 (
459 "Ok, changed your password!",
460 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
461 $pl->contr->password (encode_password $new_pw);
462
463 } else {
464 $pl->message (
465 "Ok, please confirm your new password by sending "
466 . "the command again within one minute!",
467 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
468 $pl->{password_change} = [time, $new_pw];
469 }
470 }
471};
472
390cf::register_command quit => sub { 473cf::register_command quit => sub {
391 my ($ob, $arg) = @_; 474 my ($ob, $arg) = @_;
392 475
393 $ob->send_msg (undef, 476 $ob->send_msg (undef,
394 "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " 477 "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. "
404 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 487 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub {
405 if ($_[0] !~ /^[yY]/) { 488 if ($_[0] !~ /^[yY]/) {
406 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 489 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
407 } else { 490 } else {
408 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 491 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
409 $pl->ns->flush; 492 cf::async {
410 cf::async { $pl->quit_character }; 493 $pl->quit_character;
494 };
411 } 495 }
412 }); 496 });
413}; 497};
414 498
415cf::object->attach ( 499cf::object->attach (
421 505
422 my $pl = $ob->contr; 506 my $pl = $ob->contr;
423 507
424 # update respawn position 508 # update respawn position
425 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 509 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
426 cf::async { $pl->save };
427 510
511 cf::async {
428 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 512 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
429 ext::highscore::check $ob; 513 ext::highscore::check $ob;
430 514
515 $pl->save;
516
431 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 517 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
432 518
433 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 519 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
434 if ($_[0] !~ /^[yY]/) { 520 if ($_[0] !~ /^[yY]/) {
435 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 521 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
436 $pl->deactivate; 522 $pl->deactivate;
437 $pl->ns->destroy; 523 $pl->ns->destroy;
438 } else { 524 }
439 cf::async { $pl->save };
440 } 525 });
441 }); 526 };
442 }, 527 },
443); 528);
444 529
445cf::player->attach ( 530cf::player->attach (
446 on_login => sub { 531 on_login => sub {
461 unless safe_spot $pl; 546 unless safe_spot $pl;
462 } 547 }
463 }, 548 },
464); 549);
465 550
466

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines