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.6 by root, Sun Mar 11 02:12:45 2007 UTC vs.
Revision 1.18 by root, Sat Mar 17 19:57:02 2007 UTC

20use Crossfire; 20use Crossfire;
21use Coro; 21use Coro;
22use Coro::AIO; 22use Coro::AIO;
23use POSIX (); 23use POSIX ();
24use Digest::MD5; 24use Digest::MD5;
25use Storable; $Storable::canonical = 1;
25 26
26sub usage { 27sub usage {
27 warn <<EOF; 28 warn <<EOF;
28Usage: cfutil [-v] [-q] [--force] [--cache] 29Usage: cfutil [-v] [-q] [--force] [--cache]
29 [--install-arch path] 30 [--install-arch path]
67} 68}
68 69
69sub inst_maps($) { 70sub 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
117 my ($w, $h) = unpack "NN", $1; 122 my ($w, $h) = unpack "NN", $1;
118 123
119 (my $face = $path) =~ s/^.*\///; 124 (my $face = $path) =~ s/^.*\///;
120 my $T = 32; 125 my $T = 32;
121 126
122 unless ($face =~ s/\.base\.(...)\.png$/.$1/) { 127 unless ($face =~ s/\.32x32\.png$//) {
123 warn "$path: weird filename, skipping.\n"; 128 warn "$path: weird filename, skipping.\n";
124 next; 129 next;
125 } 130 }
126 131
127 if ($w < $T || $h < $T) { 132 if ($w < $T || $h < $T) {
154 (map { 159 (map {
155 ( 160 (
156 "(", 161 "(",
157 "+clone", 162 "+clone",
158 -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",
159 -write => "png:$_->[2]~", 165 -write => "png:$_->[2]~",
160 "+delete", 166 "+delete",
161 ")", 167 ")",
162 ) 168 )
163 } @todo), 169 } @todo),
201 207
202 my $arc = read_arch "$dir/$file"; 208 my $arc = read_arch "$dir/$file";
203 for my $o (values %$arc) { 209 for my $o (values %$arc) {
204 push @ARC, $o; 210 push @ARC, $o;
205 211
212 $o->{editor_folder} = $dir;
213
206 my $visibility = delete $o->{visibility}; 214 my $visibility = delete $o->{visibility};
207 my $magicmap = delete $o->{magicmap}; 215 my $magicmap = delete $o->{magicmap};
208 216
209 # find upper left corner :/ 217 # find upper left corner :/
210 # omg, this is sooo broken 218 # omg, this is sooo broken
218 my $x = $o->{x} - $dx; 226 my $x = $o->{x} - $dx;
219 my $y = $o->{y} - $dy; 227 my $y = $o->{y} - $dy;
220 228
221 my $ext = $x|$y ? "+$x+$y" : ""; 229 my $ext = $x|$y ? "+$x+$y" : "";
222 230
223 $o->{face} .= $ext; 231 $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/;
224 232
225 my $visibility = delete $o->{visibility} if exists $o->{visibility}; 233 my $visibility = delete $o->{visibility} if exists $o->{visibility};
226 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; 234 my $magicmap = delete $o->{magicmap} if exists $o->{magicmap};
227 235
228 my $anim = delete $o->{anim}; 236 my $anim = delete $o->{anim};
229 237
230 if ($anim) { 238 if ($anim) {
231 $o->{animation} = "$o->{_name}$ext"; 239 $o->{animation} = "$o->{_name}";
232 240
233 for (@$anim) { 241 for (@$anim) {
234 $_ .= $ext unless /^facings\s/; 242 $_ .= $ext unless /^facings\s|^blank.x11$|^empty.x11$/;
235 } 243 }
236 244
237 $ANIM{"$o->{_name}$ext"} = 245 $ANIM{"$o->{_name}$ext"} =
238 join "", map "$_\n", 246 join "", map "$_\n",
239 "anim $o->{_name}$ext", 247 "anim $o->{_name}",
240 @$anim, 248 @$anim,
241 "mina"; 249 "mina";
242 } 250 }
243 251
244 for my $face ($o->{face} || (), @{$anim || []}) { 252 for my $face ($o->{face} || (), @{$anim || []}) {
245 next if /^facings\s/; 253 next if $face =~ /^facings\s|^blank.x11$|^empty.x11$/;
246 254
247 my $info = $FACEINFO{$face} ||= {}; 255 my $info = $FACEINFO{$face} ||= {};
248 256
249 $info->{visibility} = $visibility if defined $visibility; 257 $info->{visibility} = $visibility if defined $visibility;
250 $info->{magicmap} = $magicmap if defined $magicmap; 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 }
251 } 268 }
252 } 269 }
253 } 270 }
254 } 271 }
255 } 272 }
256 273
257 sub process_trs { 274 sub process_trs {
258 while (@trs) { 275 while (@trs) {
259 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;
260 } 286 }
261 } 287 }
262 288
263 sub find_files; 289 sub find_files;
264 sub find_files { 290 sub find_files {
286 } 312 }
287 313
288 sub inst_arch($) { 314 sub inst_arch($) {
289 my (undef, $path) = @_; 315 my (undef, $path) = @_;
290 316
291 print "installing '$path' to '$DATADIR'\n\n"; 317 print "installing '$path' to '$DATADIR'\n";
292 318
293 if (!-d "$path/treasures") { 319 if (!-d "$path/treasures") {
294 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";
295 exit 1 unless $FORCE; 321 exit 1 unless $FORCE;
296 } 322 }
311 } 337 }
312 338
313 { 339 {
314 open my $fh, ">:utf8", "$DATADIR/archetypes~" 340 open my $fh, ">:utf8", "$DATADIR/archetypes~"
315 or die "$DATADIR/archetypes~: $!"; 341 or die "$DATADIR/archetypes~: $!";
342 substr $_->{editor_folder}, 0, 1 + length $path, "" for @ARC;
316 print $fh Crossfire::archlist_to_string \@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;
317 } 350 }
318 351
319 { 352 {
320 while (my ($k, $v) = each %FACEINFO) { 353 while (my ($k, $v) = each %FACEINFO) {
321 $v->{data32} ||= delete $PNG32{$k}; 354 $v->{data32} ||= delete $PNG32{$k};
322 } 355 }
323 356
324 while (my ($k, $v) = each %FACEINFO) { 357 while (my ($k, $v) = each %FACEINFO) {
325 exists $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";
326 359
327 $v->{chksum32} = Digest::MD5::md5 $v->{data32}; 360 $v->{chksum32} = Digest::MD5::md5 $v->{data32};
328 } 361 }
329 362
330 open my $fh, ">:perlio", "$DATADIR/faces~" 363 open my $fh, ">:perlio", "$DATADIR/faces~"
331 or die "$DATADIR/faces~: $!"; 364 or die "$DATADIR/faces~: $!";
332 365
366 $FACEINFO{""} = { version => 1};
333 print $fh Storable::nfreeze \%FACEINFO; 367 print $fh Storable::nfreeze \%FACEINFO;
334
335 #use PApp::Util; warn PApp::Util::dumpval \%FACEINFO;
336 } 368 }
337 369
338 for (qw(archetypes faces animations)) { 370 for (qw(archetypes faces animations treasures)) {
339 chmod 0644, "$DATADIR/$_~"; 371 chmod 0644, "$DATADIR/$_~";
340 rename "$DATADIR/$_~", "$DATADIR/$_"; 372 rename "$DATADIR/$_~", "$DATADIR/$_"
373 or die "$DATADIR/$_: $!";
341 } 374 }
342 375
343 die "--install-arch not fully implemented\n"; 376 print "archetype data installed successfully.\n";
344 } 377 }
345} 378}
346 379
347Getopt::Long::Configure ("bundling", "no_ignore_case"); 380Getopt::Long::Configure ("bundling", "no_ignore_case");
348GetOptions ( 381GetOptions (

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines