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.199 by root, Mon Jan 29 14:46:01 2007 UTC vs.
Revision 1.203 by root, Thu Feb 1 19:40:42 2007 UTC

776 } 776 }
777 } else { 777 } else {
778 aio_unlink $filename; 778 aio_unlink $filename;
779 aio_unlink "$filename.pst"; 779 aio_unlink "$filename.pst";
780 } 780 }
781
782 #d##TODO# nuke non .map-files if exist
783 if ($filename =~ s/\.map$//) {
784 aio_unlink $filename;
785 aio_unlink "$filename.pst";
786 }
781 } 787 }
782} 788}
783 789
784sub object_freezer_as_string { 790sub object_freezer_as_string {
785 my ($rdata, $objs) = @_; 791 my ($rdata, $objs) = @_;
791 797
792sub object_thawer_load { 798sub object_thawer_load {
793 my ($filename) = @_; 799 my ($filename) = @_;
794 800
795 my ($data, $av); 801 my ($data, $av);
802
803 #d#TODO remove .map if file does not exist
804 aio_stat $filename and $filename =~ s/\.map$//;
796 805
797 (aio_load $filename, $data) >= 0 806 (aio_load $filename, $data) >= 0
798 or return; 807 or return;
799 808
800 unless (aio_stat "$filename.pst") { 809 unless (aio_stat "$filename.pst") {
1070=cut 1079=cut
1071 1080
1072sub maps($) { 1081sub maps($) {
1073 my ($pl) = @_; 1082 my ($pl) = @_;
1074 1083
1084 $pl = ref $pl ? $pl->ob->name : $pl;
1085
1075 my $files = aio_readdir playerdir $pl 1086 my $files = aio_readdir playerdir $pl
1076 or return; 1087 or return;
1077 1088
1078 my @paths; 1089 my @paths;
1079 1090
1080 for (@$files) { 1091 for (@$files) {
1081 utf8::decode $_; 1092 utf8::decode $_;
1082 next if /\.(?:pl|pst)$/; 1093 next if /\.(?:pl|pst)$/;
1083 next unless /^$PATH_SEP/o; 1094 next unless /^$PATH_SEP/o;
1084 1095
1085 push @paths, cf::map::normalise "~" . $pl->ob->name . "/" . $_; 1096 push @paths, cf::map::normalise "~$pl/$_";
1086 } 1097 }
1087 1098
1088 \@paths 1099 \@paths
1089} 1100}
1090 1101
1251 1262
1252# the original (read-only) location 1263# the original (read-only) location
1253sub load_path { 1264sub load_path {
1254 my ($self) = @_; 1265 my ($self) = @_;
1255 1266
1256 sprintf "%s/%s/%s", cf::datadir, cf::mapdir, $self->{path} 1267 sprintf "%s/%s/%s.map", cf::datadir, cf::mapdir, $self->{path}
1257} 1268}
1258 1269
1259# the temporary/swap location 1270# the temporary/swap location
1260sub save_path { 1271sub save_path {
1261 my ($self) = @_; 1272 my ($self) = @_;
1262 1273
1263 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; 1274 (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g;
1264 sprintf "%s/%s/%s", cf::localdir, cf::tmpdir, $path 1275 sprintf "%s/%s/%s.map", cf::localdir, cf::tmpdir, $path
1265} 1276}
1266 1277
1267# the unique path, undef == no special unique path 1278# the unique path, undef == no special unique path
1268sub uniq_path { 1279sub uniq_path {
1269 my ($self) = @_; 1280 my ($self) = @_;
1285 my ($self) = @_; 1296 my ($self) = @_;
1286 1297
1287 utf8::encode (my $save = $self->save_path); 1298 utf8::encode (my $save = $self->save_path);
1288 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save; 1299 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;
1289 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst"; 1300 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst";
1301
1302 #d#TODO remove .map and also nuke
1303 $save =~ s/\.map// or return;#d#
1304 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save;#d#
1305 IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink "$save.pst";#d#
1290} 1306}
1291 1307
1292sub load_header_from($) { 1308sub load_header_from($) {
1293 my ($self, $path) = @_; 1309 my ($self, $path) = @_;
1294 1310
1295 utf8::encode $path; 1311 utf8::encode $path;
1296 aio_open $path, O_RDONLY, 0 1312 #aio_open $path, O_RDONLY, 0
1297 or return; 1313 # or return;
1298 1314
1299 $self->_load_header ($path) 1315 $self->_load_header ($path)
1300 or return; 1316 or return;
1301 1317
1302 $self->{load_path} = $path; 1318 $self->{load_path} = $path;
1987 # get handled first 2003 # get handled first
1988 my $queue = delete $ns->{query_queue} 2004 my $queue = delete $ns->{query_queue}
1989 or return; # be conservative, not sure how that can happen, but we saw a crash here 2005 or return; # be conservative, not sure how that can happen, but we saw a crash here
1990 2006
1991 (shift @$queue)->[1]->($msg); 2007 (shift @$queue)->[1]->($msg);
2008 return unless $ns->valid; # temporary(?) workaround for callback destroying socket
1992 2009
1993 push @{ $ns->{query_queue} }, @$queue; 2010 push @{ $ns->{query_queue} }, @$queue;
1994 2011
1995 if (@{ $ns->{query_queue} } == @$queue) { 2012 if (@{ $ns->{query_queue} } == @$queue) {
1996 if (@$queue) { 2013 if (@$queue) {
2253 }, 2270 },
2254 ); 2271 );
2255} 2272}
2256 2273
2257############################################################################# 2274#############################################################################
2258# the server's main() 2275# the server's init and main functions
2276
2277sub load_resources {
2278 load_regions sprintf "%s/%s/regions", cf::datadir, cf::mapdir
2279 or die "unable to load regions file\n";#d#
2280}
2259 2281
2260sub cfg_load { 2282sub cfg_load {
2261 open my $fh, "<:utf8", cf::confdir . "/config" 2283 open my $fh, "<:utf8", cf::confdir . "/config"
2262 or return; 2284 or return;
2263 2285
2274 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" 2296 $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()"
2275 and die "WARNING: m(un)lockall failed: $!\n"; 2297 and die "WARNING: m(un)lockall failed: $!\n";
2276 }; 2298 };
2277 warn $@ if $@; 2299 warn $@ if $@;
2278 } 2300 }
2301}
2302
2303sub init {
2304 load_resources;
2279} 2305}
2280 2306
2281sub main { 2307sub main {
2282 # we must not ever block the main coroutine 2308 # we must not ever block the main coroutine
2283 local $Coro::idle = sub { 2309 local $Coro::idle = sub {
2444 warn "reattaching attachments to objects/players"; 2470 warn "reattaching attachments to objects/players";
2445 _global_reattach; 2471 _global_reattach;
2446 warn "reattaching attachments to maps"; 2472 warn "reattaching attachments to maps";
2447 reattach $_ for values %MAP; 2473 reattach $_ for values %MAP;
2448 2474
2475 warn "loading reloadable resources";
2476 load_resources;
2477
2449 warn "restarting server ticker"; 2478 warn "restarting server ticker";
2450 2479
2451 $TICK_WATCHER->start; 2480 $TICK_WATCHER->start;
2452 }; 2481 };
2453 2482

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines