--- deliantra/server/ext/login.ext 2007/04/24 00:42:02 1.45 +++ deliantra/server/ext/login.ext 2007/07/01 03:16:56 1.58 @@ -1,4 +1,4 @@ -#! perl # MANDATORY +#! perl # mandatory # login handling @@ -6,6 +6,8 @@ use Coro::AIO; use List::Util qw(min max); +our %EXT_SETUP; + # paranoia function to overwrite a string-in-place sub nuke_str { substr $_[0], 0, (length $_[0]), "x" x length $_[0] @@ -53,18 +55,44 @@ 1 } -sub check_clean_save { +sub enter_map { my ($pl) = @_; + my ($map, $x, $y) + = $pl->ob->{_link_pos} + ? @{delete $pl->ob->{_link_pos}} + : ($pl->maplevel, $pl->ob->x, $pl->ob->y); + + $pl->ob->enter_link; + if (my $time = delete $pl->{unclean_save}) { - $pl->ns->send_drawinfo ( - "You didn't use a savebed to leave this realm. This is very dangerous, " - . "as lots of things could happen when you leave by other means, such as cave-ins, " - . "or monsters suddenly snapping your body. Better use a savebed next time.", - cf::NDI_RED - ); - #d#TODO + if (my $m = cf::map::find $map) { + if ($time < $m->{instantiate_time}) { + # the map was reset in the meantime + my $age = $cf::RUNTIME - $time; + warn $pl->ob->name, " map reset after logout, logout age $age\n";#d# + + # for now, just go back to savebed + ($map, $x, $y) = $pl->savebed; + + $pl->ns->send_drawinfo ( + "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " + . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " + . "Better use a savebed next time, much worse things could have happened...", + cf::NDI_RED + ); + } else { + $pl->ns->send_drawinfo ( + "You didn't use a bed to reality to leave this realm. This is very dangerous, " + . "as lots of things could happen when you leave by other means, such as cave-ins, " + . "or monsters suddenly snapping your body. Better use a savebed next time.", + cf::NDI_RED + ); + } + } } + + $pl->ob->goto ($map, $x, $y); } # delete a player directory, be non-blocking AND synchronous... @@ -179,10 +207,18 @@ $ns->smoothing ($v); } elsif ($k eq "fxix") { + $v = 2 if $v > 2; $ns->fxix ($v); + $setup{$k} = $v; } elsif ($k eq "msg") { - $ns->can_msg ($v); + $v = 2 if $v > 2; + $ns->can_msg ($v >= 2); + $setup{$k} = $v; + + } elsif ($k eq "xwidget") { + # eXperimental server-side widgets + $ns->{can_widget} = 1; } elsif ($k eq "excmd") { # we support it @@ -334,7 +370,7 @@ # password matches, wonderful my $pl = cf::player::find $user or next; $pl->connect ($ns); - check_clean_save $pl; + enter_map $pl; last; } elsif (can_cleanup $pl, $mtime) { Coro::Timer::sleep 1; @@ -407,9 +443,10 @@ $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; + $ob->goto ($pl->maplevel, $ob->x, $ob->y); + while () { $ob->update_stats; $pl->save_stats; @@ -436,7 +473,7 @@ while () { $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); my $msg = $ob->msg; - $msg =~ s/\b\n\b/ /g; + $msg =~ s/(?<=\S)\n(?=\S)/ /g; $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); my $res = query $ns, cf::CS_QUERY_SINGLECHAR, @@ -449,6 +486,21 @@ $pl->chargen_race_done; + while () { + my $res = query $ns, cf::CS_QUERY_SINGLECHAR, + "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; + + if ($res =~ /^[fF]/) { + $pl->gender (1); + last; + } elsif ($res =~ /^[mM]/) { + $pl->gender (0); + last; + } + } + + $ob->reply (undef, "Welcome to Crossfire!"); + delete $pl->{deny_save}; last; @@ -565,29 +617,28 @@ cf::wait_for_tick_begin; $pl->save; - unless ($pl->active) { + unless ($pl->active || $pl->ns) { # check refcounts, this is tricky and needs to be adjusted to fit server internals my $ob = $pl->ob; - Scalar::Util::weaken $pl; - Scalar::Util::weaken $ob; - my $a_ = $pl->refcnt;#d# - my $b_ = $ob->refcnt;#d# + my $pl_ref = $pl->refcnt_cnt; my $ob_ref = $ob->refcnt_cnt; - ## pl_ref == one from object + one from cf::PLAYER - ## ob_ref == one from simply being an object - if ($pl_ref == 2 && $ob_ref == 1) { + ## pl_ref == $pl + ob->contr + %cf::PLAYER + ## ob_ref == $ob + pl->observe + simply being an object + if ($pl_ref == 3 && $ob_ref == 3) { warn "player-scheduler destroy ", $ob->name;#d# # remove from sight and get fresh "copies" $pl = delete $cf::PLAYER{$ob->name}; $ob = $pl->ob; - $ob->destroy; - $pl->destroy; + $pl->destroy; # destroys $ob } else { - warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# + my $a_ = $pl->refcnt;#d# + my $b_ = $ob->refcnt;#d# + + warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d# } } }