ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.478 by root, Thu Sep 17 01:57:31 2009 UTC vs.
Revision 1.490 by root, Sat Oct 24 06:16:40 2009 UTC

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
22package cf; 23package cf;
23 24
24use 5.10.0; 25use 5.10.0;
25use utf8; 26use utf8;
53use JSON::XS 2.01 (); 54use JSON::XS 2.01 ();
54use BDB (); 55use BDB ();
55use Data::Dumper; 56use Data::Dumper;
56use Digest::MD5; 57use Digest::MD5;
57use Fcntl; 58use Fcntl;
58use YAML (); 59use YAML::XS ();
59use IO::AIO (); 60use IO::AIO ();
60use Time::HiRes; 61use Time::HiRes;
61use Compress::LZF; 62use Compress::LZF;
62use Digest::MD5 (); 63use Digest::MD5 ();
63 64
88our %EXT_CORO = (); # coroutines bound to extensions 89our %EXT_CORO = (); # coroutines bound to extensions
89our %EXT_MAP = (); # pluggable maps 90our %EXT_MAP = (); # pluggable maps
90 91
91our $RELOAD; # number of reloads so far, non-zero while in reload 92our $RELOAD; # number of reloads so far, non-zero while in reload
92our @EVENT; 93our @EVENT;
94our @REFLECT; # set by XS
95our %REFLECT; # set by us
93 96
94our $CONFDIR = confdir; 97our $CONFDIR = confdir;
95our $DATADIR = datadir; 98our $DATADIR = datadir;
96our $LIBDIR = "$DATADIR/ext"; 99our $LIBDIR = "$DATADIR/ext";
97our $PODDIR = "$DATADIR/pod"; 100our $PODDIR = "$DATADIR/pod";
115our $BDB_DEADLOCK_WATCHER; 118our $BDB_DEADLOCK_WATCHER;
116our $BDB_CHECKPOINT_WATCHER; 119our $BDB_CHECKPOINT_WATCHER;
117our $BDB_TRICKLE_WATCHER; 120our $BDB_TRICKLE_WATCHER;
118our $DB_ENV; 121our $DB_ENV;
119 122
120our @EXTRA_MODULES = qw(pod mapscript); 123our @EXTRA_MODULES = qw(pod match mapscript);
121 124
122our %CFG; 125our %CFG;
123 126
124our $UPTIME; $UPTIME ||= time; 127our $UPTIME; $UPTIME ||= time;
125our $RUNTIME; 128our $RUNTIME;
161 164
162sub cf::map::normalise; 165sub cf::map::normalise;
163 166
164############################################################################# 167#############################################################################
165 168
169%REFLECT = ();
170for (@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
214returns directly I<after> the tick processing (and consequently, can only wake one process 228returns directly I<after> the tick processing (and consequently, can only wake one process
215per tick), while cf::wait_for_tick wakes up all waiters after tick processing. 229per 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
219This array contains the results of the last C<invoke ()> call. When 233This array contains the results of the last C<invoke ()> call. When
220C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of 234C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of
221that call. 235that call.
236
237=item %cf::REFLECT
238
239Contains, for each (C++) class name, a hash reference with information
240about object members (methods, scalars, arrays and flags) and other
241metadata, 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
2348Returns an arrayref if paths of all static maps (all preinstalled F<.map>
2349file in the shared directory excluding F</styles>). May block.
2350
2351=cut
2352
2353sub 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)
2749our %CHANNEL = ( 2800our %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
3367sub reload_config { 3430sub 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
3388sub pidfile() { 3455sub 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
3962require "cf/$_.pm" for @EXTRA_MODULES; 4029require "cf/$_.pm" for @EXTRA_MODULES;
4030cf::_connect_to_perl_2;
3963 4031
3964END { cf::emergency_save } 4032END { cf::emergency_save }
3965 4033
39661 40341
3967 4035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines