… | |
… | |
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 | sub encode_password { |
131 | sub 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... |
138 | sub 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 |
139 | sub nuke_playerdir { |
149 | sub 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 | |
150 | cf::client->attach (on_addme => sub { |
159 | cf::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) { |
… | |
… | |
440 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
451 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
441 | } |
452 | } |
442 | }; |
453 | }; |
443 | } else { |
454 | } else { |
444 | my $change = delete $pl->{password_change}; |
455 | my $change = delete $pl->{password_change}; |
445 | warn "CHECK: @$change | $pl->{password_change} <<<<<\n"; |
|
|
446 | |
456 | |
447 | if ($change && (time - $change->[0]) < 60) { |
457 | if ($change && (time - $change->[0]) < 60) { |
448 | $pl->message ( |
458 | $pl->message ( |
449 | "Ok, changed your password!", |
459 | "Ok, changed your password!", |
450 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
460 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
… | |
… | |
477 | $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 { |
478 | if ($_[0] !~ /^[yY]/) { |
488 | if ($_[0] !~ /^[yY]/) { |
479 | $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); |
480 | } else { |
490 | } else { |
481 | $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); |
482 | $pl->ns->flush; |
|
|
483 | cf::async { |
492 | cf::async { |
484 | ext::highscore::check $pl->ob; |
|
|
485 | $pl->quit_character; |
493 | $pl->quit_character; |
486 | }; |
494 | }; |
487 | } |
495 | } |
488 | }); |
496 | }); |
489 | }; |
497 | }; |
… | |
… | |
497 | |
505 | |
498 | my $pl = $ob->contr; |
506 | my $pl = $ob->contr; |
499 | |
507 | |
500 | # update respawn position |
508 | # update respawn position |
501 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
509 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
502 | cf::async { $pl->save }; |
|
|
503 | |
510 | |
|
|
511 | cf::async { |
504 | 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; |
505 | ext::highscore::check $ob; |
513 | ext::highscore::check $ob; |
506 | |
514 | |
|
|
515 | $pl->save; |
|
|
516 | |
507 | $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); |
508 | |
518 | |
509 | $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 { |
510 | if ($_[0] !~ /^[yY]/) { |
520 | if ($_[0] !~ /^[yY]/) { |
511 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
521 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
512 | $pl->deactivate; |
522 | $pl->deactivate; |
513 | $pl->ns->destroy; |
523 | $pl->ns->destroy; |
514 | } else { |
524 | } |
515 | cf::async { $pl->save }; |
|
|
516 | } |
525 | }); |
517 | }); |
526 | }; |
518 | }, |
527 | }, |
519 | ); |
528 | ); |
520 | |
529 | |
521 | cf::player->attach ( |
530 | cf::player->attach ( |
522 | on_login => sub { |
531 | on_login => sub { |
… | |
… | |
537 | unless safe_spot $pl; |
546 | unless safe_spot $pl; |
538 | } |
547 | } |
539 | }, |
548 | }, |
540 | ); |
549 | ); |
541 | |
550 | |
542 | |
|
|