… | |
… | |
8 | |
8 | |
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 | |
|
|
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 | } |
13 | |
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); |
… | |
… | |
279 | $ns->send_packet ("addme_success"); |
286 | $ns->send_packet ("addme_success"); |
280 | |
287 | |
281 | for (;;) { |
288 | for (;;) { |
282 | delete $ns->{login_guard}; |
289 | delete $ns->{login_guard}; |
283 | |
290 | |
284 | $ns->send_msg (log => |
291 | send_log $ns, |
285 | "Please enter your username now. If you are a new user, " |
292 | "Please enter your username now. If you are a new user, " |
286 | . "make one up that describes your character best. " |
293 | . "make one up that describes your character best. " |
287 | . "Only letters and digits are allowed, though.", |
294 | . "Only letters and digits are allowed, though.", |
288 | cf::NDI_BLUE | cf::NDI_REPLY |
295 | cf::NDI_BLUE | cf::NDI_REPLY |
289 | ); |
296 | ; |
290 | |
297 | |
291 | # read username |
298 | # read username |
292 | while () { |
299 | while () { |
293 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
300 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
294 | |
301 | |
295 | if ($user =~ $VALID_LOGIN) { |
302 | if ($user =~ $VALID_LOGIN) { |
296 | last; |
303 | last; |
297 | } else { |
304 | } else { |
298 | $ns->send_msg (log => |
305 | send_log $ns, |
299 | "Your username contains illegal characters " |
306 | "Your username contains illegal characters " |
300 | . "(only a-z, A-Z and 0-9 are allowed), " |
307 | . "(only a-z, A-Z and 0-9 are allowed), " |
301 | . "or is not between 3 and 20 characters in length.", |
308 | . "or is not between 3 and 20 characters in length.", |
302 | cf::NDI_RED | cf::NDI_REPLY |
309 | cf::NDI_RED | cf::NDI_REPLY |
303 | ); |
310 | ; |
304 | } |
311 | } |
305 | Coro::Timer::sleep 0.4; |
312 | Coro::Timer::sleep 0.4; |
306 | } |
313 | } |
307 | |
314 | |
308 | $Coro::current->{desc} = "addme($user)"; |
315 | $Coro::current->{desc} = "addme($user)"; |
309 | |
316 | |
310 | $ns->send_msg (log => |
317 | send_log $ns, |
311 | "Welcome $user, please enter your password now. " |
318 | "Welcome $user, please enter your password now. " |
312 | . "New users should now choose a password. " |
319 | . "New users should now choose a password. " |
313 | . "Anything your client lets you enter is fine.", |
320 | . "Anything your client lets you enter is fine.", |
314 | cf::NDI_BLUE | cf::NDI_REPLY |
321 | cf::NDI_BLUE | cf::NDI_REPLY |
315 | ); |
322 | ; |
316 | |
323 | |
317 | # read password |
324 | # read password |
318 | while () { |
325 | while () { |
319 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
326 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
320 | last if $pass =~ /.../; |
327 | last if $pass =~ /.../; |
321 | $ns->send_msg (log => |
328 | send_log $ns, |
322 | "Try to use at least three characters as your password please, " |
329 | "Try to use at least three characters as your password please, " |
323 | . "that cannot be too much to ask for :)", |
330 | . "that cannot be too much to ask for :)", |
324 | cf::NDI_RED | cf::NDI_REPLY |
331 | cf::NDI_RED | cf::NDI_REPLY |
325 | ); |
332 | ; |
326 | Coro::Timer::sleep 0.4; |
333 | Coro::Timer::sleep 0.4; |
327 | } |
334 | } |
328 | |
335 | |
329 | $ns->{login_guard} = login_guard $user |
336 | $ns->{login_guard} = login_guard $user |
330 | or do { |
337 | or do { |
331 | $ns->send_msg (log => |
338 | send_log $ns, |
332 | "That user is already logged in (or is logging in)." |
339 | "That user is already logged in (or is logging in)." |
333 | . "Chose another, or wait till the other session has ended.", |
340 | . "Chose another, or wait till the other session has ended.", |
334 | cf::NDI_RED | cf::NDI_REPLY |
341 | cf::NDI_RED | cf::NDI_REPLY |
335 | ); |
342 | ; |
336 | next; |
343 | next; |
337 | }; |
344 | }; |
338 | |
345 | |
339 | # try to read the user file and check the password |
346 | # try to read the user file and check the password |
340 | if (my $pl = cf::player::find $user) { |
347 | if (my $pl = cf::player::find $user) { |
… | |
… | |
352 | login $pl; |
359 | login $pl; |
353 | return; |
360 | return; |
354 | } elsif (can_cleanup $pl, $mtime) { |
361 | } elsif (can_cleanup $pl, $mtime) { |
355 | Coro::Timer::sleep 1; |
362 | Coro::Timer::sleep 1; |
356 | |
363 | |
357 | $ns->send_msg (log => |
364 | send_log $ns, |
358 | "Player exists, but password does not match. If this is your account, " |
365 | "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 " |
366 | . "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.", |
367 | . "because it has not been in-use for some time.", |
361 | cf::NDI_RED | cf::NDI_REPLY |
368 | cf::NDI_RED | cf::NDI_REPLY |
362 | ); |
369 | ; |
363 | |
370 | |
364 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
371 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
365 | or next; |
372 | or next; |
366 | |
373 | |
367 | # check if the file hasn't changed |
374 | # check if the file hasn't changed |
… | |
… | |
372 | |
379 | |
373 | # fall through to creation |
380 | # fall through to creation |
374 | } else { |
381 | } else { |
375 | Coro::Timer::sleep 1; |
382 | Coro::Timer::sleep 1; |
376 | |
383 | |
377 | $ns->send_msg (log => |
384 | send_log $ns, |
378 | "Wrong username or password. Please try again " |
385 | "Wrong username or password. Please try again " |
379 | . "(check for Numlock and other semi-obvious error sources).", |
386 | . "(check for Numlock and other semi-obvious error sources).", |
380 | cf::NDI_RED | cf::NDI_REPLY |
387 | cf::NDI_RED | cf::NDI_REPLY |
381 | ); |
388 | ; |
382 | next; |
389 | next; |
383 | } |
390 | } |
384 | } else { |
391 | } else { |
385 | # unable to load the playerfile: |
392 | # unable to load the playerfile: |
386 | # check whether the player dir exists, which means the file is corrupted or |
393 | # check whether the player dir exists, which means the file is corrupted or |
387 | # something very similar. |
394 | # something very similar. |
388 | if (!aio_stat cf::player::playerdir $user) { |
395 | if (!aio_stat cf::player::playerdir $user) { |
389 | $ns->send_msg ( log => |
396 | send_log $ns, |
390 | "Unable to retrieve this player. It might be a locked or broken account. " |
397 | "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. " |
398 | . "If this is your account, ask a dungeon master for assistance. " |
392 | . "Otherwise choose a different login name.", |
399 | . "Otherwise choose a different login name.", |
393 | cf::NDI_RED | cf::NDI_REPLY |
400 | cf::NDI_RED | cf::NDI_REPLY |
394 | ); |
401 | ; |
395 | next; |
402 | next; |
396 | } |
403 | } |
397 | } |
404 | } |
398 | |
405 | |
399 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
406 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
400 | |
407 | |
401 | if ($pass2 ne $pass) { |
408 | if ($pass2 ne $pass) { |
402 | $ns->send_msg (log => |
409 | send_log $ns, |
403 | "The passwords do not match, please try again.", |
410 | "The passwords do not match, please try again.", |
404 | cf::NDI_RED | cf::NDI_REPLY |
411 | cf::NDI_RED | cf::NDI_REPLY |
405 | ); |
412 | ; |
406 | Coro::Timer::sleep 0.5; |
413 | Coro::Timer::sleep 0.5; |
407 | next; |
414 | next; |
408 | } |
415 | } |
409 | |
416 | |
410 | last; |
417 | last; |