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 (©) 2018 Marc Alexander Lehmann / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | # Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | # |
6 | # |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
7 | # 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 |
8 | # 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 |
9 | # Free Software Foundation, either version 3 of the License, or (at your |
… | |
… | |
57 | use JSON::XS 2.01 (); |
58 | use JSON::XS 2.01 (); |
58 | use BDB (); |
59 | use BDB (); |
59 | use Data::Dumper; |
60 | use Data::Dumper; |
60 | use Fcntl; |
61 | use Fcntl; |
61 | use YAML::XS (); |
62 | use YAML::XS (); |
|
|
63 | use CBOR::XS (); |
62 | use IO::AIO (); |
64 | use IO::AIO (); |
63 | use Compress::LZF; |
65 | use Compress::LZF; |
64 | use Digest::MD5 (); |
66 | use Digest::MD5 (); |
65 | |
67 | |
66 | AnyEvent::detect; |
68 | AnyEvent::detect; |
… | |
… | |
225 | =item $cf::RUNTIME |
227 | =item $cf::RUNTIME |
226 | |
228 | |
227 | The time this server has run, starts at 0 and is increased by $cf::TICK on |
229 | The time this server has run, starts at 0 and is increased by $cf::TICK on |
228 | every server tick. |
230 | every server tick. |
229 | |
231 | |
230 | =item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR |
232 | =item $cf::CONFDIR $cf::DATADIR $cf::LIBDIR $cf::PODDIR |
231 | $cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR |
233 | $cf::MAPDIR $cf::LOCALDIR $cf::TMPDIR $cf::UNIQUEDIR |
232 | $cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR |
234 | $cf::PLAYERDIR $cf::RANDOMDIR $cf::BDBDIR |
233 | |
235 | |
234 | Various directories - "/etc", read-only install directory, perl-library |
236 | Various directories - "/etc", read-only install directory, perl-library |
235 | directory, pod-directory, read-only maps directory, "/var", "/var/tmp", |
237 | directory, pod-directory, read-only maps directory, "/var", "/var/tmp", |
… | |
… | |
464 | |
466 | |
465 | sub decode_yaml($) { |
467 | sub decode_yaml($) { |
466 | fork_call { YAML::XS::Load $_[0] } @_ |
468 | fork_call { YAML::XS::Load $_[0] } @_ |
467 | } |
469 | } |
468 | |
470 | |
|
|
471 | =item $scalar = cf::decode_cbor $scalar |
|
|
472 | |
|
|
473 | Same as CBOR::XS::decode_cbor, but takes server ticks into account, so |
|
|
474 | blocks. For small amounts of data, C<CBOR::XS::decode_cbor> is the better |
|
|
475 | alternative. |
|
|
476 | |
|
|
477 | =cut |
|
|
478 | |
|
|
479 | sub decode_cbor($) { |
|
|
480 | # we assume 10mb/s minimum decoding speed (on a ~2ghz machine) |
|
|
481 | cf::get_slot +(length $_[0]) / 10_000_000, 0, "decode_cbor"; |
|
|
482 | CBOR::XS::decode_cbor $_[0] |
|
|
483 | } |
|
|
484 | |
469 | =item $scalar = cf::unlzf $scalar |
485 | =item $scalar = cf::unlzf $scalar |
470 | |
486 | |
471 | Same as Compress::LZF::compress, but takes server ticks into account, so |
487 | Same as Compress::LZF::compress, but takes server ticks into account, so |
472 | blocks. |
488 | blocks. |
473 | |
489 | |
… | |
… | |
510 | } |
526 | } |
511 | } |
527 | } |
512 | |
528 | |
513 | =item cf::lock_wait $string |
529 | =item cf::lock_wait $string |
514 | |
530 | |
515 | Wait until the given lock is available. See cf::lock_acquire. |
531 | Wait until the given lock is available. See cf::lock_acquire. |
516 | |
532 | |
517 | =item my $lock = cf::lock_acquire $string |
533 | =item my $lock = cf::lock_acquire $string |
518 | |
534 | |
519 | Wait until the given lock is available and then acquires it and returns |
535 | Wait until the given lock is available and then acquires it and returns |
520 | a L<Guard> object. If the guard object gets destroyed (goes out of scope, |
536 | a L<Guard> object. If the guard object gets destroyed (goes out of scope, |
… | |
… | |
649 | BEGIN { *async = \&Coro::async_pool } |
665 | BEGIN { *async = \&Coro::async_pool } |
650 | |
666 | |
651 | =item cf::sync_job { BLOCK } |
667 | =item cf::sync_job { BLOCK } |
652 | |
668 | |
653 | The design of Deliantra requires that the main coroutine ($Coro::main) |
669 | The design of Deliantra requires that the main coroutine ($Coro::main) |
654 | is always able to handle events or runnable, as Deliantra is only |
670 | is always able to handle events or is runnable, as Deliantra is only |
655 | partly reentrant. Thus "blocking" it by e.g. waiting for I/O is not |
671 | partly reentrant. Thus "blocking" it by e.g. waiting for I/O is not |
656 | acceptable. |
672 | acceptable. |
657 | |
673 | |
658 | If it must be done, put the blocking parts into C<sync_job>. This will run |
674 | If it must be done, put the blocking parts into C<sync_job>. This will run |
659 | the given BLOCK in another coroutine while waiting for the result. The |
675 | the given BLOCK in another coroutine while waiting for the result. The |
… | |
… | |
2386 | $Coro::current->{desc} = "map prefetcher"; |
2402 | $Coro::current->{desc} = "map prefetcher"; |
2387 | |
2403 | |
2388 | while (%MAP_PREFETCH) { |
2404 | while (%MAP_PREFETCH) { |
2389 | for my $k (keys %MAP_PREFETCH) { |
2405 | for my $k (keys %MAP_PREFETCH) { |
2390 | if (my $map = find $k) { |
2406 | if (my $map = find $k) { |
2391 | $map->load if $v; |
2407 | $map->load if $MAP_PREFETCH{$k}; |
2392 | } |
2408 | } |
2393 | |
2409 | |
2394 | delete $MAP_PREFETCH{$k}; |
2410 | delete $MAP_PREFETCH{$k}; |
2395 | } |
2411 | } |
2396 | } |
2412 | } |
… | |
… | |
3155 | }, |
3171 | }, |
3156 | "c/body" => { |
3172 | "c/body" => { |
3157 | id => "infobox", |
3173 | id => "infobox", |
3158 | title => "Body Parts", |
3174 | title => "Body Parts", |
3159 | reply => undef, |
3175 | reply => undef, |
3160 | tooltip => "Shows which body parts you posess and are available", |
3176 | tooltip => "Shows which body parts you possess and are available", |
3161 | }, |
3177 | }, |
3162 | "c/statistics" => { |
3178 | "c/statistics" => { |
3163 | id => "infobox", |
3179 | id => "infobox", |
3164 | title => "Statistics", |
3180 | title => "Statistics", |
3165 | reply => undef, |
3181 | reply => undef, |
… | |
… | |
3927 | |
3943 | |
3928 | sub main { |
3944 | sub main { |
3929 | cf::init_globals; # initialise logging |
3945 | cf::init_globals; # initialise logging |
3930 | |
3946 | |
3931 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3947 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
|
|
3948 | LOG llevInfo, "Copyright (C) 2017-2018 Marc Alexander Lehmann / the Deliantra team."; |
3932 | LOG llevInfo, "Copyright (C) 2005-2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3949 | LOG llevInfo, "Copyright (C) 2005-2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3933 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3950 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3934 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3951 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3935 | |
3952 | |
3936 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3953 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3937 | |
3954 | |