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.466 by root, Thu Jan 8 03:03:24 2009 UTC vs.
Revision 1.478 by root, Thu Sep 17 01:57:31 2009 UTC

72 72
73# make sure c-lzf reinitialises itself 73# make sure c-lzf reinitialises itself
74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; 74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve";
75Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later 75Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later
76 76
77# strictly for debugging
78$SIG{QUIT} = sub { Carp::cluck "SIGQUIT" };
79
77sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 80sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
78 81
79our %COMMAND = (); 82our %COMMAND = ();
80our %COMMAND_TIME = (); 83our %COMMAND_TIME = ();
81 84
105our %RESOURCE; 108our %RESOURCE;
106 109
107our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 110our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
108our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 111our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
109our $NEXT_TICK; 112our $NEXT_TICK;
110our $USE_FSYNC = 1; # use fsync to write maps - default off 113our $USE_FSYNC = 1; # use fsync to write maps - default on
111 114
112our $BDB_DEADLOCK_WATCHER; 115our $BDB_DEADLOCK_WATCHER;
113our $BDB_CHECKPOINT_WATCHER; 116our $BDB_CHECKPOINT_WATCHER;
114our $BDB_TRICKLE_WATCHER; 117our $BDB_TRICKLE_WATCHER;
115our $DB_ENV; 118our $DB_ENV;
134our $JITTER; # average jitter 137our $JITTER; # average jitter
135our $TICK_START; # for load detecting purposes 138our $TICK_START; # for load detecting purposes
136 139
137our @POST_INIT; 140our @POST_INIT;
138 141
139our $REATTACH_ON_RELOAD; # ste to true to force object reattach on reload (slow) 142our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow)
143our $REALLY_UNLOOP; # never set to true, please :)
140 144
141binmode STDOUT; 145binmode STDOUT;
142binmode STDERR; 146binmode STDERR;
143 147
144# read virtual server time, if available 148# read virtual server time, if available
146 open my $fh, "<", $RUNTIMEFILE 150 open my $fh, "<", $RUNTIMEFILE
147 or die "unable to read $RUNTIMEFILE file: $!"; 151 or die "unable to read $RUNTIMEFILE file: $!";
148 $RUNTIME = <$fh> + 0.; 152 $RUNTIME = <$fh> + 0.;
149} 153}
150 154
155eval "sub TICK() { $TICK } 1" or die;
156
151mkdir $_ 157mkdir $_
152 for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; 158 for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR;
153 159
154our $EMERGENCY_POSITION; 160our $EMERGENCY_POSITION;
155 161
216 222
217=back 223=back
218 224
219=cut 225=cut
220 226
221BEGIN { 227$Coro::State::WARNHOOK = sub {
222 *CORE::GLOBAL::warn = sub {
223 my $msg = join "", @_; 228 my $msg = join "", @_;
224 229
225 $msg .= "\n" 230 $msg .= "\n"
226 unless $msg =~ /\n$/; 231 unless $msg =~ /\n$/;
227 232
228 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 233 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
229 234
230 LOG llevError, $msg; 235 LOG llevError, $msg;
231 }; 236};
232}
233 237
234$Coro::State::DIEHOOK = sub { 238$Coro::State::DIEHOOK = sub {
235 return unless $^S eq 0; # "eq", not "==" 239 return unless $^S eq 0; # "eq", not "=="
240
241 warn Carp::longmess $_[0];
236 242
237 if ($Coro::current == $Coro::main) {#d# 243 if ($Coro::current == $Coro::main) {#d#
238 warn "DIEHOOK called in main context, Coro bug?\n";#d# 244 warn "DIEHOOK called in main context, Coro bug?\n";#d#
239 return;#d# 245 return;#d#
240 }#d# 246 }#d#
241 247
242 # kill coroutine otherwise 248 # kill coroutine otherwise
243 warn Carp::longmess $_[0];
244 Coro::terminate 249 Coro::terminate
245}; 250};
246
247$SIG{__DIE__} = sub { }; #d#?
248 251
249@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 252@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
250@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 253@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
251@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 254@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
252@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 255@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
1149 $decname, length $$rdata, scalar @$objs; 1152 $decname, length $$rdata, scalar @$objs;
1150 1153
1151 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1154 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1152 aio_chmod $fh, SAVE_MODE; 1155 aio_chmod $fh, SAVE_MODE;
1153 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1156 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1154 aio_fsync $fh if $cf::USE_FSYNC; 1157 if ($cf::USE_FSYNC) {
1158 aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER;
1159 aio_fsync $fh;
1160 }
1155 aio_close $fh; 1161 aio_close $fh;
1156 1162
1157 if (@$objs) { 1163 if (@$objs) {
1158 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1164 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1159 aio_chmod $fh, SAVE_MODE; 1165 aio_chmod $fh, SAVE_MODE;
1160 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; 1166 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1161 aio_write $fh, 0, (length $data), $data, 0; 1167 aio_write $fh, 0, (length $data), $data, 0;
1162 aio_fsync $fh if $cf::USE_FSYNC; 1168 if ($cf::USE_FSYNC) {
1169 aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER;
1170 aio_fsync $fh;
1171 }
1163 aio_close $fh; 1172 aio_close $fh;
1164 aio_rename "$filename.pst~", "$filename.pst"; 1173 aio_rename "$filename.pst~", "$filename.pst";
1165 } 1174 }
1166 } else { 1175 } else {
1167 aio_unlink "$filename.pst"; 1176 aio_unlink "$filename.pst";
1318 1327
1319# "readahead" all extensions 1328# "readahead" all extensions
1320sub cache_extensions { 1329sub cache_extensions {
1321 my $grp = IO::AIO::aio_group; 1330 my $grp = IO::AIO::aio_group;
1322 1331
1323 add $grp IO::AIO::aio_readdir $LIBDIR, sub { 1332 add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub {
1324 for (grep /\.ext$/, @{$_[0]}) { 1333 for (grep /\.ext$/, @{$_[0]}) {
1325 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; 1334 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data;
1326 } 1335 }
1327 }; 1336 };
1328 1337
2211 2220
2212 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2221 my $lock = cf::lock_acquire "map_data:$self->{path}";
2213 2222
2214 return if $self->players; 2223 return if $self->players;
2215 2224
2216 warn "resetting map ", $self->path; 2225 warn "resetting map ", $self->path, "\n";
2217 2226
2218 $self->in_memory (cf::MAP_SWAPPED); 2227 $self->in_memory (cf::MAP_SWAPPED);
2219 2228
2220 # need to save uniques path 2229 # need to save uniques path
2221 unless ($self->{deny_save}) { 2230 unless ($self->{deny_save}) {
2386 2395
2387our $SAY_CHANNEL = { 2396our $SAY_CHANNEL = {
2388 id => "say", 2397 id => "say",
2389 title => "Map", 2398 title => "Map",
2390 reply => "say ", 2399 reply => "say ",
2391 tooltip => "Things said to and replied from npcs near you and other players on the same map only.", 2400 tooltip => "Things said to and replied from NPCs near you and other players on the same map only.",
2392}; 2401};
2393 2402
2394our $CHAT_CHANNEL = { 2403our $CHAT_CHANNEL = {
2395 id => "chat", 2404 id => "chat",
2396 title => "Chat", 2405 title => "Chat",
2522 2531
2523 $map->load; 2532 $map->load;
2524 $map->load_neighbours; 2533 $map->load_neighbours;
2525 2534
2526 return unless $self->contr->active; 2535 return unless $self->contr->active;
2527 $self->flag (cf::FLAG_DEBUG, 0);#d# temp
2528 $self->activate_recursive;
2529 2536
2530 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2537 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2531 $self->enter_map ($map, $x, $y); 2538 $self->enter_map ($map, $x, $y);
2539
2540 # only activate afterwards, to support waiting in hooks
2541 $self->activate_recursive;
2532} 2542}
2533 2543
2534=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) 2544=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]])
2535 2545
2536Moves the player to the given map-path and coordinates by first freezing 2546Moves the player to the given map-path and coordinates by first freezing
2783 id => "infobox", 2793 id => "infobox",
2784 title => "Skills", 2794 title => "Skills",
2785 reply => undef, 2795 reply => undef,
2786 tooltip => "Shows your experience per skill and item power", 2796 tooltip => "Shows your experience per skill and item power",
2787 }, 2797 },
2798 "c/shopitems" => {
2799 id => "infobox",
2800 title => "Shop Items",
2801 reply => undef,
2802 tooltip => "Shows the items currently for sale in this shop",
2803 },
2788 "c/resistances" => { 2804 "c/resistances" => {
2789 id => "infobox", 2805 id => "infobox",
2790 title => "Resistances", 2806 title => "Resistances",
2791 reply => undef, 2807 reply => undef,
2792 tooltip => "Shows your resistances", 2808 tooltip => "Shows your resistances",
2794 "c/pets" => { 2810 "c/pets" => {
2795 id => "infobox", 2811 id => "infobox",
2796 title => "Pets", 2812 title => "Pets",
2797 reply => undef, 2813 reply => undef,
2798 tooltip => "Shows information abotu your pets/a specific pet", 2814 tooltip => "Shows information abotu your pets/a specific pet",
2815 },
2816 "c/perceiveself" => {
2817 id => "infobox",
2818 title => "Perceive Self",
2819 reply => undef,
2820 tooltip => "You gained detailed knowledge about yourself",
2799 }, 2821 },
2800 "c/uptime" => { 2822 "c/uptime" => {
2801 id => "infobox", 2823 id => "infobox",
2802 title => "Uptime", 2824 title => "Uptime",
2803 reply => undef, 2825 reply => undef,
3380 3402
3381 seek $fh, 0, 0; 3403 seek $fh, 0, 0;
3382 print $fh $$; 3404 print $fh $$;
3383} 3405}
3384 3406
3407sub main_loop {
3408 warn "EV::loop starting\n";
3409 if (1) {
3410 EV::loop;
3411 }
3412 warn "EV::loop returned\n";
3413 goto &main_loop unless $REALLY_UNLOOP;
3414}
3415
3385sub main { 3416sub main {
3386 cf::init_globals; # initialise logging 3417 cf::init_globals; # initialise logging
3387 3418
3388 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3419 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3389 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3420 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3427 load_extensions; 3458 load_extensions;
3428 3459
3429 utime time, time, $RUNTIMEFILE; 3460 utime time, time, $RUNTIMEFILE;
3430 3461
3431 # no (long-running) fork's whatsoever before this point(!) 3462 # no (long-running) fork's whatsoever before this point(!)
3463 use POSIX ();
3432 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3464 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3433 3465
3434 (pop @POST_INIT)->(0) while @POST_INIT; 3466 (pop @POST_INIT)->(0) while @POST_INIT;
3435 }; 3467 };
3436 3468
3437 EV::loop; 3469 main_loop;
3438} 3470}
3439 3471
3440############################################################################# 3472#############################################################################
3441# initialisation and cleanup 3473# initialisation and cleanup
3442 3474
3925 LOG llevInfo, "[ABT] [suppressed]\n"; 3957 LOG llevInfo, "[ABT] [suppressed]\n";
3926 } 3958 }
3927} 3959}
3928 3960
3929# load additional modules 3961# load additional modules
3930eval "use cf::$_" for @EXTRA_MODULES; 3962require "cf/$_.pm" for @EXTRA_MODULES;
3931 3963
3932END { cf::emergency_save } 3964END { cf::emergency_save }
3933 3965
39341 39661
3935 3967

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines