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.316 by root, Mon Jul 23 21:02:50 2007 UTC vs.
Revision 1.330 by elmex, Fri Aug 10 10:35:07 2007 UTC

1370 $self->{deny_save} = 1; 1370 $self->{deny_save} = 1;
1371 1371
1372 $cf::PLAYER{$login} = $self; 1372 $cf::PLAYER{$login} = $self;
1373 1373
1374 $self 1374 $self
1375}
1376
1377=item $player->send_msg ($channel, $msg, $color, [extra...])
1378
1379=cut
1380
1381sub send_msg {
1382 my $ns = shift->ns
1383 or return;
1384 $ns->send_msg (@_);
1375} 1385}
1376 1386
1377=item $pl->quit_character 1387=item $pl->quit_character
1378 1388
1379Nukes the player without looking back. If logged in, the connection will 1389Nukes the player without looking back. If logged in, the connection will
1921 $self->set_darkness_map; 1931 $self->set_darkness_map;
1922 Coro::cede; 1932 Coro::cede;
1923 $self->activate; 1933 $self->activate;
1924 } 1934 }
1925 1935
1936 $self->{last_save} = $cf::RUNTIME;
1937 $self->last_access ($cf::RUNTIME);
1938
1926 $self->in_memory (cf::MAP_IN_MEMORY); 1939 $self->in_memory (cf::MAP_IN_MEMORY);
1927 } 1940 }
1928 1941
1929 $self->post_load; 1942 $self->post_load;
1930} 1943}
2240 $self->message ($msg, $flags); 2253 $self->message ($msg, $flags);
2241 } 2254 }
2242 } 2255 }
2243} 2256}
2244 2257
2258=item $object->send_msg ($channel, $msg, $color, [extra...])
2259
2260=cut
2261
2262sub cf::object::send_msg {
2263 my $pl = shift->contr
2264 or return;
2265 $pl->send_msg (@_);
2266}
2267
2245=item $player_object->may ("access") 2268=item $player_object->may ("access")
2246 2269
2247Returns wether the given player is authorized to access resource "access" 2270Returns wether the given player is authorized to access resource "access"
2248(e.g. "command_wizcast"). 2271(e.g. "command_wizcast").
2249 2272
2512sub cf::client::send_msg { 2535sub cf::client::send_msg {
2513 my ($self, $channel, $msg, $color, @extra) = @_; 2536 my ($self, $channel, $msg, $color, @extra) = @_;
2514 2537
2515 $msg = $self->pl->expand_cfpod ($msg); 2538 $msg = $self->pl->expand_cfpod ($msg);
2516 2539
2517 $color &= ~cf::NDI_UNIQUE; # just in case... 2540 $color &= cf::NDI_CLIENT_MASK; # just in case...
2518 2541
2519 if (ref $channel) { 2542 if (ref $channel) {
2520 # send meta info to client, if not yet sent 2543 # send meta info to client, if not yet sent
2521 unless (exists $self->{channel}{$channel->{id}}) { 2544 unless (exists $self->{channel}{$channel->{id}}) {
2522 $self->{channel}{$channel->{id}} = $channel; 2545 $self->{channel}{$channel->{id}} = $channel;
2523 $self->ext_msg (channel_info => %$channel); 2546 $self->ext_msg (channel_info => $channel);
2524 } 2547 }
2525 2548
2526 $channel = $channel->{id}; 2549 $channel = $channel->{id};
2527 } 2550 }
2528 2551
2529 return unless @extra || length $msg; 2552 return unless @extra || length $msg;
2530 2553
2531 if ($self->can_msg) { 2554 if ($self->can_msg) {
2555 # default colour, mask it out
2556 $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF)
2557 if $color & cf::NDI_DEF;
2558
2532 $self->send_packet ("msg " . $self->{json_coder}->encode ([$color, $channel, $msg, @extra])); 2559 $self->send_packet ("msg " . $self->{json_coder}->encode (
2560 [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra]));
2533 } else { 2561 } else {
2534 # replace some tags by gcfclient-compatible ones
2535 for ($msg) {
2536 1 while
2537 s/<b>([^<]*)<\/b>/[b]${1}[\/b]/
2538 || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/
2539 || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/
2540 || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/
2541 || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/;
2542 }
2543
2544 if ($color >= 0) { 2562 if ($color >= 0) {
2563 # replace some tags by gcfclient-compatible ones
2564 for ($msg) {
2565 1 while
2566 s/<b>([^<]*)<\/b>/[b]${1}[\/b]/
2567 || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/
2568 || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/
2569 || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/
2570 || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/;
2571 }
2572
2573 $color &= cf::NDI_COLOR_MASK;
2574
2575 utf8::encode $msg;
2576
2545 if (0 && $msg =~ /\[/) { 2577 if (0 && $msg =~ /\[/) {
2546 $self->send_packet ("drawextinfo $color 4 0 $msg") 2578 $self->send_packet ("drawextinfo $color 4 0 $msg")
2547 } else { 2579 } else {
2548 $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g; 2580 $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g;
2549 $self->send_packet ("drawinfo $color $msg") 2581 $self->send_packet ("drawinfo $color $msg")
2698our $safe = new Safe "safe"; 2730our $safe = new Safe "safe";
2699our $safe_hole = new Safe::Hole; 2731our $safe_hole = new Safe::Hole;
2700 2732
2701$SIG{FPE} = 'IGNORE'; 2733$SIG{FPE} = 'IGNORE';
2702 2734
2703$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); 2735$safe->permit_only (Opcode::opset qw(
2736 :base_core :base_mem :base_orig :base_math
2737 grepstart grepwhile mapstart mapwhile
2738 sort time
2739));
2704 2740
2705# here we export the classes and methods available to script code 2741# here we export the classes and methods available to script code
2706 2742
2707=pod 2743=pod
2708 2744
2709The following functions and methods are available within a safe environment: 2745The following functions and methods are available within a safe environment:
2710 2746
2711 cf::object 2747 cf::object
2712 contr pay_amount pay_player map x y force_find force_add 2748 contr pay_amount pay_player map x y force_find force_add
2713 insert remove 2749 insert remove name archname title slaying race
2714 2750
2715 cf::object::player 2751 cf::object::player
2716 player 2752 player
2717 2753
2718 cf::player 2754 cf::player
2723 2759
2724=cut 2760=cut
2725 2761
2726for ( 2762for (
2727 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 2763 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
2728 insert remove)], 2764 insert remove inv name archname title slaying race)],
2729 ["cf::object::player" => qw(player)], 2765 ["cf::object::player" => qw(player)],
2730 ["cf::player" => qw(peaceful)], 2766 ["cf::player" => qw(peaceful)],
2731 ["cf::map" => qw(trigger)], 2767 ["cf::map" => qw(trigger)],
2732) { 2768) {
2733 no strict 'refs'; 2769 no strict 'refs';
2865 # TODO: for gcfclient pleasure, we should give resources 2901 # TODO: for gcfclient pleasure, we should give resources
2866 # that gcfclient doesn't grok a >10000 face index. 2902 # that gcfclient doesn't grok a >10000 face index.
2867 my $res = $facedata->{resource}; 2903 my $res = $facedata->{resource};
2868 my $enc = JSON::XS->new->utf8->canonical; 2904 my $enc = JSON::XS->new->utf8->canonical;
2869 2905
2906 my $soundconf = delete $res->{"res/sound.conf"};
2907
2870 while (my ($name, $info) = each %$res) { 2908 while (my ($name, $info) = each %$res) {
2871 my $meta = $enc->encode ({ 2909 my $meta = $enc->encode ({
2872 name => $name, 2910 name => $name,
2873 type => $info->{type}, 2911 %{ $info->{meta} || {} },
2874 copyright => $info->{copyright}, #TODO#
2875 }); 2912 });
2876 2913
2877 my $idx = (cf::face::find $name) || cf::face::alloc $name; 2914 my $idx = (cf::face::find $name) || cf::face::alloc $name;
2878 2915
2879 if ($name =~ /\.jpg$/) { 2916 if ($info->{type} & 1) {
2880 cf::face::set_data $idx, 0, $info->{data}, $info->{chksum};#d# temp hack 2917 # prepend meta info
2881 cf::face::set_data $idx, 1, $info->{data}, $info->{chksum};#d# temp hack 2918
2882 } else {
2883 my $data = pack "(w/a*)*", $meta, $info->{data}; 2919 my $data = pack "(w/a*)*", $meta, $info->{data};
2884 my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata 2920 my $chk = Digest::MD5::md5 "$info->{chksum},$meta"; # mangle data checksum and metadata
2885 2921
2886 cf::face::set_type $idx, 1;
2887 cf::face::set_data $idx, 0, $data, $chk; 2922 cf::face::set_data $idx, 0, $data, $chk;
2923 } else {
2924 cf::face::set_data $idx, 0, $info->{data}, $info->{chksum};
2888 } 2925 }
2889 2926
2927 cf::face::set_type $idx, $info->{type};
2928
2890 cf::cede_to_tick; 2929 cf::cede_to_tick;
2891 } 2930 }
2931
2932 if ($soundconf) {
2933 $soundconf = $enc->decode (delete $soundconf->{data});
2934
2935 for (0 .. SOUND_CAST_SPELL_0 - 1) {
2936 my $sound = $soundconf->{compat}[$_]
2937 or next;
2938
2939 my $face = cf::face::find "sound/$sound->[1]";
2940 cf::sound::set $sound->[0] => $face;
2941 cf::sound::old_sound_index $_, $face; # gcfclient-compat
2942 }
2943
2944 while (my ($k, $v) = each %{$soundconf->{event}}) {
2945 my $face = cf::face::find "sound/$v";
2946 cf::sound::set $k => $face;
2947 }
2948 }
2892 } 2949 }
2893 2950
2894 1 2951 1
2895} 2952}
2953
2954register_exticmd fx_want => sub {
2955 my ($ns, $want) = @_;
2956
2957 while (my ($k, $v) = each %$want) {
2958 $ns->fx_want ($k, $v);
2959 }
2960};
2896 2961
2897sub reload_regions { 2962sub reload_regions {
2898 load_resource_file "$MAPDIR/regions" 2963 load_resource_file "$MAPDIR/regions"
2899 or die "unable to load regions file\n"; 2964 or die "unable to load regions file\n";
2900 2965

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines