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