… | |
… | |
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; |
… | |
… | |
1052 | |
1053 | |
1053 | # nuke player maps |
1054 | # nuke player maps |
1054 | $cf::MAP{$_}->nuke for grep /$prefix/, keys %cf::MAP; |
1055 | $cf::MAP{$_}->nuke for grep /$prefix/, keys %cf::MAP; |
1055 | |
1056 | |
1056 | IO::AIO::aio_rmtree $temp; |
1057 | IO::AIO::aio_rmtree $temp; |
|
|
1058 | } |
|
|
1059 | |
|
|
1060 | =item $pl->kick |
|
|
1061 | |
|
|
1062 | Kicks a player out of the game. This destroys the connection. |
|
|
1063 | |
|
|
1064 | =cut |
|
|
1065 | |
|
|
1066 | sub kick { |
|
|
1067 | my ($pl, $kicker) = @_; |
|
|
1068 | |
|
|
1069 | $pl->invoke (cf::EVENT_PLAYER_KICK, $kicker); |
|
|
1070 | $pl->killer ("kicked"); |
|
|
1071 | $pl->ns->destroy; |
1057 | } |
1072 | } |
1058 | |
1073 | |
1059 | =item cf::player::list_logins |
1074 | =item cf::player::list_logins |
1060 | |
1075 | |
1061 | Returns am arrayref of all valid playernames in the system, can take a |
1076 | Returns am arrayref of all valid playernames in the system, can take a |
… | |
… | |
2252 | } |
2267 | } |
2253 | |
2268 | |
2254 | ############################################################################# |
2269 | ############################################################################# |
2255 | # the server's init and main functions |
2270 | # the server's init and main functions |
2256 | |
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 | |
2257 | sub init_resources { |
2295 | sub reload_resources { |
2258 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2296 | load_resource_file sprintf "%s/%s/regions", cf::datadir, cf::mapdir |
2259 | 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; |
2260 | } |
2304 | } |
2261 | |
2305 | |
2262 | sub cfg_load { |
2306 | sub cfg_load { |
2263 | open my $fh, "<:utf8", cf::confdir . "/config" |
2307 | open my $fh, "<:utf8", cf::confdir . "/config" |
2264 | or return; |
2308 | or return; |
… | |
… | |
2276 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2320 | $CFG{mlockall} ? eval "mlockall()" : eval "munlockall()" |
2277 | and die "WARNING: m(un)lockall failed: $!\n"; |
2321 | and die "WARNING: m(un)lockall failed: $!\n"; |
2278 | }; |
2322 | }; |
2279 | warn $@ if $@; |
2323 | warn $@ if $@; |
2280 | } |
2324 | } |
2281 | } |
|
|
2282 | |
|
|
2283 | sub init { |
|
|
2284 | init_resources; |
|
|
2285 | } |
2325 | } |
2286 | |
2326 | |
2287 | sub main { |
2327 | sub main { |
2288 | # we must not ever block the main coroutine |
2328 | # we must not ever block the main coroutine |
2289 | local $Coro::idle = sub { |
2329 | local $Coro::idle = sub { |
… | |
… | |
2392 | Coro::cede; |
2432 | Coro::cede; |
2393 | last unless IO::AIO::nreqs || BDB::nreqs; |
2433 | last unless IO::AIO::nreqs || BDB::nreqs; |
2394 | warn "iterate..."; |
2434 | warn "iterate..."; |
2395 | } |
2435 | } |
2396 | |
2436 | |
|
|
2437 | ++$RELOAD; |
|
|
2438 | |
2397 | warn "cancelling all extension coros"; |
2439 | warn "cancelling all extension coros"; |
2398 | $_->cancel for values %EXT_CORO; |
2440 | $_->cancel for values %EXT_CORO; |
2399 | %EXT_CORO = (); |
2441 | %EXT_CORO = (); |
2400 | |
2442 | |
2401 | warn "removing commands"; |
2443 | warn "removing commands"; |
… | |
… | |
2458 | |
2500 | |
2459 | warn "loading extensions"; |
2501 | warn "loading extensions"; |
2460 | cf::load_extensions; |
2502 | cf::load_extensions; |
2461 | |
2503 | |
2462 | warn "reattaching attachments to objects/players"; |
2504 | warn "reattaching attachments to objects/players"; |
2463 | _global_reattach; |
2505 | _global_reattach; # objects, sockets |
2464 | warn "reattaching attachments to maps"; |
2506 | warn "reattaching attachments to maps"; |
2465 | reattach $_ for values %MAP; |
2507 | reattach $_ for values %MAP; |
|
|
2508 | warn "reattaching attachments to players"; |
|
|
2509 | reattach $_ for values %PLAYER; |
2466 | |
2510 | |
2467 | warn "loading reloadable resources"; |
2511 | warn "loading reloadable resources"; |
2468 | init_resources; |
2512 | reload_resources; |
2469 | |
2513 | |
2470 | warn "leaving sync_job"; |
2514 | warn "leaving sync_job"; |
2471 | |
2515 | |
2472 | 1 |
2516 | 1 |
2473 | } or do { |
2517 | } or do { |