… | |
… | |
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 | # HACK: remove when done |
|
|
15 | sub cf::client::send_drawinfo { |
|
|
16 | my ($self, $text, $flags) = @_; |
|
|
17 | |
|
|
18 | utf8::encode $text; |
|
|
19 | $self->send_packet (sprintf "msg %d log %s", $flags || cf::NDI_BLACK, $text); |
|
|
20 | } |
|
|
21 | |
13 | |
22 | sub query { |
14 | sub query { |
23 | my ($ns, $flags, $text) = @_; |
15 | my ($ns, $flags, $text) = @_; |
24 | |
16 | |
25 | $ns->query ($flags, $text, Coro::rouse_cb); |
17 | $ns->query ($flags, $text, Coro::rouse_cb); |
… | |
… | |
95 | $ob->message ( |
87 | $ob->message ( |
96 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
88 | "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. " |
89 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
98 | . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " |
90 | . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " |
99 | . "H<You disconnected too long without having used a savebed.>", |
91 | . "H<You disconnected too long without having used a savebed.>", |
100 | cf::NDI_RED |
92 | cf::NDI_RED | cf::NDI_REPLY |
101 | ); |
93 | ); |
102 | # kill them. |
94 | # kill them. |
103 | # reminds me of the famous badness 10000 syndrome... |
95 | # reminds me of the famous badness 10000 syndrome... |
104 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
96 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
105 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
97 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
… | |
… | |
109 | $ob->message ( |
101 | $ob->message ( |
110 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
102 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
111 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
103 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
112 | . "Better use a savebed next time, much worse things could have happened... " |
104 | . "Better use a savebed next time, much worse things could have happened... " |
113 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
105 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
114 | cf::NDI_RED |
106 | cf::NDI_RED | cf::NDI_REPLY |
115 | ); |
107 | ); |
116 | } |
108 | } |
117 | } else { |
109 | } else { |
118 | $ob->message ( |
110 | $ob->message ( |
119 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
111 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
120 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
112 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
121 | . "or monsters suddenly snapping your body. Better use a savebed next time. " |
113 | . "or monsters suddenly snapping your body. Better use a savebed next time. " |
122 | . "H<Always apply a bed of reality to disconnect from the server.>", |
114 | . "H<Always apply a bed of reality to disconnect from the server.>", |
123 | cf::NDI_RED |
115 | cf::NDI_RED | cf::NDI_REPLY |
124 | ); |
116 | ); |
125 | } |
117 | } |
126 | } |
118 | } |
127 | |
119 | |
128 | $ob->goto ($map, $x, $y); |
120 | $ob->goto ($map, $x, $y); |
… | |
… | |
287 | $ns->send_packet ("addme_success"); |
279 | $ns->send_packet ("addme_success"); |
288 | |
280 | |
289 | for (;;) { |
281 | for (;;) { |
290 | delete $ns->{login_guard}; |
282 | delete $ns->{login_guard}; |
291 | |
283 | |
292 | $ns->send_drawinfo ( |
284 | $ns->send_msg (log => |
293 | "Please enter your username now. If you are a new user, " |
285 | "Please enter your username now. If you are a new user, " |
294 | . "make one up that describes your character best. " |
286 | . "make one up that describes your character best. " |
295 | . "Only letters and digits are allowed, though.", |
287 | . "Only letters and digits are allowed, though.", |
296 | cf::NDI_BLUE |
288 | cf::NDI_BLUE | cf::NDI_REPLY |
297 | ); |
289 | ); |
298 | |
290 | |
299 | # read username |
291 | # read username |
300 | while () { |
292 | while () { |
301 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
293 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
302 | |
294 | |
303 | if ($user =~ $VALID_LOGIN) { |
295 | if ($user =~ $VALID_LOGIN) { |
304 | last; |
296 | last; |
305 | } else { |
297 | } else { |
306 | $ns->send_drawinfo ( |
298 | $ns->send_msg (log => |
307 | "Your username contains illegal characters " |
299 | "Your username contains illegal characters " |
308 | . "(only a-z, A-Z and 0-9 are allowed), " |
300 | . "(only a-z, A-Z and 0-9 are allowed), " |
309 | . "or is not between 3 and 20 characters in length.", |
301 | . "or is not between 3 and 20 characters in length.", |
310 | cf::NDI_RED |
302 | cf::NDI_RED | cf::NDI_REPLY |
311 | ); |
303 | ); |
312 | } |
304 | } |
313 | Coro::Timer::sleep 0.4; |
305 | Coro::Timer::sleep 0.4; |
314 | } |
306 | } |
315 | |
307 | |
316 | $Coro::current->{desc} = "addme($user)"; |
308 | $Coro::current->{desc} = "addme($user)"; |
317 | |
309 | |
318 | $ns->send_drawinfo ( |
310 | $ns->send_msg (log => |
319 | "Welcome $user, please enter your password now. " |
311 | "Welcome $user, please enter your password now. " |
320 | . "New users should now choose a password. " |
312 | . "New users should now choose a password. " |
321 | . "Anything your client lets you enter is fine.", |
313 | . "Anything your client lets you enter is fine.", |
322 | cf::NDI_BLUE |
314 | cf::NDI_BLUE | cf::NDI_REPLY |
323 | ); |
315 | ); |
324 | |
316 | |
325 | # read password |
317 | # read password |
326 | while () { |
318 | while () { |
327 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
319 | $pass = query $ns, cf::CS_QUERY_HIDEINPUT, "What is your password?\n:"; |
328 | last if $pass =~ /.../; |
320 | last if $pass =~ /.../; |
329 | $ns->send_drawinfo ( |
321 | $ns->send_msg (log => |
330 | "Try to use at least three characters as your password please, " |
322 | "Try to use at least three characters as your password please, " |
331 | . "that cannot be too much to ask for :)", |
323 | . "that cannot be too much to ask for :)", |
332 | cf::NDI_RED |
324 | cf::NDI_RED | cf::NDI_REPLY |
333 | ); |
325 | ); |
334 | Coro::Timer::sleep 0.4; |
326 | Coro::Timer::sleep 0.4; |
335 | } |
327 | } |
336 | |
328 | |
337 | $ns->{login_guard} = login_guard $user |
329 | $ns->{login_guard} = login_guard $user |
338 | or do { |
330 | or do { |
339 | $ns->send_drawinfo ( |
331 | $ns->send_msg (log => |
340 | "That user is already logged in (or is logging in)." |
332 | "That user is already logged in (or is logging in)." |
341 | . "Chose another, or wait till the other session has ended.", |
333 | . "Chose another, or wait till the other session has ended.", |
342 | cf::NDI_RED |
334 | cf::NDI_RED | cf::NDI_REPLY |
343 | ); |
335 | ); |
344 | next; |
336 | next; |
345 | }; |
337 | }; |
346 | |
338 | |
347 | # try to read the user file and check the password |
339 | # try to read the user file and check the password |
… | |
… | |
360 | login $pl; |
352 | login $pl; |
361 | return; |
353 | return; |
362 | } elsif (can_cleanup $pl, $mtime) { |
354 | } elsif (can_cleanup $pl, $mtime) { |
363 | Coro::Timer::sleep 1; |
355 | Coro::Timer::sleep 1; |
364 | |
356 | |
365 | $ns->send_drawinfo ( |
357 | $ns->send_msg (log => |
366 | "Player exists, but password does not match. If this is your account, " |
358 | "Player exists, but password does not match. If this is your account, " |
367 | . "please try again. If not, you can now decide to take over this account " |
359 | . "please try again. If not, you can now decide to take over this account " |
368 | . "because it has not been in-use for some time.", |
360 | . "because it has not been in-use for some time.", |
369 | cf::NDI_RED |
361 | cf::NDI_RED | cf::NDI_REPLY |
370 | ); |
362 | ); |
371 | |
363 | |
372 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
364 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
373 | or next; |
365 | or next; |
374 | |
366 | |
… | |
… | |
380 | |
372 | |
381 | # fall through to creation |
373 | # fall through to creation |
382 | } else { |
374 | } else { |
383 | Coro::Timer::sleep 1; |
375 | Coro::Timer::sleep 1; |
384 | |
376 | |
385 | $ns->send_drawinfo ( |
377 | $ns->send_msg (log => |
386 | "Wrong username or password. Please try again " |
378 | "Wrong username or password. Please try again " |
387 | . "(check for Numlock and other semi-obvious error sources).", |
379 | . "(check for Numlock and other semi-obvious error sources).", |
388 | cf::NDI_RED |
380 | cf::NDI_RED | cf::NDI_REPLY |
389 | ); |
381 | ); |
390 | next; |
382 | next; |
391 | } |
383 | } |
392 | } else { |
384 | } else { |
393 | # unable to load the playerfile: |
385 | # unable to load the playerfile: |
394 | # check whether the player dir exists, which means the file is corrupted or |
386 | # check whether the player dir exists, which means the file is corrupted or |
395 | # something very similar. |
387 | # something very similar. |
396 | if (!aio_stat cf::player::playerdir $user) { |
388 | if (!aio_stat cf::player::playerdir $user) { |
397 | $ns->send_drawinfo ( |
389 | $ns->send_msg ( log => |
398 | "Unable to retrieve this player. It might be a locked or broken account. " |
390 | "Unable to retrieve this player. It might be a locked or broken account. " |
399 | . "If this is your account, ask a dungeon master for assistance. " |
391 | . "If this is your account, ask a dungeon master for assistance. " |
400 | . "Otherwise choose a different login name.", |
392 | . "Otherwise choose a different login name.", |
401 | cf::NDI_RED |
393 | cf::NDI_RED | cf::NDI_REPLY |
402 | ); |
394 | ); |
403 | next; |
395 | next; |
404 | } |
396 | } |
405 | } |
397 | } |
406 | |
398 | |
407 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
399 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
408 | |
400 | |
409 | if ($pass2 ne $pass) { |
401 | if ($pass2 ne $pass) { |
410 | $ns->send_drawinfo ( |
402 | $ns->send_msg (log => |
411 | "The passwords do not match, please try again.", |
403 | "The passwords do not match, please try again.", |
412 | cf::NDI_RED |
404 | cf::NDI_RED | cf::NDI_REPLY |
413 | ); |
405 | ); |
414 | Coro::Timer::sleep 0.5; |
406 | Coro::Timer::sleep 0.5; |
415 | next; |
407 | next; |
416 | } |
408 | } |
417 | |
409 | |