… | |
… | |
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 = (); |
… | |
… | |
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; |
25 | |
29 | |
26 | our %CFG; |
30 | our %CFG; |
|
|
31 | |
|
|
32 | our $uptime; |
|
|
33 | |
|
|
34 | $uptime ||= time; |
27 | |
35 | |
28 | ############################################################################# |
36 | ############################################################################# |
29 | |
37 | |
30 | =head2 GLOBAL VARIABLES |
38 | =head2 GLOBAL VARIABLES |
31 | |
39 | |
… | |
… | |
108 | $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs |
116 | $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs |
109 | JSON::Syck::Dump $_[0] |
117 | JSON::Syck::Dump $_[0] |
110 | } |
118 | } |
111 | |
119 | |
112 | =back |
120 | =back |
|
|
121 | |
|
|
122 | =cut |
113 | |
123 | |
114 | ############################################################################# |
124 | ############################################################################# |
115 | |
125 | |
116 | =head2 EVENTS AND OBJECT ATTACHMENTS |
126 | =head2 EVENTS AND OBJECT ATTACHMENTS |
117 | |
127 | |
… | |
… | |
420 | This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be |
430 | This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be |
421 | removed in future versions), and there is no public API to access override |
431 | removed in future versions), and there is no public API to access override |
422 | results (if you must, access C<@cf::invoke_results> directly). |
432 | results (if you must, access C<@cf::invoke_results> directly). |
423 | |
433 | |
424 | =back |
434 | =back |
|
|
435 | |
|
|
436 | =cut |
425 | |
437 | |
426 | ############################################################################# |
438 | ############################################################################# |
427 | |
439 | |
428 | =head2 METHODS VALID FOR ALL CORE OBJECTS |
440 | =head2 METHODS VALID FOR ALL CORE OBJECTS |
429 | |
441 | |
… | |
… | |
762 | sub cf::player::exists($) { |
774 | sub cf::player::exists($) { |
763 | cf::player::find $_[0] |
775 | cf::player::find $_[0] |
764 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
776 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
765 | } |
777 | } |
766 | |
778 | |
767 | =item $player->reply ($npc, $msg[, $flags]) |
779 | =item $object->reply ($npc, $msg[, $flags]) |
768 | |
780 | |
769 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
781 | Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
770 | can be C<undef>. Does the right thing when the player is currently in a |
782 | can be C<undef>. Does the right thing when the player is currently in a |
771 | dialogue with the given NPC character. |
783 | dialogue with the given NPC character. |
772 | |
784 | |
… | |
… | |
912 | *{"safe::$fun"} = $safe_hole->wrap ($cb); |
924 | *{"safe::$fun"} = $safe_hole->wrap ($cb); |
913 | } |
925 | } |
914 | |
926 | |
915 | =back |
927 | =back |
916 | |
928 | |
|
|
929 | =cut |
|
|
930 | |
917 | ############################################################################# |
931 | ############################################################################# |
918 | |
932 | |
919 | =head2 EXTENSION DATABASE SUPPORT |
933 | =head2 EXTENSION DATABASE SUPPORT |
920 | |
934 | |
921 | Crossfire maintains a very simple database for extension use. It can |
935 | Crossfire maintains a very simple database for extension use. It can |
… | |
… | |
1019 | } |
1033 | } |
1020 | |
1034 | |
1021 | ############################################################################# |
1035 | ############################################################################# |
1022 | # the server's main() |
1036 | # the server's main() |
1023 | |
1037 | |
|
|
1038 | sub cfg_load { |
|
|
1039 | open my $fh, "<:utf8", cf::confdir . "/config" |
|
|
1040 | or return; |
|
|
1041 | |
|
|
1042 | local $/; |
|
|
1043 | *CFG = YAML::Syck::Load <$fh>; |
|
|
1044 | } |
|
|
1045 | |
1024 | sub main { |
1046 | sub main { |
|
|
1047 | cfg_load; |
1025 | db_load; |
1048 | db_load; |
1026 | load_extensions; |
1049 | load_extensions; |
1027 | Event::loop; |
1050 | Event::loop; |
1028 | } |
1051 | } |
1029 | |
1052 | |
… | |
… | |
1081 | |
1104 | |
1082 | # reload cf.pm |
1105 | # reload cf.pm |
1083 | $msg->("reloading cf.pm"); |
1106 | $msg->("reloading cf.pm"); |
1084 | require cf; |
1107 | require cf; |
1085 | |
1108 | |
1086 | # load database again |
1109 | # load config and database again |
|
|
1110 | cf::cfg_load; |
1087 | cf::db_load; |
1111 | cf::db_load; |
1088 | |
1112 | |
1089 | # load extensions |
1113 | # load extensions |
1090 | $msg->("load extensions"); |
1114 | $msg->("load extensions"); |
1091 | cf::load_extensions; |
1115 | cf::load_extensions; |