… | |
… | |
21 | |
21 | |
22 | package cf; |
22 | package cf; |
23 | |
23 | |
24 | use 5.10.0; |
24 | use 5.10.0; |
25 | use utf8; |
25 | use utf8; |
26 | use strict "vars", "subs"; |
26 | use strict qw(vars subs); |
27 | |
27 | |
28 | use Symbol; |
28 | use Symbol; |
29 | use List::Util; |
29 | use List::Util; |
30 | use Socket; |
30 | use Socket; |
31 | use EV; |
31 | use EV; |
… | |
… | |
111 | |
111 | |
112 | our $BDB_DEADLOCK_WATCHER; |
112 | our $BDB_DEADLOCK_WATCHER; |
113 | our $BDB_CHECKPOINT_WATCHER; |
113 | our $BDB_CHECKPOINT_WATCHER; |
114 | our $BDB_TRICKLE_WATCHER; |
114 | our $BDB_TRICKLE_WATCHER; |
115 | our $DB_ENV; |
115 | our $DB_ENV; |
|
|
116 | |
|
|
117 | our @EXTRA_MODULES = qw(pod mapscript); |
116 | |
118 | |
117 | our %CFG; |
119 | our %CFG; |
118 | |
120 | |
119 | our $UPTIME; $UPTIME ||= time; |
121 | our $UPTIME; $UPTIME ||= time; |
120 | our $RUNTIME; |
122 | our $RUNTIME; |
… | |
… | |
1862 | |
1864 | |
1863 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go; |
1865 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/go; |
1864 | "$UNIQUEDIR/$path" |
1866 | "$UNIQUEDIR/$path" |
1865 | } |
1867 | } |
1866 | |
1868 | |
1867 | # and all this just because we cannot iterate over |
|
|
1868 | # all maps in C++... |
|
|
1869 | sub change_all_map_light { |
|
|
1870 | my ($change) = @_; |
|
|
1871 | |
|
|
1872 | $_->change_map_light ($change) |
|
|
1873 | for grep $_->outdoor, values %cf::MAP; |
|
|
1874 | } |
|
|
1875 | |
|
|
1876 | sub decay_objects { |
1869 | sub decay_objects { |
1877 | my ($self) = @_; |
1870 | my ($self) = @_; |
1878 | |
1871 | |
1879 | return if $self->{deny_reset}; |
1872 | return if $self->{deny_reset}; |
1880 | |
1873 | |
… | |
… | |
2042 | |
2035 | |
2043 | unless ($self->{deny_activate}) { |
2036 | unless ($self->{deny_activate}) { |
2044 | $self->decay_objects; |
2037 | $self->decay_objects; |
2045 | $self->fix_auto_apply; |
2038 | $self->fix_auto_apply; |
2046 | $self->update_buttons; |
2039 | $self->update_buttons; |
2047 | cf::cede_to_tick; |
|
|
2048 | $self->set_darkness_map; |
|
|
2049 | cf::cede_to_tick; |
2040 | cf::cede_to_tick; |
2050 | $self->activate; |
2041 | $self->activate; |
2051 | } |
2042 | } |
2052 | |
2043 | |
2053 | $self->{last_save} = $cf::RUNTIME; |
2044 | $self->{last_save} = $cf::RUNTIME; |
… | |
… | |
2780 | id => "infobox", |
2771 | id => "infobox", |
2781 | title => "Body Parts", |
2772 | title => "Body Parts", |
2782 | reply => undef, |
2773 | reply => undef, |
2783 | tooltip => "Shows which body parts you posess and are available", |
2774 | tooltip => "Shows which body parts you posess and are available", |
2784 | }, |
2775 | }, |
|
|
2776 | "c/statistics" => { |
|
|
2777 | id => "infobox", |
|
|
2778 | title => "Statistics", |
|
|
2779 | reply => undef, |
|
|
2780 | tooltip => "Shows your primary statistics", |
|
|
2781 | }, |
2785 | "c/skills" => { |
2782 | "c/skills" => { |
2786 | id => "infobox", |
2783 | id => "infobox", |
2787 | title => "Skills", |
2784 | title => "Skills", |
2788 | reply => undef, |
2785 | reply => undef, |
2789 | tooltip => "Shows your experience per skill and item power", |
2786 | tooltip => "Shows your experience per skill and item power", |
|
|
2787 | }, |
|
|
2788 | "c/resistances" => { |
|
|
2789 | id => "infobox", |
|
|
2790 | title => "Resistances", |
|
|
2791 | reply => undef, |
|
|
2792 | tooltip => "Shows your resistances", |
|
|
2793 | }, |
|
|
2794 | "c/pets" => { |
|
|
2795 | id => "infobox", |
|
|
2796 | title => "Pets", |
|
|
2797 | reply => undef, |
|
|
2798 | tooltip => "Shows information abotu your pets/a specific pet", |
2790 | }, |
2799 | }, |
2791 | "c/uptime" => { |
2800 | "c/uptime" => { |
2792 | id => "infobox", |
2801 | id => "infobox", |
2793 | title => "Uptime", |
2802 | title => "Uptime", |
2794 | reply => undef, |
2803 | reply => undef, |
… | |
… | |
2804 | id => "party", |
2813 | id => "party", |
2805 | title => "Party", |
2814 | title => "Party", |
2806 | reply => "gsay ", |
2815 | reply => "gsay ", |
2807 | tooltip => "Messages and chat related to your party", |
2816 | tooltip => "Messages and chat related to your party", |
2808 | }, |
2817 | }, |
|
|
2818 | "c/death" => { |
|
|
2819 | id => "death", |
|
|
2820 | title => "Death", |
|
|
2821 | reply => undef, |
|
|
2822 | tooltip => "Reason for and more info about your most recent death", |
|
|
2823 | }, |
|
|
2824 | "c/say" => $SAY_CHANNEL, |
|
|
2825 | "c/chat" => $CHAT_CHANNEL, |
2809 | ); |
2826 | ); |
2810 | |
2827 | |
2811 | sub cf::client::send_msg { |
2828 | sub cf::client::send_msg { |
2812 | my ($self, $channel, $msg, $color, @extra) = @_; |
2829 | my ($self, $channel, $msg, $color, @extra) = @_; |
2813 | |
2830 | |
… | |
… | |
2818 | |
2835 | |
2819 | # check predefined channels, for the benefit of C |
2836 | # check predefined channels, for the benefit of C |
2820 | if ($CHANNEL{$channel}) { |
2837 | if ($CHANNEL{$channel}) { |
2821 | $channel = $CHANNEL{$channel}; |
2838 | $channel = $CHANNEL{$channel}; |
2822 | |
2839 | |
2823 | $self->ext_msg (channel_info => $channel) |
2840 | $self->ext_msg (channel_info => $channel); |
2824 | if $self->can_msg; |
|
|
2825 | |
|
|
2826 | $channel = $channel->{id}; |
2841 | $channel = $channel->{id}; |
2827 | |
2842 | |
2828 | } elsif (ref $channel) { |
2843 | } elsif (ref $channel) { |
2829 | # send meta info to client, if not yet sent |
2844 | # send meta info to client, if not yet sent |
2830 | unless (exists $self->{channel}{$channel->{id}}) { |
2845 | unless (exists $self->{channel}{$channel->{id}}) { |
2831 | $self->{channel}{$channel->{id}} = $channel; |
2846 | $self->{channel}{$channel->{id}} = $channel; |
2832 | $self->ext_msg (channel_info => $channel) |
2847 | $self->ext_msg (channel_info => $channel); |
2833 | if $self->can_msg; |
|
|
2834 | } |
2848 | } |
2835 | |
2849 | |
2836 | $channel = $channel->{id}; |
2850 | $channel = $channel->{id}; |
2837 | } |
2851 | } |
2838 | |
2852 | |
2839 | return unless @extra || length $msg; |
2853 | return unless @extra || length $msg; |
2840 | |
2854 | |
2841 | if ($self->can_msg) { |
|
|
2842 | # default colour, mask it out |
2855 | # default colour, mask it out |
2843 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2856 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2844 | if $color & cf::NDI_DEF; |
2857 | if $color & cf::NDI_DEF; |
2845 | |
2858 | |
2846 | my $pkt = "msg " |
2859 | my $pkt = "msg " |
2847 | . $self->{json_coder}->encode ( |
2860 | . $self->{json_coder}->encode ( |
2848 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2861 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2849 | ); |
2862 | ); |
2850 | |
2863 | |
2851 | # try lzf for large packets |
2864 | # try lzf for large packets |
2852 | $pkt = "lzf " . Compress::LZF::compress $pkt |
2865 | $pkt = "lzf " . Compress::LZF::compress $pkt |
2853 | if 1024 <= length $pkt and $self->{can_lzf}; |
2866 | if 1024 <= length $pkt and $self->{can_lzf}; |
2854 | |
2867 | |
2855 | # split very large packets |
2868 | # split very large packets |
2856 | if (8192 < length $pkt and $self->{can_lzf}) { |
2869 | if (8192 < length $pkt and $self->{can_lzf}) { |
2857 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
2870 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
2858 | $pkt = "frag"; |
2871 | $pkt = "frag"; |
2859 | } |
2872 | } |
2860 | |
2873 | |
2861 | $self->send_packet ($pkt); |
2874 | $self->send_packet ($pkt); |
2862 | } else { |
|
|
2863 | if ($color >= 0) { |
|
|
2864 | # replace some tags by gcfclient-compatible ones |
|
|
2865 | for ($msg) { |
|
|
2866 | 1 while |
|
|
2867 | s/<b>([^<]*)<\/b>/[b]${1}[\/b]/ |
|
|
2868 | || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/ |
|
|
2869 | || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/ |
|
|
2870 | || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/ |
|
|
2871 | || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/; |
|
|
2872 | } |
|
|
2873 | |
|
|
2874 | $color &= cf::NDI_COLOR_MASK; |
|
|
2875 | |
|
|
2876 | utf8::encode $msg; |
|
|
2877 | |
|
|
2878 | if (0 && $msg =~ /\[/) { |
|
|
2879 | # COMMAND/INFO |
|
|
2880 | $self->send_packet ("drawextinfo $color 10 8 $msg") |
|
|
2881 | } else { |
|
|
2882 | $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g; |
|
|
2883 | $self->send_packet ("drawinfo $color $msg") |
|
|
2884 | } |
|
|
2885 | } |
|
|
2886 | } |
|
|
2887 | } |
2875 | } |
2888 | |
2876 | |
2889 | =item $client->ext_msg ($type, @msg) |
2877 | =item $client->ext_msg ($type, @msg) |
2890 | |
2878 | |
2891 | Sends an ext event to the client. |
2879 | Sends an ext event to the client. |
… | |
… | |
3066 | The following functions and methods are available within a safe environment: |
3054 | The following functions and methods are available within a safe environment: |
3067 | |
3055 | |
3068 | cf::object |
3056 | cf::object |
3069 | contr pay_amount pay_player map x y force_find force_add destroy |
3057 | contr pay_amount pay_player map x y force_find force_add destroy |
3070 | insert remove name archname title slaying race decrease split |
3058 | insert remove name archname title slaying race decrease split |
|
|
3059 | value |
3071 | |
3060 | |
3072 | cf::object::player |
3061 | cf::object::player |
3073 | player |
3062 | player |
3074 | |
3063 | |
3075 | cf::player |
3064 | cf::player |
… | |
… | |
3081 | =cut |
3070 | =cut |
3082 | |
3071 | |
3083 | for ( |
3072 | for ( |
3084 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3073 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3085 | insert remove inv nrof name archname title slaying race |
3074 | insert remove inv nrof name archname title slaying race |
3086 | decrease split destroy change_exp)], |
3075 | decrease split destroy change_exp value msg lore send_msg)], |
3087 | ["cf::object::player" => qw(player)], |
3076 | ["cf::object::player" => qw(player)], |
3088 | ["cf::player" => qw(peaceful)], |
3077 | ["cf::player" => qw(peaceful send_msg)], |
3089 | ["cf::map" => qw(trigger)], |
3078 | ["cf::map" => qw(trigger)], |
3090 | ) { |
3079 | ) { |
3091 | no strict 'refs'; |
3080 | no strict 'refs'; |
3092 | my ($pkg, @funs) = @$_; |
3081 | my ($pkg, @funs) = @$_; |
3093 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
3082 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
… | |
… | |
3110 | my ($code, %vars) = @_; |
3099 | my ($code, %vars) = @_; |
3111 | |
3100 | |
3112 | my $qcode = $code; |
3101 | my $qcode = $code; |
3113 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3102 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3114 | $qcode =~ s/\n/\\n/g; |
3103 | $qcode =~ s/\n/\\n/g; |
|
|
3104 | |
|
|
3105 | %vars = (_dummy => 0) unless %vars; |
3115 | |
3106 | |
3116 | local $_; |
3107 | local $_; |
3117 | local @safe::cf::_safe_eval_args = values %vars; |
3108 | local @safe::cf::_safe_eval_args = values %vars; |
3118 | |
3109 | |
3119 | my $eval = |
3110 | my $eval = |
… | |
… | |
3401 | |
3392 | |
3402 | cf::init_experience; |
3393 | cf::init_experience; |
3403 | cf::init_anim; |
3394 | cf::init_anim; |
3404 | cf::init_attackmess; |
3395 | cf::init_attackmess; |
3405 | cf::init_dynamic; |
3396 | cf::init_dynamic; |
3406 | cf::init_block; |
|
|
3407 | |
3397 | |
3408 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3398 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3409 | |
3399 | |
3410 | # we must not ever block the main coroutine |
3400 | # we must not ever block the main coroutine |
3411 | local $Coro::idle = sub { |
3401 | local $Coro::idle = sub { |
… | |
… | |
3708 | clear_package "safe::$_" |
3698 | clear_package "safe::$_" |
3709 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3699 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3710 | |
3700 | |
3711 | warn "unloading cf.pm \"a bit\""; |
3701 | warn "unloading cf.pm \"a bit\""; |
3712 | delete $INC{"cf.pm"}; |
3702 | delete $INC{"cf.pm"}; |
3713 | delete $INC{"cf/pod.pm"}; |
3703 | delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; |
3714 | |
3704 | |
3715 | # don't, removes xs symbols, too, |
3705 | # don't, removes xs symbols, too, |
3716 | # and global variables created in xs |
3706 | # and global variables created in xs |
3717 | #clear_package __PACKAGE__; |
3707 | #clear_package __PACKAGE__; |
3718 | |
3708 | |
… | |
… | |
3935 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3925 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3936 | } |
3926 | } |
3937 | } |
3927 | } |
3938 | |
3928 | |
3939 | # load additional modules |
3929 | # load additional modules |
3940 | use cf::pod; |
3930 | eval "use cf::$_" for @EXTRA_MODULES; |
3941 | |
3931 | |
3942 | END { cf::emergency_save } |
3932 | END { cf::emergency_save } |
3943 | |
3933 | |
3944 | 1 |
3934 | 1 |
3945 | |
3935 | |