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.4 by root, Wed Mar 7 20:30:18 2007 UTC vs.
Revision 1.14 by root, Wed Mar 14 00:04:59 2007 UTC

19use File::Temp; 19use File::Temp;
20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5;
24 25
25sub usage { 26sub usage {
26 warn <<EOF; 27 warn <<EOF;
27Usage: cfutil [-v] [-q] [--force] [--cache] 28Usage: cfutil [-v] [-q] [--force] [--cache]
28 [--install-arch path] 29 [--install-arch path]
66} 67}
67 68
68sub inst_maps($) { 69sub inst_maps($) {
69 my (undef, $path) = @_; 70 my (undef, $path) = @_;
70 71
71 print "installing '$path' to '$DATADIR/maps'\n\n"; 72 print "installing '$path' to '$DATADIR/maps'\n";
72 73
73 if (!-f "$path/regions") { 74 if (!-f "$path/regions") {
74 warn "'$path' does not look like a maps directory ('regions' file is missing).\n"; 75 warn "'$path' does not look like a maps directory ('regions' file is missing).\n";
75 exit 1 unless $FORCE; 76 exit 1 unless $FORCE;
76 } 77 }
77 78
78 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"; 79 system $RSYNC, "-av", "$path/.", "$DATADIR/maps/.", "--delete", "--exclude", "CVS", "--delete-excluded"
80 or die "map installation failed.\n";
81
82 print "maps installed successfully.\n";
79} 83}
80 84
81{ 85{
82 our @PNG; 86 our %PNG32;
87 our %FACEINFO;
83 our @ARC; 88 our @ARC;
89 our $TRS;
84 our $NFILE; 90 our $NFILE;
91 our %ANIM;
85 92
86 our (@png, @trs, @arc); # files we are interested in 93 our (@png, @trs, @arc); # files we are interested in
87 94
88 sub commit_png { 95 sub commit_png {
89 my ($name, $data) = @_; 96 my ($name, $data) = @_;
90 #warn "$name: commited\n"; 97
98 $PNG32{$name} = $data;
99 $FACEINFO{$name} ||= {};
91 } 100 }
92 101
93 sub process_png { 102 sub process_png {
94 while (@png) { 103 while (@png) {
95 my $path = pop @png; 104 my $path = pop @png;
98 aio_lstat $path; 107 aio_lstat $path;
99 my ($size, $mtime) = (stat _)[7,9]; 108 my ($size, $mtime) = (stat _)[7,9];
100 109
101 if (0 > aio_load $path, $png) { 110 if (0 > aio_load $path, $png) {
102 warn "$path: $!, skipping.\n"; 111 warn "$path: $!, skipping.\n";
103 return; 112 next;
104 } 113 }
105 114
106 # quickly extratc width and height of the (necessarily PNG) image 115 # quickly extract width and height of the (necessarily PNG) image
107 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) { 116 unless ($png =~ /^\x89PNG\x0d\x0a\x1a\x0a....IHDR(........)/s) {
108 warn "$path: not a recongized png file, skipping.\n"; 117 warn "$path: not a recongized png file, skipping.\n";
109 return; 118 next;
110 } 119 }
111 120
112 my ($w, $h) = unpack "NN", $1; 121 my ($w, $h) = unpack "NN", $1;
113 122
114 (my $face = $path) =~ s/^.*\///; 123 (my $face = $path) =~ s/^.*\///;
115 my $T = 32; 124 my $T = 32;
116 125
117 unless ($face =~ s/\.base\.(...)\.png$/.$1/) { 126 unless ($face =~ s/\.base\.(...)\.png$/.$1/) {
118 warn "$path: weird filename, skipping.\n"; 127 warn "$path: weird filename, skipping.\n";
119 return; 128 next;
120 } 129 }
121 130
122 if ($w < $T || $h < $T) { 131 if ($w < $T || $h < $T) {
123 warn "$path: too small ($w $h), skipping.\n"; 132 warn "$path: too small ($w $h), skipping.\n";
124 return; 133 next;
125 } 134 }
126 135
127 if ($w % $T || $h % $T) { 136 if ($w % $T || $h % $T) {
128 warn "$path: weird png size ($w $h), skipping.\n"; 137 warn "$path: weird png size ($w $h), skipping.\n";
129 return; 138 next;
130 } 139 }
131 140
132 if (($w > $T || $h > $T) && $face !~ /_S\./) { 141 if (($w > $T || $h > $T) && $face !~ /_S\./) {
133 # split 142 # split
134 my @tile; 143 my @tile;
149 (map { 158 (map {
150 ( 159 (
151 "(", 160 "(",
152 "+clone", 161 "+clone",
153 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T), 162 -crop => (sprintf "%dx%d+%d+%d", $T, $T, $_->[0] * $T, $_->[1] * $T),
163 "+repage",
154 -write => "png:$_->[2]~", 164 -write => "png:$_->[2]~",
155 "+delete", 165 "+delete",
156 ")", 166 ")",
157 ) 167 )
158 } @todo), 168 } @todo),
195 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/ 205 aio_load "$dir/$file", $arc; # simply pre-cache, as read_arch wants a file :/
196 206
197 my $arc = read_arch "$dir/$file"; 207 my $arc = read_arch "$dir/$file";
198 for my $o (values %$arc) { 208 for my $o (values %$arc) {
199 push @ARC, $o; 209 push @ARC, $o;
210
211 $o->{editor_folder} = $dir;
212
213 my $visibility = delete $o->{visibility};
214 my $magicmap = delete $o->{magicmap};
215
216 # find upper left corner :/
217 # omg, this is sooo broken
200 my ($dx, $dy); 218 my ($dx, $dy);
201 # omg, this is sooo broken
202 for (my $o = $o; $o; $o = $o->{more}) { 219 for (my $o = $o; $o; $o = $o->{more}) {
203 $dx = $o->{x} if $o->{x} < $dx; 220 $dx = $o->{x} if $o->{x} < $dx;
204 $dy = $o->{y} if $o->{y} < $dy; 221 $dy = $o->{y} if $o->{y} < $dy;
205 } 222 }
223
206 for (my $o = $o; $o; $o = $o->{more}) { 224 for (my $o = $o; $o; $o = $o->{more}) {
207 my $x = $o->{x} - $dx; 225 my $x = $o->{x} - $dx;
208 my $y = $o->{y} - $dy; 226 my $y = $o->{y} - $dy;
227
228 my $ext = $x|$y ? "+$x+$y" : "";
229
230 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/;
231
232 my $visibility = delete $o->{visibility} if exists $o->{visibility};
233 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
234
235 my $anim = delete $o->{anim};
236
209 if ($x|$y) { 237 if ($anim) {
210 $_ .= "+$x+$y" for $o->{face}, @{$o->{anim} || []}; 238 $o->{animation} = "$o->{_name}";
239
240 for (@$anim) {
241 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/;
242 }
243
244 $ANIM{"$o->{_name}$ext"} =
245 join "", map "$_\n",
246 "anim $o->{_name}",
247 @$anim,
248 "mina";
249 }
250
251 for my $face ($o->{face} || (), @{$anim || []}) {
252 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
253
254 my $info = $FACEINFO{$face} ||= {};
255
256 $info->{visibility} = $visibility if defined $visibility;
257 $info->{magicmap} = $magicmap if defined $magicmap;
258 }
259
260 if (my $smooth = delete $o->{smoothface}) {
261 my ($face, $smooth) = split /\s+/, $smooth;
262 # skip empty_S.x11, it seems to server no purpose whatsoever
263 # but increases bandwidth demands and worse.
264 unless ($smooth eq "empty_S.x11") {
265 $FACEINFO{$face}{smooth} = $smooth;
266 }
211 } 267 }
212 } 268 }
213 } 269 }
214 } 270 }
215 } 271 }
216 272
217 sub process_trs { 273 sub process_trs {
218 while (@trs) { 274 while (@trs) {
219 my ($dir, $file) = @{pop @trs}; 275 my ($dir, $file) = @{pop @trs};
276 my $path = "$dir/$file";
277
278 my $trs;
279 if (0 > aio_load $path, $trs) {
280 warn "$path: $!, skipping.\n";
281 next;
282 }
283
284 $TRS .= $trs;
220 } 285 }
221 } 286 }
222 287
223 sub find_files; 288 sub find_files;
224 sub find_files { 289 sub find_files {
246 } 311 }
247 312
248 sub inst_arch($) { 313 sub inst_arch($) {
249 my (undef, $path) = @_; 314 my (undef, $path) = @_;
250 315
251 print "installing '$path' to '$DATADIR'\n\n"; 316 print "installing '$path' to '$DATADIR'\n";
252 317
253 if (!-d "$path/treasures") { 318 if (!-d "$path/treasures") {
254 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n"; 319 warn "'$path' does not look like an arch directory ('treasures' directory is missing).\n";
255 exit 1 unless $FORCE; 320 exit 1 unless $FORCE;
256 } 321 }
262 (async \&process_png), (async \&process_png), 327 (async \&process_png), (async \&process_png),
263 (async \&process_trs), (async \&process_trs), 328 (async \&process_trs), (async \&process_trs),
264 (async \&process_arc), (async \&process_arc), 329 (async \&process_arc), (async \&process_arc),
265 ); 330 );
266 331
332 {
333 open my $fh, ">:utf8", "$DATADIR/animations~"
334 or die "$DATADIR/animations~: $!";
335 print $fh join "", map $ANIM{$_}, sort keys %ANIM
336 }
337
338 {
267 open my $archetypes, ">:utf8", "$DATADIR/archetypes~" 339 open my $fh, ">:utf8", "$DATADIR/archetypes~"
268 or die "$DATADIR/archetypes~: $!"; 340 or die "$DATADIR/archetypes~: $!";
341 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC;
269 print $archetypes Crossfire::archlist_to_string \@ARC; 342 print $fh Crossfire::archlist_to_string \@ARC;
270 close $archetypes; 343 }
271 rename "$DATADIR/archetypes~", "$DATADIR/archetypes";
272 344
273 die "--install-arch not fully implemented\n"; 345 {
346 open my $fh, ">:utf8", "$DATADIR/treasures~"
347 or die "$DATADIR/treasures~: $!";
348 print $fh $TRS;
349 }
350
351 {
352 while (my ($k, $v) = each %FACEINFO) {
353 $v->{data32} ||= delete $PNG32{$k};
354 }
355
356 while (my ($k, $v) = each %FACEINFO) {
357 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
358
359 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
360 }
361
362 open my $fh, ">:perlio", "$DATADIR/faces~"
363 or die "$DATADIR/faces~: $!";
364
365 print $fh Storable::nfreeze \%FACEINFO;
366 }
367
368 for (qw(archetypes faces animations treasures)) {
369 chmod 0644, "$DATADIR/$_~";
370 rename "$DATADIR/$_~", "$DATADIR/$_"
371 or die "$DATADIR/$_: $!";
372 }
373
374 print "archetype data installed successfully.\n";
274 } 375 }
275} 376}
276 377
277Getopt::Long::Configure ("bundling", "no_ignore_case"); 378Getopt::Long::Configure ("bundling", "no_ignore_case");
278GetOptions ( 379GetOptions (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines