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 | |
23 | package cf; |
23 | package cf; |
24 | |
24 | |
… | |
… | |
129 | our $DB_ENV; |
129 | our $DB_ENV; |
130 | |
130 | |
131 | our @EXTRA_MODULES = qw(pod match mapscript incloader); |
131 | our @EXTRA_MODULES = qw(pod match mapscript incloader); |
132 | |
132 | |
133 | our %CFG; |
133 | our %CFG; |
|
|
134 | our %EXT_CFG; # cfgkeyname => [var-ref, defaultvalue] |
134 | |
135 | |
135 | our $UPTIME; $UPTIME ||= time; |
136 | our $UPTIME; $UPTIME ||= time; |
136 | our $RUNTIME = 0; |
137 | our $RUNTIME = 0; |
137 | our $SERVER_TICK = 0; |
138 | our $SERVER_TICK = 0; |
138 | our $NOW; |
139 | our $NOW; |
… | |
… | |
1531 | }; |
1532 | }; |
1532 | |
1533 | |
1533 | $grp |
1534 | $grp |
1534 | } |
1535 | } |
1535 | |
1536 | |
|
|
1537 | sub _ext_cfg_reg($$$$) { |
|
|
1538 | my ($rvar, $varname, $cfgname, $default) = @_; |
|
|
1539 | |
|
|
1540 | $cfgname = lc $varname |
|
|
1541 | unless length $cfgname; |
|
|
1542 | |
|
|
1543 | $EXT_CFG{$cfgname} = [$rvar, $default]; |
|
|
1544 | |
|
|
1545 | $$rvar = exists $CFG{$cfgname} ? $CFG{$cfgname} : $default; |
|
|
1546 | } |
|
|
1547 | |
1536 | sub load_extensions { |
1548 | sub load_extensions { |
1537 | info "loading extensions..."; |
1549 | info "loading extensions..."; |
|
|
1550 | |
|
|
1551 | %EXT_CFG = (); |
1538 | |
1552 | |
1539 | cf::sync_job { |
1553 | cf::sync_job { |
1540 | my %todo; |
1554 | my %todo; |
1541 | |
1555 | |
1542 | for my $path (<$LIBDIR/*.ext>) { |
1556 | for my $path (<$LIBDIR/*.ext>) { |
… | |
… | |
1585 | unless exists $done{$_}; |
1599 | unless exists $done{$_}; |
1586 | } |
1600 | } |
1587 | |
1601 | |
1588 | trace "... pass $pass, loading '$k' into '$v->{pkg}'\n"; |
1602 | trace "... pass $pass, loading '$k' into '$v->{pkg}'\n"; |
1589 | |
1603 | |
|
|
1604 | my $source = $v->{source}; |
|
|
1605 | |
|
|
1606 | # support "CONF varname :confname = default" pseudo-statements |
|
|
1607 | $source =~ s{ |
|
|
1608 | ^ CONF \s+ ([^\s:=]+) \s* (?:: \s* ([^\s:=]+) \s* )? = ([^\n#]+) |
|
|
1609 | }{ |
|
|
1610 | "our \$$1; BEGIN { cf::_ext_cfg_reg \\\$$1, q\x00$1\x00, q\x00$2\x00, $3 }"; |
|
|
1611 | }gmxe; |
|
|
1612 | |
1590 | my $active = eval $v->{source}; |
1613 | my $active = eval $source; |
1591 | |
1614 | |
1592 | if (length $@) { |
1615 | if (length $@) { |
1593 | error "$v->{path}: $@\n"; |
1616 | error "$v->{path}: $@\n"; |
1594 | |
1617 | |
1595 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |
1618 | cf::cleanup "mandatory extension '$k' failed to load, exiting." |