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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines