… | |
… | |
5 | use Storable; |
5 | use Storable; |
6 | use Opcode; |
6 | use Opcode; |
7 | use Safe; |
7 | use Safe; |
8 | use Safe::Hole; |
8 | use Safe::Hole; |
9 | |
9 | |
|
|
10 | use YAML::Syck (); |
10 | use Time::HiRes; |
11 | use Time::HiRes; |
11 | use Event; |
12 | use Event; |
12 | $Event::Eval = 1; # no idea why this is required, but it is |
13 | $Event::Eval = 1; # no idea why this is required, but it is |
13 | |
14 | |
|
|
15 | # work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? |
|
|
16 | $YAML::Syck::ImplicitUnicode = 1; |
|
|
17 | |
14 | use strict; |
18 | use strict; |
15 | |
19 | |
16 | _init_vars; |
20 | _init_vars; |
17 | |
21 | |
18 | our %COMMAND = (); |
22 | our %COMMAND = (); |
… | |
… | |
20 | our $LIBDIR = maps_directory "perl"; |
24 | our $LIBDIR = maps_directory "perl"; |
21 | |
25 | |
22 | our $TICK = MAX_TIME * 1e-6; |
26 | our $TICK = MAX_TIME * 1e-6; |
23 | our $TICK_WATCHER; |
27 | our $TICK_WATCHER; |
24 | our $NEXT_TICK; |
28 | our $NEXT_TICK; |
|
|
29 | |
|
|
30 | our %CFG; |
|
|
31 | |
|
|
32 | ############################################################################# |
|
|
33 | |
|
|
34 | =head2 GLOBAL VARIABLES |
|
|
35 | |
|
|
36 | =over 4 |
|
|
37 | |
|
|
38 | =item $cf::LIBDIR |
|
|
39 | |
|
|
40 | The perl library directory, where extensions and cf-specific modules can |
|
|
41 | be found. It will be added to C<@INC> automatically. |
|
|
42 | |
|
|
43 | =item $cf::TICK |
|
|
44 | |
|
|
45 | The interval between server ticks, in seconds. |
|
|
46 | |
|
|
47 | =item %cf::CFG |
|
|
48 | |
|
|
49 | Configuration for the server, loaded from C</etc/crossfire/config>, or |
|
|
50 | from wherever your confdir points to. |
|
|
51 | |
|
|
52 | =back |
|
|
53 | |
|
|
54 | =cut |
25 | |
55 | |
26 | BEGIN { |
56 | BEGIN { |
27 | *CORE::GLOBAL::warn = sub { |
57 | *CORE::GLOBAL::warn = sub { |
28 | my $msg = join "", @_; |
58 | my $msg = join "", @_; |
29 | $msg .= "\n" |
59 | $msg .= "\n" |
… | |
… | |
51 | my @exts; |
81 | my @exts; |
52 | my @hook; |
82 | my @hook; |
53 | my %command; |
83 | my %command; |
54 | my %extcmd; |
84 | my %extcmd; |
55 | |
85 | |
56 | ############################################################################# |
86 | =head2 UTILITY FUNCTIONS |
57 | # utility functions |
87 | |
|
|
88 | =over 4 |
|
|
89 | |
|
|
90 | =cut |
58 | |
91 | |
59 | use JSON::Syck (); # TODO# replace by JSON::PC once working |
92 | use JSON::Syck (); # TODO# replace by JSON::PC once working |
|
|
93 | |
|
|
94 | =item $ref = cf::from_json $json |
|
|
95 | |
|
|
96 | Converts a JSON string into the corresponding perl data structure. |
|
|
97 | |
|
|
98 | =cut |
60 | |
99 | |
61 | sub from_json($) { |
100 | sub from_json($) { |
62 | $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs |
101 | $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs |
63 | JSON::Syck::Load $_[0] |
102 | JSON::Syck::Load $_[0] |
64 | } |
103 | } |
65 | |
104 | |
|
|
105 | =item $json = cf::to_json $ref |
|
|
106 | |
|
|
107 | Converts a perl data structure into its JSON representation. |
|
|
108 | |
|
|
109 | =cut |
|
|
110 | |
66 | sub to_json($) { |
111 | sub to_json($) { |
67 | $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs |
112 | $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs |
68 | JSON::Syck::Dump $_[0] |
113 | JSON::Syck::Dump $_[0] |
69 | } |
114 | } |
70 | |
115 | |
71 | ############################################################################# |
116 | =back |
72 | # "new" plug-in system |
|
|
73 | |
117 | |
|
|
118 | =cut |
|
|
119 | |
|
|
120 | ############################################################################# |
|
|
121 | |
74 | =head3 EVENTS AND OBJECT ATTACHMENTS |
122 | =head2 EVENTS AND OBJECT ATTACHMENTS |
75 | |
123 | |
76 | =over 4 |
124 | =over 4 |
77 | |
125 | |
78 | =item $object->attach ($attachment, key => $value...) |
126 | =item $object->attach ($attachment, key => $value...) |
79 | |
127 | |
… | |
… | |
353 | for (@$callbacks) { |
401 | for (@$callbacks) { |
354 | eval { &{$_->[1]} }; |
402 | eval { &{$_->[1]} }; |
355 | |
403 | |
356 | if ($@) { |
404 | if ($@) { |
357 | warn "$@"; |
405 | warn "$@"; |
358 | warn "... while processing $EVENT[$event][0] event, skipping processing altogether.\n"; |
406 | warn "... while processing $EVENT[$event][0](@_) event, skipping processing altogether.\n"; |
359 | override; |
407 | override; |
360 | } |
408 | } |
361 | |
409 | |
362 | return 1 if $override; |
410 | return 1 if $override; |
363 | } |
411 | } |
… | |
… | |
379 | removed in future versions), and there is no public API to access override |
427 | removed in future versions), and there is no public API to access override |
380 | results (if you must, access C<@cf::invoke_results> directly). |
428 | results (if you must, access C<@cf::invoke_results> directly). |
381 | |
429 | |
382 | =back |
430 | =back |
383 | |
431 | |
384 | =head2 methods valid for all pointers |
432 | =cut |
|
|
433 | |
|
|
434 | ############################################################################# |
|
|
435 | |
|
|
436 | =head2 METHODS VALID FOR ALL CORE OBJECTS |
385 | |
437 | |
386 | =over 4 |
438 | =over 4 |
387 | |
439 | |
388 | =item $object->valid |
440 | =item $object->valid, $player->valid, $map->valid |
389 | |
|
|
390 | =item $player->valid |
|
|
391 | |
|
|
392 | =item $map->valid |
|
|
393 | |
441 | |
394 | Just because you have a perl object does not mean that the corresponding |
442 | Just because you have a perl object does not mean that the corresponding |
395 | C-level object still exists. If you try to access an object that has no |
443 | C-level object still exists. If you try to access an object that has no |
396 | valid C counterpart anymore you get an exception at runtime. This method |
444 | valid C counterpart anymore you get an exception at runtime. This method |
397 | can be used to test for existence of the C object part without causing an |
445 | can be used to test for existence of the C object part without causing an |
… | |
… | |
643 | 1 |
691 | 1 |
644 | } or warn "$ext not loaded: $@"; |
692 | } or warn "$ext not loaded: $@"; |
645 | } |
693 | } |
646 | } |
694 | } |
647 | |
695 | |
648 | sub _perl_reload(&) { |
|
|
649 | my ($msg) = @_; |
|
|
650 | |
|
|
651 | $msg->("reloading..."); |
|
|
652 | |
|
|
653 | eval { |
|
|
654 | # 1. cancel all watchers |
|
|
655 | $_->cancel for Event::all_watchers; |
|
|
656 | |
|
|
657 | # 2. unload all extensions |
|
|
658 | for (@exts) { |
|
|
659 | $msg->("unloading <$_>"); |
|
|
660 | unload_extension $_; |
|
|
661 | } |
|
|
662 | |
|
|
663 | # 3. unload all modules loaded from $LIBDIR |
|
|
664 | while (my ($k, $v) = each %INC) { |
|
|
665 | next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; |
|
|
666 | |
|
|
667 | $msg->("removing <$k>"); |
|
|
668 | delete $INC{$k}; |
|
|
669 | |
|
|
670 | $k =~ s/\.pm$//; |
|
|
671 | $k =~ s/\//::/g; |
|
|
672 | |
|
|
673 | if (my $cb = $k->can ("unload_module")) { |
|
|
674 | $cb->(); |
|
|
675 | } |
|
|
676 | |
|
|
677 | Symbol::delete_package $k; |
|
|
678 | } |
|
|
679 | |
|
|
680 | # 4. get rid of safe::, as good as possible |
|
|
681 | Symbol::delete_package "safe::$_" |
|
|
682 | for qw(cf::object cf::object::player cf::player cf::map cf::party cf::region); |
|
|
683 | |
|
|
684 | # 5. remove register_script_function callbacks |
|
|
685 | # TODO |
|
|
686 | |
|
|
687 | # 6. unload cf.pm "a bit" |
|
|
688 | delete $INC{"cf.pm"}; |
|
|
689 | |
|
|
690 | # don't, removes xs symbols, too, |
|
|
691 | # and global variables created in xs |
|
|
692 | #Symbol::delete_package __PACKAGE__; |
|
|
693 | |
|
|
694 | # 7. reload cf.pm |
|
|
695 | $msg->("reloading cf.pm"); |
|
|
696 | require cf; |
|
|
697 | |
|
|
698 | $msg->("load extensions"); |
|
|
699 | cf::load_extensions; |
|
|
700 | |
|
|
701 | $msg->("reattach"); |
|
|
702 | _global_reattach; |
|
|
703 | }; |
|
|
704 | $msg->($@) if $@; |
|
|
705 | |
|
|
706 | $msg->("reloaded"); |
|
|
707 | }; |
|
|
708 | |
|
|
709 | sub perl_reload() { |
|
|
710 | _perl_reload { |
|
|
711 | warn $_[0]; |
|
|
712 | print "$_[0]\n"; |
|
|
713 | }; |
|
|
714 | } |
|
|
715 | |
|
|
716 | register_command "perl-reload", 0, sub { |
|
|
717 | my ($who, $arg) = @_; |
|
|
718 | |
|
|
719 | if ($who->flag (FLAG_WIZ)) { |
|
|
720 | _perl_reload { |
|
|
721 | warn $_[0]; |
|
|
722 | $who->message ($_[0]); |
|
|
723 | }; |
|
|
724 | } |
|
|
725 | }; |
|
|
726 | |
|
|
727 | ############################################################################# |
696 | ############################################################################# |
728 | # extcmd framework, basically convert ext <msg> |
697 | # extcmd framework, basically convert ext <msg> |
729 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
698 | # into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
730 | |
699 | |
731 | attach_to_players |
700 | attach_to_players |
… | |
… | |
783 | } |
752 | } |
784 | }, |
753 | }, |
785 | ; |
754 | ; |
786 | |
755 | |
787 | ############################################################################# |
756 | ############################################################################# |
788 | # core extensions - in perl |
757 | |
|
|
758 | =head2 CORE EXTENSIONS |
|
|
759 | |
|
|
760 | Functions and methods that extend core crossfire objects. |
|
|
761 | |
|
|
762 | =over 4 |
789 | |
763 | |
790 | =item cf::player::exists $login |
764 | =item cf::player::exists $login |
791 | |
765 | |
792 | Returns true when the given account exists. |
766 | Returns true when the given account exists. |
793 | |
767 | |
… | |
… | |
796 | sub cf::player::exists($) { |
770 | sub cf::player::exists($) { |
797 | cf::player::find $_[0] |
771 | cf::player::find $_[0] |
798 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
772 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
799 | } |
773 | } |
800 | |
774 | |
801 | =item $player->reply ($npc, $msg[, $flags]) |
775 | =item $object->reply ($npc, $msg[, $flags]) |
802 | |
776 | |
803 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
777 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
804 | can be C<undef>. Does the right thing when the player is currently in a |
778 | can be C<undef>. Does the right thing when the player is currently in a |
805 | dialogue with the given NPC character. |
779 | dialogue with the given NPC character. |
806 | |
780 | |
… | |
… | |
833 | $msg{msgid} = $id; |
807 | $msg{msgid} = $id; |
834 | |
808 | |
835 | $self->send ("ext " . to_json \%msg); |
809 | $self->send ("ext " . to_json \%msg); |
836 | } |
810 | } |
837 | |
811 | |
|
|
812 | =back |
|
|
813 | |
|
|
814 | =cut |
|
|
815 | |
838 | ############################################################################# |
816 | ############################################################################# |
839 | # map scripting support |
817 | |
|
|
818 | =head2 SAFE SCRIPTING |
|
|
819 | |
|
|
820 | Functions that provide a safe environment to compile and execute |
|
|
821 | snippets of perl code without them endangering the safety of the server |
|
|
822 | itself. Looping constructs, I/O operators and other built-in functionality |
|
|
823 | is not available in the safe scripting environment, and the number of |
|
|
824 | functions and methods that cna be called is greatly reduced. |
|
|
825 | |
|
|
826 | =cut |
840 | |
827 | |
841 | our $safe = new Safe "safe"; |
828 | our $safe = new Safe "safe"; |
842 | our $safe_hole = new Safe::Hole; |
829 | our $safe_hole = new Safe::Hole; |
843 | |
830 | |
844 | $SIG{FPE} = 'IGNORE'; |
831 | $SIG{FPE} = 'IGNORE'; |
845 | |
832 | |
846 | $safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); |
833 | $safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); |
847 | |
834 | |
848 | # here we export the classes and methods available to script code |
835 | # here we export the classes and methods available to script code |
|
|
836 | |
|
|
837 | =pod |
|
|
838 | |
|
|
839 | The following fucntions and emthods are available within a safe environment: |
|
|
840 | |
|
|
841 | cf::object contr pay_amount pay_player |
|
|
842 | cf::object::player player |
|
|
843 | cf::player peaceful |
|
|
844 | |
|
|
845 | =cut |
849 | |
846 | |
850 | for ( |
847 | for ( |
851 | ["cf::object" => qw(contr pay_amount pay_player)], |
848 | ["cf::object" => qw(contr pay_amount pay_player)], |
852 | ["cf::object::player" => qw(player)], |
849 | ["cf::object::player" => qw(player)], |
853 | ["cf::player" => qw(peaceful)], |
850 | ["cf::player" => qw(peaceful)], |
… | |
… | |
856 | my ($pkg, @funs) = @$_; |
853 | my ($pkg, @funs) = @$_; |
857 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
854 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
858 | for @funs; |
855 | for @funs; |
859 | } |
856 | } |
860 | |
857 | |
|
|
858 | =over 4 |
|
|
859 | |
|
|
860 | =item @retval = safe_eval $code, [var => value, ...] |
|
|
861 | |
|
|
862 | Compiled and executes the given perl code snippet. additional var/value |
|
|
863 | pairs result in temporary local (my) scalar variables of the given name |
|
|
864 | that are available in the code snippet. Example: |
|
|
865 | |
|
|
866 | my $five = safe_eval '$first + $second', first => 1, second => 4; |
|
|
867 | |
|
|
868 | =cut |
|
|
869 | |
861 | sub safe_eval($;@) { |
870 | sub safe_eval($;@) { |
862 | my ($code, %vars) = @_; |
871 | my ($code, %vars) = @_; |
863 | |
872 | |
864 | my $qcode = $code; |
873 | my $qcode = $code; |
865 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
874 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
… | |
… | |
887 | } |
896 | } |
888 | |
897 | |
889 | wantarray ? @res : $res[0] |
898 | wantarray ? @res : $res[0] |
890 | } |
899 | } |
891 | |
900 | |
|
|
901 | =item cf::register_script_function $function => $cb |
|
|
902 | |
|
|
903 | Register a function that can be called from within map/npc scripts. The |
|
|
904 | function should be reasonably secure and should be put into a package name |
|
|
905 | like the extension. |
|
|
906 | |
|
|
907 | Example: register a function that gets called whenever a map script calls |
|
|
908 | C<rent::overview>, as used by the C<rent> extension. |
|
|
909 | |
|
|
910 | cf::register_script_function "rent::overview" => sub { |
|
|
911 | ... |
|
|
912 | }; |
|
|
913 | |
|
|
914 | =cut |
|
|
915 | |
892 | sub register_script_function { |
916 | sub register_script_function { |
893 | my ($fun, $cb) = @_; |
917 | my ($fun, $cb) = @_; |
894 | |
918 | |
895 | no strict 'refs'; |
919 | no strict 'refs'; |
896 | *{"safe::$fun"} = $safe_hole->wrap ($cb); |
920 | *{"safe::$fun"} = $safe_hole->wrap ($cb); |
897 | } |
921 | } |
898 | |
922 | |
|
|
923 | =back |
|
|
924 | |
|
|
925 | =cut |
|
|
926 | |
|
|
927 | ############################################################################# |
|
|
928 | |
|
|
929 | =head2 EXTENSION DATABASE SUPPORT |
|
|
930 | |
|
|
931 | Crossfire maintains a very simple database for extension use. It can |
|
|
932 | currently store anything that can be serialised using Storable, which |
|
|
933 | excludes objects. |
|
|
934 | |
|
|
935 | The parameter C<$family> should best start with the name of the extension |
|
|
936 | using it, it should be unique. |
|
|
937 | |
|
|
938 | =over 4 |
|
|
939 | |
|
|
940 | =item $hashref = cf::db_get $family |
|
|
941 | |
|
|
942 | Return a hashref for use by the extension C<$family>, which can be |
|
|
943 | modified. After modifications, you have to call C<cf::db_dirty> or |
|
|
944 | C<cf::db_sync>. |
|
|
945 | |
|
|
946 | =item $value = cf::db_get $family => $key |
|
|
947 | |
|
|
948 | Returns a single value from the database |
|
|
949 | |
|
|
950 | =item cf::db_put $family => $hashref |
|
|
951 | |
|
|
952 | Stores the given family hashref into the database. Updates are delayed, if |
|
|
953 | you want the data to be synced to disk immediately, use C<cf::db_sync>. |
|
|
954 | |
|
|
955 | =item cf::db_put $family => $key => $value |
|
|
956 | |
|
|
957 | Stores the given C<$value> in the family hash. Updates are delayed, if you |
|
|
958 | want the data to be synced to disk immediately, use C<cf::db_sync>. |
|
|
959 | |
|
|
960 | =item cf::db_dirty |
|
|
961 | |
|
|
962 | Marks the database as dirty, to be updated at a later time. |
|
|
963 | |
|
|
964 | =item cf::db_sync |
|
|
965 | |
|
|
966 | Immediately write the database to disk I<if it is dirty>. |
|
|
967 | |
|
|
968 | =cut |
|
|
969 | |
|
|
970 | { |
|
|
971 | my $db; |
|
|
972 | my $path = cf::localdir . "/database.pst"; |
|
|
973 | |
|
|
974 | sub db_load() { |
|
|
975 | warn "loading database $path\n";#d# remove later |
|
|
976 | $db = stat $path ? Storable::retrieve $path : { }; |
|
|
977 | } |
|
|
978 | |
|
|
979 | my $pid; |
|
|
980 | |
|
|
981 | sub db_save() { |
|
|
982 | warn "saving database $path\n";#d# remove later |
|
|
983 | waitpid $pid, 0 if $pid; |
|
|
984 | if (0 == ($pid = fork)) { |
|
|
985 | $db->{_meta}{version} = 1; |
|
|
986 | Storable::nstore $db, "$path~"; |
|
|
987 | rename "$path~", $path; |
|
|
988 | cf::_exit 0 if defined $pid; |
|
|
989 | } |
|
|
990 | } |
|
|
991 | |
|
|
992 | my $dirty; |
|
|
993 | |
|
|
994 | sub db_sync() { |
|
|
995 | db_save if $dirty; |
|
|
996 | undef $dirty; |
|
|
997 | } |
|
|
998 | |
|
|
999 | my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, cb => sub { |
|
|
1000 | db_sync; |
|
|
1001 | }); |
|
|
1002 | |
|
|
1003 | sub db_dirty() { |
|
|
1004 | $dirty = 1; |
|
|
1005 | $idle->start; |
|
|
1006 | } |
|
|
1007 | |
|
|
1008 | sub db_get($;$) { |
|
|
1009 | @_ >= 2 |
|
|
1010 | ? $db->{$_[0]}{$_[1]} |
|
|
1011 | : ($db->{$_[0]} ||= { }) |
|
|
1012 | } |
|
|
1013 | |
|
|
1014 | sub db_put($$;$) { |
|
|
1015 | if (@_ >= 3) { |
|
|
1016 | $db->{$_[0]}{$_[1]} = $_[2]; |
|
|
1017 | } else { |
|
|
1018 | $db->{$_[0]} = $_[1]; |
|
|
1019 | } |
|
|
1020 | db_dirty; |
|
|
1021 | } |
|
|
1022 | |
|
|
1023 | attach_global |
|
|
1024 | prio => 10000, |
|
|
1025 | on_cleanup => sub { |
|
|
1026 | db_sync; |
|
|
1027 | }, |
|
|
1028 | ; |
|
|
1029 | } |
|
|
1030 | |
899 | ############################################################################# |
1031 | ############################################################################# |
900 | # the server's main() |
1032 | # the server's main() |
901 | |
1033 | |
|
|
1034 | sub cfg_load { |
|
|
1035 | open my $fh, "<:utf8", cf::confdir . "/config" |
|
|
1036 | or return; |
|
|
1037 | |
|
|
1038 | local $/; |
|
|
1039 | *CFG = YAML::Syck::Load <$fh>; |
|
|
1040 | } |
|
|
1041 | |
902 | sub main { |
1042 | sub main { |
|
|
1043 | cfg_load; |
|
|
1044 | db_load; |
903 | load_extensions; |
1045 | load_extensions; |
904 | Event::loop; |
1046 | Event::loop; |
905 | } |
1047 | } |
906 | |
1048 | |
907 | ############################################################################# |
1049 | ############################################################################# |
908 | # initialisation |
1050 | # initialisation |
|
|
1051 | |
|
|
1052 | sub _perl_reload(&) { |
|
|
1053 | my ($msg) = @_; |
|
|
1054 | |
|
|
1055 | $msg->("reloading..."); |
|
|
1056 | |
|
|
1057 | eval { |
|
|
1058 | # cancel all watchers |
|
|
1059 | $_->cancel for Event::all_watchers; |
|
|
1060 | |
|
|
1061 | # unload all extensions |
|
|
1062 | for (@exts) { |
|
|
1063 | $msg->("unloading <$_>"); |
|
|
1064 | unload_extension $_; |
|
|
1065 | } |
|
|
1066 | |
|
|
1067 | # unload all modules loaded from $LIBDIR |
|
|
1068 | while (my ($k, $v) = each %INC) { |
|
|
1069 | next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; |
|
|
1070 | |
|
|
1071 | $msg->("removing <$k>"); |
|
|
1072 | delete $INC{$k}; |
|
|
1073 | |
|
|
1074 | $k =~ s/\.pm$//; |
|
|
1075 | $k =~ s/\//::/g; |
|
|
1076 | |
|
|
1077 | if (my $cb = $k->can ("unload_module")) { |
|
|
1078 | $cb->(); |
|
|
1079 | } |
|
|
1080 | |
|
|
1081 | Symbol::delete_package $k; |
|
|
1082 | } |
|
|
1083 | |
|
|
1084 | # sync database to disk |
|
|
1085 | cf::db_sync; |
|
|
1086 | |
|
|
1087 | # get rid of safe::, as good as possible |
|
|
1088 | Symbol::delete_package "safe::$_" |
|
|
1089 | for qw(cf::object cf::object::player cf::player cf::map cf::party cf::region); |
|
|
1090 | |
|
|
1091 | # remove register_script_function callbacks |
|
|
1092 | # TODO |
|
|
1093 | |
|
|
1094 | # unload cf.pm "a bit" |
|
|
1095 | delete $INC{"cf.pm"}; |
|
|
1096 | |
|
|
1097 | # don't, removes xs symbols, too, |
|
|
1098 | # and global variables created in xs |
|
|
1099 | #Symbol::delete_package __PACKAGE__; |
|
|
1100 | |
|
|
1101 | # reload cf.pm |
|
|
1102 | $msg->("reloading cf.pm"); |
|
|
1103 | require cf; |
|
|
1104 | |
|
|
1105 | # load config and database again |
|
|
1106 | cf::cfg_load; |
|
|
1107 | cf::db_load; |
|
|
1108 | |
|
|
1109 | # load extensions |
|
|
1110 | $msg->("load extensions"); |
|
|
1111 | cf::load_extensions; |
|
|
1112 | |
|
|
1113 | # reattach attachments to objects |
|
|
1114 | $msg->("reattach"); |
|
|
1115 | _global_reattach; |
|
|
1116 | }; |
|
|
1117 | $msg->($@) if $@; |
|
|
1118 | |
|
|
1119 | $msg->("reloaded"); |
|
|
1120 | }; |
|
|
1121 | |
|
|
1122 | sub perl_reload() { |
|
|
1123 | _perl_reload { |
|
|
1124 | warn $_[0]; |
|
|
1125 | print "$_[0]\n"; |
|
|
1126 | }; |
|
|
1127 | } |
|
|
1128 | |
|
|
1129 | register_command "perl-reload", 0, sub { |
|
|
1130 | my ($who, $arg) = @_; |
|
|
1131 | |
|
|
1132 | if ($who->flag (FLAG_WIZ)) { |
|
|
1133 | _perl_reload { |
|
|
1134 | warn $_[0]; |
|
|
1135 | $who->message ($_[0]); |
|
|
1136 | }; |
|
|
1137 | } |
|
|
1138 | }; |
909 | |
1139 | |
910 | register "<global>", __PACKAGE__; |
1140 | register "<global>", __PACKAGE__; |
911 | |
1141 | |
912 | unshift @INC, $LIBDIR; |
1142 | unshift @INC, $LIBDIR; |
913 | |
1143 | |