1 | # |
1 | # |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | # |
3 | # |
4 | # Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | # |
5 | # |
6 | # Deliantra is free software: you can redistribute it and/or modify |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
7 | # it under the terms of the GNU General Public License as published by |
7 | # the terms of the Affero GNU General Public License as published by the |
8 | # the Free Software Foundation, either version 3 of the License, or |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
9 | # (at your option) any later version. |
9 | # option) any later version. |
10 | # |
10 | # |
11 | # This program is distributed in the hope that it will be useful, |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | # GNU General Public License for more details. |
14 | # GNU General Public License for more details. |
15 | # |
15 | # |
16 | # You should have received a copy of the GNU General Public License |
16 | # You should have received a copy of the Affero GNU General Public License |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | # and the GNU General Public License along with this program. If not, see |
|
|
18 | # <http://www.gnu.org/licenses/>. |
18 | # |
19 | # |
19 | # The authors can be reached via e-mail to <support@deliantra.net> |
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
20 | # |
21 | # |
21 | |
22 | |
22 | package cf; |
23 | package cf; |
23 | |
24 | |
24 | use 5.10.0; |
25 | use 5.10.0; |
25 | use utf8; |
26 | use utf8; |
… | |
… | |
53 | use JSON::XS 2.01 (); |
54 | use JSON::XS 2.01 (); |
54 | use BDB (); |
55 | use BDB (); |
55 | use Data::Dumper; |
56 | use Data::Dumper; |
56 | use Digest::MD5; |
57 | use Digest::MD5; |
57 | use Fcntl; |
58 | use Fcntl; |
58 | use YAML (); |
59 | use YAML::XS (); |
59 | use IO::AIO (); |
60 | use IO::AIO (); |
60 | use Time::HiRes; |
61 | use Time::HiRes; |
61 | use Compress::LZF; |
62 | use Compress::LZF; |
62 | use Digest::MD5 (); |
63 | use Digest::MD5 (); |
63 | |
64 | |
… | |
… | |
88 | our %EXT_CORO = (); # coroutines bound to extensions |
89 | our %EXT_CORO = (); # coroutines bound to extensions |
89 | our %EXT_MAP = (); # pluggable maps |
90 | our %EXT_MAP = (); # pluggable maps |
90 | |
91 | |
91 | our $RELOAD; # number of reloads so far, non-zero while in reload |
92 | our $RELOAD; # number of reloads so far, non-zero while in reload |
92 | our @EVENT; |
93 | our @EVENT; |
|
|
94 | our @REFLECT; # set by XS |
|
|
95 | our %REFLECT; # set by us |
93 | |
96 | |
94 | our $CONFDIR = confdir; |
97 | our $CONFDIR = confdir; |
95 | our $DATADIR = datadir; |
98 | our $DATADIR = datadir; |
96 | our $LIBDIR = "$DATADIR/ext"; |
99 | our $LIBDIR = "$DATADIR/ext"; |
97 | our $PODDIR = "$DATADIR/pod"; |
100 | our $PODDIR = "$DATADIR/pod"; |
… | |
… | |
115 | our $BDB_DEADLOCK_WATCHER; |
118 | our $BDB_DEADLOCK_WATCHER; |
116 | our $BDB_CHECKPOINT_WATCHER; |
119 | our $BDB_CHECKPOINT_WATCHER; |
117 | our $BDB_TRICKLE_WATCHER; |
120 | our $BDB_TRICKLE_WATCHER; |
118 | our $DB_ENV; |
121 | our $DB_ENV; |
119 | |
122 | |
120 | our @EXTRA_MODULES = qw(pod mapscript); |
123 | our @EXTRA_MODULES = qw(pod match mapscript); |
121 | |
124 | |
122 | our %CFG; |
125 | our %CFG; |
123 | |
126 | |
124 | our $UPTIME; $UPTIME ||= time; |
127 | our $UPTIME; $UPTIME ||= time; |
125 | our $RUNTIME; |
128 | our $RUNTIME; |
… | |
… | |
161 | |
164 | |
162 | sub cf::map::normalise; |
165 | sub cf::map::normalise; |
163 | |
166 | |
164 | ############################################################################# |
167 | ############################################################################# |
165 | |
168 | |
|
|
169 | %REFLECT = (); |
|
|
170 | for (@REFLECT) { |
|
|
171 | my $reflect = JSON::XS::decode_json $_; |
|
|
172 | $REFLECT{$reflect->{class}} = $reflect; |
|
|
173 | } |
|
|
174 | |
|
|
175 | # this is decidedly evil |
|
|
176 | $REFLECT{object}{flags} = { map +($_ => undef), grep $_, map /^FLAG_([A-Z0-9_]+)$/ && lc $1, keys %{"cf::"} }; |
|
|
177 | |
|
|
178 | ############################################################################# |
|
|
179 | |
166 | =head2 GLOBAL VARIABLES |
180 | =head2 GLOBAL VARIABLES |
167 | |
181 | |
168 | =over 4 |
182 | =over 4 |
169 | |
183 | |
170 | =item $cf::UPTIME |
184 | =item $cf::UPTIME |
… | |
… | |
214 | returns directly I<after> the tick processing (and consequently, can only wake one process |
228 | returns directly I<after> the tick processing (and consequently, can only wake one process |
215 | per tick), while cf::wait_for_tick wakes up all waiters after tick processing. |
229 | per tick), while cf::wait_for_tick wakes up all waiters after tick processing. |
216 | |
230 | |
217 | =item @cf::INVOKE_RESULTS |
231 | =item @cf::INVOKE_RESULTS |
218 | |
232 | |
219 | This array contains the results of the last C<invoke ()> call. When |
233 | This array contains the results of the last C<invoke ()> call. When |
220 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
234 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
221 | that call. |
235 | that call. |
|
|
236 | |
|
|
237 | =item %cf::REFLECT |
|
|
238 | |
|
|
239 | Contains, for each (C++) class name, a hash reference with information |
|
|
240 | about object members (methods, scalars, arrays and flags) and other |
|
|
241 | metadata, which is useful for introspection. |
222 | |
242 | |
223 | =back |
243 | =back |
224 | |
244 | |
225 | =cut |
245 | =cut |
226 | |
246 | |
… | |
… | |
2321 | : normalise $_ |
2341 | : normalise $_ |
2322 | } @{ aio_readdir $UNIQUEDIR or [] } |
2342 | } @{ aio_readdir $UNIQUEDIR or [] } |
2323 | ] |
2343 | ] |
2324 | } |
2344 | } |
2325 | |
2345 | |
|
|
2346 | =item cf::map::static_maps |
|
|
2347 | |
|
|
2348 | Returns an arrayref if paths of all static maps (all preinstalled F<.map> |
|
|
2349 | file in the shared directory excluding F</styles>). May block. |
|
|
2350 | |
|
|
2351 | =cut |
|
|
2352 | |
|
|
2353 | sub static_maps() { |
|
|
2354 | my @dirs = ""; |
|
|
2355 | my @maps; |
|
|
2356 | |
|
|
2357 | while (@dirs) { |
|
|
2358 | my $dir = shift @dirs; |
|
|
2359 | |
|
|
2360 | next if $dir eq "/styles"; |
|
|
2361 | |
|
|
2362 | my ($dirs, $files) = Coro::AIO::aio_scandir "$MAPDIR$dir", 2 |
|
|
2363 | or return; |
|
|
2364 | |
|
|
2365 | for (@$files) { |
|
|
2366 | s/\.map$// or next; |
|
|
2367 | utf8::decode $_; |
|
|
2368 | push @maps, "$dir/$_"; |
|
|
2369 | } |
|
|
2370 | |
|
|
2371 | push @dirs, map "$dir/$_", @$dirs; |
|
|
2372 | } |
|
|
2373 | |
|
|
2374 | \@maps |
|
|
2375 | } |
|
|
2376 | |
2326 | =back |
2377 | =back |
2327 | |
2378 | |
2328 | =head3 cf::object |
2379 | =head3 cf::object |
2329 | |
2380 | |
2330 | =cut |
2381 | =cut |
… | |
… | |
2745 | |
2796 | |
2746 | =cut |
2797 | =cut |
2747 | |
2798 | |
2748 | # non-persistent channels (usually the info channel) |
2799 | # non-persistent channels (usually the info channel) |
2749 | our %CHANNEL = ( |
2800 | our %CHANNEL = ( |
|
|
2801 | "c/motd" => { |
|
|
2802 | id => "infobox", |
|
|
2803 | title => "MOTD", |
|
|
2804 | reply => undef, |
|
|
2805 | tooltip => "The message of the day", |
|
|
2806 | }, |
2750 | "c/identify" => { |
2807 | "c/identify" => { |
2751 | id => "infobox", |
2808 | id => "infobox", |
2752 | title => "Identify", |
2809 | title => "Identify", |
2753 | reply => undef, |
2810 | reply => undef, |
2754 | tooltip => "Items recently identified", |
2811 | tooltip => "Items recently identified", |
… | |
… | |
2756 | "c/examine" => { |
2813 | "c/examine" => { |
2757 | id => "infobox", |
2814 | id => "infobox", |
2758 | title => "Examine", |
2815 | title => "Examine", |
2759 | reply => undef, |
2816 | reply => undef, |
2760 | tooltip => "Signs and other items you examined", |
2817 | tooltip => "Signs and other items you examined", |
|
|
2818 | }, |
|
|
2819 | "c/shopinfo" => { |
|
|
2820 | id => "infobox", |
|
|
2821 | title => "Shop Info", |
|
|
2822 | reply => undef, |
|
|
2823 | tooltip => "What your bargaining skill tells you about the shop", |
2761 | }, |
2824 | }, |
2762 | "c/book" => { |
2825 | "c/book" => { |
2763 | id => "infobox", |
2826 | id => "infobox", |
2764 | title => "Book", |
2827 | title => "Book", |
2765 | reply => undef, |
2828 | reply => undef, |
… | |
… | |
3363 | |
3426 | |
3364 | warn "finished reloading resource files\n"; |
3427 | warn "finished reloading resource files\n"; |
3365 | } |
3428 | } |
3366 | |
3429 | |
3367 | sub reload_config { |
3430 | sub reload_config { |
|
|
3431 | warn "reloading config file...\n"; |
|
|
3432 | |
3368 | open my $fh, "<:utf8", "$CONFDIR/config" |
3433 | open my $fh, "<:utf8", "$CONFDIR/config" |
3369 | or return; |
3434 | or return; |
3370 | |
3435 | |
3371 | local $/; |
3436 | local $/; |
3372 | *CFG = YAML::Load <$fh>; |
3437 | *CFG = YAML::XS::Load scalar <$fh>; |
3373 | |
3438 | |
3374 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; |
3439 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; |
3375 | |
3440 | |
3376 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3441 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3377 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3442 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
… | |
… | |
3381 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
3446 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
3382 | and die "WARNING: m(un)lockall failed: $!\n"; |
3447 | and die "WARNING: m(un)lockall failed: $!\n"; |
3383 | }; |
3448 | }; |
3384 | warn $@ if $@; |
3449 | warn $@ if $@; |
3385 | } |
3450 | } |
|
|
3451 | |
|
|
3452 | warn "finished reloading resource files\n"; |
3386 | } |
3453 | } |
3387 | |
3454 | |
3388 | sub pidfile() { |
3455 | sub pidfile() { |
3389 | sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT |
3456 | sysopen my $fh, $PIDFILE, O_RDWR | O_CREAT |
3390 | or die "$PIDFILE: $!"; |
3457 | or die "$PIDFILE: $!"; |
… | |
… | |
3740 | |
3807 | |
3741 | warn "unload completed, starting to reload now"; |
3808 | warn "unload completed, starting to reload now"; |
3742 | |
3809 | |
3743 | warn "reloading cf.pm"; |
3810 | warn "reloading cf.pm"; |
3744 | require cf; |
3811 | require cf; |
3745 | cf::_connect_to_perl; # nominally unnecessary, but cannot hurt |
3812 | cf::_connect_to_perl_1; |
3746 | |
3813 | |
3747 | warn "loading config and database again"; |
3814 | warn "loading config and database again"; |
3748 | cf::reload_config; |
3815 | cf::reload_config; |
3749 | |
3816 | |
3750 | warn "loading extensions"; |
3817 | warn "loading extensions"; |
… | |
… | |
3958 | } |
4025 | } |
3959 | } |
4026 | } |
3960 | |
4027 | |
3961 | # load additional modules |
4028 | # load additional modules |
3962 | require "cf/$_.pm" for @EXTRA_MODULES; |
4029 | require "cf/$_.pm" for @EXTRA_MODULES; |
|
|
4030 | cf::_connect_to_perl_2; |
3963 | |
4031 | |
3964 | END { cf::emergency_save } |
4032 | END { cf::emergency_save } |
3965 | |
4033 | |
3966 | 1 |
4034 | 1 |
3967 | |
4035 | |