--- deliantra/server/utils/cfutil.in 2007/04/26 00:39:18 1.31 +++ deliantra/server/utils/cfutil.in 2007/07/24 04:55:35 1.44 @@ -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; @@ -188,7 +209,7 @@ printf "reduced %s from %d to %d bytes using %d colours.\n", $other, -s "$other~", -s "$other~~", $ncolor - if $VERBOSE > 0; + if $VERBOSE >= 2; rename "$other~~", "$other~"; } @@ -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,31 @@ } } + sub process_res { + while (@res) { + my ($dir, $file, $type) = @{pop @res}; + + my $data; + aio_load "$dir/$file", $data; + + my $copyright; + aio_load "$dir/copyright", $copyright; + + $file =~ s/\.res$//; + $file =~ /\.([^.]+)$/ + or next; + + substr $dir, 0, 1 + length $PATH, ""; + + $RESOURCE{"$dir/$file"} = { + type => $type, + copyright => $copyright, + data => $data, + chksum => Digest::MD5::md5 $data, + }; + } + } + sub find_files; sub find_files { my ($path) = @_; @@ -380,15 +426,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 =~ /^sounds(?:\/|$)/) { + 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 +463,8 @@ sub inst_arch($) { my (undef, $path) = @_; + $PATH = $path; + print "\n", "Installing '$path' to '$DATADIR'\n", "\n", @@ -420,6 +488,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 +528,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 +552,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 +566,7 @@ version => 2, faceinfo => \%FACEINFO, animinfo => \%ANIMINFO, + resource => \%RESOURCE, }; }