… | |
… | |
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) { |
… | |
… | |
476 | $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 { |
477 | if ($_[0] !~ /^[yY]/) { |
488 | if ($_[0] !~ /^[yY]/) { |
478 | $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); |
479 | } else { |
490 | } else { |
480 | $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); |
481 | $pl->ns->flush; |
|
|
482 | cf::async { |
492 | cf::async { |
483 | ext::highscore::check $pl->ob; |
|
|
484 | $pl->quit_character; |
493 | $pl->quit_character; |
485 | }; |
494 | }; |
486 | } |
495 | } |
487 | }); |
496 | }); |
488 | }; |
497 | }; |
… | |
… | |
496 | |
505 | |
497 | my $pl = $ob->contr; |
506 | my $pl = $ob->contr; |
498 | |
507 | |
499 | # update respawn position |
508 | # update respawn position |
500 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
509 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
501 | cf::async { $pl->save }; |
|
|
502 | |
510 | |
|
|
511 | cf::async { |
503 | 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; |
504 | ext::highscore::check $ob; |
513 | ext::highscore::check $ob; |
505 | |
514 | |
|
|
515 | $pl->save; |
|
|
516 | |
506 | $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); |
507 | |
518 | |
508 | $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 { |
509 | if ($_[0] !~ /^[yY]/) { |
520 | if ($_[0] !~ /^[yY]/) { |
510 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
521 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
511 | $pl->deactivate; |
522 | $pl->deactivate; |
512 | $pl->ns->destroy; |
523 | $pl->ns->destroy; |
513 | } else { |
524 | } |
514 | cf::async { $pl->save }; |
|
|
515 | } |
525 | }); |
516 | }); |
526 | }; |
517 | }, |
527 | }, |
518 | ); |
528 | ); |
519 | |
529 | |
520 | cf::player->attach ( |
530 | cf::player->attach ( |
521 | on_login => sub { |
531 | on_login => sub { |