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.81 by root, Sat Apr 3 03:13:48 2010 UTC vs.
Revision 1.100 by root, Wed Oct 6 03:44:55 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 =~ /^traps\//) {
174 "☠"
175
176 } elsif ($stem =~ /^armour\/shield/) {
177 "Ø"
178
179 } elsif ($stem =~ /^armour\//) {
180 "A"
181
182 } elsif ($stem =~ /^weapon\//) {
183 "†"
184
185 } elsif ($stem =~ /^readable\//) {
186 "✉"
187
188 } elsif ($stem =~ /^river\//) {
189 "~"
190
191 } elsif ($stem =~ /^floor\/|^ground\/|Nimfloor/) {
192 "·"
193
194 } elsif ($stem =~ /^spells\//) {
195 "!"
196
197 } elsif ($stem =~ /^player\//) {
198 "\@"
199
200 } elsif ($stem =~ /^(?:monster|misc|class|connect|gods|indoor|inorganic|mining|music|skills).*\/(.)/) {
201 $1
202
203 } else {
204 substr $stem, 0, 1
205 }
206}
207
160{ 208{
161 our %ANIMINFO; 209 our %ANIMINFO;
162 our %FACEINFO; 210 our %FACEINFO;
163 our %RESOURCE; 211 our %RESOURCE;
164 our @ARC; 212 our @ARC;
173 our $c_trs = new Coro::Channel; 221 our $c_trs = new Coro::Channel;
174 our $c_res = new Coro::Channel; 222 our $c_res = new Coro::Channel;
175 223
176 our @c_png; 224 our @c_png;
177 225
178 sub commit_png($$$) { 226 sub commit_png($$$$) {
179 my ($name, $data, $T) = @_; 227 my ($stem, $name, $data, $T) = @_;
180 228
229 $FACEINFO{$name}{"stem"} = substr $stem, 1 + length $PATH;
181 $FACEINFO{$name}{"data$T"} = $data; 230 $FACEINFO{$name}{"data$T"} = $data;
182 } 231 }
183 232
184 sub process_png { 233 sub process_png {
185 while (@c_png) { 234 while (@c_png) {
403 452
404 if (0 > aio_load $file, $tile) { 453 if (0 > aio_load $file, $tile) {
405 die "$path: unable to read tile +$x+$y, aborting.\n"; 454 die "$path: unable to read tile +$x+$y, aborting.\n";
406 } 455 }
407 IO::AIO::aio_unlink $file unless $CACHE; 456 IO::AIO::aio_unlink $file unless $CACHE;
408 commit_png $x|$y ? "$face+$x+$y" : $face, $tile, $T; 457 commit_png $stem, $x|$y ? "$face+$x+$y" : $face, $tile, $T;
409 } 458 }
410 } else { 459 } else {
411 # use as-is (either small, use smooth) 460 # use as-is (either small, use smooth)
412 commit_png $face, $png, $T; 461 commit_png $stem, $face, $png, $T;
413 } 462 }
414 463
415 aio_unlink $path if $delete; 464 aio_unlink $path if $delete;
416 } 465 }
417 } 466 }
432 481
433 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge 482 $o->{editor_folder} ||= "\x00$dir"; # horrible kludge
434 483
435 my $visibility = delete $o->{visibility}; 484 my $visibility = delete $o->{visibility};
436 my $magicmap = delete $o->{magicmap}; 485 my $magicmap = delete $o->{magicmap};
486 my $glyph = delete $o->{glyph};
437 487
438 # find upper left corner :/ 488 # find upper left corner :/
439 # omg, this is sooo broken 489 # omg, this is sooo broken
440 my ($dx, $dy); 490 my ($dx, $dy);
441 for (my $o = $o; $o; $o = $o->{more}) { 491 for (my $o = $o; $o; $o = $o->{more}) {
451 501
452 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; 502 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face};
453 503
454 $visibility = delete $o->{visibility} if exists $o->{visibility}; 504 $visibility = delete $o->{visibility} if exists $o->{visibility};
455 $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 505 $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
506 $glyph = delete $o->{glyph} if exists $o->{glyph};
456 507
457 my $anim = delete $o->{anim}; 508 my $anim = delete $o->{anim};
458 509
459 if ($anim) { 510 if ($anim) {
460 # possibly add $ext to the animation name to avoid 511 # possibly add $ext to the animation name to avoid
491 542
492 next if $face =~ /^blank.x11$|^empty.x11$/; 543 next if $face =~ /^blank.x11$|^empty.x11$/;
493 544
494 $info->{visibility} = $visibility if defined $visibility; 545 $info->{visibility} = $visibility if defined $visibility;
495 $info->{magicmap} = $magicmap if defined $magicmap; 546 $info->{magicmap} = $magicmap if defined $magicmap;
547 $info->{glyph} = $glyph if defined $glyph;
496 } 548 }
497 549
498 if (my $smooth = delete $o->{smoothface}) { 550 if (my $smooth = delete $o->{smoothface}) {
499 my %kv = split /\s+/, $smooth; 551 my %kv = split /\s+/, $smooth;
500 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support 552 my $level = $o->{smoothlevel}; #TODO: delete from $o if !gcfclient-support
569 if ($meta->{license} =~ s/^#//) { 621 if ($meta->{license} =~ s/^#//) {
570 $meta->{license} = ({ 622 $meta->{license} = ({
571 "pd" => "Public Domain", 623 "pd" => "Public Domain",
572 "gpl" => "GNU General Public License, version 3.0 or any later", 624 "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/", 625 "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/",
626 "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/", 627 "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/", 628 "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/",
576 })->{$meta->{license}} 629 })->{$meta->{license}}
577 || warn "$dir/$file: license tag '$meta->{license}' not found."; 630 || warn "$dir/$file: license tag '$meta->{license}' not found.";
631 }
632
633 if (!exists $meta->{author} && $meta->{source} =~ m%^http://www.jamendo.com/en/artist/(.*)$%) {
634 ($meta->{author} = $1) =~ s/_/ /g;
578 } 635 }
579 636
580 $file =~ s/\.res$//; 637 $file =~ s/\.res$//;
581 $file =~ s/\.(ogg|wav|jpg|png)$//; 638 $file =~ s/\.(ogg|wav|jpg|png)$//;
582 639
795 if (my $magicmap = $v->{magicmap}) { 852 if (my $magicmap = $v->{magicmap}) {
796 $magicmap =~ y/A-Z_\-/a-z/d; 853 $magicmap =~ y/A-Z_\-/a-z/d;
797 $v->{magicmap} = $COLOR{$magicmap}; 854 $v->{magicmap} = $COLOR{$magicmap};
798 } 855 }
799 856
857 my $stem = delete $v->{stem};
858 $v->{glyph} //= autoglyph $stem, $v;
859 utf8::encode $v->{glyph};
860 $v->{glyph} = (chr $v->{magicmap}) . $v->{glyph};
861
800 delete $v->{arc}; 862 delete $v->{arc};
801 } 863 }
802 864
803 print "processing resources...\n" if $VERBOSE; 865 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed; 866 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) { 867 while (my ($k, $v) = each %RESOURCE) {
806 868
869 if ($v->{meta} && $v->{meta}{datadir}) {
870 delete $RESOURCE{$k};
871
872 $k =~ s/^res\/// or die "$k: datadir files must be in res/";
873
874 printf "writing $k (%d octets)...\n", length $v->{data} if $VERBOSE;
875 open my $fh, ">:raw", "$DATADIR/$k~"
876 or die "$DATADIR/$k~: $!";
877 syswrite $fh, $v->{data};
878 push @COMMIT, $k;
879
880 } else {
807 if ($v->{type} & 1) { 881 if ($v->{type} & 1) {
808 # prepend meta info 882 # prepend meta info
809 883
810 my $meta = $enc->encode ({ 884 my $meta = $enc->encode ({
811 name => $k, 885 name => $k,
812 %{ $v->{meta} || {} }, 886 %{ $v->{meta} || {} },
813 }); 887 });
814 888
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data}; 889 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 } 890 }
817 891
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients 892 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
893 }
819 } 894 }
820 895
821 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 896 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
822 scalar keys %FACEINFO, 897 scalar keys %FACEINFO,
823 scalar keys %ANIMINFO, 898 scalar keys %ANIMINFO,
825 if $VERBOSE; 900 if $VERBOSE;
826 901
827 open my $fh, ">:perlio", "$DATADIR/facedata~" 902 open my $fh, ">:perlio", "$DATADIR/facedata~"
828 or die "$DATADIR/facedata~: $!"; 903 or die "$DATADIR/facedata~: $!";
829 904
830 print $fh freeze { 905 print $fh nfreeze {
831 version => 2, 906 version => 2,
832 faceinfo => \%FACEINFO, 907 faceinfo => \%FACEINFO,
833 animinfo => \%ANIMINFO, 908 animinfo => \%ANIMINFO,
834 resource => \%RESOURCE, 909 resource => \%RESOURCE,
835 }; 910 };
836 911
837 } 912 }
838 913
839 print "committing files...\n" if $VERBOSE; 914 print "committing files...\n" if $VERBOSE;
840 915
841 for (qw(archetypes facedata treasures)) { 916 for (qw(archetypes facedata treasures), @COMMIT) {
842 chmod 0644, "$DATADIR/$_~"; 917 chmod 0644, "$DATADIR/$_~";
843 rename "$DATADIR/$_~", "$DATADIR/$_" 918 rename "$DATADIR/$_~", "$DATADIR/$_"
844 or die "$DATADIR/$_: $!"; 919 or die "$DATADIR/$_: $!";
845 } 920 }
846 921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines