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.496 by root, Sun Nov 15 18:03:59 2009 UTC vs.
Revision 1.501 by root, Sat Jan 16 23:27:21 2010 UTC

2009 2009
2010 $cf::MAP{$path} = $map 2010 $cf::MAP{$path} = $map
2011 } 2011 }
2012} 2012}
2013 2013
2014sub pre_load { } 2014sub pre_load { }
2015sub post_load { } 2015#sub post_load { } # XS
2016 2016
2017sub load { 2017sub load {
2018 my ($self) = @_; 2018 my ($self) = @_;
2019 2019
2020 local $self->{deny_reset} = 1; # loading can take a long time 2020 local $self->{deny_reset} = 1; # loading can take a long time
3141our $safe_hole = new Safe::Hole; 3141our $safe_hole = new Safe::Hole;
3142 3142
3143$SIG{FPE} = 'IGNORE'; 3143$SIG{FPE} = 'IGNORE';
3144 3144
3145$safe->permit_only (Opcode::opset qw( 3145$safe->permit_only (Opcode::opset qw(
3146 :base_core :base_mem :base_orig :base_math 3146 :base_core :base_mem :base_orig :base_math :base_loop
3147 grepstart grepwhile mapstart mapwhile 3147 grepstart grepwhile mapstart mapwhile
3148 sort time 3148 sort time
3149)); 3149));
3150 3150
3151# here we export the classes and methods available to script code 3151# here we export the classes and methods available to script code
3203 $qcode =~ s/"/‟/g; # not allowed in #line filenames 3203 $qcode =~ s/"/‟/g; # not allowed in #line filenames
3204 $qcode =~ s/\n/\\n/g; 3204 $qcode =~ s/\n/\\n/g;
3205 3205
3206 %vars = (_dummy => 0) unless %vars; 3206 %vars = (_dummy => 0) unless %vars;
3207 3207
3208 my @res;
3208 local $_; 3209 local $_;
3209 local @safe::cf::_safe_eval_args = values %vars;
3210 3210
3211 my $eval = 3211 my $eval =
3212 "do {\n" 3212 "do {\n"
3213 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" 3213 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n"
3214 . "#line 0 \"{$qcode}\"\n" 3214 . "#line 0 \"{$qcode}\"\n"
3215 . $code 3215 . $code
3216 . "\n}" 3216 . "\n}"
3217 ; 3217 ;
3218 3218
3219 if ($CFG{safe_eval}) {
3219 sub_generation_inc; 3220 sub_generation_inc;
3221 local @safe::cf::_safe_eval_args = values %vars;
3220 my @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval); 3222 @res = wantarray ? $safe->reval ($eval) : scalar $safe->reval ($eval);
3221 sub_generation_inc; 3223 sub_generation_inc;
3224 } else {
3225 local @cf::_safe_eval_args = values %vars;
3226 @res = wantarray ? eval eval : scalar eval $eval;
3227 }
3222 3228
3223 if ($@) { 3229 if ($@) {
3224 warn "$@"; 3230 warn "$@";
3225 warn "while executing safe code '$code'\n"; 3231 warn "while executing safe code '$code'\n";
3226 warn "with arguments " . (join " ", %vars) . "\n"; 3232 warn "with arguments " . (join " ", %vars) . "\n";
3245=cut 3251=cut
3246 3252
3247sub register_script_function { 3253sub register_script_function {
3248 my ($fun, $cb) = @_; 3254 my ($fun, $cb) = @_;
3249 3255
3250 no strict 'refs'; 3256 $fun = "safe::$fun" if $CFG{safe_eval};
3251 *{"safe::$fun"} = $safe_hole->wrap ($cb); 3257 *$fun = $safe_hole->wrap ($cb);
3252} 3258}
3253 3259
3254=back 3260=back
3255 3261
3256=cut 3262=cut
3277 3283
3278 $facedata->{version} == 2 3284 $facedata->{version} == 2
3279 or cf::cleanup "$path: version mismatch, cannot proceed."; 3285 or cf::cleanup "$path: version mismatch, cannot proceed.";
3280 3286
3281 # patch in the exptable 3287 # patch in the exptable
3288 my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]);
3282 $facedata->{resource}{"res/exp_table"} = { 3289 $facedata->{resource}{"res/exp_table"} = {
3283 type => FT_RSRC, 3290 type => FT_RSRC,
3284 data => $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]), 3291 data => $exp_table,
3292 hash => (Digest::MD5::md5 $exp_table),
3285 }; 3293 };
3286 cf::cede_to_tick; 3294 cf::cede_to_tick;
3287 3295
3288 { 3296 {
3289 my $faces = $facedata->{faceinfo}; 3297 my $faces = $facedata->{faceinfo};
3880 3888
3881our @WAIT_FOR_TICK; 3889our @WAIT_FOR_TICK;
3882our @WAIT_FOR_TICK_BEGIN; 3890our @WAIT_FOR_TICK_BEGIN;
3883 3891
3884sub wait_for_tick { 3892sub wait_for_tick {
3885 return if tick_inhibit || $Coro::current == $Coro::main; 3893 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
3886 3894
3887 my $signal = new Coro::Signal; 3895 my $signal = new Coro::Signal;
3888 push @WAIT_FOR_TICK, $signal; 3896 push @WAIT_FOR_TICK, $signal;
3889 $signal->wait; 3897 $signal->wait;
3890} 3898}
3891 3899
3892sub wait_for_tick_begin { 3900sub wait_for_tick_begin {
3893 return if tick_inhibit || $Coro::current == $Coro::main; 3901 return Coro::cede if tick_inhibit || $Coro::current == $Coro::main;
3894 3902
3895 my $signal = new Coro::Signal; 3903 my $signal = new Coro::Signal;
3896 push @WAIT_FOR_TICK_BEGIN, $signal; 3904 push @WAIT_FOR_TICK_BEGIN, $signal;
3897 $signal->wait; 3905 $signal->wait;
3898} 3906}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines