… | |
… | |
43 | our @EXTS = (); # list of extension package names |
43 | our @EXTS = (); # list of extension package names |
44 | our %EXTCMD = (); |
44 | our %EXTCMD = (); |
45 | our %EXT_CORO = (); # coroutines bound to extensions |
45 | our %EXT_CORO = (); # coroutines bound to extensions |
46 | our %EXT_MAP = (); # pluggable maps |
46 | our %EXT_MAP = (); # pluggable maps |
47 | |
47 | |
|
|
48 | our $RELOAD; # number of reloads so far |
48 | our @EVENT; |
49 | our @EVENT; |
49 | our $LIBDIR = datadir . "/ext"; |
50 | our $LIBDIR = datadir . "/ext"; |
50 | |
51 | |
51 | our $TICK = MAX_TIME * 1e-6; |
52 | our $TICK = MAX_TIME * 1e-6; |
52 | our $TICK_WATCHER; |
53 | our $TICK_WATCHER; |
… | |
… | |
2266 | } |
2267 | } |
2267 | |
2268 | |
2268 | ############################################################################# |
2269 | ############################################################################# |
2269 | # the server's init and main functions |
2270 | # the server's init and main functions |
2270 | |
2271 | |
|
|
2272 | sub load_faces { |
|
|
2273 | my $path = sprintf "%s/faces", cf::datadir; |
|
|
2274 | |
|
|
2275 | warn "loading faces from $path\n"; |
|
|
2276 | |
|
|
2277 | my $faces; |
|
|
2278 | 0 < aio_load $path, $faces |
|
|
2279 | or die "$path: $!"; |
|
|
2280 | |
|
|
2281 | Coro::cede; |
|
|
2282 | $faces = Storable::thaw $faces; |
|
|
2283 | Coro::cede; |
|
|
2284 | |
|
|
2285 | while (my ($face, $info) = each %$faces) { |
|
|
2286 | my $idx = (cf::face::find $face) || cf::face::alloc $face; |
|
|
2287 | cf::face::set $idx, $info->{visibility}, $info->{magicmap}; |
|
|
2288 | cf::face::set_data $idx, 0, $info->{data32}, $info->{chksum32}; |
|
|
2289 | Coro::cede; |
|
|
2290 | } |
|
|
2291 | |
|
|
2292 | 1 |
|
|
2293 | } |
|
|
2294 | |
2271 | sub init_resources { |
2295 | sub reload_resources { |
2272 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2296 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2273 | or die "unable to load regions file\n";#d# |
2297 | or die "unable to load regions file\n";#d# |
|
|
2298 | load_faces |
|
|
2299 | or die "unable to load faces\n";#d# |
|
|
2300 | } |
|
|
2301 | |
|
|
2302 | sub init { |
|
|
2303 | reload_resources; |
2274 | } |
2304 | } |
2275 | |
2305 | |
2276 | sub cfg_load { |
2306 | sub cfg_load { |
2277 | open my $fh, "<:utf8", cf::confdir . "/config" |
2307 | open my $fh, "<:utf8", cf::confdir . "/config" |
2278 | or return; |
2308 | or return; |
… | |
… | |
2290 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2320 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2291 | and die "WARNING: m(un)lockall failed: $!\n"; |
2321 | and die "WARNING: m(un)lockall failed: $!\n"; |
2292 | }; |
2322 | }; |
2293 | warn $@ if $@; |
2323 | warn $@ if $@; |
2294 | } |
2324 | } |
2295 | } |
|
|
2296 | |
|
|
2297 | sub init { |
|
|
2298 | init_resources; |
|
|
2299 | } |
2325 | } |
2300 | |
2326 | |
2301 | sub main { |
2327 | sub main { |
2302 | # we must not ever block the main coroutine |
2328 | # we must not ever block the main coroutine |
2303 | local $Coro::idle = sub { |
2329 | local $Coro::idle = sub { |
… | |
… | |
2406 | Coro::cede; |
2432 | Coro::cede; |
2407 | last unless IO::AIO::nreqs || BDB::nreqs; |
2433 | last unless IO::AIO::nreqs || BDB::nreqs; |
2408 | warn "iterate..."; |
2434 | warn "iterate..."; |
2409 | } |
2435 | } |
2410 | |
2436 | |
|
|
2437 | ++$RELOAD; |
|
|
2438 | |
2411 | warn "cancelling all extension coros"; |
2439 | warn "cancelling all extension coros"; |
2412 | $_->cancel for values %EXT_CORO; |
2440 | $_->cancel for values %EXT_CORO; |
2413 | %EXT_CORO = (); |
2441 | %EXT_CORO = (); |
2414 | |
2442 | |
2415 | warn "removing commands"; |
2443 | warn "removing commands"; |
… | |
… | |
2479 | reattach $_ for values %MAP; |
2507 | reattach $_ for values %MAP; |
2480 | warn "reattaching attachments to players"; |
2508 | warn "reattaching attachments to players"; |
2481 | reattach $_ for values %PLAYER; |
2509 | reattach $_ for values %PLAYER; |
2482 | |
2510 | |
2483 | warn "loading reloadable resources"; |
2511 | warn "loading reloadable resources"; |
2484 | init_resources; |
2512 | reload_resources; |
2485 | |
2513 | |
2486 | warn "leaving sync_job"; |
2514 | warn "leaving sync_job"; |
2487 | |
2515 | |
2488 | 1 |
2516 | 1 |
2489 | } or do { |
2517 | } or do { |