ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.465 by root, Thu Jan 8 00:54:55 2009 UTC vs.
Revision 1.472 by root, Sat Jun 6 21:43:13 2009 UTC

21 21
22package cf; 22package cf;
23 23
24use 5.10.0; 24use 5.10.0;
25use utf8; 25use utf8;
26use strict "vars", "subs"; 26use strict qw(vars subs);
27 27
28use Symbol; 28use Symbol;
29use List::Util; 29use List::Util;
30use Socket; 30use Socket;
31use EV; 31use EV;
105our %RESOURCE; 105our %RESOURCE;
106 106
107our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 107our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
108our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 108our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
109our $NEXT_TICK; 109our $NEXT_TICK;
110our $USE_FSYNC = 1; # use fsync to write maps - default off 110our $USE_FSYNC = 1; # use fsync to write maps - default on
111 111
112our $BDB_DEADLOCK_WATCHER; 112our $BDB_DEADLOCK_WATCHER;
113our $BDB_CHECKPOINT_WATCHER; 113our $BDB_CHECKPOINT_WATCHER;
114our $BDB_TRICKLE_WATCHER; 114our $BDB_TRICKLE_WATCHER;
115our $DB_ENV; 115our $DB_ENV;
116
117our @EXTRA_MODULES = qw(pod mapscript);
116 118
117our %CFG; 119our %CFG;
118 120
119our $UPTIME; $UPTIME ||= time; 121our $UPTIME; $UPTIME ||= time;
120our $RUNTIME; 122our $RUNTIME;
143unless ($RUNTIME || !-e $RUNTIMEFILE) { 145unless ($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
151eval "sub TICK() { $TICK } 1" or die;
148 152
149mkdir $_ 153mkdir $_
150 for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; 154 for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR;
151 155
152our $EMERGENCY_POSITION; 156our $EMERGENCY_POSITION;
1316 1320
1317# "readahead" all extensions 1321# "readahead" all extensions
1318sub cache_extensions { 1322sub cache_extensions {
1319 my $grp = IO::AIO::aio_group; 1323 my $grp = IO::AIO::aio_group;
1320 1324
1321 add $grp IO::AIO::aio_readdir $LIBDIR, sub { 1325 add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub {
1322 for (grep /\.ext$/, @{$_[0]}) { 1326 for (grep /\.ext$/, @{$_[0]}) {
1323 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; 1327 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data;
1324 } 1328 }
1325 }; 1329 };
1326 1330
2384 2388
2385our $SAY_CHANNEL = { 2389our $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
2392our $CHAT_CHANNEL = { 2396our $CHAT_CHANNEL = {
2393 id => "chat", 2397 id => "chat",
2394 title => "Chat", 2398 title => "Chat",
2781 id => "infobox", 2785 id => "infobox",
2782 title => "Skills", 2786 title => "Skills",
2783 reply => undef, 2787 reply => undef,
2784 tooltip => "Shows your experience per skill and item power", 2788 tooltip => "Shows your experience per skill and item power",
2785 }, 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 },
2786 "c/resistances" => { 2796 "c/resistances" => {
2787 id => "infobox", 2797 id => "infobox",
2788 title => "Resistances", 2798 title => "Resistances",
2789 reply => undef, 2799 reply => undef,
2790 tooltip => "Shows your resistances", 2800 tooltip => "Shows your resistances",
2792 "c/pets" => { 2802 "c/pets" => {
2793 id => "infobox", 2803 id => "infobox",
2794 title => "Pets", 2804 title => "Pets",
2795 reply => undef, 2805 reply => undef,
2796 tooltip => "Shows information abotu your pets/a specific pet", 2806 tooltip => "Shows information abotu your pets/a specific pet",
2807 },
2808 "c/perceiveself" => {
2809 id => "infobox",
2810 title => "Perceive Self",
2811 reply => undef,
2812 tooltip => "You gained detailed knowledge about yourself",
2797 }, 2813 },
2798 "c/uptime" => { 2814 "c/uptime" => {
2799 id => "infobox", 2815 id => "infobox",
2800 title => "Uptime", 2816 title => "Uptime",
2801 reply => undef, 2817 reply => undef,
3052The following functions and methods are available within a safe environment: 3068The following functions and methods are available within a safe environment:
3053 3069
3054 cf::object 3070 cf::object
3055 contr pay_amount pay_player map x y force_find force_add destroy 3071 contr pay_amount pay_player map x y force_find force_add destroy
3056 insert remove name archname title slaying race decrease split 3072 insert remove name archname title slaying race decrease split
3073 value
3057 3074
3058 cf::object::player 3075 cf::object::player
3059 player 3076 player
3060 3077
3061 cf::player 3078 cf::player
3067=cut 3084=cut
3068 3085
3069for ( 3086for (
3070 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y 3087 ["cf::object" => qw(contr pay_amount pay_player map force_find force_add x y
3071 insert remove inv nrof name archname title slaying race 3088 insert remove inv nrof name archname title slaying race
3072 decrease split destroy change_exp)], 3089 decrease split destroy change_exp value msg lore send_msg)],
3073 ["cf::object::player" => qw(player)], 3090 ["cf::object::player" => qw(player)],
3074 ["cf::player" => qw(peaceful)], 3091 ["cf::player" => qw(peaceful send_msg)],
3075 ["cf::map" => qw(trigger)], 3092 ["cf::map" => qw(trigger)],
3076) { 3093) {
3077 no strict 'refs'; 3094 no strict 'refs';
3078 my ($pkg, @funs) = @$_; 3095 my ($pkg, @funs) = @$_;
3079 *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) 3096 *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"})
3096 my ($code, %vars) = @_; 3113 my ($code, %vars) = @_;
3097 3114
3098 my $qcode = $code; 3115 my $qcode = $code;
3099 $qcode =~ s/"/‟/g; # not allowed in #line filenames 3116 $qcode =~ s/"/‟/g; # not allowed in #line filenames
3100 $qcode =~ s/\n/\\n/g; 3117 $qcode =~ s/\n/\\n/g;
3118
3119 %vars = (_dummy => 0) unless %vars;
3101 3120
3102 local $_; 3121 local $_;
3103 local @safe::cf::_safe_eval_args = values %vars; 3122 local @safe::cf::_safe_eval_args = values %vars;
3104 3123
3105 my $eval = 3124 my $eval =
3693 clear_package "safe::$_" 3712 clear_package "safe::$_"
3694 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region); 3713 for qw(cf::attachable cf::object cf::object::player cf::client cf::player cf::map cf::party cf::region);
3695 3714
3696 warn "unloading cf.pm \"a bit\""; 3715 warn "unloading cf.pm \"a bit\"";
3697 delete $INC{"cf.pm"}; 3716 delete $INC{"cf.pm"};
3698 delete $INC{"cf/pod.pm"}; 3717 delete $INC{"cf/$_.pm"} for @EXTRA_MODULES;
3699 3718
3700 # don't, removes xs symbols, too, 3719 # don't, removes xs symbols, too,
3701 # and global variables created in xs 3720 # and global variables created in xs
3702 #clear_package __PACKAGE__; 3721 #clear_package __PACKAGE__;
3703 3722
3920 LOG llevInfo, "[ABT] [suppressed]\n"; 3939 LOG llevInfo, "[ABT] [suppressed]\n";
3921 } 3940 }
3922} 3941}
3923 3942
3924# load additional modules 3943# load additional modules
3925use cf::pod; 3944require "cf/$_.pm" for @EXTRA_MODULES;
3926 3945
3927END { cf::emergency_save } 3946END { cf::emergency_save }
3928 3947
39291 39481
3930 3949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines