… | |
… | |
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 | # delete a player directory, be non-blocking AND synchronous... |
135 | sub encode_password($) { |
132 | # (that's hard, so we crap out and fork). |
136 | # crypt $_[0], |
|
|
137 | # join '', |
|
|
138 | # ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)] |
|
|
139 | "!" . unpack "H*", $_[0] |
|
|
140 | } |
|
|
141 | |
|
|
142 | sub compare_password($$) { |
|
|
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 |
133 | sub nuke_playerdir { |
153 | sub nuke_playerdir { |
134 | my ($user) = @_; |
154 | my ($user) = @_; |
135 | |
155 | |
|
|
156 | my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; |
|
|
157 | |
136 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
158 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
137 | |
|
|
138 | cf::fork_call { |
|
|
139 | rename "$PLAYERDIR/$user", $temp; |
159 | aio_rename "$PLAYERDIR/$user", $temp; |
140 | system "rm", "-rf", $temp; |
160 | IO::AIO::aio_rmtree $temp; |
141 | }; |
|
|
142 | } |
161 | } |
143 | |
162 | |
144 | cf::client->attach (on_addme => sub { |
163 | cf::client->attach (on_addme => sub { |
145 | my ($ns) = @_; |
164 | my ($ns) = @_; |
146 | |
165 | |
… | |
… | |
224 | |
243 | |
225 | # try to read the user file and check the password |
244 | # try to read the user file and check the password |
226 | if (my $pl = cf::player::find $user) { |
245 | if (my $pl = cf::player::find $user) { |
227 | aio_stat $pl->path and next; |
246 | aio_stat $pl->path and next; |
228 | my $mtime = (stat _)[9]; |
247 | my $mtime = (stat _)[9]; |
229 | my $hash = $pl->password; |
248 | my $token = $pl->password; |
230 | |
249 | |
231 | 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# |
232 | nuke_str $pass; |
252 | nuke_str $pass; |
233 | # password matches, wonderful |
253 | # password matches, wonderful |
234 | my $pl = cf::player::find $user or next; |
254 | my $pl = cf::player::find $user or next; |
235 | $pl->connect ($ns); |
255 | $pl->connect ($ns); |
236 | enter_map $pl; |
256 | enter_map $pl; |
… | |
… | |
268 | ); |
288 | ); |
269 | next; |
289 | next; |
270 | } |
290 | } |
271 | } else { |
291 | } else { |
272 | # unable to load the playerfile: |
292 | # unable to load the playerfile: |
273 | # 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 |
274 | # something very similar. |
294 | # something very similar. |
275 | if (!aio_stat cf::player::playerdir $user) { |
295 | if (!aio_stat cf::player::playerdir $user) { |
276 | $ns->send_drawinfo ( |
296 | $ns->send_drawinfo ( |
277 | "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. " |
278 | . "If this is your account, ask a dungeon master for assistance. " |
298 | . "If this is your account, ask a dungeon master for assistance. " |
… | |
… | |
285 | |
305 | |
286 | # the rest of this function is character creation |
306 | # the rest of this function is character creation |
287 | $Coro::current->{desc} = "addme($user) chargen"; |
307 | $Coro::current->{desc} = "addme($user) chargen"; |
288 | |
308 | |
289 | # just to make sure nothing is left over |
309 | # just to make sure nothing is left over |
|
|
310 | # normally, nothing is there. |
290 | nuke_playerdir $user; |
311 | nuke_playerdir $user; |
291 | |
312 | |
292 | 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."; |
293 | |
314 | |
294 | if ($pass2 ne $pass) { |
315 | if ($pass2 ne $pass) { |
… | |
… | |
303 | } |
324 | } |
304 | |
325 | |
305 | nuke_str $pass2; |
326 | nuke_str $pass2; |
306 | |
327 | |
307 | my $pl = cf::player::new $user; |
328 | my $pl = cf::player::new $user; |
308 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]); |
329 | $pl->password (encode_password $pass); |
309 | nuke_str $pass; |
330 | nuke_str $pass; |
310 | $pl->connect ($ns); |
331 | $pl->connect ($ns); |
311 | my $ob = $pl->ob; |
332 | my $ob = $pl->ob; |
312 | |
333 | |
313 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
334 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
… | |
… | |
385 | $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
406 | $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
386 | } |
407 | } |
387 | }); |
408 | }); |
388 | }); |
409 | }); |
389 | |
410 | |
|
|
411 | cf::register_command password => sub { |
|
|
412 | my ($pl, $arg) = @_; |
|
|
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 | |
|
|
421 | my (@args) = split /\s+/, $arg; |
|
|
422 | my ($player, $new_pw) = @args; |
|
|
423 | |
|
|
424 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
|
|
425 | $pl->message ( |
|
|
426 | "Usage: password <player> [<new password>]", |
|
|
427 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
|
|
428 | return; |
|
|
429 | } |
|
|
430 | |
|
|
431 | if ($new_pw eq '') { |
|
|
432 | $new_pw = |
|
|
433 | join '', |
|
|
434 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
|
|
435 | 1..9; |
|
|
436 | } |
|
|
437 | |
|
|
438 | cf::async { |
|
|
439 | my $plc = cf::player::find $player; |
|
|
440 | if ($plc) { |
|
|
441 | $plc->password (encode_password $new_pw); |
|
|
442 | $pl->message ( |
|
|
443 | "Ok, changed password of '$player' to '$new_pw'!", |
|
|
444 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
445 | } else { |
|
|
446 | $pl->message ( |
|
|
447 | "Fail! Couldn't set password for '$player', " |
|
|
448 | . "he doesn't seem to exist!", |
|
|
449 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
450 | } |
|
|
451 | }; |
|
|
452 | }; |
|
|
453 | |
390 | cf::register_command quit => sub { |
454 | cf::register_command quit => sub { |
391 | my ($ob, $arg) = @_; |
455 | my ($ob, $arg) = @_; |
392 | |
456 | |
393 | $ob->send_msg (undef, |
457 | $ob->send_msg (undef, |
394 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
458 | "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 { |
468 | $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]/) { |
469 | if ($_[0] !~ /^[yY]/) { |
406 | $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); |
407 | } else { |
471 | } else { |
408 | $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); |
409 | $pl->ns->flush; |
|
|
410 | cf::async { |
473 | cf::async { |
411 | ext::highscore::check $pl->ob; |
|
|
412 | $pl->quit_character; |
474 | $pl->quit_character; |
413 | }; |
475 | }; |
414 | } |
476 | } |
415 | }); |
477 | }); |
416 | }; |
478 | }; |
… | |
… | |
424 | |
486 | |
425 | my $pl = $ob->contr; |
487 | my $pl = $ob->contr; |
426 | |
488 | |
427 | # update respawn position |
489 | # update respawn position |
428 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
490 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
429 | cf::async { $pl->save }; |
|
|
430 | |
491 | |
|
|
492 | cf::async { |
431 | 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; |
432 | ext::highscore::check $ob; |
494 | ext::highscore::check $ob; |
433 | |
495 | |
|
|
496 | $pl->save; |
|
|
497 | |
434 | $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); |
435 | |
499 | |
|
|
500 | my $ns = $pl->ns |
|
|
501 | or return; |
|
|
502 | |
436 | $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 { |
437 | if ($_[0] !~ /^[yY]/) { |
504 | if ($_[0] !~ /^[yY]/) { |
438 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
505 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
439 | $pl->deactivate; |
506 | $pl->deactivate; |
440 | $pl->ns->destroy; |
507 | $pl->ns->destroy; |
441 | } else { |
508 | } |
442 | cf::async { $pl->save }; |
|
|
443 | } |
509 | }); |
444 | }); |
510 | }; |
445 | }, |
511 | }, |
446 | ); |
512 | ); |
447 | |
513 | |
448 | cf::player->attach ( |
514 | cf::player->attach ( |
449 | on_login => sub { |
515 | on_login => sub { |
… | |
… | |
464 | unless safe_spot $pl; |
530 | unless safe_spot $pl; |
465 | } |
531 | } |
466 | }, |
532 | }, |
467 | ); |
533 | ); |
468 | |
534 | |
469 | |
|
|