--- deliantra/server/ext/login.ext 2007/04/04 02:07:19 1.35 +++ deliantra/server/ext/login.ext 2007/06/25 05:43:45 1.57 @@ -1,4 +1,4 @@ -#! perl # MANDATORY +#! perl # mandatory # login handling @@ -6,7 +6,7 @@ use Coro::AIO; use List::Util qw(min max); -my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; +our %EXT_SETUP; # paranoia function to overwrite a string-in-place sub nuke_str { @@ -17,7 +17,7 @@ my ($ns, $flags, $text) = @_; my $current = $Coro::current; - $ns->query ($flags, $text, sub { $current->ready; $current = $_[0]; }); + $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); Coro::schedule while ref $current; $current @@ -55,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... @@ -103,83 +129,103 @@ my %setup = split / +/, $args; while (my ($k, $v) = each %setup) { if ($k eq "sound") { - $ns->sound ($v); + $ns->sound ($v); } elsif ($k eq "exp64") { - $setup{$k} = 1; + $setup{$k} = 1; } elsif ($k eq "spellmon") { - $ns->monitor_spells ($v); + $ns->monitor_spells ($v); } elsif ($k eq "darkness") { - $ns->darkness ($v); + $ns->darkness ($v); } elsif ($k eq "map1cmd") { - $ns->mapmode (cf::Map1Cmd) if $v > 0; + $ns->mapmode (cf::Map1Cmd) if $v > 0; } elsif ($k eq "map1acmd") { - $ns->mapmode (cf::Map1aCmd) if $v > 0; + $ns->mapmode (cf::Map1aCmd) if $v > 0; } elsif ($k eq "map2cmd") { - # gcfclient bug, map1acmd is sent too late - $ns->mapmode (cf::Map1aCmd); - $setup{$k} = "FALSE"; + # gcfclient bug, map1acmd is sent too late + $ns->mapmode (cf::Map1aCmd); + $setup{$k} = "FALSE"; } elsif ($k eq "newmapcmd") { - $ns->newmapcmd ($v); + $ns->newmapcmd ($v); } elsif ($k eq "mapinfocmd") { - $ns->mapinfocmd ($v); + $ns->mapinfocmd ($v); } elsif ($k eq "extcmd") { - $ns->extcmd ($v > 0); - send_capabilities $ns; + $ns->extcmd ($v > 0); + send_capabilities $ns; } elsif ($k eq "extmap") { - $ns->extmap ($v); + $ns->extmap ($v); } elsif ($k eq "facecache") { - $ns->facecache ($v); + if (!$v) { + $v = 1; + $setup{$k} = $v; + $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); + } + + $ns->facecache ($v); } elsif ($k eq "faceset") { - $ns->faceset (0); - $setup{$k} = 0; - # $ns->image2 (1) + $ns->faceset (0); + $setup{$k} = 0; + # $ns->image2 (1) } elsif ($k eq "tileset") { - $setup{$k} = $ns->faceset ($v & 1); + $setup{$k} = $ns->faceset ($v & 1); } elsif ($k eq "itemcmd") { - # Version of the item protocol command to use. Currently, - # only supported versions are 1 and 2. Using a numeric - # value will make it very easy to extend this in the future. - $ns->itemcmd ($v) if $v >= 1 && $v <= 2; + # Version of the item protocol command to use. Currently, + # only supported versions are 1 and 2. Using a numeric + # value will make it very easy to extend this in the future. + $ns->itemcmd ($v) if $v >= 1 && $v <= 2; - $setup{$k} = $ns->itemcmd; + $setup{$k} = $ns->itemcmd; } elsif ($k eq "mapsize") { - my ($x, $y) = split /x/, $v; + my ($x, $y) = split /x/, $v; - $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, $x); - $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, $y); + $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); + $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); - $setup{$k} = "${x}x${y}"; + $setup{$k} = "${x}x${y}"; } elsif ($k eq "extendedMapInfos") { - $ns->ext_mapinfos ($v); + $ns->ext_mapinfos ($v); } elsif ($k eq "extendedTextInfos") { - $ns->has_readable_type ($v); + $ns->has_readable_type ($v); + + } elsif ($k eq "smoothing") { # cfplus-style smoothing + $ns->smoothing ($v); } elsif ($k eq "fxix") { - $ns->fxix ($v); + $ns->fxix ($v); + + } elsif ($k eq "msg") { + $ns->can_msg ($v >= 2); + $setup{$k} = $ns->can_msg; + + } elsif ($k eq "xwidget") { + # eXperimental server-side widgets + $ns->{can_widget} = 1; + + } elsif ($k eq "excmd") { + # we support it } else { - # other commands: - # sexp: no idea, probably for oudated servers - # tick: more stupidity, server should sned a tick per tick + # other commands: + # sexp: no idea, probably for oudated servers + # tick: more stupidity, server should send a tick per tick - $setup{$k} = "FALSE"; + $setup{$k} = "FALSE"; } } @@ -321,7 +367,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; @@ -356,6 +402,19 @@ ); next; } + } else { + # unable to load the playerfile: + # check wether the player dir exists, which means the file is corrupted or + # something very similar. + if (!aio_stat cf::player::playerdir $user) { + $ns->send_drawinfo ( + "Unable to retrieve this player. It might be a locked or broken account. " + . "If this is your account, ask a dungeon master for assistance. " + . "Otherwise choose a different login name.", + cf::NDI_RED + ); + next; + } } # the rest of this function is character creation @@ -381,9 +440,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; @@ -407,12 +467,38 @@ $ob->set_animation (2); $ob->add_statbonus; - $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); - $ns->send_packet (sprintf "query %d %s", cf::CS_QUERY_SINGLECHAR, - "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); + while () { + $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); + my $msg = $ob->msg; + $msg =~ s/(?<=\S)\n(?=\S)/ /g; + $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); + + my $res = query $ns, cf::CS_QUERY_SINGLECHAR, + "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; + + last if $res =~ /[dD]/; + + $pl->chargen_race_next; + } + + $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!"); - $ns->state (cf::ST_CHANGE_CLASS); - delete $pl->{deny_save};#d# too early + delete $pl->{deny_save}; last; } @@ -525,32 +611,31 @@ eval { if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { - $cf::WAIT_FOR_TICK_ONE->wait; + 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# } } }