--- deliantra/server/utils/cfutil.in 2007/03/08 15:19:08 1.5 +++ deliantra/server/utils/cfutil.in 2007/03/14 16:23:26 1.17 @@ -21,6 +21,8 @@ use Coro; use Coro::AIO; use POSIX (); +use Digest::MD5; +use Storable; $Storable::canonical = 1; sub usage { warn < $data]; + $PNG32{$name} = $data; + $FACEINFO{$name} ||= {}; } sub process_png { @@ -106,7 +113,7 @@ next; } - # quickly extratc width and height of the (necessarily PNG) image + # quickly extract width and height of the (necessarily PNG) image unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { warn "$path: not a recongized png file, skipping.\n"; next; @@ -149,12 +156,12 @@ fork_sub { open my $convert, "|-", $CONVERT, "png:-", - -negate,#d# (map { ( "(", "+clone", -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), + "+repage", -write => "png:$_->[2]~", "+delete", ")", @@ -201,25 +208,64 @@ my $arc = read_arch "$dir/$file"; for my $o (values %$arc) { push @ARC, $o; - my ($dx, $dy); + + $o->{editor_folder} = $dir; + + my $visibility = delete $o->{visibility}; + my $magicmap = delete $o->{magicmap}; + + # find upper left corner :/ # omg, this is sooo broken + my ($dx, $dy); for (my $o = $o; $o; $o = $o->{more}) { $dx = $o->{x} if $o->{x} < $dx; $dy = $o->{y} if $o->{y} < $dy; } + for (my $o = $o; $o; $o = $o->{more}) { my $x = $o->{x} - $dx; my $y = $o->{y} - $dy; - if ($x|$y) { - $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; + + my $ext = $x|$y ? "+$x+$y" : ""; + + $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/; + + my $visibility = delete $o->{visibility} if exists $o->{visibility}; + my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; + + my $anim = delete $o->{anim}; + + if ($anim) { + $o->{animation} = "$o->{_name}"; + + for (@$anim) { + $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/; + } + + $ANIM{"$o->{_name}$ext"} = + join "", map "$_\n", + "anim $o->{_name}", + @$anim, + "mina"; + } + + for my $face ($o->{face} || (), @{$anim || []}) { + next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/; + + my $info = $FACEINFO{$face} ||= {}; + + $info->{visibility} = $visibility if defined $visibility; + $info->{magicmap} = $magicmap if defined $magicmap; + } + + if (my $smooth = delete $o->{smoothface}) { + my ($face, $smooth) = split /\s+/, $smooth; + # skip empty_S.x11, it seems to server no purpose whatsoever + # but increases bandwidth demands and worse. + unless ($smooth eq "empty_S.x11") { + $FACEINFO{$face}{smooth} = $smooth; + } } - } - if (my $anim = delete $o->{anim}) { - $o->{animation} = $o->{_name}; - $ANIM .= join "", map "$_\n", - "anim $o->{_name}", - @$anim, - "mina"; } } } @@ -228,6 +274,15 @@ sub process_trs { while (@trs) { my ($dir, $file) = @{pop @trs}; + my $path = "$dir/$file"; + + my $trs; + if (0 > aio_load $path, $trs) { + warn "$path: $!, skipping.\n"; + next; + } + + $TRS .= $trs; } } @@ -259,7 +314,7 @@ sub inst_arch($) { my (undef, $path) = @_; - print "installing '$path' to '$DATADIR'\n\n"; + print "installing '$path' to '$DATADIR'\n"; if (!-d "$path/treasures") { warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; @@ -278,29 +333,47 @@ { open my $fh, ">:utf8", "$DATADIR/animations~" or die "$DATADIR/animations~: $!"; - print $fh $ANIM; + print $fh join "", map $ANIM{$_}, sort keys %ANIM } { open my $fh, ">:utf8", "$DATADIR/archetypes~" or die "$DATADIR/archetypes~: $!"; + substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; print $fh Crossfire::archlist_to_string \@ARC; } - @PNG = sort { $a->[0] cmp $b->[0] } @PNG; + { + open my $fh, ">:utf8", "$DATADIR/treasures~" + or die "$DATADIR/treasures~: $!"; + print $fh $TRS; + } { - open my $fh, ">:perlio", "$DATADIR/crossfire.0~" - or die "$DATADIR/crossfire.0~: $!"; - printf $fh "IMAGE %d %d %s\x0a%s", $_, (length $PNG[$_][1]), $PNG[$_][0], $PNG[$_][1] - for 0.. $#PNG; + while (my ($k, $v) = each %FACEINFO) { + $v->{data32} ||= delete $PNG32{$k}; + } + + while (my ($k, $v) = each %FACEINFO) { + length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; + + $v->{chksum32} = Digest::MD5::md5 $v->{data32}; + } + + open my $fh, ">:perlio", "$DATADIR/faces~" + or die "$DATADIR/faces~: $!"; + + $FACEINFO{""} = { version => 1}; + print $fh Storable::nfreeze \%FACEINFO; } - rename "$DATADIR/archetypes~" , "$DATADIR/archetypes"; - rename "$DATADIR/crossfire.0~", "$DATADIR/crossfire.0"; - rename "$DATADIR/animations~" , "$DATADIR/animations"; + for (qw(archetypes faces animations treasures)) { + chmod 0644, "$DATADIR/$_~"; + rename "$DATADIR/$_~", "$DATADIR/$_" + or die "$DATADIR/$_: $!"; + } - die "--install-arch not fully implemented\n"; + print "archetype data installed successfully.\n"; } }