… | |
… | |
20 | use Crossfire; |
20 | use Crossfire; |
21 | use Coro; |
21 | use Coro; |
22 | use Coro::AIO; |
22 | use Coro::AIO; |
23 | use POSIX (); |
23 | use POSIX (); |
24 | use Digest::MD5; |
24 | use Digest::MD5; |
|
|
25 | use Storable; $Storable::canonical = 1; |
25 | |
26 | |
26 | sub usage { |
27 | sub usage { |
27 | warn <<EOF; |
28 | warn <<EOF; |
28 | Usage: cfutil [-v] [-q] [--force] [--cache] |
29 | Usage: cfutil [-v] [-q] [--force] [--cache] |
29 | [--install-arch path] |
30 | [--install-arch path] |
… | |
… | |
67 | } |
68 | } |
68 | |
69 | |
69 | sub inst_maps($) { |
70 | sub inst_maps($) { |
70 | my (undef, $path) = @_; |
71 | my (undef, $path) = @_; |
71 | |
72 | |
72 | print "installing '$path' to '$DATADIR/maps'\n\n"; |
73 | print "installing '$path' to '$DATADIR/maps'\n"; |
73 | |
74 | |
74 | if (!-f "$path/regions") { |
75 | if (!-f "$path/regions") { |
75 | 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"; |
76 | exit 1 unless $FORCE; |
77 | exit 1 unless $FORCE; |
77 | } |
78 | } |
78 | |
79 | |
79 | 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"; |
80 | } |
84 | } |
81 | |
85 | |
82 | { |
86 | { |
83 | our %PNG32; |
87 | our %PNG32; |
84 | our %FACEINFO; |
88 | our %FACEINFO; |
85 | our @ARC; |
89 | our @ARC; |
|
|
90 | our $TRS; |
86 | our $NFILE; |
91 | our $NFILE; |
87 | our %ANIM; |
92 | our %ANIM; |
88 | |
93 | |
89 | our (@png, @trs, @arc); # files we are interested in |
94 | our (@png, @trs, @arc); # files we are interested in |
90 | |
95 | |
… | |
… | |
250 | my $info = $FACEINFO{$face} ||= {}; |
255 | my $info = $FACEINFO{$face} ||= {}; |
251 | |
256 | |
252 | $info->{visibility} = $visibility if defined $visibility; |
257 | $info->{visibility} = $visibility if defined $visibility; |
253 | $info->{magicmap} = $magicmap if defined $magicmap; |
258 | $info->{magicmap} = $magicmap if defined $magicmap; |
254 | } |
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 | } |
255 | } |
269 | } |
256 | } |
270 | } |
257 | } |
271 | } |
258 | } |
272 | } |
259 | |
273 | |
260 | sub process_trs { |
274 | sub process_trs { |
261 | while (@trs) { |
275 | while (@trs) { |
262 | 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; |
263 | } |
286 | } |
264 | } |
287 | } |
265 | |
288 | |
266 | sub find_files; |
289 | sub find_files; |
267 | sub find_files { |
290 | sub find_files { |
… | |
… | |
289 | } |
312 | } |
290 | |
313 | |
291 | sub inst_arch($) { |
314 | sub inst_arch($) { |
292 | my (undef, $path) = @_; |
315 | my (undef, $path) = @_; |
293 | |
316 | |
294 | print "installing '$path' to '$DATADIR'\n\n"; |
317 | print "installing '$path' to '$DATADIR'\n"; |
295 | |
318 | |
296 | if (!-d "$path/treasures") { |
319 | if (!-d "$path/treasures") { |
297 | 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"; |
298 | exit 1 unless $FORCE; |
321 | exit 1 unless $FORCE; |
299 | } |
322 | } |
… | |
… | |
319 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
342 | substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC; |
320 | print $fh Crossfire::archlist_to_string \@ARC; |
343 | print $fh Crossfire::archlist_to_string \@ARC; |
321 | } |
344 | } |
322 | |
345 | |
323 | { |
346 | { |
|
|
347 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
|
|
348 | or die "$DATADIR/treasures~: $!"; |
|
|
349 | print $fh $TRS; |
|
|
350 | } |
|
|
351 | |
|
|
352 | { |
324 | while (my ($k, $v) = each %FACEINFO) { |
353 | while (my ($k, $v) = each %FACEINFO) { |
325 | $v->{data32} ||= delete $PNG32{$k}; |
354 | $v->{data32} ||= delete $PNG32{$k}; |
326 | } |
355 | } |
327 | |
356 | |
328 | while (my ($k, $v) = each %FACEINFO) { |
357 | while (my ($k, $v) = each %FACEINFO) { |
329 | length $v->{data32} or warn "$k: face has no png32. this will crash the server.\n"; |
358 | length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; |
330 | |
359 | |
331 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
360 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
332 | } |
361 | } |
333 | |
362 | |
334 | open my $fh, ">:perlio", "$DATADIR/faces~" |
363 | open my $fh, ">:perlio", "$DATADIR/faces~" |
335 | or die "$DATADIR/faces~: $!"; |
364 | or die "$DATADIR/faces~: $!"; |
336 | |
365 | |
|
|
366 | $FACEINFO{""} = { version => 1}; |
337 | print $fh Storable::nfreeze \%FACEINFO; |
367 | print $fh Storable::nfreeze \%FACEINFO; |
338 | |
|
|
339 | #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO; |
|
|
340 | } |
368 | } |
341 | |
369 | |
342 | for (qw(archetypes faces animations)) { |
370 | for (qw(archetypes faces animations treasures)) { |
343 | chmod 0644, "$DATADIR/$_~"; |
371 | chmod 0644, "$DATADIR/$_~"; |
344 | rename "$DATADIR/$_~", "$DATADIR/$_"; |
372 | rename "$DATADIR/$_~", "$DATADIR/$_" |
|
|
373 | or die "$DATADIR/$_: $!"; |
345 | } |
374 | } |
346 | |
375 | |
347 | die "--install-arch not fully implemented\n"; |
376 | print "archetype data installed successfully.\n"; |
348 | } |
377 | } |
349 | } |
378 | } |
350 | |
379 | |
351 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
380 | Getopt::Long::Configure ("bundling", "no_ignore_case"); |
352 | GetOptions ( |
381 | GetOptions ( |