… | |
… | |
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; |
… | |
… | |
2769 | id => "infobox", |
2771 | id => "infobox", |
2770 | title => "Body Parts", |
2772 | title => "Body Parts", |
2771 | reply => undef, |
2773 | reply => undef, |
2772 | tooltip => "Shows which body parts you posess and are available", |
2774 | tooltip => "Shows which body parts you posess and are available", |
2773 | }, |
2775 | }, |
|
|
2776 | "c/statistics" => { |
|
|
2777 | id => "infobox", |
|
|
2778 | title => "Statistics", |
|
|
2779 | reply => undef, |
|
|
2780 | tooltip => "Shows your primary statistics", |
|
|
2781 | }, |
2774 | "c/skills" => { |
2782 | "c/skills" => { |
2775 | id => "infobox", |
2783 | id => "infobox", |
2776 | title => "Skills", |
2784 | title => "Skills", |
2777 | reply => undef, |
2785 | reply => undef, |
2778 | 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", |
2779 | }, |
2799 | }, |
2780 | "c/uptime" => { |
2800 | "c/uptime" => { |
2781 | id => "infobox", |
2801 | id => "infobox", |
2782 | title => "Uptime", |
2802 | title => "Uptime", |
2783 | reply => undef, |
2803 | reply => undef, |
… | |
… | |
2793 | id => "party", |
2813 | id => "party", |
2794 | title => "Party", |
2814 | title => "Party", |
2795 | reply => "gsay ", |
2815 | reply => "gsay ", |
2796 | tooltip => "Messages and chat related to your party", |
2816 | tooltip => "Messages and chat related to your party", |
2797 | }, |
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 | }, |
2798 | "c/say" => $SAY_CHANNEL, |
2824 | "c/say" => $SAY_CHANNEL, |
2799 | "c/chat" => $CHAT_CHANNEL, |
2825 | "c/chat" => $CHAT_CHANNEL, |
2800 | ); |
2826 | ); |
2801 | |
2827 | |
2802 | sub cf::client::send_msg { |
2828 | sub cf::client::send_msg { |
… | |
… | |
2809 | |
2835 | |
2810 | # check predefined channels, for the benefit of C |
2836 | # check predefined channels, for the benefit of C |
2811 | if ($CHANNEL{$channel}) { |
2837 | if ($CHANNEL{$channel}) { |
2812 | $channel = $CHANNEL{$channel}; |
2838 | $channel = $CHANNEL{$channel}; |
2813 | |
2839 | |
2814 | $self->ext_msg (channel_info => $channel) |
2840 | $self->ext_msg (channel_info => $channel); |
2815 | if $self->can_msg; |
|
|
2816 | |
|
|
2817 | $channel = $channel->{id}; |
2841 | $channel = $channel->{id}; |
2818 | |
2842 | |
2819 | } elsif (ref $channel) { |
2843 | } elsif (ref $channel) { |
2820 | # send meta info to client, if not yet sent |
2844 | # send meta info to client, if not yet sent |
2821 | unless (exists $self->{channel}{$channel->{id}}) { |
2845 | unless (exists $self->{channel}{$channel->{id}}) { |
2822 | $self->{channel}{$channel->{id}} = $channel; |
2846 | $self->{channel}{$channel->{id}} = $channel; |
2823 | $self->ext_msg (channel_info => $channel) |
2847 | $self->ext_msg (channel_info => $channel); |
2824 | if $self->can_msg; |
|
|
2825 | } |
2848 | } |
2826 | |
2849 | |
2827 | $channel = $channel->{id}; |
2850 | $channel = $channel->{id}; |
2828 | } |
2851 | } |
2829 | |
2852 | |
2830 | return unless @extra || length $msg; |
2853 | return unless @extra || length $msg; |
2831 | |
2854 | |
2832 | if ($self->can_msg) { |
|
|
2833 | # default colour, mask it out |
2855 | # default colour, mask it out |
2834 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2856 | $color &= ~(cf::NDI_COLOR_MASK | cf::NDI_DEF) |
2835 | if $color & cf::NDI_DEF; |
2857 | if $color & cf::NDI_DEF; |
2836 | |
2858 | |
2837 | my $pkt = "msg " |
2859 | my $pkt = "msg " |
2838 | . $self->{json_coder}->encode ( |
2860 | . $self->{json_coder}->encode ( |
2839 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2861 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2840 | ); |
2862 | ); |
2841 | |
2863 | |
2842 | # try lzf for large packets |
2864 | # try lzf for large packets |
2843 | $pkt = "lzf " . Compress::LZF::compress $pkt |
2865 | $pkt = "lzf " . Compress::LZF::compress $pkt |
2844 | if 1024 <= length $pkt and $self->{can_lzf}; |
2866 | if 1024 <= length $pkt and $self->{can_lzf}; |
2845 | |
2867 | |
2846 | # split very large packets |
2868 | # split very large packets |
2847 | if (8192 < length $pkt and $self->{can_lzf}) { |
2869 | if (8192 < length $pkt and $self->{can_lzf}) { |
2848 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
2870 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
2849 | $pkt = "frag"; |
2871 | $pkt = "frag"; |
2850 | } |
2872 | } |
2851 | |
2873 | |
2852 | $self->send_packet ($pkt); |
2874 | $self->send_packet ($pkt); |
2853 | } else { |
|
|
2854 | if ($color >= 0) { |
|
|
2855 | # replace some tags by gcfclient-compatible ones |
|
|
2856 | for ($msg) { |
|
|
2857 | 1 while |
|
|
2858 | s/<b>([^<]*)<\/b>/[b]${1}[\/b]/ |
|
|
2859 | || s/<i>([^<]*)<\/i>/[i]${1}[\/i]/ |
|
|
2860 | || s/<u>([^<]*)<\/u>/[ul]${1}[\/ul]/ |
|
|
2861 | || s/<tt>([^<]*)<\/tt>/[fixed]${1}[\/fixed]/ |
|
|
2862 | || s/<fg name=\"([^"]+)\">([^<]*)<\/fg>/[color=$1]${2}[\/color]/; |
|
|
2863 | } |
|
|
2864 | |
|
|
2865 | $color &= cf::NDI_COLOR_MASK; |
|
|
2866 | |
|
|
2867 | utf8::encode $msg; |
|
|
2868 | |
|
|
2869 | if (0 && $msg =~ /\[/) { |
|
|
2870 | # COMMAND/INFO |
|
|
2871 | $self->send_packet ("drawextinfo $color 10 8 $msg") |
|
|
2872 | } else { |
|
|
2873 | $msg =~ s/\[\/?(?:b|i|u|fixed|color)[^\]]*\]//g; |
|
|
2874 | $self->send_packet ("drawinfo $color $msg") |
|
|
2875 | } |
|
|
2876 | } |
|
|
2877 | } |
|
|
2878 | } |
2875 | } |
2879 | |
2876 | |
2880 | =item $client->ext_msg ($type, @msg) |
2877 | =item $client->ext_msg ($type, @msg) |
2881 | |
2878 | |
2882 | Sends an ext event to the client. |
2879 | Sends an ext event to the client. |
… | |
… | |
3057 | The following functions and methods are available within a safe environment: |
3054 | The following functions and methods are available within a safe environment: |
3058 | |
3055 | |
3059 | cf::object |
3056 | cf::object |
3060 | 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 |
3061 | insert remove name archname title slaying race decrease split |
3058 | insert remove name archname title slaying race decrease split |
|
|
3059 | value |
3062 | |
3060 | |
3063 | cf::object::player |
3061 | cf::object::player |
3064 | player |
3062 | player |
3065 | |
3063 | |
3066 | cf::player |
3064 | cf::player |
… | |
… | |
3072 | =cut |
3070 | =cut |
3073 | |
3071 | |
3074 | for ( |
3072 | for ( |
3075 | ["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 |
3076 | insert remove inv nrof name archname title slaying race |
3074 | insert remove inv nrof name archname title slaying race |
3077 | decrease split destroy change_exp)], |
3075 | decrease split destroy change_exp value msg lore send_msg)], |
3078 | ["cf::object::player" => qw(player)], |
3076 | ["cf::object::player" => qw(player)], |
3079 | ["cf::player" => qw(peaceful)], |
3077 | ["cf::player" => qw(peaceful send_msg)], |
3080 | ["cf::map" => qw(trigger)], |
3078 | ["cf::map" => qw(trigger)], |
3081 | ) { |
3079 | ) { |
3082 | no strict 'refs'; |
3080 | no strict 'refs'; |
3083 | my ($pkg, @funs) = @$_; |
3081 | my ($pkg, @funs) = @$_; |
3084 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
3082 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
… | |
… | |
3101 | my ($code, %vars) = @_; |
3099 | my ($code, %vars) = @_; |
3102 | |
3100 | |
3103 | my $qcode = $code; |
3101 | my $qcode = $code; |
3104 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3102 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3105 | $qcode =~ s/\n/\\n/g; |
3103 | $qcode =~ s/\n/\\n/g; |
|
|
3104 | |
|
|
3105 | %vars = (_dummy => 0) unless %vars; |
3106 | |
3106 | |
3107 | local $_; |
3107 | local $_; |
3108 | local @safe::cf::_safe_eval_args = values %vars; |
3108 | local @safe::cf::_safe_eval_args = values %vars; |
3109 | |
3109 | |
3110 | my $eval = |
3110 | my $eval = |
… | |
… | |
3698 | clear_package "safe::$_" |
3698 | clear_package "safe::$_" |
3699 | 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); |
3700 | |
3700 | |
3701 | warn "unloading cf.pm \"a bit\""; |
3701 | warn "unloading cf.pm \"a bit\""; |
3702 | delete $INC{"cf.pm"}; |
3702 | delete $INC{"cf.pm"}; |
3703 | delete $INC{"cf/pod.pm"}; |
3703 | delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; |
3704 | |
3704 | |
3705 | # don't, removes xs symbols, too, |
3705 | # don't, removes xs symbols, too, |
3706 | # and global variables created in xs |
3706 | # and global variables created in xs |
3707 | #clear_package __PACKAGE__; |
3707 | #clear_package __PACKAGE__; |
3708 | |
3708 | |
… | |
… | |
3925 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3925 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3926 | } |
3926 | } |
3927 | } |
3927 | } |
3928 | |
3928 | |
3929 | # load additional modules |
3929 | # load additional modules |
3930 | use cf::pod; |
3930 | eval "use cf::$_" for @EXTRA_MODULES; |
3931 | |
3931 | |
3932 | END { cf::emergency_save } |
3932 | END { cf::emergency_save } |
3933 | |
3933 | |
3934 | 1 |
3934 | 1 |
3935 | |
3935 | |