--- deliantra/server/utils/cfutil.in 2007/04/26 00:41:32 1.32 +++ deliantra/server/utils/cfutil.in 2007/08/09 22:46:08 1.49 @@ -8,7 +8,7 @@ my $DATADIR = "@datadir@/@PACKAGE@"; my $CONVERT = "@CONVERT@"; -my $IDENTIFY = "@IDENTIFY@"; +#my $IDENTIFY = "@IDENTIFY@"; my $OPTIPNG = "@OPTIPNG@"; my $RSYNC = "@RSYNC@"; my $PNGNQ = "@PNGNQ@"; @@ -23,8 +23,11 @@ use Coro::AIO; use POSIX (); use Digest::MD5; +use Carp; use Coro::Storable; $Storable::canonical = 1; +$SIG{QUIT} = sub { Carp::cluck "QUIT" }; + sub usage { warn < 0, + white => 1, + navy => 2, + red => 3, + orange => 4, + blue => 5, + darkorange => 6, + green => 7, + lightgreen => 8, + grey => 9, + brown => 10, + gold => 11, + tan => 12, +); + END { system "rm", "-rf", $TMPDIR } Event->signal (signal => "INT", cb => sub { exit 1 }); @@ -78,7 +97,7 @@ exit 1 unless $FORCE; } - system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" + system $RSYNC, "-a", "--chmod=u=rwX,go=rX", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded" and die "map installation failed.\n"; print "maps installed successfully.\n"; @@ -87,14 +106,16 @@ { our %ANIMINFO; our %FACEINFO; + our %RESOURCE; our @ARC; our %ARC; our $TRS; our $NFILE; + our $PATH; our $QUANTIZE = "+dither -colorspace RGB -colors 256"; - our (@png, @trs, @arc); # files we are interested in + our (@png, @trs, @arc, @res); # files we are interested in sub commit_png($$$) { my ($name, $data, $T) = @_; @@ -179,7 +200,7 @@ if ($stem =~ /_S\./ && (-s "$other~") > 10000) { my $ncolor = 256; while () { - system "<\Q$other~\E $PNGNQ -n$ncolor >\Q$other~~\E"; + system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; system $OPTIPNG, "-i0", "-q", "$other~~"; last if 10000 > -s "$other~~"; $ncolor = int $ncolor * 0.9; @@ -303,8 +324,8 @@ $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; - my $visibility = delete $o->{visibility} if exists $o->{visibility}; - my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; + $visibility = delete $o->{visibility} if exists $o->{visibility}; + $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; my $anim = delete $o->{anim}; @@ -369,6 +390,65 @@ } } + my %FILECACHE; + + sub load_cached($;$) { + unless (exists $FILECACHE{$_[0]}) { + my $data; + if (0 < aio_load $_[0], $data) { + if ($_[1]) { + $data = eval { $_[1]->($data) }; + warn "$_[0]: $@" if $@; + } + } + + $FILECACHE{$_[0]} = $data; + } + + $FILECACHE{$_[0]} + } + + sub process_res { + while (@res) { + my ($dir, $file, $type) = @{pop @res}; + + my $data; + aio_load "$dir/$file", $data; + + my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; + + return if $meta && !exists $meta->{$file}; + + $meta = { + %{ $meta->{"" } || {} }, + %{ $meta->{$file} || {} }, + }; + + if ($meta->{license} =~ s/^#//) { + $meta->{license} = ({ + "pd" => "Public Domain", + "gpl" => "GNU General Public License, version 3.0 or any later", + "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", + "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", + "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", + })->{$meta->{license}} + || warn "$dir/$file: license tag '$meta->{license}' not found."; + } + + $file =~ s/\.res$//; + $file =~ s/\.(ogg|wav|jpg|png)$//; + + substr $dir, 0, 1 + length $PATH, ""; + + $RESOURCE{"$dir/$file"} = { + type => (delete $meta->{type}) || $type, + data => $data, + chksum => (Digest::MD5::md5 $data), + %$meta ? (meta => $meta) : (), + }; + } + } + sub find_files; sub find_files { my ($path) = @_; @@ -380,15 +460,35 @@ find_files "$path/$_" for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; + my $dir = $path; + substr $dir, 0, 1 + length $PATH, ""; + for my $file (@$nondirs) { - if ($file =~ /\.png$/) { + if ($dir =~ /^music(?:\/|$)/) { + push @res, [$path, $file, 3] # FT_MUSIC + if $file =~ /\.(ogg)$/; + + } elsif ($dir =~ /^sound(?:\/|$)/) { + push @res, [$path, $file, 5] # FT_SOUND + if $file =~ /\.(wav|ogg)$/; + + } elsif ($dir =~ /^res(?:\/|$)/) { + push @res, [$path, $file, 0] # FT_FACE + if $file =~ /\.(jpg|png)$/; + push @res, [$path, $file, 7] # FT_RSRC + if $file =~ /\.(res)$/; + + } elsif ($file =~ /\.png$/) { push @png, ["$path/$file", 0]; + } elsif ($file =~ /\.trs$/) { push @trs, [$path, $file]; + } elsif ($file =~ /\.arc$/) { push @arc, [$path, $file]; + } else { - warn "ignoring $path/$file\n" if $VERBOSE >= 2; + warn "ignoring $path/$file\n" if $VERBOSE >= 3; } } }; @@ -397,6 +497,8 @@ sub inst_arch($) { my (undef, $path) = @_; + $PATH = $path; + print "\n", "Installing '$path' to '$DATADIR'\n", "\n", @@ -420,6 +522,7 @@ (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_png), (async \&process_trs), (async \&process_trs), (async \&process_arc), (async \&process_arc), + (async \&process_res), (async \&process_res), ); { @@ -459,6 +562,9 @@ } } + # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit + @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; + open my $fh, ">:utf8", "$DATADIR/archetypes~" or die "$DATADIR/archetypes~: $!"; print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; @@ -480,6 +586,11 @@ $v->{chksum32} = Digest::MD5::md5 $v->{data32}; $v->{chksum64} = Digest::MD5::md5 $v->{data64}; + + if (my $magicmap = $v->{magicmap}) { + $magicmap =~ y/A-Z_\-/a-z/d; + $v->{magicmap} = $COLOR{$magicmap}; + } } open my $fh, ">:perlio", "$DATADIR/facedata~" @@ -489,6 +600,7 @@ version => 2, faceinfo => \%FACEINFO, animinfo => \%ANIMINFO, + resource => \%RESOURCE, }; }