--- deliantra/server/ext/login.ext 2006/12/22 16:34:00 1.1 +++ deliantra/server/ext/login.ext 2006/12/26 04:46:06 1.6 @@ -83,13 +83,23 @@ # read username while () { $user = query $ns, 0, "What is your name?\n:"; - last if $user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}$/; - $ns->send_drawinfo ( - "Your username contains illegal characters " - . "(only a-z, A-Z and 0-9 are allowed), " - . "or is not between 3 and 18 characters in length.", - cf::NDI_RED - ); + + if ($cf::LOGIN_LOCK{$user}) { + $ns->send_drawinfo ( + "That username is currently used in another login session. " + . "Chose another, or wait till the other session has ended.", + cf::NDI_RED + ); + } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}$/) { + last; + } else { + $ns->send_drawinfo ( + "Your username contains illegal characters " + . "(only a-z, A-Z and 0-9 are allowed), " + . "or is not between 3 and 18 characters in length.", + cf::NDI_RED + ); + } } check_playing $ns, $user and next; @@ -112,11 +122,22 @@ ); } - check_playing $ns, $user and next; - my $dir = "$PLAYERDIR/$user"; my $plfile = "$dir/$user.pl"; + # lock this username for the remainder of this login session + if ($cf::LOGIN_LOCK{$user}) { + $ns->send_drawinfo ( + "That username is currently used in another login session. " + . "Chose another, or wait till the other session has ended.", + cf::NDI_RED + ); + next; + } + local $cf::LOGIN_LOCK{$user} = 1; + + check_playing $ns, $user and next; + # try to read the user file and check the password if (my $fh = aio_open $plfile, O_RDONLY, 0) { my $mtime = (stat $fh)[9]; @@ -125,22 +146,18 @@ $buf =~ /^password (\S+)$/m or next; my $hash = $1; - check_playing $ns, $user and next; - if ($hash eq crypt $pass, $hash) { # password matches, wonderful my $pl = cf::player::load $plfile or next; $pl->enable_save (1); $pl->connect ($ns); last; - } - - if (can_cleanup $buf, $mtime) { + } elsif (can_cleanup $buf, $mtime) { Coro::Timer::sleep 1; $ns->send_drawinfo ( - "Player exists, but password does not match. If this is you account, " - . "please try again. If not, you can now opt to take over this account " + "Player exists, but password does not match. If this is your account, " + . "please try again. If not, you can now decide to take over this account " . "because it has not been in-use for some time.", cf::NDI_RED ); @@ -149,10 +166,9 @@ or next; # check if the file hasn't changed - aio_stat $plfile or next; + aio_stat $plfile and next; $mtime == (stat _)[9] or next; - # nuke playerdir, this might block, but it needs to be atomic nuke_playerdir $user; # fall through to creation @@ -169,14 +185,25 @@ } # the rest of this function is character creation - check_playing $ns, $user and next; + # just to make sure nothing is left over nuke_playerdir $user; + my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; + + if ($pass2 ne $pass) { + $ns->send_drawinfo ( + "The passwords do not match, please try again.", + cf::NDI_RED + ); + next; + } + my $pl = cf::player::create; $pl->ob->name ($user); $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); $pl->connect ($ns); + my $ob = $pl->ob; while () { @@ -207,6 +234,7 @@ "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); $ns->state (cf::ST_CHANGE_CLASS); + $pl->enable_save (1);#d# too early last; } @@ -220,23 +248,21 @@ return cf::override 0 unless $ob->type == cf::PLAYER; - my $ns = $ob->contr->ns; - # update respawn position $ob->contr->savebed ($bed->map->path, $bed->x, $bed->y); - #TODO? - #strcpy (pl->contr->killer, "left"); - #check_score (pl); /* Always check score */ + $ob->contr->killer ("left"); + $ob->check_score; $ob->reply (undef, "In the future, you will wake up here when you die."); - $ob->contr->save (); + $ob->contr->save (1); - $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { - if ($_[0] !~ /^[yY]/) { - $ob->contr->save (1); - $ns->destroy (); - } + $ob->contr->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { + $ob->contr->enable_save (1); + if ($_[0] !~ /^[yY]/) { + $ob->contr->save (1); + $ob->contr->ns->destroy; + } }); }, );