… | |
… | |
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 (); |
58 | use IO::AIO (); |
62 | use IO::AIO (); |
59 | use Time::HiRes; |
|
|
60 | use Compress::LZF; |
63 | use Compress::LZF; |
61 | use Digest::MD5 (); |
64 | use Digest::MD5 (); |
62 | |
65 | |
63 | AnyEvent::detect; |
66 | AnyEvent::detect; |
64 | |
67 | |
… | |
… | |
83 | our %COMMAND = (); |
86 | our %COMMAND = (); |
84 | our %COMMAND_TIME = (); |
87 | our %COMMAND_TIME = (); |
85 | |
88 | |
86 | our @EXTS = (); # list of extension package names |
89 | our @EXTS = (); # list of extension package names |
87 | our %EXTCMD = (); |
90 | our %EXTCMD = (); |
|
|
91 | our %EXTACMD = (); |
88 | our %EXTICMD = (); |
92 | our %EXTICMD = (); |
|
|
93 | our %EXTIACMD = (); |
89 | our %EXT_CORO = (); # coroutines bound to extensions |
94 | our %EXT_CORO = (); # coroutines bound to extensions |
90 | our %EXT_MAP = (); # pluggable maps |
95 | our %EXT_MAP = (); # pluggable maps |
91 | |
96 | |
92 | our $RELOAD; # number of reloads so far, non-zero while in reload |
97 | our $RELOAD; # number of reloads so far, non-zero while in reload |
93 | our @EVENT; |
98 | our @EVENT; |
… | |
… | |
220 | =item $cf::RUNTIME |
225 | =item $cf::RUNTIME |
221 | |
226 | |
222 | The time this server has run, starts at 0 and is increased by $cf::TICK on |
227 | The time this server has run, starts at 0 and is increased by $cf::TICK on |
223 | every server tick. |
228 | every server tick. |
224 | |
229 | |
225 | =item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR |
230 | =item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR |
226 | $cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR |
231 | $cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR |
227 | $cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR |
232 | $cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR |
228 | |
233 | |
229 | Various directories - "/etc", read-only install directory, perl-library |
234 | Various directories - "/etc", read-only install directory, perl-library |
230 | directory, pod-directory, read-only maps directory, "/var", "/var/tmp", |
235 | directory, pod-directory, read-only maps directory, "/var", "/var/tmp", |
231 | unique-items directory, player file directory, random maps directory and |
236 | unique-items directory, player file directory, random maps directory and |
232 | database environment. |
237 | database environment. |
… | |
… | |
336 | )) { |
341 | )) { |
337 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
342 | @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
338 | } |
343 | } |
339 | |
344 | |
340 | $EV::DIED = sub { |
345 | $EV::DIED = sub { |
341 | Carp::cluck "error in event callback: @_"; |
346 | warn "error in event callback: $@"; |
342 | }; |
347 | }; |
343 | |
348 | |
344 | ############################################################################# |
349 | ############################################################################# |
345 | |
350 | |
346 | sub fork_call(&@); |
351 | sub fork_call(&@); |
… | |
… | |
895 | |
900 | |
896 | return db_get cache => "$id/data"; |
901 | return db_get cache => "$id/data"; |
897 | } |
902 | } |
898 | } |
903 | } |
899 | |
904 | |
900 | my $t1 = Time::HiRes::time; |
905 | my $t1 = EV::time; |
901 | my $data = $process->(\@data); |
906 | my $data = $process->(\@data); |
902 | my $t2 = Time::HiRes::time; |
907 | my $t2 = EV::time; |
903 | |
908 | |
904 | info "cache: '$id' processed in ", $t2 - $t1, "s\n"; |
909 | info "cache: '$id' processed in ", $t2 - $t1, "s\n"; |
905 | |
910 | |
906 | db_put cache => "$id/data", $data; |
911 | db_put cache => "$id/data", $data; |
907 | db_put cache => "$id/md5" , $md5; |
912 | db_put cache => "$id/md5" , $md5; |
… | |
… | |
1427 | =cut |
1432 | =cut |
1428 | |
1433 | |
1429 | ############################################################################# |
1434 | ############################################################################# |
1430 | # command handling &c |
1435 | # command handling &c |
1431 | |
1436 | |
1432 | =item cf::register_command $name => \&callback($ob,$args); |
1437 | =item cf::register_command $name => \&callback($ob,$args) |
1433 | |
1438 | |
1434 | Register a callback for execution when the client sends the user command |
1439 | Register a callback for execution when the client sends the user command |
1435 | $name. |
1440 | $name. |
1436 | |
1441 | |
1437 | =cut |
1442 | =cut |
… | |
… | |
1443 | #warn "registering command '$name/$time' to '$caller'"; |
1448 | #warn "registering command '$name/$time' to '$caller'"; |
1444 | |
1449 | |
1445 | push @{ $COMMAND{$name} }, [$caller, $cb]; |
1450 | push @{ $COMMAND{$name} }, [$caller, $cb]; |
1446 | } |
1451 | } |
1447 | |
1452 | |
1448 | =item cf::register_extcmd $name => \&callback($pl,$packet); |
1453 | =item cf::register_extcmd $name => \&callback($pl,@args) |
1449 | |
1454 | |
1450 | Register a callback for execution when the client sends an (synchronous) |
1455 | Register a callback for execution when the client sends an (synchronous) |
1451 | extcmd packet. Ext commands will be processed in the order they are |
1456 | extcmd packet. Ext commands will be processed in the order they are |
1452 | received by the server, like other user commands. The first argument is |
1457 | received by the server, like other user commands. The first argument is |
1453 | the logged-in player. Ext commands can only be processed after a player |
1458 | the logged-in player. Ext commands can only be processed after a player |
1454 | has logged in successfully. |
1459 | has logged in successfully. |
1455 | |
1460 | |
1456 | If the callback returns something, it is sent back as if reply was being |
1461 | The values will be sent back to the client. |
1457 | called. |
|
|
1458 | |
1462 | |
|
|
1463 | =item cf::register_async_extcmd $name => \&callback($pl,$reply->(...),@args) |
|
|
1464 | |
|
|
1465 | Same as C<cf::register_extcmd>, but instead of returning values, the |
|
|
1466 | callback needs to clal the C<$reply> function. |
|
|
1467 | |
1459 | =item cf::register_exticmd $name => \&callback($ns,$packet); |
1468 | =item cf::register_exticmd $name => \&callback($ns,@args) |
1460 | |
1469 | |
1461 | Register a callback for execution when the client sends an (asynchronous) |
1470 | Register a callback for execution when the client sends an (asynchronous) |
1462 | exticmd packet. Exti commands are processed by the server as soon as they |
1471 | exticmd packet. Exti commands are processed by the server as soon as they |
1463 | are received, i.e. out of order w.r.t. other commands. The first argument |
1472 | are received, i.e. out of order w.r.t. other commands. The first argument |
1464 | is a client socket. Exti commands can be received anytime, even before |
1473 | is a client socket. Exti commands can be received anytime, even before |
1465 | log-in. |
1474 | log-in. |
1466 | |
1475 | |
1467 | If the callback returns something, it is sent back as if reply was being |
1476 | The values will be sent back to the client. |
1468 | called. |
|
|
1469 | |
1477 | |
1470 | =cut |
1478 | =item cf::register_async_exticmd $name => \&callback($ns,$reply->(...),@args) |
1471 | |
1479 | |
|
|
1480 | Same as C<cf::register_extcmd>, but instead of returning values, the |
|
|
1481 | callback needs to clal the C<$reply> function. |
|
|
1482 | |
|
|
1483 | =cut |
|
|
1484 | |
1472 | sub register_extcmd { |
1485 | sub register_extcmd($$) { |
1473 | my ($name, $cb) = @_; |
1486 | my ($name, $cb) = @_; |
1474 | |
1487 | |
1475 | $EXTCMD{$name} = $cb; |
1488 | $EXTCMD{$name} = $cb; |
1476 | } |
1489 | } |
1477 | |
1490 | |
1478 | sub register_exticmd { |
1491 | sub register_async_extcmd($$) { |
1479 | my ($name, $cb) = @_; |
1492 | my ($name, $cb) = @_; |
1480 | |
1493 | |
|
|
1494 | $EXTACMD{$name} = $cb; |
|
|
1495 | } |
|
|
1496 | |
|
|
1497 | sub register_exticmd($$) { |
|
|
1498 | my ($name, $cb) = @_; |
|
|
1499 | |
1481 | $EXTICMD{$name} = $cb; |
1500 | $EXTICMD{$name} = $cb; |
|
|
1501 | } |
|
|
1502 | |
|
|
1503 | sub register_async_exticmd($$) { |
|
|
1504 | my ($name, $cb) = @_; |
|
|
1505 | |
|
|
1506 | $EXTIACMD{$name} = $cb; |
1482 | } |
1507 | } |
1483 | |
1508 | |
1484 | use File::Glob (); |
1509 | use File::Glob (); |
1485 | |
1510 | |
1486 | cf::player->attach ( |
1511 | cf::player->attach ( |
… | |
… | |
1502 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1527 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1503 | |
1528 | |
1504 | if (ref $msg) { |
1529 | if (ref $msg) { |
1505 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
1530 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
1506 | |
1531 | |
1507 | my @reply; |
|
|
1508 | |
|
|
1509 | if (my $cb = $EXTCMD{$type}) { |
1532 | if (my $cb = $EXTACMD{$type}) { |
|
|
1533 | $cb->( |
|
|
1534 | $pl, |
|
|
1535 | sub { |
|
|
1536 | $pl->ext_msg ("reply-$reply", @_) |
|
|
1537 | if $reply; |
|
|
1538 | }, |
|
|
1539 | @payload |
|
|
1540 | ); |
|
|
1541 | } else { |
|
|
1542 | my @reply; |
|
|
1543 | |
|
|
1544 | if (my $cb = $EXTCMD{$type}) { |
1510 | @reply = $cb->($pl, @payload); |
1545 | @reply = $cb->($pl, @payload); |
|
|
1546 | } |
|
|
1547 | |
|
|
1548 | $pl->ext_msg ("reply-$reply", @reply) |
|
|
1549 | if $reply; |
1511 | } |
1550 | } |
1512 | |
|
|
1513 | $pl->ext_reply ($reply, @reply) |
|
|
1514 | if $reply; |
|
|
1515 | |
1551 | |
1516 | } else { |
1552 | } else { |
1517 | error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
1553 | error "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
1518 | } |
1554 | } |
1519 | |
1555 | |
… | |
… | |
1905 | } |
1941 | } |
1906 | |
1942 | |
1907 | =item $protocol_xml = $player->expand_cfpod ($cfpod) |
1943 | =item $protocol_xml = $player->expand_cfpod ($cfpod) |
1908 | |
1944 | |
1909 | Expand deliantra pod fragments into protocol xml. |
1945 | Expand deliantra pod fragments into protocol xml. |
1910 | |
|
|
1911 | =item $player->ext_reply ($msgid, @msg) |
|
|
1912 | |
|
|
1913 | Sends an ext reply to the player. |
|
|
1914 | |
|
|
1915 | =cut |
|
|
1916 | |
|
|
1917 | sub ext_reply($$@) { |
|
|
1918 | my ($self, $id, @msg) = @_; |
|
|
1919 | |
|
|
1920 | $self->ns->ext_reply ($id, @msg) |
|
|
1921 | } |
|
|
1922 | |
1946 | |
1923 | =item $player->ext_msg ($type, @msg) |
1947 | =item $player->ext_msg ($type, @msg) |
1924 | |
1948 | |
1925 | Sends an ext event to the client. |
1949 | Sends an ext event to the client. |
1926 | |
1950 | |
… | |
… | |
3231 | =cut |
3255 | =cut |
3232 | |
3256 | |
3233 | sub cf::client::ext_msg($$@) { |
3257 | sub cf::client::ext_msg($$@) { |
3234 | my ($self, $type, @msg) = @_; |
3258 | my ($self, $type, @msg) = @_; |
3235 | |
3259 | |
3236 | if ($self->extcmd == 2) { |
|
|
3237 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
3260 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
3238 | } elsif ($self->extcmd == 1) { # TODO: remove |
|
|
3239 | push @msg, msgtype => "event_$type"; |
|
|
3240 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
|
|
3241 | } |
|
|
3242 | } |
|
|
3243 | |
|
|
3244 | =item $client->ext_reply ($msgid, @msg) |
|
|
3245 | |
|
|
3246 | Sends an ext reply to the client. |
|
|
3247 | |
|
|
3248 | =cut |
|
|
3249 | |
|
|
3250 | sub cf::client::ext_reply($$@) { |
|
|
3251 | my ($self, $id, @msg) = @_; |
|
|
3252 | |
|
|
3253 | return unless $self->extcmd == 2; |
|
|
3254 | |
|
|
3255 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
|
|
3256 | } |
3261 | } |
3257 | |
3262 | |
3258 | =item $success = $client->query ($flags, "text", \&cb) |
3263 | =item $success = $client->query ($flags, "text", \&cb) |
3259 | |
3264 | |
3260 | Queues a query to the client, calling the given callback with |
3265 | Queues a query to the client, calling the given callback with |
… | |
… | |
3317 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3322 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3318 | |
3323 | |
3319 | if (ref $msg) { |
3324 | if (ref $msg) { |
3320 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
3325 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
3321 | |
3326 | |
3322 | my @reply; |
|
|
3323 | |
|
|
3324 | if (my $cb = $EXTICMD{$type}) { |
3327 | if (my $cb = $EXTIACMD{$type}) { |
|
|
3328 | $cb->( |
|
|
3329 | $ns, |
|
|
3330 | sub { |
|
|
3331 | $ns->ext_msg ("reply-$reply", @_) |
|
|
3332 | if $reply; |
|
|
3333 | }, |
|
|
3334 | @payload |
|
|
3335 | ); |
|
|
3336 | } else { |
|
|
3337 | my @reply; |
|
|
3338 | |
|
|
3339 | if (my $cb = $EXTICMD{$type}) { |
3325 | @reply = $cb->($ns, @payload); |
3340 | @reply = $cb->($ns, @payload); |
|
|
3341 | } |
|
|
3342 | |
|
|
3343 | $ns->ext_msg ("reply-$reply", @reply) |
|
|
3344 | if $reply; |
3326 | } |
3345 | } |
3327 | |
|
|
3328 | $ns->ext_reply ($reply, @reply) |
|
|
3329 | if $reply; |
|
|
3330 | |
|
|
3331 | } else { |
3346 | } else { |
3332 | error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; |
3347 | error "client " . ($ns->pl ? $ns->pl->ob->name : $ns->host) . " sent unparseable exti message: <$buf>\n"; |
3333 | } |
3348 | } |
3334 | |
3349 | |
3335 | cf::override; |
3350 | cf::override; |
… | |
… | |
3505 | ############################################################################# |
3520 | ############################################################################# |
3506 | # the server's init and main functions |
3521 | # the server's init and main functions |
3507 | |
3522 | |
3508 | our %FACEHASH; # hash => idx, #d# HACK for http server |
3523 | our %FACEHASH; # hash => idx, #d# HACK for http server |
3509 | |
3524 | |
|
|
3525 | # internal api, not fianlised |
|
|
3526 | sub set_face { |
|
|
3527 | my ($name, $type, $data) = @_; |
|
|
3528 | |
|
|
3529 | my $idx = cf::face::find $name; |
|
|
3530 | |
|
|
3531 | if ($idx) { |
|
|
3532 | delete $FACEHASH{cf::face::get_chksum $idx}; |
|
|
3533 | } else { |
|
|
3534 | $idx = cf::face::alloc $name; |
|
|
3535 | } |
|
|
3536 | |
|
|
3537 | my $hash = cf::face::mangle_chksum Digest::MD5::md5 $data; |
|
|
3538 | |
|
|
3539 | cf::face::set_type $idx, $type; |
|
|
3540 | cf::face::set_data $idx, 0, $data, $hash; |
|
|
3541 | cf::face::set_meta $idx, $type & 1 ? undef : undef; |
|
|
3542 | $FACEHASH{$hash} = $idx;#d# |
|
|
3543 | |
|
|
3544 | $idx |
|
|
3545 | } |
|
|
3546 | |
3510 | sub load_facedata($) { |
3547 | sub load_facedata($) { |
3511 | my ($path) = @_; |
3548 | my ($path) = @_; |
3512 | |
3549 | |
3513 | # HACK to clear player env face cache, we need some signal framework |
3550 | # HACK to clear player env face cache, we need some signal framework |
3514 | # for this (global event?) |
3551 | # for this (global event?) |
… | |
… | |
3521 | my $facedata = decode_storable load_file $path; |
3558 | my $facedata = decode_storable load_file $path; |
3522 | |
3559 | |
3523 | $facedata->{version} == 2 |
3560 | $facedata->{version} == 2 |
3524 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3561 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3525 | |
3562 | |
3526 | # patch in the exptable |
|
|
3527 | my $exp_table = $enc->encode ([map cf::level_to_min_exp $_, 1 .. cf::settings->max_level]); |
|
|
3528 | $facedata->{resource}{"res/exp_table"} = { |
|
|
3529 | type => FT_RSRC, |
|
|
3530 | data => $exp_table, |
|
|
3531 | hash => (Digest::MD5::md5 $exp_table), |
|
|
3532 | }; |
|
|
3533 | cf::cede_to_tick; |
3563 | cf::cede_to_tick; |
3534 | |
3564 | |
3535 | { |
3565 | { |
3536 | my $faces = $facedata->{faceinfo}; |
3566 | my $faces = delete $facedata->{faceinfo}; |
3537 | |
3567 | |
3538 | while (my ($face, $info) = each %$faces) { |
3568 | for my $face (sort keys %$faces) { |
|
|
3569 | my $info = $faces->{$face}; |
3539 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3570 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
3540 | |
3571 | |
3541 | cf::face::set_visibility $idx, $info->{visibility}; |
3572 | cf::face::set_visibility $idx, $info->{visibility}; |
3542 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3573 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3543 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3574 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3544 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3575 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3545 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
3576 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
3546 | $FACEHASH{$info->{hash64}} = $idx;#d# |
3577 | $FACEHASH{$info->{hash64}} = $idx;#d# |
3547 | |
3578 | |
3548 | cf::cede_to_tick; |
3579 | cf::cede_to_tick; |
3549 | } |
3580 | } |
3550 | |
3581 | |
3551 | while (my ($face, $info) = each %$faces) { |
3582 | while (my ($face, $info) = each %$faces) { |
3552 | next unless $info->{smooth}; |
3583 | next unless $info->{smooth}; |
… | |
… | |
3564 | cf::cede_to_tick; |
3595 | cf::cede_to_tick; |
3565 | } |
3596 | } |
3566 | } |
3597 | } |
3567 | |
3598 | |
3568 | { |
3599 | { |
3569 | my $anims = $facedata->{animinfo}; |
3600 | my $anims = delete $facedata->{animinfo}; |
3570 | |
3601 | |
3571 | while (my ($anim, $info) = each %$anims) { |
3602 | while (my ($anim, $info) = each %$anims) { |
3572 | cf::anim::set $anim, $info->{frames}, $info->{facings}; |
3603 | cf::anim::set $anim, $info->{frames}, $info->{facings}; |
3573 | cf::cede_to_tick; |
3604 | cf::cede_to_tick; |
3574 | } |
3605 | } |
3575 | |
3606 | |
3576 | cf::anim::invalidate_all; # d'oh |
3607 | cf::anim::invalidate_all; # d'oh |
3577 | } |
3608 | } |
3578 | |
3609 | |
3579 | { |
3610 | { |
3580 | my $res = $facedata->{resource}; |
3611 | my $res = delete $facedata->{resource}; |
3581 | |
3612 | |
3582 | while (my ($name, $info) = each %$res) { |
3613 | while (my ($name, $info) = each %$res) { |
3583 | if (defined (my $type = $info->{type})) { |
3614 | if (defined (my $type = $info->{type})) { |
3584 | # TODO: different hash - must free and use new index, or cache ixface data queue |
3615 | # TODO: different hash - must free and use new index, or cache ixface data queue |
3585 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3616 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3586 | |
3617 | |
|
|
3618 | cf::face::set_type $idx, $type; |
3587 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3619 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3588 | cf::face::set_type $idx, $type; |
|
|
3589 | cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already |
3620 | cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already |
3590 | $FACEHASH{$info->{hash}} = $idx;#d# |
3621 | $FACEHASH{$info->{hash}} = $idx;#d# |
3591 | } else { |
3622 | } else { |
3592 | # $RESOURCE{$name} = $info; # unused |
3623 | # $RESOURCE{$name} = $info; # unused |
3593 | } |
3624 | } |
… | |
… | |
3617 | cf::arch::commit_load; |
3648 | cf::arch::commit_load; |
3618 | |
3649 | |
3619 | $status |
3650 | $status |
3620 | } |
3651 | } |
3621 | |
3652 | |
|
|
3653 | sub reload_exp_table { |
|
|
3654 | _reload_exp_table; |
|
|
3655 | |
|
|
3656 | set_face "res/exp_table" => FT_RSRC, |
|
|
3657 | JSON::XS->new->utf8->canonical->encode ( |
|
|
3658 | [map cf::level_to_min_exp $_, 1 .. cf::settings->max_level] |
|
|
3659 | ); |
|
|
3660 | } |
|
|
3661 | |
|
|
3662 | sub reload_materials { |
|
|
3663 | _reload_materials; |
|
|
3664 | } |
|
|
3665 | |
3622 | sub reload_regions { |
3666 | sub reload_regions { |
3623 | # HACK to clear player env face cache, we need some signal framework |
3667 | # HACK to clear player env face cache, we need some signal framework |
3624 | # for this (global event?) |
3668 | # for this (global event?) |
3625 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3669 | %ext::player_env::MUSIC_FACE_CACHE = (); |
3626 | |
3670 | |
… | |
… | |
3639 | } |
3683 | } |
3640 | |
3684 | |
3641 | sub reload_archetypes { |
3685 | sub reload_archetypes { |
3642 | load_resource_file "$DATADIR/archetypes" |
3686 | load_resource_file "$DATADIR/archetypes" |
3643 | or die "unable to load archetypes\n"; |
3687 | or die "unable to load archetypes\n"; |
|
|
3688 | |
|
|
3689 | set_face "res/skill_info" => FT_RSRC, |
|
|
3690 | JSON::XS->new->utf8->canonical->encode ( |
|
|
3691 | [map [cf::arch::skillvec ($_)->name], 0 .. cf::arch::skillvec_size - 1] |
|
|
3692 | ); |
|
|
3693 | set_face "res/spell_paths" => FT_RSRC, |
|
|
3694 | JSON::XS->new->utf8->canonical->encode ( |
|
|
3695 | [map [cf::spellpathnames ($_)], 0 .. NRSPELLPATHS - 1] |
|
|
3696 | ); |
3644 | } |
3697 | } |
3645 | |
3698 | |
3646 | sub reload_treasures { |
3699 | sub reload_treasures { |
3647 | load_resource_file "$DATADIR/treasures" |
3700 | load_resource_file "$DATADIR/treasures" |
3648 | or die "unable to load treasurelists\n"; |
3701 | or die "unable to load treasurelists\n"; |
… | |
… | |
3669 | } |
3722 | } |
3670 | |
3723 | |
3671 | sub reload_resources { |
3724 | sub reload_resources { |
3672 | trace "reloading resource files...\n"; |
3725 | trace "reloading resource files...\n"; |
3673 | |
3726 | |
3674 | reload_exp_table; |
|
|
3675 | reload_materials; |
3727 | reload_materials; |
3676 | reload_facedata; |
3728 | reload_facedata; |
|
|
3729 | reload_exp_table; |
3677 | reload_sound; |
3730 | reload_sound; |
3678 | reload_archetypes; |
3731 | reload_archetypes; |
3679 | reload_regions; |
3732 | reload_regions; |
3680 | reload_treasures; |
3733 | reload_treasures; |
3681 | |
3734 | |
… | |
… | |
3740 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3793 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3741 | |
3794 | |
3742 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3795 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3743 | |
3796 | |
3744 | # we must not ever block the main coroutine |
3797 | # we must not ever block the main coroutine |
3745 | local $Coro::idle = sub { |
3798 | $Coro::idle = sub { |
3746 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3799 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3747 | (async { |
3800 | (async { |
3748 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3801 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3749 | EV::loop EV::LOOP_ONESHOT; |
3802 | EV::loop EV::LOOP_ONESHOT; |
3750 | })->prio (Coro::PRIO_MAX); |
3803 | })->prio (Coro::PRIO_MAX); |
… | |
… | |
3753 | evthread_start IO::AIO::poll_fileno; |
3806 | evthread_start IO::AIO::poll_fileno; |
3754 | |
3807 | |
3755 | cf::sync_job { |
3808 | cf::sync_job { |
3756 | cf::incloader::init (); |
3809 | cf::incloader::init (); |
3757 | |
3810 | |
|
|
3811 | db_init; |
|
|
3812 | |
3758 | cf::init_anim; |
3813 | cf::init_anim; |
3759 | cf::init_attackmess; |
3814 | cf::init_attackmess; |
3760 | cf::init_dynamic; |
3815 | cf::init_dynamic; |
3761 | |
3816 | |
3762 | cf::load_settings; |
3817 | cf::load_settings; |
3763 | |
3818 | |
3764 | reload_resources; |
3819 | reload_resources; |
3765 | reload_config; |
3820 | reload_config; |
3766 | db_init; |
|
|
3767 | |
3821 | |
3768 | cf::init_uuid; |
3822 | cf::init_uuid; |
3769 | cf::init_signals; |
3823 | cf::init_signals; |
3770 | cf::init_skills; |
3824 | cf::init_skills; |
3771 | |
3825 | |
… | |
… | |
4196 | } |
4250 | } |
4197 | } |
4251 | } |
4198 | |
4252 | |
4199 | { |
4253 | { |
4200 | # configure BDB |
4254 | # configure BDB |
|
|
4255 | info "initialising database"; |
4201 | |
4256 | |
4202 | BDB::min_parallel 16; |
4257 | BDB::min_parallel 16; |
4203 | BDB::max_poll_reqs $TICK * 0.1; |
4258 | BDB::max_poll_reqs $TICK * 0.1; |
4204 | #$AnyEvent::BDB::WATCHER->priority (1); |
4259 | #$AnyEvent::BDB::WATCHER->priority (1); |
4205 | |
4260 | |
… | |
… | |
4234 | BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; |
4289 | BDB::db_env_txn_checkpoint $DB_ENV, 0, 0, 0, sub { }; |
4235 | }; |
4290 | }; |
4236 | $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub { |
4291 | $BDB_TRICKLE_WATCHER = EV::periodic 0, 10, 0, sub { |
4237 | BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { }; |
4292 | BDB::db_env_memp_trickle $DB_ENV, 20, 0, sub { }; |
4238 | }; |
4293 | }; |
|
|
4294 | |
|
|
4295 | info "database initialised"; |
4239 | } |
4296 | } |
4240 | |
4297 | |
4241 | { |
4298 | { |
4242 | # configure IO::AIO |
4299 | # configure IO::AIO |
4243 | |
4300 | |
|
|
4301 | info "initialising aio"; |
4244 | IO::AIO::min_parallel 8; |
4302 | IO::AIO::min_parallel 8; |
4245 | IO::AIO::max_poll_time $TICK * 0.1; |
4303 | IO::AIO::max_poll_time $TICK * 0.1; |
4246 | undef $AnyEvent::AIO::WATCHER; |
4304 | undef $AnyEvent::AIO::WATCHER; |
|
|
4305 | info "aio initialised"; |
4247 | } |
4306 | } |
4248 | |
4307 | |
4249 | our $_log_backtrace; |
4308 | our $_log_backtrace; |
4250 | our $_log_backtrace_last; |
4309 | our $_log_backtrace_last; |
4251 | |
4310 | |