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.200 by root, Mon Jan 29 17:57:22 2007 UTC vs.
Revision 1.205 by root, Mon Feb 5 18:29:20 2007 UTC

48our $TICK_WATCHER; 48our $TICK_WATCHER;
49our $AIO_POLL_WATCHER; 49our $AIO_POLL_WATCHER;
50our $WRITE_RUNTIME_WATCHER; 50our $WRITE_RUNTIME_WATCHER;
51our $NEXT_TICK; 51our $NEXT_TICK;
52our $NOW; 52our $NOW;
53our $USE_FSYNC = 1; # use fsync to write maps - default off
53 54
54our %CFG; 55our %CFG;
55 56
56our $UPTIME; $UPTIME ||= time; 57our $UPTIME; $UPTIME ||= time;
57our $RUNTIME; 58our $RUNTIME;
358 # 60 allows for the watchdog to kill the server. 359 # 60 allows for the watchdog to kill the server.
359 360
360 (aio_write $fh, 0, (length $value), $value, 0) <= 0 361 (aio_write $fh, 0, (length $value), $value, 0) <= 0
361 and return; 362 and return;
362 363
364 # always fsync - this file is important
363 aio_fsync $fh 365 aio_fsync $fh
364 and return; 366 and return;
365 367
366 close $fh 368 close $fh
367 or return; 369 or return;
752 $filename, length $$rdata, scalar @$objs; 754 $filename, length $$rdata, scalar @$objs;
753 755
754 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 756 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
755 chmod SAVE_MODE, $fh; 757 chmod SAVE_MODE, $fh;
756 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 758 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
757 aio_fsync $fh; 759 aio_fsync $fh if $cf::USE_FSYNC;
758 close $fh; 760 close $fh;
759 761
760 if (@$objs) { 762 if (@$objs) {
761 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 763 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
762 chmod SAVE_MODE, $fh; 764 chmod SAVE_MODE, $fh;
763 my $data = Storable::nfreeze { version => 1, objs => $objs }; 765 my $data = Storable::nfreeze { version => 1, objs => $objs };
764 aio_write $fh, 0, (length $data), $data, 0; 766 aio_write $fh, 0, (length $data), $data, 0;
765 aio_fsync $fh; 767 aio_fsync $fh if $cf::USE_FSYNC;
766 close $fh; 768 close $fh;
767 aio_rename "$filename.pst~", "$filename.pst"; 769 aio_rename "$filename.pst~", "$filename.pst";
768 } 770 }
769 } else { 771 } else {
770 aio_unlink "$filename.pst"; 772 aio_unlink "$filename.pst";
1079=cut 1081=cut
1080 1082
1081sub maps($) { 1083sub maps($) {
1082 my ($pl) = @_; 1084 my ($pl) = @_;
1083 1085
1086 $pl = ref $pl ? $pl->ob->name : $pl;
1087
1084 my $files = aio_readdir playerdir $pl 1088 my $files = aio_readdir playerdir $pl
1085 or return; 1089 or return;
1086 1090
1087 my @paths; 1091 my @paths;
1088 1092
1089 for (@$files) { 1093 for (@$files) {
1090 utf8::decode $_; 1094 utf8::decode $_;
1091 next if /\.(?:pl|pst)$/; 1095 next if /\.(?:pl|pst)$/;
1092 next unless /^$PATH_SEP/o; 1096 next unless /^$PATH_SEP/o;
1093 1097
1094 push @paths, cf::map::normalise "~" . $pl->ob->name . "/" . $_; 1098 push @paths, cf::map::normalise "~$pl/$_";
1095 } 1099 }
1096 1100
1097 \@paths 1101 \@paths
1098} 1102}
1099 1103
2001 # get handled first 2005 # get handled first
2002 my $queue = delete $ns->{query_queue} 2006 my $queue = delete $ns->{query_queue}
2003 or return; # be conservative, not sure how that can happen, but we saw a crash here 2007 or return; # be conservative, not sure how that can happen, but we saw a crash here
2004 2008
2005 (shift @$queue)->[1]->($msg); 2009 (shift @$queue)->[1]->($msg);
2010 return unless $ns->valid; # temporary(?) workaround for callback destroying socket
2006 2011
2007 push @{ $ns->{query_queue} }, @$queue; 2012 push @{ $ns->{query_queue} }, @$queue;
2008 2013
2009 if (@{ $ns->{query_queue} } == @$queue) { 2014 if (@{ $ns->{query_queue} } == @$queue) {
2010 if (@$queue) { 2015 if (@$queue) {
2267 }, 2272 },
2268 ); 2273 );
2269} 2274}
2270 2275
2271############################################################################# 2276#############################################################################
2272# the server's main() 2277# the server's init and main functions
2278
2279sub load_resources {
2280 load_regions sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2281 or die "unable to load regions file\n";#d#
2282}
2273 2283
2274sub cfg_load { 2284sub cfg_load {
2275 open my $fh, "<:utf8", cf::confdir . "/config" 2285 open my $fh, "<:utf8", cf::confdir . "/config"
2276 or return; 2286 or return;
2277 2287
2288 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 2298 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
2289 and die "WARNING: m(un)lockall failed: $!\n"; 2299 and die "WARNING: m(un)lockall failed: $!\n";
2290 }; 2300 };
2291 warn $@ if $@; 2301 warn $@ if $@;
2292 } 2302 }
2303}
2304
2305sub init {
2306 load_resources;
2293} 2307}
2294 2308
2295sub main { 2309sub main {
2296 # we must not ever block the main coroutine 2310 # we must not ever block the main coroutine
2297 local $Coro::idle = sub { 2311 local $Coro::idle = sub {
2458 warn "reattaching attachments to objects/players"; 2472 warn "reattaching attachments to objects/players";
2459 _global_reattach; 2473 _global_reattach;
2460 warn "reattaching attachments to maps"; 2474 warn "reattaching attachments to maps";
2461 reattach $_ for values %MAP; 2475 reattach $_ for values %MAP;
2462 2476
2477 warn "loading reloadable resources";
2478 load_resources;
2479
2463 warn "restarting server ticker"; 2480 warn "restarting server ticker";
2464 2481
2465 $TICK_WATCHER->start; 2482 $TICK_WATCHER->start;
2466 }; 2483 };
2467 2484

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines