… | |
… | |
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; |
… | |
… | |
105 | our %RESOURCE; |
105 | our %RESOURCE; |
106 | |
106 | |
107 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
107 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
108 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
108 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
109 | our $NEXT_TICK; |
109 | our $NEXT_TICK; |
110 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
110 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
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; |
… | |
… | |
143 | unless ($RUNTIME || !-e $RUNTIMEFILE) { |
145 | unless ($RUNTIME || !-e $RUNTIMEFILE) { |
144 | open my $fh, "<", $RUNTIMEFILE |
146 | open my $fh, "<", $RUNTIMEFILE |
145 | or die "unable to read $RUNTIMEFILE file: $!"; |
147 | or die "unable to read $RUNTIMEFILE file: $!"; |
146 | $RUNTIME = <$fh> + 0.; |
148 | $RUNTIME = <$fh> + 0.; |
147 | } |
149 | } |
|
|
150 | |
|
|
151 | eval "sub TICK() { $TICK } 1" or die; |
148 | |
152 | |
149 | mkdir $_ |
153 | mkdir $_ |
150 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
154 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
151 | |
155 | |
152 | our $EMERGENCY_POSITION; |
156 | our $EMERGENCY_POSITION; |
… | |
… | |
2384 | |
2388 | |
2385 | our $SAY_CHANNEL = { |
2389 | our $SAY_CHANNEL = { |
2386 | id => "say", |
2390 | id => "say", |
2387 | title => "Map", |
2391 | title => "Map", |
2388 | reply => "say ", |
2392 | reply => "say ", |
2389 | tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
2393 | tooltip => "Things said to and replied from NPCs near you and other players on the same map only.", |
2390 | }; |
2394 | }; |
2391 | |
2395 | |
2392 | our $CHAT_CHANNEL = { |
2396 | our $CHAT_CHANNEL = { |
2393 | id => "chat", |
2397 | id => "chat", |
2394 | title => "Chat", |
2398 | title => "Chat", |
… | |
… | |
2769 | id => "infobox", |
2773 | id => "infobox", |
2770 | title => "Body Parts", |
2774 | title => "Body Parts", |
2771 | reply => undef, |
2775 | reply => undef, |
2772 | tooltip => "Shows which body parts you posess and are available", |
2776 | tooltip => "Shows which body parts you posess and are available", |
2773 | }, |
2777 | }, |
|
|
2778 | "c/statistics" => { |
|
|
2779 | id => "infobox", |
|
|
2780 | title => "Statistics", |
|
|
2781 | reply => undef, |
|
|
2782 | tooltip => "Shows your primary statistics", |
|
|
2783 | }, |
2774 | "c/skills" => { |
2784 | "c/skills" => { |
2775 | id => "infobox", |
2785 | id => "infobox", |
2776 | title => "Skills", |
2786 | title => "Skills", |
2777 | reply => undef, |
2787 | reply => undef, |
2778 | tooltip => "Shows your experience per skill and item power", |
2788 | tooltip => "Shows your experience per skill and item power", |
|
|
2789 | }, |
|
|
2790 | "c/shopitems" => { |
|
|
2791 | id => "infobox", |
|
|
2792 | title => "Shop Items", |
|
|
2793 | reply => undef, |
|
|
2794 | tooltip => "Shows the items currently for sale in this shop", |
|
|
2795 | }, |
|
|
2796 | "c/resistances" => { |
|
|
2797 | id => "infobox", |
|
|
2798 | title => "Resistances", |
|
|
2799 | reply => undef, |
|
|
2800 | tooltip => "Shows your resistances", |
|
|
2801 | }, |
|
|
2802 | "c/pets" => { |
|
|
2803 | id => "infobox", |
|
|
2804 | title => "Pets", |
|
|
2805 | reply => undef, |
|
|
2806 | tooltip => "Shows information abotu your pets/a specific pet", |
2779 | }, |
2807 | }, |
2780 | "c/uptime" => { |
2808 | "c/uptime" => { |
2781 | id => "infobox", |
2809 | id => "infobox", |
2782 | title => "Uptime", |
2810 | title => "Uptime", |
2783 | reply => undef, |
2811 | reply => undef, |
… | |
… | |
2793 | id => "party", |
2821 | id => "party", |
2794 | title => "Party", |
2822 | title => "Party", |
2795 | reply => "gsay ", |
2823 | reply => "gsay ", |
2796 | tooltip => "Messages and chat related to your party", |
2824 | tooltip => "Messages and chat related to your party", |
2797 | }, |
2825 | }, |
|
|
2826 | "c/death" => { |
|
|
2827 | id => "death", |
|
|
2828 | title => "Death", |
|
|
2829 | reply => undef, |
|
|
2830 | tooltip => "Reason for and more info about your most recent death", |
|
|
2831 | }, |
2798 | "c/say" => $SAY_CHANNEL, |
2832 | "c/say" => $SAY_CHANNEL, |
2799 | "c/chat" => $CHAT_CHANNEL, |
2833 | "c/chat" => $CHAT_CHANNEL, |
2800 | ); |
2834 | ); |
2801 | |
2835 | |
2802 | sub cf::client::send_msg { |
2836 | sub cf::client::send_msg { |
… | |
… | |
3028 | The following functions and methods are available within a safe environment: |
3062 | The following functions and methods are available within a safe environment: |
3029 | |
3063 | |
3030 | cf::object |
3064 | cf::object |
3031 | contr pay_amount pay_player map x y force_find force_add destroy |
3065 | contr pay_amount pay_player map x y force_find force_add destroy |
3032 | insert remove name archname title slaying race decrease split |
3066 | insert remove name archname title slaying race decrease split |
|
|
3067 | value |
3033 | |
3068 | |
3034 | cf::object::player |
3069 | cf::object::player |
3035 | player |
3070 | player |
3036 | |
3071 | |
3037 | cf::player |
3072 | cf::player |
… | |
… | |
3043 | =cut |
3078 | =cut |
3044 | |
3079 | |
3045 | for ( |
3080 | for ( |
3046 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3081 | ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y |
3047 | insert remove inv nrof name archname title slaying race |
3082 | insert remove inv nrof name archname title slaying race |
3048 | decrease split destroy change_exp)], |
3083 | decrease split destroy change_exp value msg lore send_msg)], |
3049 | ["cf::object::player" => qw(player)], |
3084 | ["cf::object::player" => qw(player)], |
3050 | ["cf::player" => qw(peaceful)], |
3085 | ["cf::player" => qw(peaceful send_msg)], |
3051 | ["cf::map" => qw(trigger)], |
3086 | ["cf::map" => qw(trigger)], |
3052 | ) { |
3087 | ) { |
3053 | no strict 'refs'; |
3088 | no strict 'refs'; |
3054 | my ($pkg, @funs) = @$_; |
3089 | my ($pkg, @funs) = @$_; |
3055 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
3090 | *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
… | |
… | |
3072 | my ($code, %vars) = @_; |
3107 | my ($code, %vars) = @_; |
3073 | |
3108 | |
3074 | my $qcode = $code; |
3109 | my $qcode = $code; |
3075 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3110 | $qcode =~ s/"/‟/g; # not allowed in #line filenames |
3076 | $qcode =~ s/\n/\\n/g; |
3111 | $qcode =~ s/\n/\\n/g; |
|
|
3112 | |
|
|
3113 | %vars = (_dummy => 0) unless %vars; |
3077 | |
3114 | |
3078 | local $_; |
3115 | local $_; |
3079 | local @safe::cf::_safe_eval_args = values %vars; |
3116 | local @safe::cf::_safe_eval_args = values %vars; |
3080 | |
3117 | |
3081 | my $eval = |
3118 | my $eval = |
… | |
… | |
3669 | clear_package "safe::$_" |
3706 | clear_package "safe::$_" |
3670 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3707 | for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); |
3671 | |
3708 | |
3672 | warn "unloading cf.pm \"a bit\""; |
3709 | warn "unloading cf.pm \"a bit\""; |
3673 | delete $INC{"cf.pm"}; |
3710 | delete $INC{"cf.pm"}; |
3674 | delete $INC{"cf/pod.pm"}; |
3711 | delete $INC{"cf/$_.pm"} for @EXTRA_MODULES; |
3675 | |
3712 | |
3676 | # don't, removes xs symbols, too, |
3713 | # don't, removes xs symbols, too, |
3677 | # and global variables created in xs |
3714 | # and global variables created in xs |
3678 | #clear_package __PACKAGE__; |
3715 | #clear_package __PACKAGE__; |
3679 | |
3716 | |
… | |
… | |
3896 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3933 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3897 | } |
3934 | } |
3898 | } |
3935 | } |
3899 | |
3936 | |
3900 | # load additional modules |
3937 | # load additional modules |
3901 | use cf::pod; |
3938 | require "cf/$_.pm" for @EXTRA_MODULES; |
3902 | |
3939 | |
3903 | END { cf::emergency_save } |
3940 | END { cf::emergency_save } |
3904 | |
3941 | |
3905 | 1 |
3942 | 1 |
3906 | |
3943 | |