… | |
… | |
43 | use Coro::EV; |
43 | use Coro::EV; |
44 | use AnyEvent; |
44 | use AnyEvent; |
45 | use YAML::XS (); |
45 | use YAML::XS (); |
46 | use JSON::XS (); |
46 | use JSON::XS (); |
47 | use IO::AIO (); |
47 | use IO::AIO (); |
|
|
48 | use Digest::MD5 (); |
48 | |
49 | |
49 | use Coro 5.12; |
50 | use Coro 5.12; |
50 | use Coro::AIO; |
51 | use Coro::AIO; |
51 | use Coro::Util; |
52 | use Coro::Util; |
52 | use Coro::Channel; |
53 | use Coro::Channel; |
… | |
… | |
94 | |
95 | |
95 | END { system "rm", "-rf", $TMPDIR } |
96 | END { system "rm", "-rf", $TMPDIR } |
96 | |
97 | |
97 | my $s_INT = EV::signal INT => sub { exit 1 }; |
98 | my $s_INT = EV::signal INT => sub { exit 1 }; |
98 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
99 | my $s_TERM = EV::signal TERM => sub { exit 1 }; |
|
|
100 | |
|
|
101 | our %hash; |
|
|
102 | |
|
|
103 | # here we could try to avoid collisions and reduce chksum size further |
|
|
104 | sub 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 | |
100 | mkdir $TMPDIR, 0700 |
123 | mkdir $TMPDIR, 0700 |
101 | or die "$TMPDIR: $!"; |
124 | or die "$TMPDIR: $!"; |
102 | |
125 | |
103 | sub fork_sub(&) { |
126 | sub fork_sub(&) { |
… | |
… | |
587 | IO::AIO::aioreq_pri 4; |
610 | IO::AIO::aioreq_pri 4; |
588 | IO::AIO::aio_scandir $path, 4, sub { |
611 | IO::AIO::aio_scandir $path, 4, sub { |
589 | my ($dirs, $nondirs) = @_; |
612 | my ($dirs, $nondirs) = @_; |
590 | |
613 | |
591 | find_files "$path/$_" |
614 | find_files "$path/$_" |
592 | for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; |
615 | for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs; |
593 | |
616 | |
594 | my $dir = $path; |
617 | my $dir = $path; |
595 | substr $dir, 0, 1 + length $PATH, ""; |
618 | substr $dir, 0, 1 + length $PATH, ""; |
596 | |
619 | |
597 | for my $file (@$nondirs) { |
620 | for my $file (@$nondirs) { |
… | |
… | |
710 | while () { |
733 | while () { |
711 | my $progress; |
734 | my $progress; |
712 | my $loop; |
735 | my $loop; |
713 | |
736 | |
714 | for my $o (values %ARC) { |
737 | for my $o (values %ARC) { |
715 | if (my $other = $o->{inherit}) { |
738 | for my $other (split /,/, $o->{inherit}) { |
716 | if (my $s = $ARC{$other}) { |
739 | if (my $s = $ARC{$other}) { |
717 | if ($s->{inherit}) { |
740 | if ($s->{inherit}) { |
718 | $loop = $s; |
741 | $loop = $s; |
719 | } else { |
742 | } else { |
720 | delete $o->{inherit}; |
743 | delete $o->{inherit}; |
… | |
… | |
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, |