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 | |
… | |
… | |
32 | use Safe; |
32 | use Safe; |
33 | use Safe::Hole; |
33 | use Safe::Hole; |
34 | use Storable (); |
34 | use Storable (); |
35 | use Carp (); |
35 | use Carp (); |
36 | |
36 | |
37 | use Guard (); |
37 | use AnyEvent (); |
|
|
38 | use AnyEvent::IO (); |
|
|
39 | use AnyEvent::DNS (); |
|
|
40 | |
38 | use Coro (); |
41 | use Coro (); |
39 | use Coro::State; |
42 | use Coro::State; |
40 | use Coro::Handle; |
43 | use Coro::Handle; |
41 | use Coro::EV; |
44 | use Coro::EV; |
42 | use Coro::AnyEvent; |
45 | use Coro::AnyEvent; |
… | |
… | |
48 | use Coro::AIO; |
51 | use Coro::AIO; |
49 | use Coro::BDB 1.6; |
52 | use Coro::BDB 1.6; |
50 | use Coro::Storable; |
53 | use Coro::Storable; |
51 | use Coro::Util (); |
54 | use Coro::Util (); |
52 | |
55 | |
|
|
56 | use Guard (); |
53 | use JSON::XS 2.01 (); |
57 | use JSON::XS 2.01 (); |
54 | use BDB (); |
58 | use BDB (); |
55 | use Data::Dumper; |
59 | use Data::Dumper; |
56 | use Fcntl; |
60 | use Fcntl; |
57 | use YAML::XS (); |
61 | use YAML::XS (); |
… | |
… | |
336 | )) { |
340 | )) { |
337 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
341 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
338 | } |
342 | } |
339 | |
343 | |
340 | $EV::DIED = sub { |
344 | $EV::DIED = sub { |
341 | Carp::cluck "error in event callback: @_"; |
345 | warn "error in event callback: $@"; |
342 | }; |
346 | }; |
343 | |
347 | |
344 | ############################################################################# |
348 | ############################################################################# |
345 | |
349 | |
346 | sub fork_call(&@); |
350 | sub fork_call(&@); |
… | |
… | |
3503 | =cut |
3507 | =cut |
3504 | |
3508 | |
3505 | ############################################################################# |
3509 | ############################################################################# |
3506 | # the server's init and main functions |
3510 | # the server's init and main functions |
3507 | |
3511 | |
|
|
3512 | our %FACEHASH; # hash => idx, #d# HACK for http server |
|
|
3513 | |
3508 | sub load_facedata($) { |
3514 | sub load_facedata($) { |
3509 | my ($path) = @_; |
3515 | my ($path) = @_; |
3510 | |
3516 | |
3511 | # HACK to clear player env face cache, we need some signal framework |
3517 | # HACK to clear player env face cache, we need some signal framework |
3512 | # for this (global event?) |
3518 | # for this (global event?) |
… | |
… | |
3531 | cf::cede_to_tick; |
3537 | cf::cede_to_tick; |
3532 | |
3538 | |
3533 | { |
3539 | { |
3534 | my $faces = $facedata->{faceinfo}; |
3540 | my $faces = $facedata->{faceinfo}; |
3535 | |
3541 | |
3536 | while (my ($face, $info) = each %$faces) { |
3542 | for my $face (sort keys %$faces) { |
|
|
3543 | my $info = $faces->{$face}; |
3537 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3544 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3538 | |
3545 | |
3539 | cf::face::set_visibility $idx, $info->{visibility}; |
3546 | cf::face::set_visibility $idx, $info->{visibility}; |
3540 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3547 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3541 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3548 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3542 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3549 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3543 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
3550 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
|
|
3551 | $FACEHASH{$info->{hash64}} = $idx;#d# |
3544 | |
3552 | |
3545 | cf::cede_to_tick; |
3553 | cf::cede_to_tick; |
3546 | } |
3554 | } |
3547 | |
3555 | |
3548 | while (my ($face, $info) = each %$faces) { |
3556 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
3582 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3590 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3583 | |
3591 | |
3584 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3592 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3585 | cf::face::set_type $idx, $type; |
3593 | cf::face::set_type $idx, $type; |
3586 | cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already |
3594 | cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already |
|
|
3595 | $FACEHASH{$info->{hash}} = $idx;#d# |
3587 | } else { |
3596 | } else { |
3588 | # $RESOURCE{$name} = $info; # unused |
3597 | # $RESOURCE{$name} = $info; # unused |
3589 | } |
3598 | } |
3590 | |
3599 | |
3591 | cf::cede_to_tick; |
3600 | cf::cede_to_tick; |
… | |
… | |
3736 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3745 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3737 | |
3746 | |
3738 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3747 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3739 | |
3748 | |
3740 | # we must not ever block the main coroutine |
3749 | # we must not ever block the main coroutine |
3741 | local $Coro::idle = sub { |
3750 | $Coro::idle = sub { |
3742 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3751 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3743 | (async { |
3752 | (async { |
3744 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3753 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3745 | EV::loop EV::LOOP_ONESHOT; |
3754 | EV::loop EV::LOOP_ONESHOT; |
3746 | })->prio (Coro::PRIO_MAX); |
3755 | })->prio (Coro::PRIO_MAX); |