… | |
… | |
106 | our $RANDOMDIR = "$LOCALDIR/random"; |
106 | our $RANDOMDIR = "$LOCALDIR/random"; |
107 | our $BDBDIR = "$LOCALDIR/db"; |
107 | our $BDBDIR = "$LOCALDIR/db"; |
108 | our $PIDFILE = "$LOCALDIR/pid"; |
108 | our $PIDFILE = "$LOCALDIR/pid"; |
109 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
109 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
110 | |
110 | |
111 | our %RESOURCE; |
111 | our %RESOURCE; # unused |
112 | |
112 | |
113 | our $OUTPUT_RATE_MIN = 4000; |
113 | our $OUTPUT_RATE_MIN = 3000; |
114 | our $OUTPUT_RATE_MAX = 100000; |
114 | our $OUTPUT_RATE_MAX = 1000000; |
|
|
115 | |
|
|
116 | our $MAX_LINKS = 32; # how many chained exits to follow |
|
|
117 | our $VERBOSE_IO = 1; |
115 | |
118 | |
116 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
119 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
117 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
120 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
118 | our $NEXT_TICK; |
121 | our $NEXT_TICK; |
119 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
122 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
… | |
… | |
1192 | |
1195 | |
1193 | sync_job { |
1196 | sync_job { |
1194 | if (length $$rdata) { |
1197 | if (length $$rdata) { |
1195 | utf8::decode (my $decname = $filename); |
1198 | utf8::decode (my $decname = $filename); |
1196 | warn sprintf "saving %s (%d,%d)\n", |
1199 | warn sprintf "saving %s (%d,%d)\n", |
1197 | $decname, length $$rdata, scalar @$objs; |
1200 | $decname, length $$rdata, scalar @$objs |
|
|
1201 | if $VERBOSE_IO; |
1198 | |
1202 | |
1199 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1203 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1200 | aio_chmod $fh, SAVE_MODE; |
1204 | aio_chmod $fh, SAVE_MODE; |
1201 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1205 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1202 | if ($cf::USE_FSYNC) { |
1206 | if ($cf::USE_FSYNC) { |
… | |
… | |
1259 | $av = $st->{objs}; |
1263 | $av = $st->{objs}; |
1260 | } |
1264 | } |
1261 | |
1265 | |
1262 | utf8::decode (my $decname = $filename); |
1266 | utf8::decode (my $decname = $filename); |
1263 | warn sprintf "loading %s (%d,%d)\n", |
1267 | warn sprintf "loading %s (%d,%d)\n", |
1264 | $decname, length $data, scalar @{$av || []}; |
1268 | $decname, length $data, scalar @{$av || []} |
|
|
1269 | if $VERBOSE_IO; |
1265 | |
1270 | |
1266 | ($data, $av) |
1271 | ($data, $av) |
1267 | } |
1272 | } |
1268 | |
1273 | |
1269 | =head2 COMMAND CALLBACKS |
1274 | =head2 COMMAND CALLBACKS |
… | |
… | |
1630 | $pl->password ("*"); # this should lock out the player until we have nuked the dir |
1635 | $pl->password ("*"); # this should lock out the player until we have nuked the dir |
1631 | |
1636 | |
1632 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1637 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1) if $pl->active; |
1633 | $pl->deactivate; |
1638 | $pl->deactivate; |
1634 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
1639 | my $killer = cf::arch::get "killer_quit"; $pl->killer ($killer); $killer->destroy; |
1635 | $pl->ob->check_score; |
|
|
1636 | $pl->invoke (cf::EVENT_PLAYER_QUIT); |
1640 | $pl->invoke (cf::EVENT_PLAYER_QUIT); |
1637 | $pl->ns->destroy if $pl->ns; |
1641 | $pl->ns->destroy if $pl->ns; |
1638 | |
1642 | |
1639 | my $path = playerdir $pl; |
1643 | my $path = playerdir $pl; |
1640 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
1644 | my $temp = "$path~$cf::RUNTIME~deleting~"; |
… | |
… | |
1842 | |
1846 | |
1843 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1847 | $EXT_MAP{$pkg} = [$prio, qr<$regex>]; |
1844 | } |
1848 | } |
1845 | |
1849 | |
1846 | # also paths starting with '/' |
1850 | # also paths starting with '/' |
1847 | $EXT_MAP{"cf::map"} = [0, qr{^(?=/)}]; |
1851 | $EXT_MAP{"cf::map::wrap"} = [0, qr{^(?=/)}]; |
1848 | |
1852 | |
1849 | sub thawer_merge { |
1853 | sub thawer_merge { |
1850 | my ($self, $merge) = @_; |
1854 | my ($self, $merge) = @_; |
1851 | |
1855 | |
1852 | # we have to keep some variables in memory intact |
1856 | # we have to keep some variables in memory intact |
… | |
… | |
2162 | or next; |
2166 | or next; |
2163 | $neigh = find $neigh, $map |
2167 | $neigh = find $neigh, $map |
2164 | or next; |
2168 | or next; |
2165 | $neigh->load; |
2169 | $neigh->load; |
2166 | |
2170 | |
|
|
2171 | # now find the diagonal neighbours |
2167 | push @neigh, |
2172 | push @neigh, |
2168 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
2173 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
2169 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
2174 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
2170 | } |
2175 | } |
2171 | |
2176 | |
… | |
… | |
2343 | |
2348 | |
2344 | delete $cf::MAP{$self->path}; |
2349 | delete $cf::MAP{$self->path}; |
2345 | |
2350 | |
2346 | $self->unlink_save; |
2351 | $self->unlink_save; |
2347 | |
2352 | |
2348 | bless $self, "cf::map"; |
2353 | bless $self, "cf::map::wrap"; |
2349 | delete $self->{deny_reset}; |
2354 | delete $self->{deny_reset}; |
2350 | $self->{deny_save} = 1; |
2355 | $self->{deny_save} = 1; |
2351 | $self->reset_timeout (1); |
2356 | $self->reset_timeout (1); |
2352 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2357 | $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); |
2353 | |
2358 | |
… | |
… | |
2583 | |
2588 | |
2584 | Freezes the player and moves him/her to a special map (C<{link}>). |
2589 | Freezes the player and moves him/her to a special map (C<{link}>). |
2585 | |
2590 | |
2586 | The player should be reasonably safe there for short amounts of time (e.g. |
2591 | The player should be reasonably safe there for short amounts of time (e.g. |
2587 | for loading a map). You I<MUST> call C<leave_link> as soon as possible, |
2592 | for loading a map). You I<MUST> call C<leave_link> as soon as possible, |
2588 | though, as the palyer cannot control the character while it is on the link |
2593 | though, as the player cannot control the character while it is on the link |
2589 | map. |
2594 | map. |
2590 | |
2595 | |
2591 | Will never block. |
2596 | Will never block. |
2592 | |
2597 | |
2593 | =item $player_object->leave_link ($map, $x, $y) |
2598 | =item $player_object->leave_link ($map, $x, $y) |
… | |
… | |
2614 | sub cf::object::player::enter_link { |
2619 | sub cf::object::player::enter_link { |
2615 | my ($self) = @_; |
2620 | my ($self) = @_; |
2616 | |
2621 | |
2617 | $self->deactivate_recursive; |
2622 | $self->deactivate_recursive; |
2618 | |
2623 | |
|
|
2624 | ++$self->{_link_recursion}; |
|
|
2625 | |
2619 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2626 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2620 | |
2627 | |
2621 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2628 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2622 | if $self->map && $self->map->{path} ne "{link}"; |
2629 | if $self->map && $self->map->{path} ne "{link}"; |
2623 | |
2630 | |
… | |
… | |
2654 | $map->load_neighbours; |
2661 | $map->load_neighbours; |
2655 | |
2662 | |
2656 | return unless $self->contr->active; |
2663 | return unless $self->contr->active; |
2657 | |
2664 | |
2658 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2665 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2659 | $self->enter_map ($map, $x, $y); |
2666 | if ($self->enter_map ($map, $x, $y)) { |
2660 | |
2667 | # entering was successful |
|
|
2668 | delete $self->{_link_recursion}; |
2661 | # only activate afterwards, to support waiting in hooks |
2669 | # only activate afterwards, to support waiting in hooks |
2662 | $self->activate_recursive; |
2670 | $self->activate_recursive; |
2663 | } |
2671 | } |
2664 | |
2672 | |
|
|
2673 | } |
|
|
2674 | |
2665 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2675 | =item $player_object->goto ($path, $x, $y[, $check->($map, $x, $y, $player)[, $done->($player)]]) |
2666 | |
2676 | |
2667 | Moves the player to the given map-path and coordinates by first freezing |
2677 | Moves the player to the given map-path and coordinates by first freezing |
2668 | her, loading and preparing them map, calling the provided $check callback |
2678 | her, loading and preparing them map, calling the provided $check callback |
2669 | that has to return the map if sucecssful, and then unfreezes the player on |
2679 | that has to return the map if sucecssful, and then unfreezes the player on |
2670 | the new (success) or old (failed) map position. In either case, $done will |
2680 | the new (success) or old (failed) map position. In either case, $done will |
… | |
… | |
2677 | |
2687 | |
2678 | our $GOTOGEN; |
2688 | our $GOTOGEN; |
2679 | |
2689 | |
2680 | sub cf::object::player::goto { |
2690 | sub cf::object::player::goto { |
2681 | my ($self, $path, $x, $y, $check, $done) = @_; |
2691 | my ($self, $path, $x, $y, $check, $done) = @_; |
|
|
2692 | |
|
|
2693 | if ($self->{_link_recursion} >= $MAX_LINKS) { |
|
|
2694 | warn "FATAL: link recursion exceeded, ", $self->name, " goto $path $x $y, redirecting."; |
|
|
2695 | $self->failmsg ("Something went wrong inside the server - please contact an administrator!"); |
|
|
2696 | ($path, $x, $y) = @$EMERGENCY_POSITION; |
|
|
2697 | } |
2682 | |
2698 | |
2683 | # do generation counting so two concurrent goto's will be executed in-order |
2699 | # do generation counting so two concurrent goto's will be executed in-order |
2684 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2700 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2685 | |
2701 | |
2686 | $self->enter_link; |
2702 | $self->enter_link; |
… | |
… | |
2710 | my $map = eval { |
2726 | my $map = eval { |
2711 | my $map = defined $path ? cf::map::find $path : undef; |
2727 | my $map = defined $path ? cf::map::find $path : undef; |
2712 | |
2728 | |
2713 | if ($map) { |
2729 | if ($map) { |
2714 | $map = $map->customise_for ($self); |
2730 | $map = $map->customise_for ($self); |
2715 | $map = $check->($map) if $check && $map; |
2731 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2716 | } else { |
2732 | } else { |
2717 | $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); |
2733 | $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); |
2718 | } |
2734 | } |
2719 | |
2735 | |
2720 | $map |
2736 | $map |
… | |
… | |
2728 | if ($gen == $self->{_goto_generation}) { |
2744 | if ($gen == $self->{_goto_generation}) { |
2729 | delete $self->{_goto_generation}; |
2745 | delete $self->{_goto_generation}; |
2730 | $self->leave_link ($map, $x, $y); |
2746 | $self->leave_link ($map, $x, $y); |
2731 | } |
2747 | } |
2732 | |
2748 | |
2733 | $done->() if $done; |
2749 | $done->($self) if $done; |
2734 | })->prio (1); |
2750 | })->prio (1); |
2735 | } |
2751 | } |
2736 | |
2752 | |
2737 | =item $player_object->enter_exit ($exit_object) |
2753 | =item $player_object->enter_exit ($exit_object) |
2738 | |
2754 | |
… | |
… | |
3412 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3428 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3413 | |
3429 | |
3414 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3430 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3415 | cf::face::set_type $idx, $info->{type}; |
3431 | cf::face::set_type $idx, $info->{type}; |
3416 | } else { |
3432 | } else { |
3417 | $RESOURCE{$name} = $info; |
3433 | $RESOURCE{$name} = $info; # unused |
3418 | } |
3434 | } |
3419 | |
3435 | |
3420 | cf::cede_to_tick; |
3436 | cf::cede_to_tick; |
3421 | } |
3437 | } |
3422 | } |
3438 | } |
3423 | |
3439 | |
3424 | cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE); |
3440 | cf::global->invoke (EVENT_GLOBAL_RESOURCE_UPDATE); |
3425 | |
3441 | |
3426 | 1 |
3442 | 1 |
3427 | } |
3443 | } |
3428 | |
|
|
3429 | cf::global->attach (on_resource_update => sub { |
|
|
3430 | if (my $soundconf = $RESOURCE{"res/sound.conf"}) { |
|
|
3431 | $soundconf = JSON::XS->new->utf8->relaxed->decode ($soundconf->{data}); |
|
|
3432 | |
|
|
3433 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
|
|
3434 | my $sound = $soundconf->{compat}[$_] |
|
|
3435 | or next; |
|
|
3436 | |
|
|
3437 | my $face = cf::face::find "sound/$sound->[1]"; |
|
|
3438 | cf::sound::set $sound->[0] => $face; |
|
|
3439 | cf::sound::old_sound_index $_, $face; # gcfclient-compat |
|
|
3440 | } |
|
|
3441 | |
|
|
3442 | while (my ($k, $v) = each %{$soundconf->{event}}) { |
|
|
3443 | my $face = cf::face::find "sound/$v"; |
|
|
3444 | cf::sound::set $k => $face; |
|
|
3445 | } |
|
|
3446 | } |
|
|
3447 | }); |
|
|
3448 | |
3444 | |
3449 | register_exticmd fx_want => sub { |
3445 | register_exticmd fx_want => sub { |
3450 | my ($ns, $want) = @_; |
3446 | my ($ns, $want) = @_; |
3451 | |
3447 | |
3452 | while (my ($k, $v) = each %$want) { |
3448 | while (my ($k, $v) = each %$want) { |
… | |
… | |
3491 | sub reload_treasures { |
3487 | sub reload_treasures { |
3492 | load_resource_file "$DATADIR/treasures" |
3488 | load_resource_file "$DATADIR/treasures" |
3493 | or die "unable to load treasurelists\n"; |
3489 | or die "unable to load treasurelists\n"; |
3494 | } |
3490 | } |
3495 | |
3491 | |
|
|
3492 | sub reload_sound { |
|
|
3493 | 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data |
|
|
3494 | or die "$DATADIR/sound $!"; |
|
|
3495 | |
|
|
3496 | my $soundconf = JSON::XS->new->utf8->relaxed->decode ($data); |
|
|
3497 | |
|
|
3498 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
|
|
3499 | my $sound = $soundconf->{compat}[$_] |
|
|
3500 | or next; |
|
|
3501 | |
|
|
3502 | my $face = cf::face::find "sound/$sound->[1]"; |
|
|
3503 | cf::sound::set $sound->[0] => $face; |
|
|
3504 | cf::sound::old_sound_index $_, $face; # gcfclient-compat |
|
|
3505 | } |
|
|
3506 | |
|
|
3507 | while (my ($k, $v) = each %{$soundconf->{event}}) { |
|
|
3508 | my $face = cf::face::find "sound/$v"; |
|
|
3509 | cf::sound::set $k => $face; |
|
|
3510 | } |
|
|
3511 | } |
|
|
3512 | |
3496 | sub reload_resources { |
3513 | sub reload_resources { |
3497 | warn "reloading resource files...\n"; |
3514 | warn "reloading resource files...\n"; |
3498 | |
3515 | |
3499 | reload_facedata; |
3516 | reload_facedata; |
|
|
3517 | reload_sound; |
3500 | reload_archetypes; |
3518 | reload_archetypes; |
3501 | reload_regions; |
3519 | reload_regions; |
3502 | reload_treasures; |
3520 | reload_treasures; |
3503 | |
3521 | |
3504 | warn "finished reloading resource files\n"; |
3522 | warn "finished reloading resource files\n"; |
… | |
… | |
3511 | or return; |
3529 | or return; |
3512 | |
3530 | |
3513 | local $/; |
3531 | local $/; |
3514 | *CFG = YAML::XS::Load scalar <$fh>; |
3532 | *CFG = YAML::XS::Load scalar <$fh>; |
3515 | |
3533 | |
3516 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; |
3534 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3517 | |
3535 | |
3518 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3536 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3519 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3537 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3520 | |
3538 | |
3521 | if (exists $CFG{mlockall}) { |
3539 | if (exists $CFG{mlockall}) { |