ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.332 by root, Sat Aug 18 17:33:53 2007 UTC vs.
Revision 1.336 by root, Tue Aug 21 00:31:18 2007 UTC

1505=cut 1505=cut
1506 1506
1507sub ext_reply($$@) { 1507sub ext_reply($$@) {
1508 my ($self, $id, @msg) = @_; 1508 my ($self, $id, @msg) = @_;
1509 1509
1510 if ($self->ns->extcmd == 2) { 1510 $self->ns->ext_reply ($id, @msg)
1511 $self->send ("ext " . $self->ns->{json_coder}->encode (["reply-$id", @msg]));
1512 } elsif ($self->ns->extcmd == 1) {
1513 #TODO: version 1, remove
1514 unshift @msg, msgtype => "reply", msgid => $id;
1515 $self->send ("ext " . $self->ns->{json_coder}->encode ({@msg}));
1516 }
1517} 1511}
1518 1512
1519=item $player->ext_msg ($type, @msg) 1513=item $player->ext_msg ($type, @msg)
1520 1514
1521Sends an ext event to the client. 1515Sends an ext event to the client.
1916 1910
1917 $self 1911 $self
1918} 1912}
1919 1913
1920# find and load all maps in the 3x3 area around a map 1914# find and load all maps in the 3x3 area around a map
1921sub load_diag { 1915sub load_neighbours {
1922 my ($map) = @_; 1916 my ($map) = @_;
1923 1917
1924 my @diag; # diagonal neighbours 1918 my @neigh; # diagonal neighbours
1925 1919
1926 for (0 .. 3) { 1920 for (0 .. 3) {
1927 my $neigh = $map->tile_path ($_) 1921 my $neigh = $map->tile_path ($_)
1928 or next; 1922 or next;
1929 $neigh = find $neigh, $map 1923 $neigh = find $neigh, $map
1930 or next; 1924 or next;
1931 $neigh->load; 1925 $neigh->load;
1932 1926
1927 push @neigh,
1933 push @diag, [$neigh->tile_path (($_ + 3) % 4), $neigh], 1928 [$neigh->tile_path (($_ + 3) % 4), $neigh],
1934 [$neigh->tile_path (($_ + 1) % 4), $neigh]; 1929 [$neigh->tile_path (($_ + 1) % 4), $neigh];
1935 } 1930 }
1936 1931
1937 for (@diag) { 1932 for (grep defined $_->[0], @neigh) {
1933 my ($path, $origin) = @$_;
1938 my $neigh = find @$_ 1934 my $neigh = find $path, $origin
1939 or next; 1935 or next;
1940 $neigh->load; 1936 $neigh->load;
1941 } 1937 }
1942} 1938}
1943 1939
2312 # use -1 or undef as default coordinates, not 0, 0 2308 # use -1 or undef as default coordinates, not 0, 0
2313 ($x, $y) = ($map->enter_x, $map->enter_y) 2309 ($x, $y) = ($map->enter_x, $map->enter_y)
2314 if $x <=0 && $y <= 0; 2310 if $x <=0 && $y <= 0;
2315 2311
2316 $map->load; 2312 $map->load;
2317 $map->load_diag; 2313 $map->load_neighbours;
2318 2314
2319 return unless $self->contr->active; 2315 return unless $self->contr->active;
2320 $self->activate_recursive; 2316 $self->activate_recursive;
2321 2317
2322 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2318 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2565 push @msg, msgtype => "event_$type"; 2561 push @msg, msgtype => "event_$type";
2566 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); 2562 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2567 } 2563 }
2568} 2564}
2569 2565
2566=item $client->ext_reply ($msgid, @msg)
2567
2568Sends an ext reply to the client.
2569
2570=cut
2571
2572sub cf::client::ext_reply($$@) {
2573 my ($self, $id, @msg) = @_;
2574
2575 if ($self->extcmd == 2) {
2576 $self->send_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
2577 } elsif ($self->ns->extcmd == 1) {
2578 #TODO: version 1, remove
2579 unshift @msg, msgtype => "reply", msgid => $id;
2580 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2581 }
2582}
2583
2570=item $success = $client->query ($flags, "text", \&cb) 2584=item $success = $client->query ($flags, "text", \&cb)
2571 2585
2572Queues a query to the client, calling the given callback with 2586Queues a query to the client, calling the given callback with
2573the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, 2587the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>,
2574C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>. 2588C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>.
2809# the server's init and main functions 2823# the server's init and main functions
2810 2824
2811sub load_facedata($) { 2825sub load_facedata($) {
2812 my ($path) = @_; 2826 my ($path) = @_;
2813 2827
2828 my $enc = JSON::XS->new->utf8->canonical;
2829
2814 warn "loading facedata from $path\n"; 2830 warn "loading facedata from $path\n";
2815 2831
2816 my $facedata; 2832 my $facedata;
2817 0 < aio_load $path, $facedata 2833 0 < aio_load $path, $facedata
2818 or die "$path: $!"; 2834 or die "$path: $!";
2819 2835
2820 $facedata = Coro::Storable::thaw $facedata; 2836 $facedata = Coro::Storable::thaw $facedata;
2821 2837
2822 $facedata->{version} == 2 2838 $facedata->{version} == 2
2823 or cf::cleanup "$path: version mismatch, cannot proceed."; 2839 or cf::cleanup "$path: version mismatch, cannot proceed.";
2840
2841 # patch in the exptable
2842 $facedata->{resource}{"res/exp_table"} = {
2843 type => FT_RSRC,
2844 data => $enc->encode ([map cf::level_to_min_exp $_, 0 .. cf::settings->max_level]),
2845 };
2846 cf::cede_to_tick;
2824 2847
2825 { 2848 {
2826 my $faces = $facedata->{faceinfo}; 2849 my $faces = $facedata->{faceinfo};
2827 2850
2828 while (my ($face, $info) = each %$faces) { 2851 while (my ($face, $info) = each %$faces) {
2829 my $idx = (cf::face::find $face) || cf::face::alloc $face; 2852 my $idx = (cf::face::find $face) || cf::face::alloc $face;
2830 cf::face::set_visibility $idx, $info->{visibility}; 2853 cf::face::set_visibility $idx, $info->{visibility};
2831 cf::face::set_magicmap $idx, $info->{magicmap}; 2854 cf::face::set_magicmap $idx, $info->{magicmap};
2832 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; 2855 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32};
2833 cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; 2856 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64};
2834 2857
2835 cf::cede_to_tick; 2858 cf::cede_to_tick;
2836 } 2859 }
2837 2860
2838 while (my ($face, $info) = each %$faces) { 2861 while (my ($face, $info) = each %$faces) {
2863 2886
2864 { 2887 {
2865 # TODO: for gcfclient pleasure, we should give resources 2888 # TODO: for gcfclient pleasure, we should give resources
2866 # that gcfclient doesn't grok a >10000 face index. 2889 # that gcfclient doesn't grok a >10000 face index.
2867 my $res = $facedata->{resource}; 2890 my $res = $facedata->{resource};
2868 my $enc = JSON::XS->new->utf8->canonical;
2869 2891
2870 my $soundconf = delete $res->{"res/sound.conf"}; 2892 my $soundconf = delete $res->{"res/sound.conf"};
2871 2893
2872 while (my ($name, $info) = each %$res) { 2894 while (my ($name, $info) = each %$res) {
2873 my $meta = $enc->encode ({
2874 name => $name,
2875 %{ $info->{meta} || {} },
2876 });
2877
2878 my $idx = (cf::face::find $name) || cf::face::alloc $name; 2895 my $idx = (cf::face::find $name) || cf::face::alloc $name;
2896 my $data;
2879 2897
2880 if ($info->{type} & 1) { 2898 if ($info->{type} & 1) {
2881 # prepend meta info 2899 # prepend meta info
2882 2900
2901 my $meta = $enc->encode ({
2902 name => $name,
2903 %{ $info->{meta} || {} },
2904 });
2905
2883 my $data = pack "(w/a*)*", $meta, $info->{data}; 2906 $data = pack "(w/a*)*", $meta, $info->{data};
2884 my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata
2885
2886 cf::face::set_data $idx, 0, $data, $chk;
2887 } else {
2888 cf::face::set_data $idx, 0, $info->{data}, $info->{chksum};
2889 } 2907 }
2890 2908
2909 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
2891 cf::face::set_type $idx, $info->{type}; 2910 cf::face::set_type $idx, $info->{type};
2892 2911
2893 cf::cede_to_tick; 2912 cf::cede_to_tick;
2894 } 2913 }
2895 2914

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines