--- deliantra/server/ext/login.ext 2006/12/23 07:28:02 1.5 +++ deliantra/server/ext/login.ext 2007/01/05 20:04:02 1.10 @@ -7,7 +7,10 @@ my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; -# testbed for coroutines in crossfire : +# paranoia function to overwrite a string-in-place +sub nuke_str { + substr $_[0], 0, (length $_[0]), "x" x length $_[0] +} sub query { my ($ns, $flags, $text) = @_; @@ -62,12 +65,12 @@ . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; } -sub on_addme { +sub addme { my ($ns) = @_; $ns->destroy if $ns->pl; - $ns->coro (sub { + $ns->async (sub { my ($user, $pass); $ns->send_packet ("addme_success"); @@ -147,6 +150,7 @@ my $hash = $1; if ($hash eq crypt $pass, $hash) { + nuke_str $pass; # password matches, wonderful my $pl = cf::player::load $plfile or next; $pl->enable_save (1); @@ -162,6 +166,7 @@ cf::NDI_RED ); + #TODO: nuke_str (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ or next; @@ -173,6 +178,8 @@ # fall through to creation } else { + nuke_str $pass; + Coro::Timer::sleep 1; $ns->send_drawinfo ( @@ -192,6 +199,8 @@ my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; if ($pass2 ne $pass) { + nuke_str $pass; + nuke_str $pass2; $ns->send_drawinfo ( "The passwords do not match, please try again.", cf::NDI_RED @@ -199,9 +208,12 @@ next; } + nuke_str $pass2; + my $pl = cf::player::create; $pl->ob->name ($user); $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); + nuke_str $pass; $pl->connect ($ns); my $ob = $pl->ob; @@ -255,16 +267,39 @@ $ob->check_score; $ob->reply (undef, "In the future, you will wake up here when you die."); - $ob->contr->save; + $ob->contr->save (1); $ob->contr->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { - if ($_[0] !~ /^[yY]/) { - $ob->contr->save (1); - $ob->contr->ns->destroy; - } + if ($_[0] !~ /^[yY]/) { + $ob->contr->invoke (cf::EVENT_PLAYER_LOGOUT, 1); + $ob->contr->ns->destroy; + } else { + $ob->contr->enable_save (1); + } }); }, ); -cf::client->attach (package => __PACKAGE__); +cf::player->attach ( + on_login => sub { + my ($pl) = @_; + my $name = $pl->ob->name; + + $_->ob->message ("$name has entered the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; + }, + on_logout => sub { + my ($pl, $cleanly) = @_; + my $name = $pl->ob->name; + + if ($cleanly) { + $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; + } else { + $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; + } + }, +); + +cf::client->attach ( + on_addme => \&addme, +);