ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.130 by root, Sun Nov 18 10:00:55 2012 UTC vs.
Revision 1.132 by root, Tue Nov 20 14:30:22 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines