… | |
… | |
82 | mkdir cf::localdir . "/" . cf::tmpdir; |
82 | mkdir cf::localdir . "/" . cf::tmpdir; |
83 | mkdir cf::localdir . "/" . cf::uniquedir; |
83 | mkdir cf::localdir . "/" . cf::uniquedir; |
84 | mkdir $RANDOM_MAPS; |
84 | mkdir $RANDOM_MAPS; |
85 | |
85 | |
86 | our $EMERGENCY_POSITION; |
86 | our $EMERGENCY_POSITION; |
|
|
87 | |
|
|
88 | sub cf::map::normalise; |
87 | |
89 | |
88 | ############################################################################# |
90 | ############################################################################# |
89 | |
91 | |
90 | =head2 GLOBAL VARIABLES |
92 | =head2 GLOBAL VARIABLES |
91 | |
93 | |
… | |
… | |
774 | } |
776 | } |
775 | } else { |
777 | } else { |
776 | aio_unlink $filename; |
778 | aio_unlink $filename; |
777 | aio_unlink "$filename.pst"; |
779 | aio_unlink "$filename.pst"; |
778 | } |
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 | } |
779 | } |
787 | } |
780 | } |
788 | } |
781 | |
789 | |
782 | sub object_freezer_as_string { |
790 | sub object_freezer_as_string { |
783 | my ($rdata, $objs) = @_; |
791 | my ($rdata, $objs) = @_; |
… | |
… | |
789 | |
797 | |
790 | sub object_thawer_load { |
798 | sub object_thawer_load { |
791 | my ($filename) = @_; |
799 | my ($filename) = @_; |
792 | |
800 | |
793 | 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$//; |
794 | |
805 | |
795 | (aio_load $filename, $data) >= 0 |
806 | (aio_load $filename, $data) >= 0 |
796 | or return; |
807 | or return; |
797 | |
808 | |
798 | unless (aio_stat "$filename.pst") { |
809 | unless (aio_stat "$filename.pst") { |
… | |
… | |
1068 | =cut |
1079 | =cut |
1069 | |
1080 | |
1070 | sub maps($) { |
1081 | sub maps($) { |
1071 | my ($pl) = @_; |
1082 | my ($pl) = @_; |
1072 | |
1083 | |
|
|
1084 | $pl = ref $pl ? $pl->ob->name : $pl; |
|
|
1085 | |
1073 | my $files = aio_readdir playerdir $pl |
1086 | my $files = aio_readdir playerdir $pl |
1074 | or return; |
1087 | or return; |
1075 | |
1088 | |
1076 | my @paths; |
1089 | my @paths; |
1077 | |
1090 | |
1078 | for (@$files) { |
1091 | for (@$files) { |
1079 | utf8::decode $_; |
1092 | utf8::decode $_; |
1080 | next if /\.(?:pl|pst)$/; |
1093 | next if /\.(?:pl|pst)$/; |
1081 | next unless /^$PATH_SEP/o; |
1094 | next unless /^$PATH_SEP/o; |
1082 | |
1095 | |
1083 | s/\.map$//; |
1096 | push @paths, cf::map::normalise "~$pl/$_"; |
1084 | push @paths, "~" . $pl->ob->name . "/" . $_; |
|
|
1085 | } |
1097 | } |
1086 | |
1098 | |
1087 | \@paths |
1099 | \@paths |
1088 | } |
1100 | } |
1089 | |
1101 | |
… | |
… | |
1178 | sub normalise { |
1190 | sub normalise { |
1179 | my ($path, $base) = @_; |
1191 | my ($path, $base) = @_; |
1180 | |
1192 | |
1181 | $path = "$path"; # make sure its a string |
1193 | $path = "$path"; # make sure its a string |
1182 | |
1194 | |
|
|
1195 | $path =~ s/\.map$//; |
|
|
1196 | |
1183 | # map plan: |
1197 | # map plan: |
1184 | # |
1198 | # |
1185 | # /! non-realised random map exit (special hack!) |
1199 | # /! non-realised random map exit (special hack!) |
1186 | # {... are special paths that are not being touched |
1200 | # {... are special paths that are not being touched |
1187 | # ?xxx/... are special absolute paths |
1201 | # ?xxx/... are special absolute paths |
… | |
… | |
1248 | |
1262 | |
1249 | # the original (read-only) location |
1263 | # the original (read-only) location |
1250 | sub load_path { |
1264 | sub load_path { |
1251 | my ($self) = @_; |
1265 | my ($self) = @_; |
1252 | |
1266 | |
1253 | sprintf "%s/%s/%s", cf::datadir, cf::mapdir, $self->{path} |
1267 | sprintf "%s/%s/%s.map", cf::datadir, cf::mapdir, $self->{path} |
1254 | } |
1268 | } |
1255 | |
1269 | |
1256 | # the temporary/swap location |
1270 | # the temporary/swap location |
1257 | sub save_path { |
1271 | sub save_path { |
1258 | my ($self) = @_; |
1272 | my ($self) = @_; |
1259 | |
1273 | |
1260 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; |
1274 | (my $path = $_[0]{path}) =~ s/\//$PATH_SEP/g; |
1261 | sprintf "%s/%s/%s", cf::localdir, cf::tmpdir, $path |
1275 | sprintf "%s/%s/%s.map", cf::localdir, cf::tmpdir, $path |
1262 | } |
1276 | } |
1263 | |
1277 | |
1264 | # the unique path, undef == no special unique path |
1278 | # the unique path, undef == no special unique path |
1265 | sub uniq_path { |
1279 | sub uniq_path { |
1266 | my ($self) = @_; |
1280 | my ($self) = @_; |
… | |
… | |
1282 | my ($self) = @_; |
1296 | my ($self) = @_; |
1283 | |
1297 | |
1284 | utf8::encode (my $save = $self->save_path); |
1298 | utf8::encode (my $save = $self->save_path); |
1285 | IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save; |
1299 | IO::AIO::aioreq_pri 4; Coro::AIO::aio_unlink $save; |
1286 | 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# |
1287 | } |
1306 | } |
1288 | |
1307 | |
1289 | sub load_header_from($) { |
1308 | sub load_header_from($) { |
1290 | my ($self, $path) = @_; |
1309 | my ($self, $path) = @_; |
1291 | |
1310 | |
1292 | utf8::encode $path; |
1311 | utf8::encode $path; |
1293 | aio_open $path, O_RDONLY, 0 |
1312 | #aio_open $path, O_RDONLY, 0 |
1294 | or return; |
1313 | # or return; |
1295 | |
1314 | |
1296 | $self->_load_header ($path) |
1315 | $self->_load_header ($path) |
1297 | or return; |
1316 | or return; |
1298 | |
1317 | |
1299 | $self->{load_path} = $path; |
1318 | $self->{load_path} = $path; |
… | |
… | |
1379 | sub pre_load { } |
1398 | sub pre_load { } |
1380 | sub post_load { } |
1399 | sub post_load { } |
1381 | |
1400 | |
1382 | sub load { |
1401 | sub load { |
1383 | my ($self) = @_; |
1402 | my ($self) = @_; |
|
|
1403 | |
|
|
1404 | local $self->{deny_reset} = 1; # loading can take a long time |
1384 | |
1405 | |
1385 | my $path = $self->{path}; |
1406 | my $path = $self->{path}; |
1386 | my $guard = cf::lock_acquire "map_load:$path"; |
1407 | my $guard = cf::lock_acquire "map_load:$path"; |
1387 | |
1408 | |
1388 | return if $self->in_memory != cf::MAP_SWAPPED; |
1409 | return if $self->in_memory != cf::MAP_SWAPPED; |
… | |
… | |
1626 | for (@$files) { |
1647 | for (@$files) { |
1627 | utf8::decode $_; |
1648 | utf8::decode $_; |
1628 | next if /\.pst$/; |
1649 | next if /\.pst$/; |
1629 | next unless /^$PATH_SEP/o; |
1650 | next unless /^$PATH_SEP/o; |
1630 | |
1651 | |
1631 | s/\.map$//; |
1652 | push @paths, cf::map::normalise $_; |
1632 | push @paths, $_; |
|
|
1633 | } |
1653 | } |
1634 | |
1654 | |
1635 | \@paths |
1655 | \@paths |
1636 | } |
1656 | } |
1637 | |
1657 | |
… | |
… | |
1731 | =cut |
1751 | =cut |
1732 | |
1752 | |
1733 | sub link_map { |
1753 | sub link_map { |
1734 | unless ($LINK_MAP) { |
1754 | unless ($LINK_MAP) { |
1735 | $LINK_MAP = cf::map::find "{link}" |
1755 | $LINK_MAP = cf::map::find "{link}" |
1736 | or do { warn "FATAL: unable to provide {link} map, exiting."; exit 1 }; |
1756 | or cf::cleanup "FATAL: unable to provide {link} map, exiting."; |
1737 | $LINK_MAP->load; |
1757 | $LINK_MAP->load; |
1738 | } |
1758 | } |
1739 | |
1759 | |
1740 | $LINK_MAP |
1760 | $LINK_MAP |
1741 | } |
1761 | } |
… | |
… | |
1825 | my ($self, $path, $x, $y) = @_; |
1845 | my ($self, $path, $x, $y) = @_; |
1826 | |
1846 | |
1827 | $self->enter_link; |
1847 | $self->enter_link; |
1828 | |
1848 | |
1829 | (async { |
1849 | (async { |
|
|
1850 | my $map = eval { |
1830 | my $map = cf::map::find $path; |
1851 | my $map = cf::map::find $path; |
1831 | $map = $map->customise_for ($self) if $map; |
1852 | $map = $map->customise_for ($self) if $map; |
1832 | |
1853 | $map |
1833 | # warn "entering ", $map->path, " at ($x, $y)\n" |
1854 | } or |
1834 | # if $map; |
|
|
1835 | |
|
|
1836 | $map or $self->message ("The exit to '" . ($path->visible_name) . "' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1855 | $self->message ("The exit to '$path' is closed", cf::NDI_UNIQUE | cf::NDI_RED); |
1837 | |
1856 | |
1838 | $self->leave_link ($map, $x, $y); |
1857 | $self->leave_link ($map, $x, $y); |
1839 | })->prio (1); |
1858 | })->prio (1); |
1840 | } |
1859 | } |
1841 | |
1860 | |
… | |
… | |
1872 | # that depends on the exit object |
1891 | # that depends on the exit object |
1873 | |
1892 | |
1874 | my $rmp = parse_random_map_params $exit->msg; |
1893 | my $rmp = parse_random_map_params $exit->msg; |
1875 | |
1894 | |
1876 | if ($exit->map) { |
1895 | if ($exit->map) { |
1877 | $rmp->{region} = $exit->map->region_name; |
1896 | $rmp->{region} = $exit->region->name; |
1878 | $rmp->{origin_map} = $exit->map->path; |
1897 | $rmp->{origin_map} = $exit->map->path; |
1879 | $rmp->{origin_x} = $exit->x; |
1898 | $rmp->{origin_x} = $exit->x; |
1880 | $rmp->{origin_y} = $exit->y; |
1899 | $rmp->{origin_y} = $exit->y; |
1881 | } |
1900 | } |
1882 | |
1901 | |
… | |
… | |
1984 | # get handled first |
2003 | # get handled first |
1985 | my $queue = delete $ns->{query_queue} |
2004 | my $queue = delete $ns->{query_queue} |
1986 | 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 |
1987 | |
2006 | |
1988 | (shift @$queue)->[1]->($msg); |
2007 | (shift @$queue)->[1]->($msg); |
|
|
2008 | return unless $ns->valid; # temporary(?) workaround for callback destroying socket |
1989 | |
2009 | |
1990 | push @{ $ns->{query_queue} }, @$queue; |
2010 | push @{ $ns->{query_queue} }, @$queue; |
1991 | |
2011 | |
1992 | if (@{ $ns->{query_queue} } == @$queue) { |
2012 | if (@{ $ns->{query_queue} } == @$queue) { |
1993 | if (@$queue) { |
2013 | if (@$queue) { |
… | |
… | |
2250 | }, |
2270 | }, |
2251 | ); |
2271 | ); |
2252 | } |
2272 | } |
2253 | |
2273 | |
2254 | ############################################################################# |
2274 | ############################################################################# |
2255 | # the server's main() |
2275 | # the server's init and main functions |
|
|
2276 | |
|
|
2277 | sub load_resources { |
|
|
2278 | load_regions sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
|
|
2279 | or die "unable to load regions file\n";#d# |
|
|
2280 | } |
2256 | |
2281 | |
2257 | sub cfg_load { |
2282 | sub cfg_load { |
2258 | open my $fh, "<:utf8", cf::confdir . "/config" |
2283 | open my $fh, "<:utf8", cf::confdir . "/config" |
2259 | or return; |
2284 | or return; |
2260 | |
2285 | |
… | |
… | |
2271 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2296 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2272 | and die "WARNING: m(un)lockall failed: $!\n"; |
2297 | and die "WARNING: m(un)lockall failed: $!\n"; |
2273 | }; |
2298 | }; |
2274 | warn $@ if $@; |
2299 | warn $@ if $@; |
2275 | } |
2300 | } |
|
|
2301 | } |
|
|
2302 | |
|
|
2303 | sub init { |
|
|
2304 | load_resources; |
2276 | } |
2305 | } |
2277 | |
2306 | |
2278 | sub main { |
2307 | sub main { |
2279 | # we must not ever block the main coroutine |
2308 | # we must not ever block the main coroutine |
2280 | local $Coro::idle = sub { |
2309 | local $Coro::idle = sub { |
… | |
… | |
2441 | warn "reattaching attachments to objects/players"; |
2470 | warn "reattaching attachments to objects/players"; |
2442 | _global_reattach; |
2471 | _global_reattach; |
2443 | warn "reattaching attachments to maps"; |
2472 | warn "reattaching attachments to maps"; |
2444 | reattach $_ for values %MAP; |
2473 | reattach $_ for values %MAP; |
2445 | |
2474 | |
|
|
2475 | warn "loading reloadable resources"; |
|
|
2476 | load_resources; |
|
|
2477 | |
2446 | warn "restarting server ticker"; |
2478 | warn "restarting server ticker"; |
2447 | |
2479 | |
2448 | $TICK_WATCHER->start; |
2480 | $TICK_WATCHER->start; |
2449 | }; |
2481 | }; |
2450 | |
2482 | |