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.338 by root, Tue Aug 21 01:07:47 2007 UTC

1149 my ($type, $reply, @payload) = 1149 my ($type, $reply, @payload) =
1150 "ARRAY" eq ref $msg 1150 "ARRAY" eq ref $msg
1151 ? @$msg 1151 ? @$msg
1152 : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove 1152 : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove
1153 1153
1154 my @reply;
1155
1154 if (my $cb = $EXTCMD{$type}) { 1156 if (my $cb = $EXTCMD{$type}) {
1155 my @reply = $cb->($pl, @payload); 1157 @reply = $cb->($pl, @payload);
1156
1157 $pl->ext_reply ($reply, @reply)
1158 if $reply;
1159 } 1158 }
1159
1160 $pl->ext_reply ($reply, @reply)
1161 if $reply;
1162
1160 } else { 1163 } else {
1161 warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; 1164 warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n";
1162 } 1165 }
1163 1166
1164 cf::override; 1167 cf::override;
1505=cut 1508=cut
1506 1509
1507sub ext_reply($$@) { 1510sub ext_reply($$@) {
1508 my ($self, $id, @msg) = @_; 1511 my ($self, $id, @msg) = @_;
1509 1512
1510 if ($self->ns->extcmd == 2) { 1513 $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} 1514}
1518 1515
1519=item $player->ext_msg ($type, @msg) 1516=item $player->ext_msg ($type, @msg)
1520 1517
1521Sends an ext event to the client. 1518Sends an ext event to the client.
1916 1913
1917 $self 1914 $self
1918} 1915}
1919 1916
1920# find and load all maps in the 3x3 area around a map 1917# find and load all maps in the 3x3 area around a map
1921sub load_diag { 1918sub load_neighbours {
1922 my ($map) = @_; 1919 my ($map) = @_;
1923 1920
1924 my @diag; # diagonal neighbours 1921 my @neigh; # diagonal neighbours
1925 1922
1926 for (0 .. 3) { 1923 for (0 .. 3) {
1927 my $neigh = $map->tile_path ($_) 1924 my $neigh = $map->tile_path ($_)
1928 or next; 1925 or next;
1929 $neigh = find $neigh, $map 1926 $neigh = find $neigh, $map
1930 or next; 1927 or next;
1931 $neigh->load; 1928 $neigh->load;
1932 1929
1930 push @neigh,
1933 push @diag, [$neigh->tile_path (($_ + 3) % 4), $neigh], 1931 [$neigh->tile_path (($_ + 3) % 4), $neigh],
1934 [$neigh->tile_path (($_ + 1) % 4), $neigh]; 1932 [$neigh->tile_path (($_ + 1) % 4), $neigh];
1935 } 1933 }
1936 1934
1937 for (@diag) { 1935 for (grep defined $_->[0], @neigh) {
1936 my ($path, $origin) = @$_;
1938 my $neigh = find @$_ 1937 my $neigh = find $path, $origin
1939 or next; 1938 or next;
1940 $neigh->load; 1939 $neigh->load;
1941 } 1940 }
1942} 1941}
1943 1942
2312 # use -1 or undef as default coordinates, not 0, 0 2311 # use -1 or undef as default coordinates, not 0, 0
2313 ($x, $y) = ($map->enter_x, $map->enter_y) 2312 ($x, $y) = ($map->enter_x, $map->enter_y)
2314 if $x <=0 && $y <= 0; 2313 if $x <=0 && $y <= 0;
2315 2314
2316 $map->load; 2315 $map->load;
2317 $map->load_diag; 2316 $map->load_neighbours;
2318 2317
2319 return unless $self->contr->active; 2318 return unless $self->contr->active;
2320 $self->activate_recursive; 2319 $self->activate_recursive;
2321 2320
2322 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2321 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2565 push @msg, msgtype => "event_$type"; 2564 push @msg, msgtype => "event_$type";
2566 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); 2565 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2567 } 2566 }
2568} 2567}
2569 2568
2569=item $client->ext_reply ($msgid, @msg)
2570
2571Sends an ext reply to the client.
2572
2573=cut
2574
2575sub cf::client::ext_reply($$@) {
2576 my ($self, $id, @msg) = @_;
2577
2578 if ($self->extcmd == 2) {
2579 $self->send_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
2580 } elsif ($self->ns->extcmd == 1) {
2581 #TODO: version 1, remove
2582 unshift @msg, msgtype => "reply", msgid => $id;
2583 $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg}));
2584 }
2585}
2586
2570=item $success = $client->query ($flags, "text", \&cb) 2587=item $success = $client->query ($flags, "text", \&cb)
2571 2588
2572Queues a query to the client, calling the given callback with 2589Queues a query to the client, calling the given callback with
2573the reply text on a reply. flags can be C<cf::CS_QUERY_YESNO>, 2590the 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>. 2591C<cf::CS_QUERY_SINGLECHAR> or C<cf::CS_QUERY_HIDEINPUT> or C<0>.
2632 my ($type, $reply, @payload) = 2649 my ($type, $reply, @payload) =
2633 "ARRAY" eq ref $msg 2650 "ARRAY" eq ref $msg
2634 ? @$msg 2651 ? @$msg
2635 : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove 2652 : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove
2636 2653
2654 my @reply;
2655
2637 if (my $cb = $EXTICMD{$type}) { 2656 if (my $cb = $EXTICMD{$type}) {
2638 my @reply = $cb->($ns, @payload); 2657 @reply = $cb->($ns, @payload);
2639
2640 $ns->ext_reply ($reply, @reply)
2641 if $reply;
2642 } 2658 }
2659
2660 $ns->ext_reply ($reply, @reply)
2661 if $reply;
2662
2643 } else { 2663 } else {
2644 warn "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; 2664 warn "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n";
2645 } 2665 }
2646 2666
2647 cf::override; 2667 cf::override;
2809# the server's init and main functions 2829# the server's init and main functions
2810 2830
2811sub load_facedata($) { 2831sub load_facedata($) {
2812 my ($path) = @_; 2832 my ($path) = @_;
2813 2833
2834 my $enc = JSON::XS->new->utf8->canonical;
2835
2814 warn "loading facedata from $path\n"; 2836 warn "loading facedata from $path\n";
2815 2837
2816 my $facedata; 2838 my $facedata;
2817 0 < aio_load $path, $facedata 2839 0 < aio_load $path, $facedata
2818 or die "$path: $!"; 2840 or die "$path: $!";
2819 2841
2820 $facedata = Coro::Storable::thaw $facedata; 2842 $facedata = Coro::Storable::thaw $facedata;
2821 2843
2822 $facedata->{version} == 2 2844 $facedata->{version} == 2
2823 or cf::cleanup "$path: version mismatch, cannot proceed."; 2845 or cf::cleanup "$path: version mismatch, cannot proceed.";
2846
2847 # patch in the exptable
2848 $facedata->{resource}{"res/exp_table"} = {
2849 type => FT_RSRC,
2850 data => $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]),
2851 };
2852 cf::cede_to_tick;
2824 2853
2825 { 2854 {
2826 my $faces = $facedata->{faceinfo}; 2855 my $faces = $facedata->{faceinfo};
2827 2856
2828 while (my ($face, $info) = each %$faces) { 2857 while (my ($face, $info) = each %$faces) {
2829 my $idx = (cf::face::find $face) || cf::face::alloc $face; 2858 my $idx = (cf::face::find $face) || cf::face::alloc $face;
2830 cf::face::set_visibility $idx, $info->{visibility}; 2859 cf::face::set_visibility $idx, $info->{visibility};
2831 cf::face::set_magicmap $idx, $info->{magicmap}; 2860 cf::face::set_magicmap $idx, $info->{magicmap};
2832 cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; 2861 cf::face::set_data $idx, 0, $info->{data32}, Digest::MD5::md5 $info->{data32};
2833 cf::face::set_data $idx, 1, $info->{data64}, $info->{chksum64}; 2862 cf::face::set_data $idx, 1, $info->{data64}, Digest::MD5::md5 $info->{data64};
2834 2863
2835 cf::cede_to_tick; 2864 cf::cede_to_tick;
2836 } 2865 }
2837 2866
2838 while (my ($face, $info) = each %$faces) { 2867 while (my ($face, $info) = each %$faces) {
2863 2892
2864 { 2893 {
2865 # TODO: for gcfclient pleasure, we should give resources 2894 # TODO: for gcfclient pleasure, we should give resources
2866 # that gcfclient doesn't grok a >10000 face index. 2895 # that gcfclient doesn't grok a >10000 face index.
2867 my $res = $facedata->{resource}; 2896 my $res = $facedata->{resource};
2868 my $enc = JSON::XS->new->utf8->canonical;
2869 2897
2870 my $soundconf = delete $res->{"res/sound.conf"}; 2898 my $soundconf = delete $res->{"res/sound.conf"};
2871 2899
2872 while (my ($name, $info) = each %$res) { 2900 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; 2901 my $idx = (cf::face::find $name) || cf::face::alloc $name;
2902 my $data;
2879 2903
2880 if ($info->{type} & 1) { 2904 if ($info->{type} & 1) {
2881 # prepend meta info 2905 # prepend meta info
2882 2906
2907 my $meta = $enc->encode ({
2908 name => $name,
2909 %{ $info->{meta} || {} },
2910 });
2911
2883 my $data = pack "(w/a*)*", $meta, $info->{data}; 2912 $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 { 2913 } else {
2888 cf::face::set_data $idx, 0, $info->{data}, $info->{chksum}; 2914 $data = $info->{data};
2889 } 2915 }
2890 2916
2917 cf::face::set_data $idx, 0, $data, Digest::MD5::md5 $data;
2891 cf::face::set_type $idx, $info->{type}; 2918 cf::face::set_type $idx, $info->{type};
2892 2919
2893 cf::cede_to_tick; 2920 cf::cede_to_tick;
2894 } 2921 }
2895 2922

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines