… | |
… | |
9 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | CONF MAX_DISCONNECT_TIME = 3600; |
10 | |
10 | |
11 | our $VALID_LOGIN = qr<^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z>; |
11 | our $VALID_LOGIN = qr<^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z>; |
12 | our %LOGIN_LOCK; |
12 | our %LOGIN_LOCK; |
13 | |
13 | |
|
|
14 | # utility function to send messages to the client before |
|
|
15 | # we have a player object to format them for. does not |
|
|
16 | # escape anything. |
|
|
17 | sub send_log ($$$) { |
|
|
18 | $_[0]->send_packet ("msg $_[2] log $_[1]"); |
|
|
19 | } |
|
|
20 | |
14 | sub query { |
21 | sub query { |
15 | my ($ns, $flags, $text) = @_; |
22 | my ($ns, $flags, $text) = @_; |
16 | |
23 | |
17 | $ns->query ($flags, $text, Coro::rouse_cb); |
24 | $ns->query ($flags, $text, Coro::rouse_cb); |
18 | Coro::rouse_wait |
25 | Coro::rouse_wait |
19 | } |
26 | } |
20 | |
27 | |
21 | sub can_cleanup { |
28 | sub can_cleanup { |
|
|
29 | return 0; # highscore list is not cleared out, rethink |
|
|
30 | |
22 | my ($pl, $mtime) = @_; |
31 | my ($pl, $mtime) = @_; |
23 | |
32 | |
24 | my $age = time - $mtime; |
33 | my $age = time - $mtime; |
25 | my $level = $pl->ob->level; |
34 | my $level = $pl->ob->level; |
26 | |
35 | |
… | |
… | |
130 | if ($token =~ /!!(.*)/) { |
139 | if ($token =~ /!!(.*)/) { |
131 | return +(substr $pass, 0, 8) eq pack "H*", $1; |
140 | return +(substr $pass, 0, 8) eq pack "H*", $1; |
132 | } elsif ($token =~ /!(.*)/) { |
141 | } elsif ($token =~ /!(.*)/) { |
133 | return $pass eq pack "H*", $1; |
142 | return $pass eq pack "H*", $1; |
134 | } else { |
143 | } else { |
135 | return $token eq crypt $pass, $token; |
144 | return $token eq encode_password $pass; |
136 | } |
145 | } |
137 | } |
146 | } |
138 | |
147 | |
139 | # delete a player directory |
148 | # delete a player directory |
140 | sub nuke_playerdir { |
149 | sub nuke_playerdir { |
… | |
… | |
241 | $pl->esrv_new_player; |
250 | $pl->esrv_new_player; |
242 | |
251 | |
243 | $pl->{chargen} = "done"; |
252 | $pl->{chargen} = "done"; |
244 | } |
253 | } |
245 | |
254 | |
|
|
255 | $ns->update_command_faces; |
|
|
256 | |
246 | $ob->reply (undef, "Welcome to Deliantra!"); |
257 | $ob->reply (undef, "Welcome to Deliantra!"); |
247 | |
258 | |
248 | if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { |
259 | if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { |
249 | $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
260 | $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
250 | } |
261 | } |
… | |
… | |
279 | $ns->send_packet ("addme_success"); |
290 | $ns->send_packet ("addme_success"); |
280 | |
291 | |
281 | for (;;) { |
292 | for (;;) { |
282 | delete $ns->{login_guard}; |
293 | delete $ns->{login_guard}; |
283 | |
294 | |
284 | $ns->send_msg (log => |
295 | send_log $ns, |
285 | "Please enter your username now. If you are a new user, " |
296 | "Please enter your username now. If you are a new user, " |
286 | . "make one up that describes your character best. " |
297 | . "make one up that describes your character best. " |
287 | . "Only letters and digits are allowed, though.", |
298 | . "Only letters and digits are allowed, though.", |
288 | cf::NDI_BLUE | cf::NDI_REPLY |
299 | cf::NDI_BLUE | cf::NDI_REPLY |
289 | ); |
300 | ; |
290 | |
301 | |
291 | # read username |
302 | # read username |
292 | while () { |
303 | while () { |
293 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
304 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
294 | |
305 | |
295 | if ($user =~ $VALID_LOGIN) { |
306 | if ($user =~ $VALID_LOGIN) { |
296 | last; |
307 | last; |
297 | } else { |
308 | } else { |
298 | $ns->send_msg (log => |
309 | send_log $ns, |
299 | "Your username contains illegal characters " |
310 | "Your username contains illegal characters " |
300 | . "(only a-z, A-Z and 0-9 are allowed), " |
311 | . "(only a-z, A-Z and 0-9 are allowed), " |
301 | . "or is not between 3 and 20 characters in length.", |
312 | . "or is not between 3 and 20 characters in length.", |
302 | cf::NDI_RED | cf::NDI_REPLY |
313 | cf::NDI_RED | cf::NDI_REPLY |
303 | ); |
314 | ; |
304 | } |
315 | } |
305 | Coro::Timer::sleep 0.4; |
316 | Coro::Timer::sleep 0.4; |
306 | } |
317 | } |
307 | |
318 | |
308 | $Coro::current->{desc} = "addme($user)"; |
319 | $Coro::current->{desc} = "addme($user)"; |
309 | |
320 | |
310 | $ns->send_msg (log => |
321 | send_log $ns, |
311 | "Welcome $user, please enter your password now. " |
322 | "Welcome $user, please enter your password now. " |
312 | . "New users should now choose a password. " |
323 | . "New users should now choose a password. " |
313 | . "Anything your client lets you enter is fine.", |
324 | . "Anything your client lets you enter is fine.", |
314 | cf::NDI_BLUE | cf::NDI_REPLY |
325 | cf::NDI_BLUE | cf::NDI_REPLY |
315 | ); |
326 | ; |
316 | |
327 | |
317 | # read password |
328 | # read password |
318 | while () { |
329 | while () { |
319 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
330 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
320 | last if $pass =~ /.../; |
331 | last if $pass =~ /.../; |
321 | $ns->send_msg (log => |
332 | send_log $ns, |
322 | "Try to use at least three characters as your password please, " |
333 | "Try to use at least three characters as your password please, " |
323 | . "that cannot be too much to ask for :)", |
334 | . "that cannot be too much to ask for :)", |
324 | cf::NDI_RED | cf::NDI_REPLY |
335 | cf::NDI_RED | cf::NDI_REPLY |
325 | ); |
336 | ; |
326 | Coro::Timer::sleep 0.4; |
337 | Coro::Timer::sleep 0.4; |
327 | } |
338 | } |
328 | |
339 | |
329 | $ns->{login_guard} = login_guard $user |
340 | $ns->{login_guard} = login_guard $user |
330 | or do { |
341 | or do { |
331 | $ns->send_msg (log => |
342 | send_log $ns, |
332 | "That user is already logged in (or is logging in)." |
343 | "That user is already logged in (or is logging in)." |
333 | . "Chose another, or wait till the other session has ended.", |
344 | . "Chose another, or wait till the other session has ended.", |
334 | cf::NDI_RED | cf::NDI_REPLY |
345 | cf::NDI_RED | cf::NDI_REPLY |
335 | ); |
346 | ; |
336 | next; |
347 | next; |
337 | }; |
348 | }; |
338 | |
349 | |
339 | # try to read the user file and check the password |
350 | # try to read the user file and check the password |
340 | if (my $pl = cf::player::find $user) { |
351 | if (my $pl = cf::player::find $user) { |
… | |
… | |
352 | login $pl; |
363 | login $pl; |
353 | return; |
364 | return; |
354 | } elsif (can_cleanup $pl, $mtime) { |
365 | } elsif (can_cleanup $pl, $mtime) { |
355 | Coro::Timer::sleep 1; |
366 | Coro::Timer::sleep 1; |
356 | |
367 | |
357 | $ns->send_msg (log => |
368 | send_log $ns, |
358 | "Player exists, but password does not match. If this is your account, " |
369 | "Player exists, but password does not match. If this is your account, " |
359 | . "please try again. If not, you can now decide to take over this account " |
370 | . "please try again. If not, you can now decide to take over this account " |
360 | . "because it has not been in-use for some time.", |
371 | . "because it has not been in-use for some time.", |
361 | cf::NDI_RED | cf::NDI_REPLY |
372 | cf::NDI_RED | cf::NDI_REPLY |
362 | ); |
373 | ; |
363 | |
374 | |
364 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
375 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
365 | or next; |
376 | or next; |
366 | |
377 | |
367 | # check if the file hasn't changed |
378 | # check if the file hasn't changed |
… | |
… | |
372 | |
383 | |
373 | # fall through to creation |
384 | # fall through to creation |
374 | } else { |
385 | } else { |
375 | Coro::Timer::sleep 1; |
386 | Coro::Timer::sleep 1; |
376 | |
387 | |
377 | $ns->send_msg (log => |
388 | send_log $ns, |
378 | "Wrong username or password. Please try again " |
389 | "Wrong username or password. Please try again " |
379 | . "(check for Numlock and other semi-obvious error sources).", |
390 | . "(check for Numlock and other semi-obvious error sources).", |
380 | cf::NDI_RED | cf::NDI_REPLY |
391 | cf::NDI_RED | cf::NDI_REPLY |
381 | ); |
392 | ; |
382 | next; |
393 | next; |
383 | } |
394 | } |
384 | } else { |
395 | } else { |
385 | # unable to load the playerfile: |
396 | # unable to load the playerfile: |
386 | # check whether the player dir exists, which means the file is corrupted or |
397 | # check whether the player dir exists, which means the file is corrupted or |
387 | # something very similar. |
398 | # something very similar. |
388 | if (!aio_stat cf::player::playerdir $user) { |
399 | if (!aio_stat cf::player::playerdir $user) { |
389 | $ns->send_msg ( log => |
400 | send_log $ns, |
390 | "Unable to retrieve this player. It might be a locked or broken account. " |
401 | "Unable to retrieve this player. It might be a locked or broken account. " |
391 | . "If this is your account, ask a dungeon master for assistance. " |
402 | . "If this is your account, ask a dungeon master for assistance. " |
392 | . "Otherwise choose a different login name.", |
403 | . "Otherwise choose a different login name.", |
393 | cf::NDI_RED | cf::NDI_REPLY |
404 | cf::NDI_RED | cf::NDI_REPLY |
394 | ); |
405 | ; |
395 | next; |
406 | next; |
396 | } |
407 | } |
397 | } |
408 | } |
398 | |
409 | |
399 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
410 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
400 | |
411 | |
401 | if ($pass2 ne $pass) { |
412 | if ($pass2 ne $pass) { |
402 | $ns->send_msg (log => |
413 | send_log $ns, |
403 | "The passwords do not match, please try again.", |
414 | "The passwords do not match, please try again.", |
404 | cf::NDI_RED | cf::NDI_REPLY |
415 | cf::NDI_RED | cf::NDI_REPLY |
405 | ); |
416 | ; |
406 | Coro::Timer::sleep 0.5; |
417 | Coro::Timer::sleep 0.5; |
407 | next; |
418 | next; |
408 | } |
419 | } |
409 | |
420 | |
410 | last; |
421 | last; |