… | |
… | |
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 | |
63 | |
|
|
64 | # never happens normally, but helps when shell users make mistakes |
|
|
65 | $m->linkable |
|
|
66 | or return 1; |
|
|
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; |
68 | |
72 | |
… | |
… | |
87 | if ($time && $m) { |
91 | if ($time && $m) { |
88 | if ($time < $m->{instantiate_time}) { |
92 | if ($time < $m->{instantiate_time}) { |
89 | # the map was reset in the meantime |
93 | # the map was reset in the meantime |
90 | my $age = $cf::RUNTIME - $time; |
94 | my $age = $cf::RUNTIME - $time; |
91 | |
95 | |
92 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
96 | cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
93 | |
97 | |
94 | if ($age >= $MAX_DISCONNECT_TIME) { |
98 | if ($age >= $MAX_DISCONNECT_TIME) { |
95 | $ob->message ( |
99 | $ob->message ( |
96 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
100 | "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. " |
101 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
… | |
… | |
126 | } |
130 | } |
127 | |
131 | |
128 | $ob->goto ($map, $x, $y); |
132 | $ob->goto ($map, $x, $y); |
129 | } |
133 | } |
130 | |
134 | |
131 | sub encode_password { |
135 | sub 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... |
142 | sub compare_password($$) { |
138 | # (that's hard, so we crap out and fork). |
143 | my ($pass, $token) = @_; |
|
|
144 | |
|
|
145 | if ($token =~ /\!(.*)/) { |
|
|
146 | return $pass eq pack "H*", $1; |
|
|
147 | } else { |
|
|
148 | return $token eq crypt $pass, $token; |
|
|
149 | } |
|
|
150 | } |
|
|
151 | |
|
|
152 | # delete a player directory |
139 | sub nuke_playerdir { |
153 | sub nuke_playerdir { |
140 | my ($user) = @_; |
154 | my ($user) = @_; |
141 | |
155 | |
|
|
156 | my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; |
|
|
157 | |
142 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
158 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
143 | |
|
|
144 | cf::fork_call { |
|
|
145 | rename "$PLAYERDIR/$user", $temp; |
159 | aio_rename "$PLAYERDIR/$user", $temp; |
146 | system "rm", "-rf", $temp; |
160 | IO::AIO::aio_rmtree $temp; |
147 | }; |
|
|
148 | } |
161 | } |
149 | |
162 | |
150 | cf::client->attach (on_addme => sub { |
163 | cf::client->attach (on_addme => sub { |
151 | my ($ns) = @_; |
164 | my ($ns) = @_; |
152 | |
165 | |
… | |
… | |
230 | |
243 | |
231 | # try to read the user file and check the password |
244 | # try to read the user file and check the password |
232 | if (my $pl = cf::player::find $user) { |
245 | if (my $pl = cf::player::find $user) { |
233 | aio_stat $pl->path and next; |
246 | aio_stat $pl->path and next; |
234 | my $mtime = (stat _)[9]; |
247 | my $mtime = (stat _)[9]; |
235 | my $hash = $pl->password; |
248 | my $token = $pl->password; |
236 | |
249 | |
237 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
250 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
|
|
251 | $pl->password (encode_password $pass); # make sure we store the new encoding #d# |
238 | nuke_str $pass; |
252 | nuke_str $pass; |
239 | # password matches, wonderful |
253 | # password matches, wonderful |
240 | my $pl = cf::player::find $user or next; |
254 | my $pl = cf::player::find $user or next; |
241 | $pl->connect ($ns); |
255 | $pl->connect ($ns); |
242 | enter_map $pl; |
256 | enter_map $pl; |
… | |
… | |
274 | ); |
288 | ); |
275 | next; |
289 | next; |
276 | } |
290 | } |
277 | } else { |
291 | } else { |
278 | # unable to load the playerfile: |
292 | # unable to load the playerfile: |
279 | # check wether the player dir exists, which means the file is corrupted or |
293 | # check whether the player dir exists, which means the file is corrupted or |
280 | # something very similar. |
294 | # something very similar. |
281 | if (!aio_stat cf::player::playerdir $user) { |
295 | if (!aio_stat cf::player::playerdir $user) { |
282 | $ns->send_drawinfo ( |
296 | $ns->send_drawinfo ( |
283 | "Unable to retrieve this player. It might be a locked or broken account. " |
297 | "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. " |
298 | . "If this is your account, ask a dungeon master for assistance. " |
… | |
… | |
291 | |
305 | |
292 | # the rest of this function is character creation |
306 | # the rest of this function is character creation |
293 | $Coro::current->{desc} = "addme($user) chargen"; |
307 | $Coro::current->{desc} = "addme($user) chargen"; |
294 | |
308 | |
295 | # just to make sure nothing is left over |
309 | # just to make sure nothing is left over |
|
|
310 | # normally, nothing is there. |
296 | nuke_playerdir $user; |
311 | nuke_playerdir $user; |
297 | |
312 | |
298 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
313 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
299 | |
314 | |
300 | if ($pass2 ne $pass) { |
315 | if ($pass2 ne $pass) { |
… | |
… | |
394 | }); |
409 | }); |
395 | |
410 | |
396 | cf::register_command password => sub { |
411 | cf::register_command password => sub { |
397 | my ($pl, $arg) = @_; |
412 | my ($pl, $arg) = @_; |
398 | |
413 | |
|
|
414 | unless ($pl->flag (cf::FLAG_WIZ)) { |
|
|
415 | $pl->message ( |
|
|
416 | "The password can currently only changed by a DM.", |
|
|
417 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
|
|
418 | return; |
|
|
419 | } |
|
|
420 | |
399 | my (@args) = split /\s+/, $arg; |
421 | my (@args) = split /\s+/, $arg; |
400 | |
|
|
401 | my ($new_pw, $player); |
|
|
402 | |
|
|
403 | if ($pl->flag (cf::FLAG_WIZ)) { |
|
|
404 | ($player, $new_pw) = @args; |
422 | my ($player, $new_pw) = @args; |
405 | } else { |
|
|
406 | $new_pw = $args[0]; |
|
|
407 | } |
|
|
408 | |
423 | |
409 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
424 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
410 | $pl->message ( |
425 | $pl->message ( |
411 | "Usage: password <player> [<new password>]", |
426 | "Usage: password <player> [<new password>]", |
412 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
427 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
413 | return; |
428 | 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 | } |
429 | } |
420 | |
430 | |
421 | if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) { |
|
|
422 | unless ($new_pw ne '') { |
431 | if ($new_pw eq '') { |
423 | $new_pw = |
432 | $new_pw = |
424 | join '', |
433 | join '', |
425 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
434 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
426 | 1..9; |
435 | 1..9; |
427 | } |
436 | } |
428 | |
437 | |
429 | cf::async { |
438 | cf::async { |
430 | my $plc = cf::player::find $player; |
439 | my $plc = cf::player::find $player; |
431 | if ($plc) { |
440 | if ($plc) { |
432 | $plc->password (encode_password $new_pw); |
441 | $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 | warn "CHECK: @$change | $pl->{password_change} <<<<<\n"; |
|
|
446 | |
|
|
447 | if ($change && (time - $change->[0]) < 60) { |
|
|
448 | $pl->message ( |
442 | $pl->message ( |
449 | "Ok, changed your password!", |
443 | "Ok, changed password of '$player' to '$new_pw'!", |
450 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
444 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
451 | $pl->contr->password (encode_password $new_pw); |
|
|
452 | |
|
|
453 | } else { |
445 | } else { |
454 | $pl->message ( |
446 | $pl->message ( |
455 | "Ok, please confirm your new password by sending " |
447 | "Fail! Couldn't set password for '$player', " |
456 | . "the command again within one minute!", |
448 | . "he doesn't seem to exist!", |
457 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
449 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
458 | $pl->{password_change} = [time, $new_pw]; |
|
|
459 | } |
450 | } |
460 | } |
451 | }; |
461 | }; |
452 | }; |
462 | |
453 | |
463 | cf::register_command quit => sub { |
454 | cf::register_command quit => sub { |
464 | my ($ob, $arg) = @_; |
455 | my ($ob, $arg) = @_; |
465 | |
456 | |
… | |
… | |
477 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
468 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
478 | if ($_[0] !~ /^[yY]/) { |
469 | if ($_[0] !~ /^[yY]/) { |
479 | $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
470 | $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
480 | } else { |
471 | } else { |
481 | $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
472 | $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
482 | $pl->ns->flush; |
|
|
483 | cf::async { |
473 | cf::async { |
484 | ext::highscore::check $pl->ob; |
|
|
485 | $pl->quit_character; |
474 | $pl->quit_character; |
486 | }; |
475 | }; |
487 | } |
476 | } |
488 | }); |
477 | }); |
489 | }; |
478 | }; |
… | |
… | |
497 | |
486 | |
498 | my $pl = $ob->contr; |
487 | my $pl = $ob->contr; |
499 | |
488 | |
500 | # update respawn position |
489 | # update respawn position |
501 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
490 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
502 | cf::async { $pl->save }; |
|
|
503 | |
491 | |
|
|
492 | cf::async { |
504 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
493 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
505 | ext::highscore::check $ob; |
494 | ext::highscore::check $ob; |
506 | |
495 | |
|
|
496 | $pl->save; |
|
|
497 | |
507 | $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); |
498 | $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); |
508 | |
499 | |
|
|
500 | my $ns = $pl->ns |
|
|
501 | or return; |
|
|
502 | |
509 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
503 | $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
510 | if ($_[0] !~ /^[yY]/) { |
504 | if ($_[0] !~ /^[yY]/) { |
511 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
505 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
512 | $pl->deactivate; |
506 | $pl->deactivate; |
513 | $pl->ns->destroy; |
507 | $pl->ns->destroy; |
514 | } else { |
508 | } |
515 | cf::async { $pl->save }; |
|
|
516 | } |
509 | }); |
517 | }); |
510 | }; |
518 | }, |
511 | }, |
519 | ); |
512 | ); |
520 | |
513 | |
521 | cf::player->attach ( |
514 | cf::player->attach ( |
522 | on_login => sub { |
515 | on_login => sub { |
… | |
… | |
537 | unless safe_spot $pl; |
530 | unless safe_spot $pl; |
538 | } |
531 | } |
539 | }, |
532 | }, |
540 | ); |
533 | ); |
541 | |
534 | |
542 | |
|
|