… | |
… | |
354 | |
354 | |
355 | $coro |
355 | $coro |
356 | } |
356 | } |
357 | |
357 | |
358 | sub write_runtime { |
358 | sub write_runtime { |
|
|
359 | my $guard = cf::lock_acquire "write_runtime"; |
|
|
360 | |
359 | my $runtime = cf::localdir . "/runtime"; |
361 | my $runtime = cf::localdir . "/runtime"; |
360 | |
362 | |
361 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
363 | my $fh = aio_open "$runtime~", O_WRONLY | O_CREAT, 0644 |
362 | or return; |
364 | or return; |
363 | |
365 | |
… | |
… | |
1028 | =cut |
1030 | =cut |
1029 | |
1031 | |
1030 | sub quit_character { |
1032 | sub quit_character { |
1031 | my ($pl) = @_; |
1033 | my ($pl) = @_; |
1032 | |
1034 | |
|
|
1035 | my $name = $pl->ob->name; |
|
|
1036 | |
1033 | $pl->{deny_save} = 1; |
1037 | $pl->{deny_save} = 1; |
1034 | $pl->password ("*"); # this should lock out the player until we nuked the dir |
1038 | $pl->password ("*"); # this should lock out the player until we nuked the dir |
1035 | |
1039 | |
1036 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1040 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1037 | $pl->deactivate; |
1041 | $pl->deactivate; |
… | |
… | |
1041 | my $path = playerdir $pl; |
1045 | my $path = playerdir $pl; |
1042 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
1046 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
1043 | aio_rename $path, $temp; |
1047 | aio_rename $path, $temp; |
1044 | delete $cf::PLAYER{$pl->ob->name}; |
1048 | delete $cf::PLAYER{$pl->ob->name}; |
1045 | $pl->destroy; |
1049 | $pl->destroy; |
|
|
1050 | |
|
|
1051 | my $prefix = qr<^~\Q$name\E/>; |
|
|
1052 | |
|
|
1053 | # nuke player maps |
|
|
1054 | $cf::MAP{$_}->nuke for grep /$prefix/, keys %cf::MAP; |
|
|
1055 | |
1046 | IO::AIO::aio_rmtree $temp; |
1056 | IO::AIO::aio_rmtree $temp; |
1047 | } |
1057 | } |
1048 | |
1058 | |
1049 | =item cf::player::list_logins |
1059 | =item cf::player::list_logins |
1050 | |
1060 | |
… | |
… | |
2242 | } |
2252 | } |
2243 | |
2253 | |
2244 | ############################################################################# |
2254 | ############################################################################# |
2245 | # the server's init and main functions |
2255 | # the server's init and main functions |
2246 | |
2256 | |
2247 | sub load_resources { |
2257 | sub init_resources { |
2248 | load_regions sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2258 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2249 | or die "unable to load regions file\n";#d# |
2259 | or die "unable to load regions file\n";#d# |
2250 | } |
2260 | } |
2251 | |
2261 | |
2252 | sub cfg_load { |
2262 | sub cfg_load { |
2253 | open my $fh, "<:utf8", cf::confdir . "/config" |
2263 | open my $fh, "<:utf8", cf::confdir . "/config" |
… | |
… | |
2269 | warn $@ if $@; |
2279 | warn $@ if $@; |
2270 | } |
2280 | } |
2271 | } |
2281 | } |
2272 | |
2282 | |
2273 | sub init { |
2283 | sub init { |
2274 | load_resources; |
2284 | init_resources; |
2275 | } |
2285 | } |
2276 | |
2286 | |
2277 | sub main { |
2287 | sub main { |
2278 | # we must not ever block the main coroutine |
2288 | # we must not ever block the main coroutine |
2279 | local $Coro::idle = sub { |
2289 | local $Coro::idle = sub { |
… | |
… | |
2453 | _global_reattach; |
2463 | _global_reattach; |
2454 | warn "reattaching attachments to maps"; |
2464 | warn "reattaching attachments to maps"; |
2455 | reattach $_ for values %MAP; |
2465 | reattach $_ for values %MAP; |
2456 | |
2466 | |
2457 | warn "loading reloadable resources"; |
2467 | warn "loading reloadable resources"; |
2458 | load_resources; |
2468 | init_resources; |
2459 | |
2469 | |
2460 | warn "leaving sync_job"; |
2470 | warn "leaving sync_job"; |
2461 | |
2471 | |
2462 | 1 |
2472 | 1 |
2463 | } or do { |
2473 | } or do { |
… | |
… | |
2520 | Coro::async_pool { |
2530 | Coro::async_pool { |
2521 | write_runtime |
2531 | write_runtime |
2522 | or warn "ERROR: unable to write runtime file: $!"; |
2532 | or warn "ERROR: unable to write runtime file: $!"; |
2523 | }; |
2533 | }; |
2524 | } |
2534 | } |
2525 | |
|
|
2526 | |
2535 | |
2527 | $WAIT_FOR_TICK->broadcast; |
2536 | $WAIT_FOR_TICK->broadcast; |
2528 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
2537 | $WAIT_FOR_TICK_ONE->send if $WAIT_FOR_TICK_ONE->awaited; |
2529 | |
2538 | |
2530 | # my $AFTER = Event::time; |
2539 | # my $AFTER = Event::time; |