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.86 by root, Thu Dec 14 05:09:32 2006 UTC vs.
Revision 1.91 by elmex, Sun Dec 17 22:03:44 2006 UTC

16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode? 16# work around bug in YAML::Syck - bad news for perl6, will it be as broken wrt. unicode?
17$YAML::Syck::ImplicitUnicode = 1; 17$YAML::Syck::ImplicitUnicode = 1;
18 18
19use strict; 19use strict;
20 20
21sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
22
21our %COMMAND = (); 23our %COMMAND = ();
22our %COMMAND_TIME = (); 24our %COMMAND_TIME = ();
23our %EXTCMD = (); 25our %EXTCMD = ();
24 26
25_init_vars; 27_init_vars;
26 28
27our @EVENT; 29our @EVENT;
28our $LIBDIR = maps_directory "perl"; 30our $LIBDIR = datadir . "/ext";
29 31
30our $TICK = MAX_TIME * 1e-6; 32our $TICK = MAX_TIME * 1e-6;
31our $TICK_WATCHER; 33our $TICK_WATCHER;
32our $NEXT_TICK; 34our $NEXT_TICK;
33 35
78 80
79# we bless all objects into (empty) derived classes to force a method lookup 81# we bless all objects into (empty) derived classes to force a method lookup
80# within the Safe compartment. 82# within the Safe compartment.
81for my $pkg (qw( 83for my $pkg (qw(
82 cf::object cf::object::player 84 cf::object cf::object::player
83 cf::client_socket cf::player 85 cf::client cf::player
84 cf::arch cf::living 86 cf::arch cf::living
85 cf::map cf::party cf::region 87 cf::map cf::party cf::region
86)) { 88)) {
87 no strict 'refs'; 89 no strict 'refs';
88 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 90 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
718 720
719 Symbol::delete_package $pkg; 721 Symbol::delete_package $pkg;
720} 722}
721 723
722sub load_extensions { 724sub load_extensions {
723 my $LIBDIR = maps_directory "perl";
724
725 for my $ext (<$LIBDIR/*.ext>) { 725 for my $ext (<$LIBDIR/*.ext>) {
726 next unless -r $ext; 726 next unless -r $ext;
727 eval { 727 eval {
728 load_extension $ext; 728 load_extension $ext;
729 1 729 1
864 864
865=pod 865=pod
866 866
867The following fucntions and emthods are available within a safe environment: 867The following fucntions and emthods are available within a safe environment:
868 868
869 cf::object contr pay_amount pay_player 869 cf::object contr pay_amount pay_player map
870 cf::object::player player 870 cf::object::player player
871 cf::player peaceful 871 cf::player peaceful
872 cf::map trigger
872 873
873=cut 874=cut
874 875
875for ( 876for (
876 ["cf::object" => qw(contr pay_amount pay_player)], 877 ["cf::object" => qw(contr pay_amount pay_player map)],
877 ["cf::object::player" => qw(player)], 878 ["cf::object::player" => qw(player)],
878 ["cf::player" => qw(peaceful)], 879 ["cf::player" => qw(peaceful)],
880 ["cf::map" => qw(trigger)],
879) { 881) {
880 no strict 'refs'; 882 no strict 'refs';
881 my ($pkg, @funs) = @$_; 883 my ($pkg, @funs) = @$_;
882 *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) 884 *{"safe::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"})
883 for @funs; 885 for @funs;
1023 sub db_sync() { 1025 sub db_sync() {
1024 db_save if $dirty; 1026 db_save if $dirty;
1025 undef $dirty; 1027 undef $dirty;
1026 } 1028 }
1027 1029
1028 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, cb => sub { 1030 my $idle = Event->idle (min => $TICK * 2.8, max => 10, repeat => 0, data => WF_AUTOCANCEL, cb => sub {
1029 db_sync; 1031 db_sync;
1030 }); 1032 });
1031 1033
1032 sub db_dirty() { 1034 sub db_dirty() {
1033 $dirty = 1; 1035 $dirty = 1;
1083 1085
1084 $msg->("reloading..."); 1086 $msg->("reloading...");
1085 1087
1086 eval { 1088 eval {
1087 # cancel all watchers 1089 # cancel all watchers
1088 $_->cancel for Event::all_watchers; 1090 for (Event::all_watchers) {
1091 $_->cancel if $_->data & WF_AUTOCANCEL;
1092 }
1089 1093
1090 # unload all extensions 1094 # unload all extensions
1091 for (@exts) { 1095 for (@exts) {
1092 $msg->("unloading <$_>"); 1096 $msg->("unloading <$_>");
1093 unload_extension $_; 1097 unload_extension $_;
1169}; 1173};
1170 1174
1171unshift @INC, $LIBDIR; 1175unshift @INC, $LIBDIR;
1172 1176
1173$TICK_WATCHER = Event->timer ( 1177$TICK_WATCHER = Event->timer (
1174 prio => 1, 1178 prio => 0,
1175 async => 1,
1176 at => $NEXT_TICK || 1, 1179 at => $NEXT_TICK || 1,
1180 data => WF_AUTOCANCEL,
1177 cb => sub { 1181 cb => sub {
1178 cf::server_tick; # one server iteration 1182 cf::server_tick; # one server iteration
1179 1183
1180 my $NOW = Event::time; 1184 my $NOW = Event::time;
1181 $NEXT_TICK += $TICK; 1185 $NEXT_TICK += $TICK;
1191IO::AIO::max_poll_time $TICK * 0.2; 1195IO::AIO::max_poll_time $TICK * 0.2;
1192 1196
1193Event->io (fd => IO::AIO::poll_fileno, 1197Event->io (fd => IO::AIO::poll_fileno,
1194 poll => 'r', 1198 poll => 'r',
1195 prio => 5, 1199 prio => 5,
1200 data => WF_AUTOCANCEL,
1196 cb => \&IO::AIO::poll_cb); 1201 cb => \&IO::AIO::poll_cb);
1197 1202
11981 12031
1199 1204

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines