ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/utils/cfutil.in
(Generate patch)

Comparing deliantra/server/utils/cfutil.in (file contents):
Revision 1.80 by root, Fri Mar 19 14:36:39 2010 UTC vs.
Revision 1.97 by root, Wed Oct 6 01:23:11 2010 UTC

20# <http://www.gnu.org/licenses/>. 20# <http://www.gnu.org/licenses/>.
21# 21#
22# The authors can be reached via e-mail to <support@deliantra.net> 22# The authors can be reached via e-mail to <support@deliantra.net>
23# 23#
24 24
25use strict; 25use common::sense;
26 26
27my $prefix = "@prefix@"; 27my $prefix = "@prefix@";
28my $exec_prefix = "@exec_prefix@"; 28my $exec_prefix = "@exec_prefix@";
29my $datarootdir = "@datarootdir@"; 29my $datarootdir = "@datarootdir@";
30my $DATADIR = "@datadir@/@PACKAGE@"; 30my $DATADIR = "@datadir@/@PACKAGE@";
74my $VERBOSE = 1; 74my $VERBOSE = 1;
75my $CACHE = 0; 75my $CACHE = 0;
76my $FORCE; 76my $FORCE;
77my $TMPDIR = "/tmp/cfutil$$~"; 77my $TMPDIR = "/tmp/cfutil$$~";
78my $TMPFILE = "aaaa0"; 78my $TMPFILE = "aaaa0";
79my @COMMIT;
79 80
80our %COLOR = ( 81our %COLOR = (
81 black => 0, 82 black => 0,
82 white => 1, 83 white => 1,
83 navy => 2, 84 navy => 2,
105 my ($id, $dataref, $hashref, $clen) = @_; 106 my ($id, $dataref, $hashref, $clen) = @_;
106 107
107 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4; 108 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4;
108 109
109 if (exists $hash{$hash}) { 110 if (exists $hash{$hash}) {
110 # hahs collinion, but some files are simply identical 111 # hash collision, but some files are simply identical
111 if (${$hash{$hash}[1]} ne $$dataref) { 112 if (${$hash{$hash}[1]} ne $$dataref) {
112 warn "hash collision $hash{$hash}[0] vs. $id\n"; 113 warn "hash collision $hash{$hash}[0] vs. $id\n";
113 exit 1; 114 exit 1;
114 } else { 115 } else {
115 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3; 116 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3;
155 and die "map installation failed.\n"; 156 and die "map installation failed.\n";
156 157
157 print "maps installed successfully.\n"; 158 print "maps installed successfully.\n";
158} 159}
159 160
161our @WALL_SUFFIX = qw(⬤ ╹ ╺ ┗ ╻ ┃ ┏ ┣ ╸ ┛ ━ ┻ ┓ ┫ ┳ ╋);
162
163# used to create crude text glyphs for text-based clients
164sub autoglyph {
165 my ($stem, $face) = @_;
166
167 if ($stem =~ /^wall\/|Nimwall/) {
168 return $WALL_SUFFIX[hex $1]
169 if $stem =~ /(_[0-9A-F]).x11/;
170
171 "+"
172
173 } elsif ($stem =~ /^monster.*\/(.)/) {
174 $1
175
176 } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) {
177 "."
178
179 } elsif ($stem =~ /^player\//) {
180 "\@"
181
182 } else {
183 substr $stem, 0, 1
184 }
185}
186
160{ 187{
161 our %ANIMINFO; 188 our %ANIMINFO;
162 our %FACEINFO; 189 our %FACEINFO;
163 our %RESOURCE; 190 our %RESOURCE;
164 our @ARC; 191 our @ARC;
173 our $c_trs = new Coro::Channel; 200 our $c_trs = new Coro::Channel;
174 our $c_res = new Coro::Channel; 201 our $c_res = new Coro::Channel;
175 202
176 our @c_png; 203 our @c_png;
177 204
178 sub commit_png($$$) { 205 sub commit_png($$$$) {
179 my ($name, $data, $T) = @_; 206 my ($stem, $name, $data, $T) = @_;
180 207
208 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH;
181 $FACEINFO{$name}{"data$T"} = $data; 209 $FACEINFO{$name}{"data$T"} = $data;
182 } 210 }
183 211
184 sub process_png { 212 sub process_png {
185 while (@c_png) { 213 while (@c_png) {
403 431
404 if (0 > aio_load $file, $tile) { 432 if (0 > aio_load $file, $tile) {
405 die "$path: unable to read tile +$x+$y, aborting.\n"; 433 die "$path: unable to read tile +$x+$y, aborting.\n";
406 } 434 }
407 IO::AIO::aio_unlink $file unless $CACHE; 435 IO::AIO::aio_unlink $file unless $CACHE;
408 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; 436 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T;
409 } 437 }
410 } else { 438 } else {
411 # use as-is (either small, use smooth) 439 # use as-is (either small, use smooth)
412 commit_png $face, $png, $T; 440 commit_png $stem, $face, $png, $T;
413 } 441 }
414 442
415 aio_unlink $path if $delete; 443 aio_unlink $path if $delete;
416 } 444 }
417 } 445 }
432 460
433 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge 461 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
434 462
435 my $visibility = delete $o->{visibility}; 463 my $visibility = delete $o->{visibility};
436 my $magicmap = delete $o->{magicmap}; 464 my $magicmap = delete $o->{magicmap};
465 my $glyph = delete $o->{glyph};
437 466
438 # find upper left corner :/ 467 # find upper left corner :/
439 # omg, this is sooo broken 468 # omg, this is sooo broken
440 my ($dx, $dy); 469 my ($dx, $dy);
441 for (my $o = $o; $o; $o = $o->{more}) { 470 for (my $o = $o; $o; $o = $o->{more}) {
451 480
452 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; 481 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
453 482
454 $visibility = delete $o->{visibility} if exists $o->{visibility}; 483 $visibility = delete $o->{visibility} if exists $o->{visibility};
455 $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 484 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
485 $glyph = delete $o->{glyph} if exists $o->{glyph};
456 486
457 my $anim = delete $o->{anim}; 487 my $anim = delete $o->{anim};
458 488
459 if ($anim) { 489 if ($anim) {
460 # possibly add $ext to the animation name to avoid 490 # possibly add $ext to the animation name to avoid
491 521
492 next if $face =~ /^blank.x11$|^empty.x11$/; 522 next if $face =~ /^blank.x11$|^empty.x11$/;
493 523
494 $info->{visibility} = $visibility if defined $visibility; 524 $info->{visibility} = $visibility if defined $visibility;
495 $info->{magicmap} = $magicmap if defined $magicmap; 525 $info->{magicmap} = $magicmap if defined $magicmap;
526 $info->{glyph} = $glyph if defined $glyph;
496 } 527 }
497 528
498 if (my $smooth = delete $o->{smoothface}) { 529 if (my $smooth = delete $o->{smoothface}) {
499 my %kv = split /\s+/, $smooth; 530 my %kv = split /\s+/, $smooth;
500 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 531 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
569 if ($meta->{license} =~ s/^#//) { 600 if ($meta->{license} =~ s/^#//) {
570 $meta->{license} = ({ 601 $meta->{license} = ({
571 "pd" => "Public Domain", 602 "pd" => "Public Domain",
572 "gpl" => "GNU General Public License, version 3.0 or any later", 603 "gpl" => "GNU General Public License, version 3.0 or any later",
573 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", 604 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
605 "cc/by/2.1" => "Licensed under Creative Commons Attribution 2.1 http://creativecommons.org/licenses/by/2.1/",
574 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/", 606 "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.5 http://creativecommons.org/licenses/by/2.5/",
575 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", 607 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
576 })->{$meta->{license}} 608 })->{$meta->{license}}
577 || warn "$dir/$file: license tag '$meta->{license}' not found."; 609 || warn "$dir/$file: license tag '$meta->{license}' not found.";
610 }
611
612 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
613 ($meta->{author} = $1) =~ s/_/ /g;
578 } 614 }
579 615
580 $file =~ s/\.res$//; 616 $file =~ s/\.res$//;
581 $file =~ s/\.(ogg|wav|jpg|png)$//; 617 $file =~ s/\.(ogg|wav|jpg|png)$//;
582 618
733 while () { 769 while () {
734 my $progress; 770 my $progress;
735 my $loop; 771 my $loop;
736 772
737 for my $o (values %ARC) { 773 for my $o (values %ARC) {
738 if (my $other = $o->{inherit}) { 774 for my $other (split /,/, $o->{inherit}) {
739 if (my $s = $ARC{$other}) { 775 if (my $s = $ARC{$other}) {
740 if ($s->{inherit}) { 776 if ($s->{inherit}) {
741 $loop = $s; 777 $loop = $s;
742 } else { 778 } else {
743 delete $o->{inherit}; 779 delete $o->{inherit};
795 if (my $magicmap = $v->{magicmap}) { 831 if (my $magicmap = $v->{magicmap}) {
796 $magicmap =~ y/A-Z_\-/a-z/d; 832 $magicmap =~ y/A-Z_\-/a-z/d;
797 $v->{magicmap} = $COLOR{$magicmap}; 833 $v->{magicmap} = $COLOR{$magicmap};
798 } 834 }
799 835
836 my $stem = delete $v->{stem};
837 $v->{glyph} //= autoglyph $stem, $v;
838 utf8::encode $v->{glyph};
839 $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph};
840
800 delete $v->{arc}; 841 delete $v->{arc};
801 } 842 }
802 843
803 print "processing resources...\n" if $VERBOSE; 844 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed; 845 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) { 846 while (my ($k, $v) = each %RESOURCE) {
806 847
848 if ($v->{meta} && $v->{meta}{datadir}) {
849 delete $RESOURCE{$k};
850
851 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
852
853 printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE;
854 open my $fh, ">:raw", "$DATADIR/$k~"
855 or die "$DATADIR/$k~: $!";
856 syswrite $fh, $v->{data};
857 push @COMMIT, $k;
858
859 } else {
807 if ($v->{type} & 1) { 860 if ($v->{type} & 1) {
808 # prepend meta info 861 # prepend meta info
809 862
810 my $meta = $enc->encode ({ 863 my $meta = $enc->encode ({
811 name => $k, 864 name => $k,
812 %{ $v->{meta} || {} }, 865 %{ $v->{meta} || {} },
813 }); 866 });
814 867
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data}; 868 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 } 869 }
817 870
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 871 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
872 }
819 } 873 }
820 874
821 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 875 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
822 scalar keys %FACEINFO, 876 scalar keys %FACEINFO,
823 scalar keys %ANIMINFO, 877 scalar keys %ANIMINFO,
825 if $VERBOSE; 879 if $VERBOSE;
826 880
827 open my $fh, ">:perlio", "$DATADIR/facedata~" 881 open my $fh, ">:perlio", "$DATADIR/facedata~"
828 or die "$DATADIR/facedata~: $!"; 882 or die "$DATADIR/facedata~: $!";
829 883
830 print $fh freeze { 884 print $fh nfreeze {
831 version => 2, 885 version => 2,
832 faceinfo => \%FACEINFO, 886 faceinfo => \%FACEINFO,
833 animinfo => \%ANIMINFO, 887 animinfo => \%ANIMINFO,
834 resource => \%RESOURCE, 888 resource => \%RESOURCE,
835 }; 889 };
836 890
837 } 891 }
838 892
839 print "committing files...\n" if $VERBOSE; 893 print "committing files...\n" if $VERBOSE;
840 894
841 for (qw(archetypes facedata treasures)) { 895 for (qw(archetypes facedata treasures), @COMMIT) {
842 chmod 0644, "$DATADIR/$_~"; 896 chmod 0644, "$DATADIR/$_~";
843 rename "$DATADIR/$_~", "$DATADIR/$_" 897 rename "$DATADIR/$_~", "$DATADIR/$_"
844 or die "$DATADIR/$_: $!"; 898 or die "$DATADIR/$_: $!";
845 } 899 }
846 900

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines