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 |
… | |
… | |
687 | |
703 | |
688 | while ($busy) { |
704 | while ($busy) { |
689 | if (Coro::nready) { |
705 | if (Coro::nready) { |
690 | Coro::cede_notself; |
706 | Coro::cede_notself; |
691 | } else { |
707 | } else { |
692 | EV::loop EV::LOOP_ONESHOT; |
708 | EV::run EV::RUN_ONCE; |
693 | } |
709 | } |
694 | } |
710 | } |
695 | |
711 | |
696 | my $time = AE::time - $time; |
712 | my $time = AE::time - $time; |
697 | |
713 | |
… | |
… | |
2384 | |
2400 | |
2385 | $MAP_PREFETCHER ||= cf::async { |
2401 | $MAP_PREFETCHER ||= cf::async { |
2386 | $Coro::current->{desc} = "map prefetcher"; |
2402 | $Coro::current->{desc} = "map prefetcher"; |
2387 | |
2403 | |
2388 | while (%MAP_PREFETCH) { |
2404 | while (%MAP_PREFETCH) { |
2389 | while (my ($k, $v) = each %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 | } |
… | |
… | |
2742 | =item $player_object->may ("access") |
2758 | =item $player_object->may ("access") |
2743 | |
2759 | |
2744 | Returns wether the given player is authorized to access resource "access" |
2760 | Returns wether the given player is authorized to access resource "access" |
2745 | (e.g. "command_wizcast"). |
2761 | (e.g. "command_wizcast"). |
2746 | |
2762 | |
|
|
2763 | This is implemented by checking a config setting of C<may_access> where |
|
|
2764 | C<access> is replaced by the access string. The following alternatives are |
|
|
2765 | possible (and are tested in order): |
|
|
2766 | |
|
|
2767 | =over 4 |
|
|
2768 | |
|
|
2769 | =item * Player is DM |
|
|
2770 | |
|
|
2771 | The request will succeed. |
|
|
2772 | |
|
|
2773 | =item * may_access is an array reference |
|
|
2774 | |
|
|
2775 | If either the player nickname or UUID is in the array, the request will |
|
|
2776 | succeed, otherwise it will fail. |
|
|
2777 | |
|
|
2778 | =item * may_access is a true value |
|
|
2779 | |
|
|
2780 | The request will succeed. |
|
|
2781 | |
|
|
2782 | =item * may_access is missing or false |
|
|
2783 | |
|
|
2784 | The request will fail. |
|
|
2785 | |
|
|
2786 | =back |
|
|
2787 | |
2747 | =cut |
2788 | =cut |
2748 | |
2789 | |
2749 | sub cf::object::player::may { |
2790 | sub cf::object::player::may { |
2750 | my ($self, $access) = @_; |
2791 | my ($self, $access) = @_; |
2751 | |
2792 | |
2752 | $self->flag (cf::FLAG_WIZ) || |
2793 | $self->flag (cf::FLAG_WIZ) || |
2753 | (ref $cf::CFG{"may_$access"} |
2794 | (ref $cf::CFG{"may_$access"} |
2754 | ? scalar grep $self->name eq $_, @{$cf::CFG{"may_$access"}} |
2795 | ? scalar grep $self->name eq $_ || $self->uuid eq $_, @{$cf::CFG{"may_$access"}} |
2755 | : $cf::CFG{"may_$access"}) |
2796 | : $cf::CFG{"may_$access"}) |
2756 | } |
2797 | } |
2757 | |
2798 | |
2758 | =item $player_object->enter_link |
2799 | =item $player_object->enter_link |
2759 | |
2800 | |
… | |
… | |
2762 | The player should be reasonably safe there for short amounts of time (e.g. |
2803 | The player should be reasonably safe there for short amounts of time (e.g. |
2763 | for loading a map). You I<MUST> call C<leave_link> as soon as possible, |
2804 | for loading a map). You I<MUST> call C<leave_link> as soon as possible, |
2764 | though, as the player cannot control the character while it is on the link |
2805 | though, as the player cannot control the character while it is on the link |
2765 | map. |
2806 | map. |
2766 | |
2807 | |
2767 | Will never block. |
2808 | This method will never block, which is the whole reaosn for it's |
|
|
2809 | existance: you can I<always> put a player onto the link map, which is the |
|
|
2810 | only place to put objects that is guaranteed to exist. |
|
|
2811 | |
|
|
2812 | A typical usage pattern is to call C<enter_link> synchronously from the |
|
|
2813 | server, then start a new thread, do your blocking stuff there and then |
|
|
2814 | call C<leave_link> from that thread. |
2768 | |
2815 | |
2769 | =item $player_object->leave_link ($map, $x, $y) |
2816 | =item $player_object->leave_link ($map, $x, $y) |
2770 | |
2817 | |
2771 | Moves the player out of the special C<{link}> map onto the specified |
2818 | Moves the player out of the special C<{link}> map onto the specified |
2772 | map. If the map is not valid (or omitted), the player will be moved back |
2819 | map. If the map is not valid (or omitted), the player will be moved back |
… | |
… | |
3124 | }, |
3171 | }, |
3125 | "c/body" => { |
3172 | "c/body" => { |
3126 | id => "infobox", |
3173 | id => "infobox", |
3127 | title => "Body Parts", |
3174 | title => "Body Parts", |
3128 | reply => undef, |
3175 | reply => undef, |
3129 | tooltip => "Shows which body parts you posess and are available", |
3176 | tooltip => "Shows which body parts you possess and are available", |
3130 | }, |
3177 | }, |
3131 | "c/statistics" => { |
3178 | "c/statistics" => { |
3132 | id => "infobox", |
3179 | id => "infobox", |
3133 | title => "Statistics", |
3180 | title => "Statistics", |
3134 | reply => undef, |
3181 | reply => undef, |
… | |
… | |
3286 | |
3333 | |
3287 | sub cf::client::update_command_faces { |
3334 | sub cf::client::update_command_faces { |
3288 | my ($self) = @_; |
3335 | my ($self) = @_; |
3289 | |
3336 | |
3290 | my @faces = grep $_, |
3337 | my @faces = grep $_, |
|
|
3338 | $COMMAND_FACE{preferred}, |
3291 | $COMMAND_FACE{standard}, |
3339 | $COMMAND_FACE{standard}, |
3292 | $COMMAND_FACE{emote}, |
|
|
3293 | $COMMAND_FACE{skill}, |
3340 | $COMMAND_FACE{skill}, |
3294 | $self->pl->ob->flag (cf::FLAG_WIZ) ? $COMMAND_FACE{dm} : (), |
3341 | $self->pl->ob->flag (cf::FLAG_WIZ) ? $COMMAND_FACE{dm} : (), |
|
|
3342 | $COMMAND_FACE{emote}, |
3295 | ; |
3343 | ; |
3296 | |
3344 | |
3297 | $self->send_face ($_) |
3345 | $self->send_face ($_) |
3298 | for @faces; |
3346 | for @faces; |
3299 | $self->flush_fx; |
3347 | $self->flush_fx; |
… | |
… | |
3883 | seek $fh, 0, 0; |
3931 | seek $fh, 0, 0; |
3884 | print $fh $$; |
3932 | print $fh $$; |
3885 | } |
3933 | } |
3886 | |
3934 | |
3887 | sub main_loop { |
3935 | sub main_loop { |
3888 | trace "EV::loop starting\n"; |
3936 | trace "EV::run starting\n"; |
3889 | if (1) { |
3937 | if (1) { |
3890 | EV::loop; |
3938 | EV::run; |
3891 | } |
3939 | } |
3892 | trace "EV::loop returned\n"; |
3940 | trace "EV::run returned\n"; |
3893 | goto &main_loop unless $REALLY_UNLOOP; |
3941 | goto &main_loop unless $REALLY_UNLOOP; |
3894 | } |
3942 | } |
3895 | |
3943 | |
3896 | sub main { |
3944 | sub main { |
3897 | cf::init_globals; # initialise logging |
3945 | cf::init_globals; # initialise logging |
3898 | |
3946 | |
3899 | 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."; |
3900 | 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."; |
3901 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3950 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3902 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3951 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3903 | |
3952 | |
3904 | $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 |
3905 | |
3954 | |
3906 | # we must not ever block the main coroutine |
3955 | # we must not ever block the main coroutine |
3907 | $Coro::idle = sub { |
3956 | $Coro::idle = sub { |
3908 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3957 | Carp::cluck "FATAL: Coro::idle was called, major BUG, use cf::sync_job!\n";#d# |
3909 | (async { |
3958 | (async { |
3910 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3959 | $Coro::current->{desc} = "IDLE BUG HANDLER"; |
3911 | EV::loop EV::LOOP_ONESHOT; |
3960 | EV::run EV::RUN_ONCE; |
3912 | })->prio (Coro::PRIO_MAX); |
3961 | })->prio (Coro::PRIO_MAX); |
3913 | }; |
3962 | }; |
3914 | |
3963 | |
3915 | evthread_start IO::AIO::poll_fileno; |
3964 | evthread_start IO::AIO::poll_fileno; |
3916 | |
3965 | |