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.581 by root, Fri Feb 3 02:04:11 2012 UTC vs.
Revision 1.594 by root, Fri Nov 9 02:50:50 2012 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,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4# Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5# 5#
6# Deliantra is free software: you can redistribute it and/or modify it under 6# Deliantra is free software: you can redistribute it and/or modify it under
7# the terms of the Affero GNU General Public License as published by the 7# the terms of the Affero GNU General Public License as published by the
8# Free Software Foundation, either version 3 of the License, or (at your 8# Free Software Foundation, either version 3 of the License, or (at your
9# 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 Affero GNU General Public License 16# You should have received a copy of the Affero GNU General Public License
17# and the GNU General Public License along with this program. If not, see 17# and the GNU General Public License along with this program. If not, see
18# <http://www.gnu.org/licenses/>. 18# <http://www.gnu.org/licenses/>.
19# 19#
20# 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>
21# 21#
22 22
23package cf; 23package cf;
24 24
32use Safe; 32use Safe;
33use Safe::Hole; 33use Safe::Hole;
34use Storable (); 34use Storable ();
35use Carp (); 35use Carp ();
36 36
37use Guard (); 37use AnyEvent ();
38use AnyEvent::IO ();
39use AnyEvent::DNS ();
40
38use Coro (); 41use Coro ();
39use Coro::State; 42use Coro::State;
40use Coro::Handle; 43use Coro::Handle;
41use Coro::EV; 44use Coro::EV;
42use Coro::AnyEvent; 45use Coro::AnyEvent;
48use Coro::AIO; 51use Coro::AIO;
49use Coro::BDB 1.6; 52use Coro::BDB 1.6;
50use Coro::Storable; 53use Coro::Storable;
51use Coro::Util (); 54use Coro::Util ();
52 55
56use Guard ();
53use JSON::XS 2.01 (); 57use JSON::XS 2.01 ();
54use BDB (); 58use BDB ();
55use Data::Dumper; 59use Data::Dumper;
56use Fcntl; 60use Fcntl;
57use YAML::XS (); 61use YAML::XS ();
83our %COMMAND = (); 87our %COMMAND = ();
84our %COMMAND_TIME = (); 88our %COMMAND_TIME = ();
85 89
86our @EXTS = (); # list of extension package names 90our @EXTS = (); # list of extension package names
87our %EXTCMD = (); 91our %EXTCMD = ();
92our %EXTACMD = ();
88our %EXTICMD = (); 93our %EXTICMD = ();
94our %EXTIACMD = ();
89our %EXT_CORO = (); # coroutines bound to extensions 95our %EXT_CORO = (); # coroutines bound to extensions
90our %EXT_MAP = (); # pluggable maps 96our %EXT_MAP = (); # pluggable maps
91 97
92our $RELOAD; # number of reloads so far, non-zero while in reload 98our $RELOAD; # number of reloads so far, non-zero while in reload
93our @EVENT; 99our @EVENT;
129our $DB_ENV; 135our $DB_ENV;
130 136
131our @EXTRA_MODULES = qw(pod match mapscript incloader); 137our @EXTRA_MODULES = qw(pod match mapscript incloader);
132 138
133our %CFG; 139our %CFG;
140our %EXT_CFG; # cfgkeyname => [var-ref, defaultvalue]
134 141
135our $UPTIME; $UPTIME ||= time; 142our $UPTIME; $UPTIME ||= time;
136our $RUNTIME = 0; 143our $RUNTIME = 0;
137our $SERVER_TICK = 0; 144our $SERVER_TICK = 0;
138our $NOW; 145our $NOW;
219=item $cf::RUNTIME 226=item $cf::RUNTIME
220 227
221The time this server has run, starts at 0 and is increased by $cf::TICK on 228The time this server has run, starts at 0 and is increased by $cf::TICK on
222every server tick. 229every server tick.
223 230
224=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR 231=item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR
225$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR 232$cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR
226$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR 233$cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR
227 234
228Various directories - "/etc", read-only install directory, perl-library 235Various directories - "/etc", read-only install directory, perl-library
229directory, pod-directory, read-only maps directory, "/var", "/var/tmp", 236directory, pod-directory, read-only maps directory, "/var", "/var/tmp",
230unique-items directory, player file directory, random maps directory and 237unique-items directory, player file directory, random maps directory and
231database environment. 238database environment.
335)) { 342)) {
336 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 343 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
337} 344}
338 345
339$EV::DIED = sub { 346$EV::DIED = sub {
340 Carp::cluck "error in event callback: @_"; 347 warn "error in event callback: $@";
341}; 348};
342 349
343############################################################################# 350#############################################################################
344 351
345sub fork_call(&@); 352sub fork_call(&@);
1426=cut 1433=cut
1427 1434
1428############################################################################# 1435#############################################################################
1429# command handling &c 1436# command handling &c
1430 1437
1431=item cf::register_command $name => \&callback($ob,$args); 1438=item cf::register_command $name => \&callback($ob,$args)
1432 1439
1433Register a callback for execution when the client sends the user command 1440Register a callback for execution when the client sends the user command
1434$name. 1441$name.
1435 1442
1436=cut 1443=cut
1442 #warn "registering command '$name/$time' to '$caller'"; 1449 #warn "registering command '$name/$time' to '$caller'";
1443 1450
1444 push @{ $COMMAND{$name} }, [$caller, $cb]; 1451 push @{ $COMMAND{$name} }, [$caller, $cb];
1445} 1452}
1446 1453
1447=item cf::register_extcmd $name => \&callback($pl,$packet); 1454=item cf::register_extcmd $name => \&callback($pl,@args)
1448 1455
1449Register a callback for execution when the client sends an (synchronous) 1456Register a callback for execution when the client sends an (synchronous)
1450extcmd packet. Ext commands will be processed in the order they are 1457extcmd packet. Ext commands will be processed in the order they are
1451received by the server, like other user commands. The first argument is 1458received by the server, like other user commands. The first argument is
1452the logged-in player. Ext commands can only be processed after a player 1459the logged-in player. Ext commands can only be processed after a player
1453has logged in successfully. 1460has logged in successfully.
1454 1461
1455If the callback returns something, it is sent back as if reply was being 1462The values will be sent back to the client.
1456called.
1457 1463
1464=item cf::register_async_extcmd $name => \&callback($pl,$reply->(...),@args)
1465
1466Same as C<cf::register_extcmd>, but instead of returning values, the
1467callback needs to clal the C<$reply> function.
1468
1458=item cf::register_exticmd $name => \&callback($ns,$packet); 1469=item cf::register_exticmd $name => \&callback($ns,@args)
1459 1470
1460Register a callback for execution when the client sends an (asynchronous) 1471Register a callback for execution when the client sends an (asynchronous)
1461exticmd packet. Exti commands are processed by the server as soon as they 1472exticmd packet. Exti commands are processed by the server as soon as they
1462are received, i.e. out of order w.r.t. other commands. The first argument 1473are received, i.e. out of order w.r.t. other commands. The first argument
1463is a client socket. Exti commands can be received anytime, even before 1474is a client socket. Exti commands can be received anytime, even before
1464log-in. 1475log-in.
1465 1476
1466If the callback returns something, it is sent back as if reply was being 1477The values will be sent back to the client.
1467called.
1468 1478
1469=cut 1479=item cf::register_async_exticmd $name => \&callback($ns,$reply->(...),@args)
1470 1480
1481Same as C<cf::register_extcmd>, but instead of returning values, the
1482callback needs to clal the C<$reply> function.
1483
1484=cut
1485
1471sub register_extcmd { 1486sub register_extcmd($$) {
1472 my ($name, $cb) = @_; 1487 my ($name, $cb) = @_;
1473 1488
1474 $EXTCMD{$name} = $cb; 1489 $EXTCMD{$name} = $cb;
1475} 1490}
1476 1491
1477sub register_exticmd { 1492sub register_async_extcmd($$) {
1478 my ($name, $cb) = @_; 1493 my ($name, $cb) = @_;
1479 1494
1495 $EXTACMD{$name} = $cb;
1496}
1497
1498sub register_exticmd($$) {
1499 my ($name, $cb) = @_;
1500
1480 $EXTICMD{$name} = $cb; 1501 $EXTICMD{$name} = $cb;
1502}
1503
1504sub register_async_exticmd($$) {
1505 my ($name, $cb) = @_;
1506
1507 $EXTIACMD{$name} = $cb;
1481} 1508}
1482 1509
1483use File::Glob (); 1510use File::Glob ();
1484 1511
1485cf::player->attach ( 1512cf::player->attach (
1501 my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; 1528 my $msg = eval { $pl->ns->{json_coder}->decode ($buf) };
1502 1529
1503 if (ref $msg) { 1530 if (ref $msg) {
1504 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash 1531 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash
1505 1532
1506 my @reply;
1507
1508 if (my $cb = $EXTCMD{$type}) { 1533 if (my $cb = $EXTACMD{$type}) {
1534 $cb->(
1535 $pl,
1536 sub {
1537 $pl->ext_msg ("reply-$reply", @_)
1538 if $reply;
1539 },
1540 @payload
1541 );
1542 } else {
1543 my @reply;
1544
1545 if (my $cb = $EXTCMD{$type}) {
1509 @reply = $cb->($pl, @payload); 1546 @reply = $cb->($pl, @payload);
1547 }
1548
1549 $pl->ext_msg ("reply-$reply", @reply)
1550 if $reply;
1510 } 1551 }
1511
1512 $pl->ext_reply ($reply, @reply)
1513 if $reply;
1514 1552
1515 } else { 1553 } else {
1516 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; 1554 error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n";
1517 } 1555 }
1518 1556
1531 }; 1569 };
1532 1570
1533 $grp 1571 $grp
1534} 1572}
1535 1573
1574sub _ext_cfg_reg($$$$) {
1575 my ($rvar, $varname, $cfgname, $default) = @_;
1576
1577 $cfgname = lc $varname
1578 unless length $cfgname;
1579
1580 $EXT_CFG{$cfgname} = [$rvar, $default];
1581
1582 $$rvar = exists $CFG{$cfgname} ? $CFG{$cfgname} : $default;
1583}
1584
1536sub load_extensions { 1585sub load_extensions {
1537 info "loading extensions..."; 1586 info "loading extensions...";
1587
1588 %EXT_CFG = ();
1538 1589
1539 cf::sync_job { 1590 cf::sync_job {
1540 my %todo; 1591 my %todo;
1541 1592
1542 for my $path (<$LIBDIR/*.ext>) { 1593 for my $path (<$LIBDIR/*.ext>) {
1585 unless exists $done{$_}; 1636 unless exists $done{$_};
1586 } 1637 }
1587 1638
1588 trace "... pass $pass, loading '$k' into '$v->{pkg}'\n"; 1639 trace "... pass $pass, loading '$k' into '$v->{pkg}'\n";
1589 1640
1641 my $source = $v->{source};
1642
1643 # support "CONF varname :confname = default" pseudo-statements
1644 $source =~ s{
1645 ^ CONF \s+ ([^\s:=]+) \s* (?:: \s* ([^\s:=]+) \s* )? = ([^\n#]+)
1646 }{
1647 "our \$$1; BEGIN { cf::_ext_cfg_reg \\\$$1, q\x00$1\x00, q\x00$2\x00, $3 }";
1648 }gmxe;
1649
1590 my $active = eval $v->{source}; 1650 my $active = eval $source;
1591 1651
1592 if (length $@) { 1652 if (length $@) {
1593 error "$v->{path}: $@\n"; 1653 error "$v->{path}: $@\n";
1594 1654
1595 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1655 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1882} 1942}
1883 1943
1884=item $protocol_xml = $player->expand_cfpod ($cfpod) 1944=item $protocol_xml = $player->expand_cfpod ($cfpod)
1885 1945
1886Expand deliantra pod fragments into protocol xml. 1946Expand deliantra pod fragments into protocol xml.
1887
1888=item $player->ext_reply ($msgid, @msg)
1889
1890Sends an ext reply to the player.
1891
1892=cut
1893
1894sub ext_reply($$@) {
1895 my ($self, $id, @msg) = @_;
1896
1897 $self->ns->ext_reply ($id, @msg)
1898}
1899 1947
1900=item $player->ext_msg ($type, @msg) 1948=item $player->ext_msg ($type, @msg)
1901 1949
1902Sends an ext event to the client. 1950Sends an ext event to the client.
1903 1951
3208=cut 3256=cut
3209 3257
3210sub cf::client::ext_msg($$@) { 3258sub cf::client::ext_msg($$@) {
3211 my ($self, $type, @msg) = @_; 3259 my ($self, $type, @msg) = @_;
3212 3260
3213 if ($self->extcmd == 2) {
3214 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); 3261 $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg]));
3215 } elsif ($self->extcmd == 1) { # TODO: remove
3216 push @msg, msgtype => "event_$type";
3217 $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg}));
3218 }
3219}
3220
3221=item $client->ext_reply ($msgid, @msg)
3222
3223Sends an ext reply to the client.
3224
3225=cut
3226
3227sub cf::client::ext_reply($$@) {
3228 my ($self, $id, @msg) = @_;
3229
3230 return unless $self->extcmd == 2;
3231
3232 $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg]));
3233} 3262}
3234 3263
3235=item $success = $client->query ($flags, "text", \&cb) 3264=item $success = $client->query ($flags, "text", \&cb)
3236 3265
3237Queues a query to the client, calling the given callback with 3266Queues a query to the client, calling the given callback with
3294 my $msg = eval { $ns->{json_coder}->decode ($buf) }; 3323 my $msg = eval { $ns->{json_coder}->decode ($buf) };
3295 3324
3296 if (ref $msg) { 3325 if (ref $msg) {
3297 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash 3326 my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash
3298 3327
3299 my @reply;
3300
3301 if (my $cb = $EXTICMD{$type}) { 3328 if (my $cb = $EXTIACMD{$type}) {
3329 $cb->(
3330 $ns,
3331 sub {
3332 $ns->ext_msg ("reply-$reply", @_)
3333 if $reply;
3334 },
3335 @payload
3336 );
3337 } else {
3338 my @reply;
3339
3340 if (my $cb = $EXTICMD{$type}) {
3302 @reply = $cb->($ns, @payload); 3341 @reply = $cb->($ns, @payload);
3342 }
3343
3344 $ns->ext_msg ("reply-$reply", @reply)
3345 if $reply;
3303 } 3346 }
3304
3305 $ns->ext_reply ($reply, @reply)
3306 if $reply;
3307
3308 } else { 3347 } else {
3309 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; 3348 error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n";
3310 } 3349 }
3311 3350
3312 cf::override; 3351 cf::override;
3480=cut 3519=cut
3481 3520
3482############################################################################# 3521#############################################################################
3483# the server's init and main functions 3522# the server's init and main functions
3484 3523
3524our %FACEHASH; # hash => idx, #d# HACK for http server
3525
3526# internal api, not fianlised
3527sub add_face {
3528 my ($name, $type, $data) = @_;
3529
3530 my $idx = cf::face::find $name;
3531
3532 if ($idx) {
3533 delete $FACEHASH{cf::face::get_chksum $idx};
3534 } else {
3535 $idx = cf::face::alloc $name;
3536 }
3537
3538 my $hash = cf::face::mangle_chksum Digest::MD5::md5 $data;
3539
3540 cf::face::set_type $idx, $type;
3541 cf::face::set_data $idx, 0, $data, $hash;
3542 cf::face::set_meta $idx, $type & 1 ? undef : undef;
3543 $FACEHASH{$hash} = $idx;#d#
3544
3545 $idx
3546}
3547
3485sub load_facedata($) { 3548sub load_facedata($) {
3486 my ($path) = @_; 3549 my ($path) = @_;
3487 3550
3488 # HACK to clear player env face cache, we need some signal framework 3551 # HACK to clear player env face cache, we need some signal framework
3489 # for this (global event?) 3552 # for this (global event?)
3496 my $facedata = decode_storable load_file $path; 3559 my $facedata = decode_storable load_file $path;
3497 3560
3498 $facedata->{version} == 2 3561 $facedata->{version} == 2
3499 or cf::cleanup "$path: version mismatch, cannot proceed."; 3562 or cf::cleanup "$path: version mismatch, cannot proceed.";
3500 3563
3501 # patch in the exptable
3502 my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]);
3503 $facedata->{resource}{"res/exp_table"} = {
3504 type => FT_RSRC,
3505 data => $exp_table,
3506 hash => (Digest::MD5::md5 $exp_table),
3507 };
3508 cf::cede_to_tick; 3564 cf::cede_to_tick;
3509 3565
3510 { 3566 {
3511 my $faces = $facedata->{faceinfo}; 3567 my $faces = $facedata->{faceinfo};
3512 3568
3513 while (my ($face, $info) = each %$faces) { 3569 for my $face (sort keys %$faces) {
3570 my $info = $faces->{$face};
3514 my $idx = (cf::face::find $face) || cf::face::alloc $face; 3571 my $idx = (cf::face::find $face) || cf::face::alloc $face;
3515 3572
3516 cf::face::set_visibility $idx, $info->{visibility}; 3573 cf::face::set_visibility $idx, $info->{visibility};
3517 cf::face::set_magicmap $idx, $info->{magicmap}; 3574 cf::face::set_magicmap $idx, $info->{magicmap};
3518 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; 3575 cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32};
3519 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; 3576 cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64};
3520 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; 3577 cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ;
3578 $FACEHASH{$info->{hash64}} = $idx;#d#
3521 3579
3522 cf::cede_to_tick; 3580 cf::cede_to_tick;
3523 } 3581 }
3524 3582
3525 while (my ($face, $info) = each %$faces) { 3583 while (my ($face, $info) = each %$faces) {
3556 while (my ($name, $info) = each %$res) { 3614 while (my ($name, $info) = each %$res) {
3557 if (defined (my $type = $info->{type})) { 3615 if (defined (my $type = $info->{type})) {
3558 # TODO: different hash - must free and use new index, or cache ixface data queue 3616 # TODO: different hash - must free and use new index, or cache ixface data queue
3559 my $idx = (cf::face::find $name) || cf::face::alloc $name; 3617 my $idx = (cf::face::find $name) || cf::face::alloc $name;
3560 3618
3619 cf::face::set_type $idx, $type;
3561 cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; 3620 cf::face::set_data $idx, 0, $info->{data}, $info->{hash};
3562 cf::face::set_type $idx, $type;
3563 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already 3621 cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already
3622 $FACEHASH{$info->{hash}} = $idx;#d#
3564 } else { 3623 } else {
3565# $RESOURCE{$name} = $info; # unused 3624# $RESOURCE{$name} = $info; # unused
3566 } 3625 }
3567 3626
3568 cf::cede_to_tick; 3627 cf::cede_to_tick;
3588 my $status = load_resource_file_ $_[0]; 3647 my $status = load_resource_file_ $_[0];
3589 get_slot 0.1, 100; 3648 get_slot 0.1, 100;
3590 cf::arch::commit_load; 3649 cf::arch::commit_load;
3591 3650
3592 $status 3651 $status
3652}
3653
3654sub reload_exp_table {
3655 _reload_exp_table;
3656
3657 add_face "res/exp_table" => FT_RSRC,
3658 JSON::XS->new->utf8->canonical->encode (
3659 [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]
3660 );
3661}
3662
3663sub reload_materials {
3664 _reload_materials;
3593} 3665}
3594 3666
3595sub reload_regions { 3667sub reload_regions {
3596 # HACK to clear player env face cache, we need some signal framework 3668 # HACK to clear player env face cache, we need some signal framework
3597 # for this (global event?) 3669 # for this (global event?)
3612} 3684}
3613 3685
3614sub reload_archetypes { 3686sub reload_archetypes {
3615 load_resource_file "$DATADIR/archetypes" 3687 load_resource_file "$DATADIR/archetypes"
3616 or die "unable to load archetypes\n"; 3688 or die "unable to load archetypes\n";
3689
3690 add_face "res/skill_info" => FT_RSRC,
3691 JSON::XS->new->utf8->canonical->encode (
3692 [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1]
3693 );
3694 add_face "res/spell_paths" => FT_RSRC,
3695 JSON::XS->new->utf8->canonical->encode (
3696 [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1]
3697 );
3617} 3698}
3618 3699
3619sub reload_treasures { 3700sub reload_treasures {
3620 load_resource_file "$DATADIR/treasures" 3701 load_resource_file "$DATADIR/treasures"
3621 or die "unable to load treasurelists\n"; 3702 or die "unable to load treasurelists\n";
3639 my $face = cf::face::find "sound/$v"; 3720 my $face = cf::face::find "sound/$v";
3640 cf::sound::set $k => $face; 3721 cf::sound::set $k => $face;
3641 } 3722 }
3642} 3723}
3643 3724
3725#d# move docstuff to help or so
3726our %DOCSTRING;
3727
3728sub reload_pod {
3729 trace "loading pods $PODDIR\n";
3730
3731 %DOCSTRING = ();
3732 my @command_list;
3733
3734 for (
3735 [0, "command_help"],
3736 [1, "emote_help"],
3737 [2, "dmcommand_help"],
3738 ) {
3739 my ($type, $path) = @$_;
3740
3741 my $paragraphs = &cf::pod::load_pod ("$PODDIR/$path.pod")
3742 or die "unable to load $path";
3743
3744 my $level = 1e9;
3745 my $rpar;
3746
3747 for my $par (@$paragraphs) {
3748 if ($par->{type} eq "head2") {
3749 # this code taken almost verbatim from DC/Protocol.pm
3750
3751 if ($par->{markup} =~ /^(\S+) (?:\s+ \( ([^\)]*) \) )?/x) {
3752 my $cmd = $1;
3753 my @args = split /\|/, $2;
3754 @args = (".*") unless @args;
3755
3756 $_ = $_ eq ".*" ? "" : " $_"
3757 for @args;
3758
3759 my @variants = map "$cmd$_", sort { (length $a) <=> (length $b) } @args;
3760
3761 $rpar = \($DOCSTRING{"command/$cmd"} = &cf::pod::as_cfpod ([$par]));
3762
3763 push @command_list, [$type, \@variants];
3764 $level = $par->{level};
3765 } else {
3766 error "$par->{markup}: unparsable command heading";
3767 }
3768 } elsif ($par->{level} > $level) {
3769 $$rpar .= &cf::pod::as_cfpod ([$par]);
3770 }
3771
3772 cf::cede_to_tick;
3773 }
3774 }
3775
3776 @command_list = sort {
3777 $a->[0] <=> $b->[0]
3778 or $a->[1] cmp $b->[1]
3779 } @command_list;
3780
3781 cf::cede_to_tick;
3782
3783 add_face "res/command_list" => FT_RSRC,
3784 JSON::XS->new->utf8->encode (\@command_list);
3785}
3786
3644sub reload_resources { 3787sub reload_resources {
3645 trace "reloading resource files...\n"; 3788 trace "reloading resource files...\n";
3646 3789
3647 reload_exp_table;
3648 reload_materials; 3790 reload_materials;
3649 reload_facedata; 3791 reload_facedata;
3792 reload_exp_table;
3650 reload_sound; 3793 reload_sound;
3651 reload_archetypes; 3794 reload_archetypes;
3652 reload_regions; 3795 reload_regions;
3653 reload_treasures; 3796 reload_treasures;
3797 reload_pod;
3654 3798
3655 trace "finished reloading resource files\n"; 3799 trace "finished reloading resource files\n";
3656} 3800}
3657 3801
3658sub reload_config { 3802sub reload_config {
3713 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; 3857 LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen.";
3714 3858
3715 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority 3859 $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority
3716 3860
3717 # we must not ever block the main coroutine 3861 # we must not ever block the main coroutine
3718 local $Coro::idle = sub { 3862 $Coro::idle = sub {
3719 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# 3863 Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d#
3720 (async { 3864 (async {
3721 $Coro::current->{desc} = "IDLE BUG HANDLER"; 3865 $Coro::current->{desc} = "IDLE BUG HANDLER";
3722 EV::loop EV::LOOP_ONESHOT; 3866 EV::loop EV::LOOP_ONESHOT;
3723 })->prio (Coro::PRIO_MAX); 3867 })->prio (Coro::PRIO_MAX);
3726 evthread_start IO::AIO::poll_fileno; 3870 evthread_start IO::AIO::poll_fileno;
3727 3871
3728 cf::sync_job { 3872 cf::sync_job {
3729 cf::incloader::init (); 3873 cf::incloader::init ();
3730 3874
3875 db_init;
3876
3731 cf::init_anim; 3877 cf::init_anim;
3732 cf::init_attackmess; 3878 cf::init_attackmess;
3733 cf::init_dynamic; 3879 cf::init_dynamic;
3734 3880
3735 cf::load_settings; 3881 cf::load_settings;
3736 3882
3737 reload_resources; 3883 reload_resources;
3738 reload_config; 3884 reload_config;
3739 db_init;
3740 3885
3741 cf::init_uuid; 3886 cf::init_uuid;
3742 cf::init_signals; 3887 cf::init_signals;
3743 cf::init_skills; 3888 cf::init_skills;
3744 3889
4169 } 4314 }
4170} 4315}
4171 4316
4172{ 4317{
4173 # configure BDB 4318 # configure BDB
4319 info "initialising database";
4174 4320
4175 BDB::min_parallel 16; 4321 BDB::min_parallel 16;
4176 BDB::max_poll_reqs $TICK * 0.1; 4322 BDB::max_poll_reqs $TICK * 0.1;
4177 #$AnyEvent::BDB::WATCHER->priority (1); 4323 #$AnyEvent::BDB::WATCHER->priority (1);
4178 4324
4207 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; 4353 BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { };
4208 }; 4354 };
4209 $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub { 4355 $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub {
4210 BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { }; 4356 BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { };
4211 }; 4357 };
4358
4359 info "database initialised";
4212} 4360}
4213 4361
4214{ 4362{
4215 # configure IO::AIO 4363 # configure IO::AIO
4216 4364
4365 info "initialising aio";
4217 IO::AIO::min_parallel 8; 4366 IO::AIO::min_parallel 8;
4218 IO::AIO::max_poll_time $TICK * 0.1; 4367 IO::AIO::max_poll_time $TICK * 0.1;
4219 undef $AnyEvent::AIO::WATCHER; 4368 undef $AnyEvent::AIO::WATCHER;
4369 info "aio initialised";
4220} 4370}
4221 4371
4222our $_log_backtrace; 4372our $_log_backtrace;
4223our $_log_backtrace_last; 4373our $_log_backtrace_last;
4224 4374

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines