--- deliantra/server/ext/login.ext 2007/04/02 18:14:24 1.33 +++ deliantra/server/ext/login.ext 2007/04/24 00:42:02 1.45 @@ -6,8 +6,6 @@ use Coro::AIO; use List::Util qw(min max); -my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; - # paranoia function to overwrite a string-in-place sub nuke_str { substr $_[0], 0, (length $_[0]), "x" x length $_[0] @@ -17,7 +15,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 @@ -80,6 +78,17 @@ . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; } +sub send_capabilities { + my ($ns) = @_; + + return unless $ns->extcmd; + + $ns->ext_event (capabilities => + # id, name, flags (1 == 2d), edge length + tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]], + ); +} + sub setup { my ($ns, $args) = @_; @@ -91,78 +100,99 @@ 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); + $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); } 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); + + } elsif ($k eq "msg") { + $ns->can_msg ($v); + + } 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"; } } @@ -339,6 +369,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 @@ -390,12 +433,23 @@ $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/\b\n\b/ /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; - $ns->state (cf::ST_CHANGE_CLASS); - delete $pl->{deny_save};#d# too early + delete $pl->{deny_save}; last; } @@ -508,7 +562,7 @@ 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) {