… | |
… | |
28 | our $TICK_WATCHER; |
28 | our $TICK_WATCHER; |
29 | our $NEXT_TICK; |
29 | our $NEXT_TICK; |
30 | |
30 | |
31 | our %CFG; |
31 | our %CFG; |
32 | |
32 | |
33 | our $uptime; |
33 | our $uptime;#d# |
34 | |
34 | our $UPTIME; |
35 | $uptime ||= time; |
35 | $UPTIME ||= $uptime;#d# |
|
|
36 | $UPTIME ||= time; |
36 | |
37 | |
37 | ############################################################################# |
38 | ############################################################################# |
38 | |
39 | |
39 | =head2 GLOBAL VARIABLES |
40 | =head2 GLOBAL VARIABLES |
40 | |
41 | |
41 | =over 4 |
42 | =over 4 |
|
|
43 | |
|
|
44 | =item $cf::UPTIME |
|
|
45 | |
|
|
46 | The timestamp of the server start (so not actually an uptime). |
42 | |
47 | |
43 | =item $cf::LIBDIR |
48 | =item $cf::LIBDIR |
44 | |
49 | |
45 | The perl library directory, where extensions and cf-specific modules can |
50 | The perl library directory, where extensions and cf-specific modules can |
46 | be found. It will be added to C<@INC> automatically. |
51 | be found. It will be added to C<@INC> automatically. |
… | |
… | |
523 | unlink $filename; |
528 | unlink $filename; |
524 | unlink "$filename.pst"; |
529 | unlink "$filename.pst"; |
525 | } |
530 | } |
526 | } |
531 | } |
527 | |
532 | |
|
|
533 | sub object_freezer_as_string { |
|
|
534 | my ($rdata, $objs) = @_; |
|
|
535 | |
|
|
536 | use Data::Dumper; |
|
|
537 | |
|
|
538 | $$rdata . Dumper $objs |
|
|
539 | } |
|
|
540 | |
528 | sub object_thawer_load { |
541 | sub object_thawer_load { |
529 | my ($filename) = @_; |
542 | my ($filename) = @_; |
530 | |
543 | |
531 | local $/; |
544 | local $/; |
532 | |
545 | |
… | |
… | |
634 | . "#line 1 \"$path\"\n{\n" |
647 | . "#line 1 \"$path\"\n{\n" |
635 | . (do { local $/; <$fh> }) |
648 | . (do { local $/; <$fh> }) |
636 | . "\n};\n1"; |
649 | . "\n};\n1"; |
637 | |
650 | |
638 | eval $source |
651 | eval $source |
639 | or die "$path: $@"; |
652 | or die $@ ? "$path: $@\n" |
|
|
653 | : "extension disabled.\n"; |
640 | |
654 | |
641 | push @exts, $pkg; |
655 | push @exts, $pkg; |
642 | $ext_pkg{$base} = $pkg; |
656 | $ext_pkg{$base} = $pkg; |
643 | |
657 | |
644 | # no strict 'refs'; |
658 | # no strict 'refs'; |
… | |
… | |
775 | sub cf::player::exists($) { |
789 | sub cf::player::exists($) { |
776 | cf::player::find $_[0] |
790 | cf::player::find $_[0] |
777 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
791 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
778 | } |
792 | } |
779 | |
793 | |
780 | =item $object->reply ($npc, $msg[, $flags]) |
794 | =item $player_object->reply ($npc, $msg[, $flags]) |
781 | |
795 | |
782 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
796 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
783 | can be C<undef>. Does the right thing when the player is currently in a |
797 | can be C<undef>. Does the right thing when the player is currently in a |
784 | dialogue with the given NPC character. |
798 | dialogue with the given NPC character. |
785 | |
799 | |
… | |
… | |
812 | $msg{msgid} = $id; |
826 | $msg{msgid} = $id; |
813 | |
827 | |
814 | $self->send ("ext " . to_json \%msg); |
828 | $self->send ("ext " . to_json \%msg); |
815 | } |
829 | } |
816 | |
830 | |
817 | =back |
831 | =item $player_object->may ("access") |
|
|
832 | |
|
|
833 | Returns wether the given player is authorized to access resource "access" |
|
|
834 | (e.g. "command_wizcast"). |
|
|
835 | |
|
|
836 | =cut |
|
|
837 | |
|
|
838 | sub cf::object::player::may { |
|
|
839 | my ($self, $access) = @_; |
|
|
840 | |
|
|
841 | $self->flag (cf::FLAG_WIZ) || |
|
|
842 | (ref $cf::CFG{"may_$access"} |
|
|
843 | ? scalar grep $self->name eq $_, @{$cf::CFG{"may_$access"}} |
|
|
844 | : $cf::CFG{"may_$access"}) |
|
|
845 | } |
818 | |
846 | |
819 | =cut |
847 | =cut |
820 | |
848 | |
821 | ############################################################################# |
849 | ############################################################################# |
822 | |
850 | |
… | |
… | |
824 | |
852 | |
825 | Functions that provide a safe environment to compile and execute |
853 | Functions that provide a safe environment to compile and execute |
826 | snippets of perl code without them endangering the safety of the server |
854 | snippets of perl code without them endangering the safety of the server |
827 | itself. Looping constructs, I/O operators and other built-in functionality |
855 | itself. Looping constructs, I/O operators and other built-in functionality |
828 | is not available in the safe scripting environment, and the number of |
856 | is not available in the safe scripting environment, and the number of |
829 | functions and methods that cna be called is greatly reduced. |
857 | functions and methods that can be called is greatly reduced. |
830 | |
858 | |
831 | =cut |
859 | =cut |
832 | |
860 | |
833 | our $safe = new Safe "safe"; |
861 | our $safe = new Safe "safe"; |
834 | our $safe_hole = new Safe::Hole; |
862 | our $safe_hole = new Safe::Hole; |
… | |
… | |
1163 | $TICK_WATCHER->at ($NEXT_TICK); |
1191 | $TICK_WATCHER->at ($NEXT_TICK); |
1164 | $TICK_WATCHER->start; |
1192 | $TICK_WATCHER->start; |
1165 | }, |
1193 | }, |
1166 | ); |
1194 | ); |
1167 | |
1195 | |
1168 | eval { IO::AIO::max_poll_time $TICK * 0.2 }; #d# remove eval after restart |
1196 | IO::AIO::max_poll_time $TICK * 0.2; |
1169 | |
1197 | |
1170 | Event->io (fd => IO::AIO::poll_fileno, |
1198 | Event->io (fd => IO::AIO::poll_fileno, |
1171 | poll => 'r', |
1199 | poll => 'r', |
1172 | prio => 5, |
1200 | prio => 5, |
1173 | cb => \&IO::AIO::poll_cb); |
1201 | cb => \&IO::AIO::poll_cb); |