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.78 by root, Wed Nov 4 13:46:37 2009 UTC vs.
Revision 1.79 by root, Sun Nov 15 18:04:00 2009 UTC

43use Coro::EV; 43use Coro::EV;
44use AnyEvent; 44use AnyEvent;
45use YAML::XS (); 45use YAML::XS ();
46use JSON::XS (); 46use JSON::XS ();
47use IO::AIO (); 47use IO::AIO ();
48use Digest::MD5 ();
48 49
49use Coro 5.12; 50use Coro 5.12;
50use Coro::AIO; 51use Coro::AIO;
51use Coro::Util; 52use Coro::Util;
52use Coro::Channel; 53use Coro::Channel;
94 95
95END { system "rm", "-rf", $TMPDIR } 96END { system "rm", "-rf", $TMPDIR }
96 97
97my $s_INT = EV::signal INT => sub { exit 1 }; 98my $s_INT = EV::signal INT => sub { exit 1 };
98my $s_TERM = EV::signal TERM => sub { exit 1 }; 99my $s_TERM = EV::signal TERM => sub { exit 1 };
100
101our %hash;
102
103# here we could try to avoid collisions and reduce chksum size further
104sub make_hash($\$\$;$) {
105 my ($id, $dataref, $hashref, $clen) = @_;
106
107 my $hash = substr +(Digest::MD5::md5 $$dataref), 0, $clen || 4;
108
109 if (exists $hash{$hash}) {
110 # hahs collinion, but some files are simply identical
111 if (${$hash{$hash}[1]} ne $$dataref) {
112 warn "hash collision $hash{$hash}[0] vs. $id\n";
113 exit 1;
114 } else {
115 print "$hash{$hash}[0] and $id are identical (which is fine).\n" if $VERBOSE >= 3;
116 }
117 }
118 $hash{$hash} = [$id, $dataref, $hashref];
119
120 $$hashref = $hash;
121}
99 122
100mkdir $TMPDIR, 0700 123mkdir $TMPDIR, 0700
101 or die "$TMPDIR: $!"; 124 or die "$TMPDIR: $!";
102 125
103sub fork_sub(&) { 126sub fork_sub(&) {
761 print "processing facedata...\n" if $VERBOSE; 784 print "processing facedata...\n" if $VERBOSE;
762 while (my ($k, $v) = each %FACEINFO) { 785 while (my ($k, $v) = each %FACEINFO) {
763 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n"; 786 length $v->{data32} or warn "$k: face has no png32. this will not work (shoddy gcfclient will crash of course).\n";
764 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n"; 787 length $v->{data64} or warn "$k: face has no png64. this will not work very well.\n";
765 788
789 make_hash $k, $v->{data32}, $v->{hash32};
790 make_hash $k, $v->{data64}, $v->{hash64};
791
766 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; 792 #length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n";
767 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; 793 #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n";
768 794
769 if (my $magicmap = $v->{magicmap}) { 795 if (my $magicmap = $v->{magicmap}) {
770 $magicmap =~ y/A-Z_\-/a-z/d; 796 $magicmap =~ y/A-Z_\-/a-z/d;
771 $v->{magicmap} = $COLOR{$magicmap}; 797 $v->{magicmap} = $COLOR{$magicmap};
772 } 798 }
773 799
774 delete $v->{arc}; 800 delete $v->{arc};
801 }
802
803 print "processing resources...\n" if $VERBOSE;
804 my $enc = JSON::XS->new->utf8->canonical->relaxed;
805 while (my ($k, $v) = each %RESOURCE) {
806
807 if ($v->{type} & 1) {
808 # prepend meta info
809
810 my $meta = $enc->encode ({
811 name => $k,
812 %{ $v->{meta} || {} },
813 });
814
815 $v->{data} = pack "(w/a*)*", $meta, $v->{data};
816 }
817
818 make_hash $k, $v->{data}, $v->{hash}, 6; # 6 for the benefit of existing clients
775 } 819 }
776 820
777 printf "writing facedata (%d faces, %d anims, %d resources)...\n", 821 printf "writing facedata (%d faces, %d anims, %d resources)...\n",
778 scalar keys %FACEINFO, 822 scalar keys %FACEINFO,
779 scalar keys %ANIMINFO, 823 scalar keys %ANIMINFO,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines