… | |
… | |
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; |
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 = 0;#d# |
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 |
… | |
… | |
2162 | or next; |
2167 | or next; |
2163 | $neigh = find $neigh, $map |
2168 | $neigh = find $neigh, $map |
2164 | or next; |
2169 | or next; |
2165 | $neigh->load; |
2170 | $neigh->load; |
2166 | |
2171 | |
|
|
2172 | # now find the diagonal neighbours |
2167 | push @neigh, |
2173 | push @neigh, |
2168 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
2174 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
2169 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
2175 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
2170 | } |
2176 | } |
2171 | |
2177 | |
… | |
… | |
2583 | |
2589 | |
2584 | Freezes the player and moves him/her to a special map (C<{link}>). |
2590 | Freezes the player and moves him/her to a special map (C<{link}>). |
2585 | |
2591 | |
2586 | The player should be reasonably safe there for short amounts of time (e.g. |
2592 | 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, |
2593 | 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 |
2594 | though, as the player cannot control the character while it is on the link |
2589 | map. |
2595 | map. |
2590 | |
2596 | |
2591 | Will never block. |
2597 | Will never block. |
2592 | |
2598 | |
2593 | =item $player_object->leave_link ($map, $x, $y) |
2599 | =item $player_object->leave_link ($map, $x, $y) |
… | |
… | |
2614 | sub cf::object::player::enter_link { |
2620 | sub cf::object::player::enter_link { |
2615 | my ($self) = @_; |
2621 | my ($self) = @_; |
2616 | |
2622 | |
2617 | $self->deactivate_recursive; |
2623 | $self->deactivate_recursive; |
2618 | |
2624 | |
|
|
2625 | ++$self->{_link_recursion}; |
|
|
2626 | |
2619 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2627 | return if UNIVERSAL::isa $self->map, "ext::map_link"; |
2620 | |
2628 | |
2621 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2629 | $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] |
2622 | if $self->map && $self->map->{path} ne "{link}"; |
2630 | if $self->map && $self->map->{path} ne "{link}"; |
2623 | |
2631 | |
… | |
… | |
2654 | $map->load_neighbours; |
2662 | $map->load_neighbours; |
2655 | |
2663 | |
2656 | return unless $self->contr->active; |
2664 | return unless $self->contr->active; |
2657 | |
2665 | |
2658 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2666 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2659 | $self->enter_map ($map, $x, $y); |
2667 | if ($self->enter_map ($map, $x, $y)) { |
2660 | |
2668 | # entering was successful |
|
|
2669 | delete $self->{_link_recursion}; |
2661 | # only activate afterwards, to support waiting in hooks |
2670 | # only activate afterwards, to support waiting in hooks |
2662 | $self->activate_recursive; |
2671 | $self->activate_recursive; |
2663 | # unless exists $self->{_link_pos}; # maybe we re in-flight again |
2672 | } |
2664 | } |
|
|
2665 | |
2673 | |
|
|
2674 | } |
|
|
2675 | |
2666 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2676 | =item $player_object->goto ($path, $x, $y[, $check->($map, $x, $y, $player)[, $done->($player)]]) |
2667 | |
2677 | |
2668 | Moves the player to the given map-path and coordinates by first freezing |
2678 | Moves the player to the given map-path and coordinates by first freezing |
2669 | her, loading and preparing them map, calling the provided $check callback |
2679 | her, loading and preparing them map, calling the provided $check callback |
2670 | that has to return the map if sucecssful, and then unfreezes the player on |
2680 | that has to return the map if sucecssful, and then unfreezes the player on |
2671 | the new (success) or old (failed) map position. In either case, $done will |
2681 | the new (success) or old (failed) map position. In either case, $done will |
… | |
… | |
2678 | |
2688 | |
2679 | our $GOTOGEN; |
2689 | our $GOTOGEN; |
2680 | |
2690 | |
2681 | sub cf::object::player::goto { |
2691 | sub cf::object::player::goto { |
2682 | my ($self, $path, $x, $y, $check, $done) = @_; |
2692 | my ($self, $path, $x, $y, $check, $done) = @_; |
|
|
2693 | |
|
|
2694 | if ($self->{_link_recursion} >= $MAX_LINKS) { |
|
|
2695 | warn "FATAL: link recursion exceeded, ", $self->name, " goto $path $x $y, redirecting."; |
|
|
2696 | $self->failmsg ("Something went wrong inside the server - please contact an administrator!"); |
|
|
2697 | ($path, $x, $y) = @$EMERGENCY_POSITION; |
|
|
2698 | } |
2683 | |
2699 | |
2684 | # do generation counting so two concurrent goto's will be executed in-order |
2700 | # do generation counting so two concurrent goto's will be executed in-order |
2685 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2701 | my $gen = $self->{_goto_generation} = ++$GOTOGEN; |
2686 | |
2702 | |
2687 | $self->enter_link; |
2703 | $self->enter_link; |
… | |
… | |
2711 | my $map = eval { |
2727 | my $map = eval { |
2712 | my $map = defined $path ? cf::map::find $path : undef; |
2728 | my $map = defined $path ? cf::map::find $path : undef; |
2713 | |
2729 | |
2714 | if ($map) { |
2730 | if ($map) { |
2715 | $map = $map->customise_for ($self); |
2731 | $map = $map->customise_for ($self); |
2716 | $map = $check->($map) if $check && $map; |
2732 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2717 | } else { |
2733 | } else { |
2718 | $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); |
2734 | $self->message ("The exit to '$path' is closed.", cf::NDI_UNIQUE | cf::NDI_RED); |
2719 | } |
2735 | } |
2720 | |
2736 | |
2721 | $map |
2737 | $map |
… | |
… | |
2729 | if ($gen == $self->{_goto_generation}) { |
2745 | if ($gen == $self->{_goto_generation}) { |
2730 | delete $self->{_goto_generation}; |
2746 | delete $self->{_goto_generation}; |
2731 | $self->leave_link ($map, $x, $y); |
2747 | $self->leave_link ($map, $x, $y); |
2732 | } |
2748 | } |
2733 | |
2749 | |
2734 | $done->() if $done; |
2750 | $done->($self) if $done; |
2735 | })->prio (1); |
2751 | })->prio (1); |
2736 | } |
2752 | } |
2737 | |
2753 | |
2738 | =item $player_object->enter_exit ($exit_object) |
2754 | =item $player_object->enter_exit ($exit_object) |
2739 | |
2755 | |
… | |
… | |
3512 | or return; |
3528 | or return; |
3513 | |
3529 | |
3514 | local $/; |
3530 | local $/; |
3515 | *CFG = YAML::XS::Load scalar <$fh>; |
3531 | *CFG = YAML::XS::Load scalar <$fh>; |
3516 | |
3532 | |
3517 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; |
3533 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3518 | |
3534 | |
3519 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3535 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3520 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3536 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3521 | |
3537 | |
3522 | if (exists $CFG{mlockall}) { |
3538 | if (exists $CFG{mlockall}) { |