1 | #!@PERL@ |
1 | #!@PERL@ |
|
|
2 | |
|
|
3 | # |
|
|
4 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
5 | # |
|
|
6 | # Copyright (©) 2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
7 | # |
|
|
8 | # Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | # the terms of the Affero GNU General Public License as published by the |
|
|
10 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | # option) any later version. |
|
|
12 | # |
|
|
13 | # This program is distributed in the hope that it will be useful, |
|
|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | # GNU General Public License for more details. |
|
|
17 | # |
|
|
18 | # You should have received a copy of the Affero GNU General Public License |
|
|
19 | # and the GNU General Public License along with this program. If not, see |
|
|
20 | # <http://www.gnu.org/licenses/>. |
|
|
21 | # |
|
|
22 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
23 | # |
2 | |
24 | |
3 | use strict; |
25 | use strict; |
4 | |
26 | |
5 | my $prefix = "@prefix@"; |
27 | my $prefix = "@prefix@"; |
6 | my $exec_prefix = "@exec_prefix@"; |
28 | my $exec_prefix = "@exec_prefix@"; |
… | |
… | |
21 | use Coro::EV; |
43 | use Coro::EV; |
22 | use AnyEvent; |
44 | use AnyEvent; |
23 | use YAML::XS (); |
45 | use YAML::XS (); |
24 | use JSON::XS (); |
46 | use JSON::XS (); |
25 | use IO::AIO (); |
47 | use IO::AIO (); |
|
|
48 | use Digest::MD5 (); |
26 | |
49 | |
27 | use Coro 5.12; |
50 | use Coro 5.12; |
28 | use Coro::AIO; |
51 | use Coro::AIO; |
29 | use Coro::Util; |
52 | use Coro::Util; |
30 | use Coro::Channel; |
53 | use Coro::Channel; |
… | |
… | |
72 | |
95 | |
73 | END { system "rm", "-rf", $TMPDIR } |
96 | END { system "rm", "-rf", $TMPDIR } |
74 | |
97 | |
75 | my $s_INT = EV::signal INT => sub { exit 1 }; |
98 | my $s_INT = EV::signal INT => sub { exit 1 }; |
76 | 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 | } |
77 | |
122 | |
78 | mkdir $TMPDIR, 0700 |
123 | mkdir $TMPDIR, 0700 |
79 | or die "$TMPDIR: $!"; |
124 | or die "$TMPDIR: $!"; |
80 | |
125 | |
81 | sub fork_sub(&) { |
126 | sub fork_sub(&) { |
… | |
… | |
383 | push @ARC, $o; |
428 | push @ARC, $o; |
384 | for (my $m = $o; $m; $m = $m->{more}) { |
429 | for (my $m = $o; $m; $m = $m->{more}) { |
385 | $ARC{$m->{_name}} = $m; |
430 | $ARC{$m->{_name}} = $m; |
386 | } |
431 | } |
387 | |
432 | |
388 | $o->{editor_folder} = $dir; |
433 | $o->{editor_folder} ||= "\x00$dir"; # horrible kludge |
389 | |
434 | |
390 | my $visibility = delete $o->{visibility}; |
435 | my $visibility = delete $o->{visibility}; |
391 | my $magicmap = delete $o->{magicmap}; |
436 | my $magicmap = delete $o->{magicmap}; |
392 | |
437 | |
393 | # find upper left corner :/ |
438 | # find upper left corner :/ |
… | |
… | |
607 | } |
652 | } |
608 | |
653 | |
609 | sub generate_plurals { |
654 | sub generate_plurals { |
610 | # use Lingua::EN::Inflect (); |
655 | # use Lingua::EN::Inflect (); |
611 | # Lingua::EN::Inflect::classical; |
656 | # Lingua::EN::Inflect::classical; |
612 | # Lingua::EN::Inflect::def_noun 'talisman' => 'talismans'; |
657 | # Lingua::EN::Inflect::def_noun '(.*)staff' => '$1staves'; # policy |
613 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
658 | # Lingua::EN::Inflect::def_noun '(.*)boots' => '$1boots'; # hack |
614 | # |
659 | # |
615 | # for my $a (@ARC) { |
660 | # for my $a (@ARC) { |
616 | # my $name = $a->{name} || $a->{_name}; |
661 | # my $name = $a->{name} || $a->{_name}; |
617 | # |
662 | # |
618 | # next unless $a->{name_pl}; |
663 | # next unless $a->{name_pl}; |
619 | # |
664 | # next if $a->{invisible}; |
|
|
665 | # next if $a->{is_floor}; |
|
|
666 | # next if $a->{no_pick}; |
620 | # |
667 | # |
621 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
668 | # my $test = Lingua::EN::Inflect::PL_N_eq $name, Lingua::EN::Inflect::PL $name; |
622 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
669 | # my $pl = $test =~ /^(?:eq|p:.)$/ |
623 | # ? $name |
670 | # ? $name |
624 | # : Lingua::EN::Inflect::PL $name; |
671 | # : Lingua::EN::Inflect::PL $name; |
625 | # die "$test $pl" if $pl =~ /bootss/;#d# |
|
|
626 | # |
672 | # |
627 | # if ($pl ne $a->{name_pl}) { |
673 | # if ($pl ne $a->{name_pl}) { |
628 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
674 | # warn "$a->{_name}: plural differs, $pl vs $a->{name_pl}\n"; |
629 | # } |
675 | # } |
630 | # } |
676 | # } |
… | |
… | |
676 | $_->join for (@a_trs, @a_res, @a_png); |
722 | $_->join for (@a_trs, @a_res, @a_png); |
677 | |
723 | |
678 | print "scanning done, processing results...\n" if $VERBOSE; |
724 | print "scanning done, processing results...\n" if $VERBOSE; |
679 | { |
725 | { |
680 | # remove path prefix from editor_folder |
726 | # remove path prefix from editor_folder |
|
|
727 | $_->{editor_folder} =~ /^\x00/ |
681 | substr $_->{editor_folder}, 0, 1 + length $path, "" |
728 | and substr $_->{editor_folder}, 0, 2 + length $path, "" |
682 | for values %ARC; |
729 | for values %ARC; |
683 | |
730 | |
684 | print "resolving inheritance tree...\n" if $VERBOSE; |
731 | print "resolving inheritance tree...\n" if $VERBOSE; |
685 | # resolve inherit |
732 | # resolve inherit |
686 | while () { |
733 | while () { |
687 | my $progress; |
734 | my $progress; |
… | |
… | |
718 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
765 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
719 | |
766 | |
720 | print "generating plurals...\n" if $VERBOSE; |
767 | print "generating plurals...\n" if $VERBOSE; |
721 | generate_plurals; |
768 | generate_plurals; |
722 | |
769 | |
723 | print "writing archetypes...\n" if $VERBOSE; |
770 | printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE; |
724 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
771 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
725 | or die "$DATADIR/archetypes~: $!"; |
772 | or die "$DATADIR/archetypes~: $!"; |
726 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
773 | print $fh Deliantra::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
727 | } |
774 | } |
728 | |
775 | |
729 | { |
776 | { |
730 | print "writing treasures...\n" if $VERBOSE; |
777 | printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE; |
731 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
778 | open my $fh, ">:utf8", "$DATADIR/treasures~" |
732 | or die "$DATADIR/treasures~: $!"; |
779 | or die "$DATADIR/treasures~: $!"; |
733 | print $fh $TRS; |
780 | print $fh $TRS; |
734 | } |
781 | } |
735 | |
782 | |
… | |
… | |
737 | print "processing facedata...\n" if $VERBOSE; |
784 | print "processing facedata...\n" if $VERBOSE; |
738 | while (my ($k, $v) = each %FACEINFO) { |
785 | while (my ($k, $v) = each %FACEINFO) { |
739 | 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"; |
740 | 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"; |
741 | |
788 | |
|
|
789 | make_hash $k, $v->{data32}, $v->{hash32}; |
|
|
790 | make_hash $k, $v->{data64}, $v->{hash64}; |
|
|
791 | |
742 | #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"; |
743 | #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"; |
744 | |
794 | |
745 | if (my $magicmap = $v->{magicmap}) { |
795 | if (my $magicmap = $v->{magicmap}) { |
746 | $magicmap =~ y/A-Z_\-/a-z/d; |
796 | $magicmap =~ y/A-Z_\-/a-z/d; |
… | |
… | |
748 | } |
798 | } |
749 | |
799 | |
750 | delete $v->{arc}; |
800 | delete $v->{arc}; |
751 | } |
801 | } |
752 | |
802 | |
753 | print "writing facedata...\n" if $VERBOSE; |
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 |
|
|
819 | } |
|
|
820 | |
|
|
821 | printf "writing facedata (%d faces, %d anims, %d resources)...\n", |
|
|
822 | scalar keys %FACEINFO, |
|
|
823 | scalar keys %ANIMINFO, |
|
|
824 | scalar keys %RESOURCE |
|
|
825 | if $VERBOSE; |
|
|
826 | |
754 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
827 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
755 | or die "$DATADIR/facedata~: $!"; |
828 | or die "$DATADIR/facedata~: $!"; |
756 | |
829 | |
757 | print $fh freeze { |
830 | print $fh freeze { |
758 | version => 2, |
831 | version => 2, |
759 | faceinfo => \%FACEINFO, |
832 | faceinfo => \%FACEINFO, |
760 | animinfo => \%ANIMINFO, |
833 | animinfo => \%ANIMINFO, |
761 | resource => \%RESOURCE, |
834 | resource => \%RESOURCE, |
762 | }; |
835 | }; |
|
|
836 | |
763 | } |
837 | } |
764 | |
838 | |
765 | print "committing files...\n" if $VERBOSE; |
839 | print "committing files...\n" if $VERBOSE; |
766 | |
840 | |
767 | for (qw(archetypes facedata treasures)) { |
841 | for (qw(archetypes facedata treasures)) { |