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.76 by root, Tue Nov 3 14:49:39 2009 UTC vs.
Revision 1.80 by root, Fri Mar 19 14:36:39 2010 UTC

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
3use strict; 25use strict;
4 26
5my $prefix = "@prefix@"; 27my $prefix = "@prefix@";
6my $exec_prefix = "@exec_prefix@"; 28my $exec_prefix = "@exec_prefix@";
21use Coro::EV; 43use Coro::EV;
22use AnyEvent; 44use AnyEvent;
23use YAML::XS (); 45use YAML::XS ();
24use JSON::XS (); 46use JSON::XS ();
25use IO::AIO (); 47use IO::AIO ();
48use Digest::MD5 ();
26 49
27use Coro 5.12; 50use Coro 5.12;
28use Coro::AIO; 51use Coro::AIO;
29use Coro::Util; 52use Coro::Util;
30use Coro::Channel; 53use Coro::Channel;
72 95
73END { system "rm", "-rf", $TMPDIR } 96END { system "rm", "-rf", $TMPDIR }
74 97
75my $s_INT = EV::signal INT => sub { exit 1 }; 98my $s_INT = EV::signal INT => sub { exit 1 };
76my $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}
77 122
78mkdir $TMPDIR, 0700 123mkdir $TMPDIR, 0700
79 or die "$TMPDIR: $!"; 124 or die "$TMPDIR: $!";
80 125
81sub fork_sub(&) { 126sub fork_sub(&) {
565 IO::AIO::aioreq_pri 4; 610 IO::AIO::aioreq_pri 4;
566 IO::AIO::aio_scandir $path, 4, sub { 611 IO::AIO::aio_scandir $path, 4, sub {
567 my ($dirs, $nondirs) = @_; 612 my ($dirs, $nondirs) = @_;
568 613
569 find_files "$path/$_" 614 find_files "$path/$_"
570 for grep $_ !~ /^(?:CVS|dev)$/, @$dirs; 615 for grep $_ !~ /^(?:CVS|dev|\..*)$/, @$dirs;
571 616
572 my $dir = $path; 617 my $dir = $path;
573 substr $dir, 0, 1 + length $PATH, ""; 618 substr $dir, 0, 1 + length $PATH, "";
574 619
575 for my $file (@$nondirs) { 620 for my $file (@$nondirs) {
720 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; 765 @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC;
721 766
722 print "generating plurals...\n" if $VERBOSE; 767 print "generating plurals...\n" if $VERBOSE;
723 generate_plurals; 768 generate_plurals;
724 769
725 print "writing archetypes...\n" if $VERBOSE; 770 printf "writing %d archetypes...\n", scalar @ARC if $VERBOSE;
726 open my $fh, ">:utf8", "$DATADIR/archetypes~" 771 open my $fh, ">:utf8", "$DATADIR/archetypes~"
727 or die "$DATADIR/archetypes~: $!"; 772 or die "$DATADIR/archetypes~: $!";
728 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];
729 } 774 }
730 775
731 { 776 {
732 print "writing treasures...\n" if $VERBOSE; 777 printf "writing treasures (%d octets)...\n", length $TRS if $VERBOSE;
733 open my $fh, ">:utf8", "$DATADIR/treasures~" 778 open my $fh, ">:utf8", "$DATADIR/treasures~"
734 or die "$DATADIR/treasures~: $!"; 779 or die "$DATADIR/treasures~: $!";
735 print $fh $TRS; 780 print $fh $TRS;
736 } 781 }
737 782
739 print "processing facedata...\n" if $VERBOSE; 784 print "processing facedata...\n" if $VERBOSE;
740 while (my ($k, $v) = each %FACEINFO) { 785 while (my ($k, $v) = each %FACEINFO) {
741 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";
742 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";
743 788
789 make_hash $k, $v->{data32}, $v->{hash32};
790 make_hash $k, $v->{data64}, $v->{hash64};
791
744 #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";
745 #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";
746 794
747 if (my $magicmap = $v->{magicmap}) { 795 if (my $magicmap = $v->{magicmap}) {
748 $magicmap =~ y/A-Z_\-/a-z/d; 796 $magicmap =~ y/A-Z_\-/a-z/d;
750 } 798 }
751 799
752 delete $v->{arc}; 800 delete $v->{arc};
753 } 801 }
754 802
755 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
756 open my $fh, ">:perlio", "$DATADIR/facedata~" 827 open my $fh, ">:perlio", "$DATADIR/facedata~"
757 or die "$DATADIR/facedata~: $!"; 828 or die "$DATADIR/facedata~: $!";
758 829
759 print $fh freeze { 830 print $fh freeze {
760 version => 2, 831 version => 2,
761 faceinfo => \%FACEINFO, 832 faceinfo => \%FACEINFO,
762 animinfo => \%ANIMINFO, 833 animinfo => \%ANIMINFO,
763 resource => \%RESOURCE, 834 resource => \%RESOURCE,
764 }; 835 };
836
765 } 837 }
766 838
767 print "committing files...\n" if $VERBOSE; 839 print "committing files...\n" if $VERBOSE;
768 840
769 for (qw(archetypes facedata treasures)) { 841 for (qw(archetypes facedata treasures)) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines