--- deliantra/server/lib/cf.pm 2012/11/11 04:31:57 1.600 +++ deliantra/server/lib/cf.pm 2012/11/20 14:30:22 1.609 @@ -575,7 +575,7 @@ C<$time> seconds of cpu time till the next tick. The slot is only valid till the next cede. -Background jobs should use a priority les than zero, interactive jobs +Background jobs should use a priority less than zero, interactive jobs should use 100 or more. The optional C<$name> can be used to identify the job to run. It might be @@ -741,10 +741,6 @@ sub fork_call(&@) { my ($cb, @args) = @_; - # we seemingly have to make a local copy of the whole thing, - # otherwise perl prematurely frees the stuff :/ - # TODO: investigate and fix (likely this will be rather laborious) - my @res = Coro::Util::fork_eval { cf::post_fork; &$cb @@ -2656,7 +2652,7 @@ =item $ob = cf::object::deref ($refstring) -returns the objetc referenced by refstring. may return undef when it cnanot find the object, +returns the objetc referenced by refstring. may return undef when it cannot find the object, even if the object actually exists. May block. =cut @@ -3048,20 +3044,6 @@ =over 4 -=item $client->send_drawinfo ($text, $flags) - -Sends a drawinfo packet to the client. Circumvents output buffering so -should not be used under normal circumstances. - -=cut - -sub cf::client::send_drawinfo { - my ($self, $text, $flags) = @_; - - utf8::encode $text; - $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); -} - =item $client->send_big_packet ($pkt) Like C, but tries to compress large packets, and fragments @@ -3089,9 +3071,9 @@ =item $client->send_msg ($channel, $msg, $color, [extra...]) -Send a drawinfo or msg packet to the client, formatting the msg for the -client if neccessary. C<$type> should be a string identifying the type of -the message, with C being the default. If C<$color> is negative, suppress +Send a msg packet to the client, formatting the msg for the client if +necessary. C<$type> should be a string identifying the type of the +message, with C being the default. If C<$color> is negative, suppress the message unless the client supports the msg packet. =cut @@ -3206,6 +3188,12 @@ reply => undef, tooltip => "Reason for and more info about your most recent death", }, + "c/fatal" => { + id => "fatal", + title => "Fatal Error", + reply => undef, + tooltip => "Reason for the server disconnect", + }, "c/say" => $SAY_CHANNEL, "c/chat" => $CHAT_CHANNEL, ); @@ -3290,6 +3278,36 @@ 1 } +=item $client->update_command_faces + +=cut + +our @COMMAND_FACES; # [normal commands, emotes, dm commands] + +sub cf::client::update_command_faces { + my ($self) = @_; + + my @faces = ( + $COMMAND_FACES[0], + $COMMAND_FACES[1], + $self->pl->ob->flag (cf::FLAG_WIZ) ? $COMMAND_FACES[2] : () + ); + + $self->send_face ($_) + for @faces; + $self->flush_fx; + + $self->ext_msg (command_list => @faces); +} + +=item cf::client::set_command_faces $normal_commands, $emotes, $dm_commands + +=cut + +sub cf::client::set_command_faces { + @COMMAND_FACES = @_; +} + cf::client->attach ( on_connect => sub { my ($ns) = @_; @@ -3521,78 +3539,83 @@ ############################################################################# # the server's init and main functions -our %FACEHASH; # hash => idx, #d# HACK for http server -our @FACEDATA; # dynamically-created facedata +{ + package cf::face; -# internal api, not fianlised -sub set_face { - my ($name, $type, $data) = @_; + our %HASH; # hash => idx + our @DATA; # dynamically-created facedata, only faceste 0 used + our @FOFS; # file offset, if > 0 + our @SIZE; # size of face, in octets + our @META; # meta hash of face, if any + our $DATAFH; # facedata filehandle + + # internal api, not finalised + sub set { + my ($name, $type, $data) = @_; - my $idx = cf::face::find $name; + my $idx = cf::face::find $name; - if ($idx) { - delete $FACEHASH{cf::face::get_chksum $idx}; - } else { - $idx = cf::face::alloc $name; - } + if ($idx) { + delete $HASH{cf::face::get_csum $idx}; + } else { + $idx = cf::face::alloc $name; + } - my $hash = cf::face::mangle_chksum Digest::MD5::md5 $data; + my $hash = cf::face::mangle_csum Digest::MD5::md5 $data; - cf::face::set_type $idx, $type; - cf::face::set_data $idx, 0, (length $data), 0, $hash; - cf::face::set_meta $idx, $type & 1 ? undef : undef; + cf::face::set_type $idx, $type; + cf::face::set_csum $idx, 0, $hash; - # we need to destroy the SV itself, not just overwrite, - # as a running ix might hold a reference to it. - # delete achieves that. - delete $FACEDATA[$idx]; - $FACEDATA[$idx] = $data; - $FACEHASH{$hash} = $idx;#d# + # we need to destroy the SV itself, not just modify it, as a running ix + # might hold a reference to it: "delete" achieves that. + delete $FOFS[0][$idx]; + delete $DATA[0][$idx]; + $DATA[0][$idx] = $data; + $SIZE[0][$idx] = length $data; + delete $META[$idx]; + $HASH{$hash} = $idx;#d# + + $idx + } + + sub _get_data($$$) { + my ($idx, $set, $cb) = @_; + + if (defined $DATA[$set][$idx]) { + $cb->($DATA[$set][$idx]); + } elsif (my $fofs = $FOFS[$set][$idx]) { + my $size = $SIZE[$set][$idx]; + my $buf; + IO::AIO::aio_read $DATAFH, $fofs, $size, $buf, 0, sub { + if ($_[0] == $size) { + #cf::debug "read face $idx, $size from $fofs as ", length $buf;#d# + $cb->($buf); + } else { + cf::error "INTERNAL ERROR: unable to read facedata for face $idx#$set ($size, $fofs), ignoring request."; + } + }; + } else { + cf::error "requested facedata for unknown face $idx#$set, ignoring."; + } + } - $idx -} + # rather ineffient + sub cf::face::get_data($;$) { + my ($idx, $set) = @_; -our $FACEDATA; # facedata filehandle + _get_data $idx, $set, Coro::rouse_cb; + Coro::rouse_wait + } -sub _face_get_data($$$$) { - my ($idx, $size, $fofs, $cb) = @_; + sub cf::face::ix { + my ($ns, $set, $idx, $pri) = @_; - if (defined $FACEDATA[$idx]) { - $cb->($FACEDATA[$idx]); - } elsif ($fofs) { - my $buf; - IO::AIO::aio_read $FACEDATA, $fofs, $size, $buf, 0, sub { - if ($_[0] == $size) { - #cf::debug "read face $idx, $size from $fofs as ", length $buf;#d# - $cb->($buf); - } else { - cf::error "INTERNAL ERROR: unable to read facedata for face $idx ($size, $fofs), ignoring request."; - } + _get_data $idx, $set, sub { + $ns->ix_send ($idx, $pri, $_[0]); }; - } else { - cf::error "requested facedata for unknown face $idx ($size, $fofs), ignoring."; } } -# rather ineffient -sub cf::face::get_data($;$) { - my ($idx, $faceset) = @_; - - my $size = cf::face::get_size $idx, $faceset; - my $fofs = cf::face::get_fofs $idx, $faceset; - - _face_get_data $idx, $size, $fofs, Coro::rouse_cb; - Coro::rouse_wait -} - -sub cf::face::ix { - my ($ns, $idx, $pri, $size, $fofs) = @_; - - _face_get_data $idx, $size, $fofs, sub { - $ns->ix_send ($idx, $pri, $_[0]); - }; -} - sub load_facedata($) { my ($path) = @_; @@ -3606,7 +3629,7 @@ or cf::cleanup "$path/faceinfo: version mismatch, cannot proceed."; my $fh = aio_open "$DATADIR/facedata", IO::AIO::O_RDONLY, 0 - or cf::cleanup "$path/facedata: $!, cnanot proceed."; + or cf::cleanup "$path/facedata: $!, cannot proceed."; get_slot 1, -100, "load_facedata"; # make sure we get a very big slot @@ -3623,10 +3646,11 @@ cf::face::set_visibility $idx, $info->{visibility}; cf::face::set_magicmap $idx, $info->{magicmap}; - cf::face::set_data $idx, 0, $info->{size32}, $info->{fofs32}, $info->{hash32}; - cf::face::set_data $idx, 1, $info->{size64}, $info->{fofs64}, $info->{hash64}; - #cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph}; # glyphs no longer downloadable via ix - $FACEHASH{$info->{hash64}} = $idx;#d# + cf::face::set_csum $idx, 0, $info->{hash64}; $cf::face::SIZE[0][$idx] = $info->{size64}; $cf::face::FOFS[0][$idx] = $info->{fofs64}; + cf::face::set_csum $idx, 1, $info->{hash32}; $cf::face::SIZE[1][$idx] = $info->{size32}; $cf::face::FOFS[1][$idx] = $info->{fofs32}; + cf::face::set_csum $idx, 2, $info->{glyph}; $cf::face::DATA[2][$idx] = $info->{glyph}; + $cf::face::HASH{$info->{hash64}} = $idx; + delete $cf::face::META[$idx]; } while (my ($face, $info) = each %$faces) { @@ -3663,16 +3687,18 @@ my $idx = (cf::face::find $name) || cf::face::alloc $name; cf::face::set_type $idx, $type; - cf::face::set_data $idx, 0, $info->{size}, $info->{fofs}, $info->{hash}; - cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already - $FACEHASH{$info->{hash}} = $idx;#d# + cf::face::set_csum $idx, 0, $info->{hash}; + $cf::face::SIZE[0][$idx] = $info->{size}; + $cf::face::FOFS[0][$idx] = $info->{fofs}; + $cf::face::META[$idx] = $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already + $cf::face::HASH{$info->{hash}} = $idx; } else { # $RESOURCE{$name} = $info; # unused } } } - ($fh, $FACEDATA) = ($FACEDATA, $fh); + ($fh, $cf::face::DATAFH) = ($cf::face::DATAFH, $fh); # HACK to clear player env face cache, we need some signal framework # for this (global event?) @@ -3710,10 +3736,11 @@ sub reload_exp_table { _reload_exp_table; - set_face "res/exp_table" => FT_RSRC, - JSON::XS->new->utf8->canonical->encode ( - [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level] - ); + cf::face::set + "res/exp_table" => FT_RSRC, + JSON::XS->new->utf8->canonical->encode ( + [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level] + ); } sub reload_materials { @@ -3743,14 +3770,17 @@ load_resource_file "$DATADIR/archetypes" or die "unable to load archetypes\n"; - set_face "res/skill_info" => FT_RSRC, - JSON::XS->new->utf8->canonical->encode ( - [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1] - ); - set_face "res/spell_paths" => FT_RSRC, - JSON::XS->new->utf8->canonical->encode ( - [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1] - ); + cf::face::set + "res/skill_info" => FT_RSRC, + JSON::XS->new->utf8->canonical->encode ( + [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1] + ); + + cf::face::set + "res/spell_paths" => FT_RSRC, + JSON::XS->new->utf8->canonical->encode ( + [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1] + ); } sub reload_treasures {