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.99 by root, Mon Jun 29 06:11:01 2009 UTC vs.
Revision 1.111 by root, Sun May 9 22:51:13 2010 UTC

1#! perl # mandatory 1#! perl # mandatory depends=highscore
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
70} 70}
71 71
72sub enter_map { 72sub enter_map {
73 my ($pl) = @_; 73 my ($pl) = @_;
74 74
75 warn $pl->ob->name, ": enter map 1\n";#d#
76 my $ob = $pl->ob; 75 my $ob = $pl->ob;
77 76
78 my ($map, $x, $y) 77 my ($map, $x, $y)
79 = $ob->{_link_pos} 78 = $ob->{_link_pos}
80 ? @{delete $ob->{_link_pos}} 79 ? @{delete $ob->{_link_pos}}
81 : ($pl->maplevel, $ob->x, $ob->y); 80 : ($pl->maplevel, $ob->x, $ob->y);
82 81
83 warn $pl->ob->name, ": enter map 2\n";#d#
84 $ob->enter_link; 82 $ob->enter_link;
85 warn $pl->ob->name, ": enter map 3\n";#d#
86 83
87 my $m = cf::map::find $map; 84 my $m = cf::map::find $map;
88 my $time = delete $pl->{unclean_save}; 85 my $time = delete $pl->{unclean_save};
89 warn $pl->ob->name, ": enter map 4\n";#d#
90 86
91 if ($time && $m) { 87 if ($time && $m) {
92 if ($time < $m->{instantiate_time}) { 88 if ($time < $m->{instantiate_time}) {
93 # the map was reset in the meantime 89 # the map was reset in the meantime
94 my $age = $cf::RUNTIME - $time; 90 my $age = $cf::RUNTIME - $time;
95 91
96 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#
97 93
98 if ($age >= $MAX_DISCONNECT_TIME) { 94 if ($age >= $MAX_DISCONNECT_TIME) {
99 $ob->message ( 95 $ob->message (
100 "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. "
101 . "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. "
127 cf::NDI_RED 123 cf::NDI_RED
128 ); 124 );
129 } 125 }
130 } 126 }
131 127
132 warn $pl->ob->name, ": enter map 5\n";#d#
133 #$ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
134 $ob->goto ($map, $x, $y, sub { 129}
135 warn $pl->ob->name, ": enter map check\n";#d# 130
136 $_[0] 131sub encode_password($) {
137 }, sub { 132# crypt $_[0],
138 warn $pl->ob->name, ": enter map done\n";#d# 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;
139 }); 145 }
140 warn $pl->ob->name, ": enter map 6\n";#d#
141
142} 146}
143 147
144# delete a player directory, be non-blocking AND synchronous... 148# delete a player directory
145# (that's hard, so we crap out and fork).
146sub nuke_playerdir { 149sub nuke_playerdir {
147 my ($user) = @_; 150 my ($user) = @_;
148 151
152 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
153
149 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 154 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
150
151 cf::fork_call {
152 rename "$PLAYERDIR/$user", $temp; 155 aio_rename "$PLAYERDIR/$user", $temp;
153 system "rm", "-rf", $temp; 156 IO::AIO::aio_rmtree $temp;
154 };
155} 157}
156 158
157cf::client->attach (on_addme => sub { 159cf::client->attach (on_addme => sub {
158 my ($ns) = @_; 160 my ($ns) = @_;
159 161
237 239
238 # try to read the user file and check the password 240 # try to read the user file and check the password
239 if (my $pl = cf::player::find $user) { 241 if (my $pl = cf::player::find $user) {
240 aio_stat $pl->path and next; 242 aio_stat $pl->path and next;
241 my $mtime = (stat _)[9]; 243 my $mtime = (stat _)[9];
242 my $hash = $pl->password; 244 my $token = $pl->password;
243 245
244 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#
245 nuke_str $pass; 248 nuke_str $pass;
246 # password matches, wonderful 249 # password matches, wonderful
247 my $pl = cf::player::find $user or next; 250 my $pl = cf::player::find $user or next;
248 $pl->connect ($ns); 251 $pl->connect ($ns);
249 $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp
250 enter_map $pl; 252 enter_map $pl;
251 last; 253 last;
252 } elsif (can_cleanup $pl, $mtime) { 254 } elsif (can_cleanup $pl, $mtime) {
253 Coro::Timer::sleep 1; 255 Coro::Timer::sleep 1;
254 256
299 301
300 # the rest of this function is character creation 302 # the rest of this function is character creation
301 $Coro::current->{desc} = "addme($user) chargen"; 303 $Coro::current->{desc} = "addme($user) chargen";
302 304
303 # just to make sure nothing is left over 305 # just to make sure nothing is left over
306 # normally, nothing is there.
304 nuke_playerdir $user; 307 nuke_playerdir $user;
305 308
306 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.";
307 310
308 if ($pass2 ne $pass) { 311 if ($pass2 ne $pass) {
317 } 320 }
318 321
319 nuke_str $pass2; 322 nuke_str $pass2;
320 323
321 my $pl = cf::player::new $user; 324 my $pl = cf::player::new $user;
322 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 325 $pl->password (encode_password $pass);
323 nuke_str $pass; 326 nuke_str $pass;
324 $pl->connect ($ns); 327 $pl->connect ($ns);
325 my $ob = $pl->ob; 328 my $ob = $pl->ob;
326 329
327 $ob->goto ($pl->maplevel, $ob->x, $ob->y); 330 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
361 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 364 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
362 365
363 last if $res =~ /[dD]/; 366 last if $res =~ /[dD]/;
364 367
365 $pl->chargen_race_next; 368 $pl->chargen_race_next;
366 Coro::Timer::sleep 0.2; 369 Coro::Timer::sleep 0.05;
367 } 370 }
368 371
369 # create the playerdir, if necessary, as chargen_race_done did it before 372 # create the playerdir, if necessary, as chargen_race_done did it before
370 # presumably because of unique maps 373 # presumably because of unique maps
371 aio_mkdir playerdir $pl, 0770; 374 aio_mkdir playerdir $pl, 0770;
380 last; 383 last;
381 } elsif ($res =~ /^[mM]/) { 384 } elsif ($res =~ /^[mM]/) {
382 $pl->gender (0); 385 $pl->gender (0);
383 last; 386 last;
384 } 387 }
385 Coro::Timer::sleep 0.2; 388 Coro::Timer::sleep 0.05;
386 } 389 }
387 390
388 $ob->reply (undef, "Welcome to Deliantra!"); 391 $ob->reply (undef, "Welcome to Deliantra!");
389 392
390 # XXX: Workaround for delayed client ext protocol handshake 393 # XXX: Workaround for delayed client ext protocol handshake
392 395
393 delete $pl->{deny_save}; 396 delete $pl->{deny_save};
394 397
395 last; 398 last;
396 } 399 }
400
401 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
402 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
403 }
397 }); 404 });
398}); 405});
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};
399 472
400cf::register_command quit => sub { 473cf::register_command quit => sub {
401 my ($ob, $arg) = @_; 474 my ($ob, $arg) = @_;
402 475
403 $ob->send_msg (undef, 476 $ob->send_msg (undef,
414 $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 {
415 if ($_[0] !~ /^[yY]/) { 488 if ($_[0] !~ /^[yY]/) {
416 $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);
417 } else { 490 } else {
418 $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);
419 $pl->ns->flush; 492 cf::async {
420 cf::async { $pl->quit_character }; 493 $pl->quit_character;
494 };
421 } 495 }
422 }); 496 });
423}; 497};
424 498
425cf::object->attach ( 499cf::object->attach (
431 505
432 my $pl = $ob->contr; 506 my $pl = $ob->contr;
433 507
434 # update respawn position 508 # update respawn position
435 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 509 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
436 cf::async { $pl->save };
437 510
511 cf::async {
438 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;
439 $ob->check_score; 513 ext::highscore::check $ob;
440 514
515 $pl->save;
516
441 $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);
442 518
443 $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 {
444 if ($_[0] !~ /^[yY]/) { 520 if ($_[0] !~ /^[yY]/) {
445 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 521 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
446 $pl->deactivate; 522 $pl->deactivate;
447 $pl->ns->destroy; 523 $pl->ns->destroy;
448 } else { 524 }
449 cf::async { $pl->save };
450 } 525 });
451 }); 526 };
452 }, 527 },
453); 528);
454 529
455cf::player->attach ( 530cf::player->attach (
456 on_login => sub { 531 on_login => sub {
471 unless safe_spot $pl; 546 unless safe_spot $pl;
472 } 547 }
473 }, 548 },
474); 549);
475 550
476

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines