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.23 by root, Wed Jul 19 22:19:19 2006 UTC vs.
Revision 1.25 by root, Thu Jul 20 07:22:40 2006 UTC

64prop_gen MAP_PROP => "cf::map"; 64prop_gen MAP_PROP => "cf::map";
65prop_gen ARCH_PROP => "cf::arch"; 65prop_gen ARCH_PROP => "cf::arch";
66 66
67# guessed hierarchies 67# guessed hierarchies
68 68
69@cf::object::player::ISA = 'cf::object'; 69@ext::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object';
70@cf::object::map::ISA = 'cf::object'; 70@ext::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object';
71
72# we bless all objects into derived classes to force a method lookup
73# within the Safe compartment.
74for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region)) {
75 no strict 'refs';
76 @{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
77}
71 78
72$Event::DIED = sub { 79$Event::DIED = sub {
73 warn "error in event callback: @_"; 80 warn "error in event callback: @_";
74}; 81};
75 82
371sub cf::object::player::reply($$$;$) { 378sub cf::object::player::reply($$$;$) {
372 my ($self, $npc, $msg, $flags) = @_; 379 my ($self, $npc, $msg, $flags) = @_;
373 380
374 $flags = cf::NDI_BROWN | cf::NDI_UNIQUE unless @_ >= 4; 381 $flags = cf::NDI_BROWN | cf::NDI_UNIQUE unless @_ >= 4;
375 382
383 if ($self->{record_replies}) {
384 push @{ $self->{record_replies} }, [$npc, $msg, $flags];
385 } else {
376 $msg = $npc->name . " says: $msg" if $npc; 386 $msg = $npc->name . " says: $msg" if $npc;
377
378 $self->message ($msg, $flags); 387 $self->message ($msg, $flags);
388 }
379} 389}
380 390
381############################################################################# 391#############################################################################
382# map scripting support 392# map scripting support
383 393
386 396
387$SIG{FPE} = 'IGNORE'; 397$SIG{FPE} = 'IGNORE';
388 398
389$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); 399$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time));
390 400
391# here we would export the classes and methods available to script code 401# here we export the classes and methods available to script code
392#@ext::cf::object::player::ISA = @cf::object::player::ISA; 402
393#@ext::cf::object::map::ISA = @cf::object::map::ISA; 403for (
404 ["cf::object" => qw(contr)],
405 ["cf::object::player" => qw(player)],
406 ["cf::player" => qw(peaceful)],
407) {
408 no strict 'refs';
409 my ($pkg, @funs) = @$_;
410 *{"ext::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"})
411 for @funs;
412}
394 413
395sub safe_eval($;@) { 414sub safe_eval($;@) {
396 my ($code, %vars) = @_; 415 my ($code, %vars) = @_;
397 416
398 my $qcode = $code; 417 my $qcode = $code;
400 $qcode =~ s/\n/\\n/g; 419 $qcode =~ s/\n/\\n/g;
401 420
402 local $_; 421 local $_;
403 local @ext::cf::_safe_eval_args = values %vars; 422 local @ext::cf::_safe_eval_args = values %vars;
404 423
405 $safe->reval ( 424 $code =
406 "do {\n" 425 "do {\n"
407 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" 426 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n"
408 . "#line 0 \"{$qcode}\"\n" 427 . "#line 0 \"{$qcode}\"\n"
409 . $code 428 . $code
410 . "\n}" 429 . "\n}"
411 ) 430 ;
431
432 sub_generation_inc;
433 my @res = wantarray ? $safe->reval ($code) : scalar $safe->reval ($code);
434 sub_generation_inc;
435
436 wantarray ? @res : $res[0]
412} 437}
413 438
414sub register_script_function { 439sub register_script_function {
415 my ($fun, $cb) = @_; 440 my ($fun, $cb) = @_;
416 441

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines