ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.519 by root, Fri Apr 16 02:32:25 2010 UTC vs.
Revision 1.528 by root, Fri Apr 23 04:42:12 2010 UTC

108our $PIDFILE = "$LOCALDIR/pid"; 108our $PIDFILE = "$LOCALDIR/pid";
109our $RUNTIMEFILE = "$LOCALDIR/runtime"; 109our $RUNTIMEFILE = "$LOCALDIR/runtime";
110 110
111our %RESOURCE; 111our %RESOURCE;
112 112
113our $OUTPUT_RATE_MIN = 4000; 113our $OUTPUT_RATE_MIN = 3000;
114our $OUTPUT_RATE_MAX = 100000; 114our $OUTPUT_RATE_MAX = 1000000;
115
116our $MAX_LINKS = 32; # how many chained exits to follow
117our $VERBOSE_IO = 1;
115 118
116our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 119our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
117our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 120our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
118our $NEXT_TICK; 121our $NEXT_TICK;
119our $USE_FSYNC = 1; # use fsync to write maps - default on 122our $USE_FSYNC = 1; # use fsync to write maps - default on
165 168
166our $EMERGENCY_POSITION; 169our $EMERGENCY_POSITION;
167 170
168sub cf::map::normalise; 171sub cf::map::normalise;
169 172
173sub in_main() {
174 $Coro::current == $Coro::main
175}
176
170############################################################################# 177#############################################################################
171 178
172%REFLECT = (); 179%REFLECT = ();
173for (@REFLECT) { 180for (@REFLECT) {
174 my $reflect = JSON::XS::decode_json $_; 181 my $reflect = JSON::XS::decode_json $_;
261$Coro::State::DIEHOOK = sub { 268$Coro::State::DIEHOOK = sub {
262 return unless $^S eq 0; # "eq", not "==" 269 return unless $^S eq 0; # "eq", not "=="
263 270
264 warn Carp::longmess $_[0]; 271 warn Carp::longmess $_[0];
265 272
266 if ($Coro::current == $Coro::main) {#d# 273 if (in_main) {#d#
267 warn "DIEHOOK called in main context, Coro bug?\n";#d# 274 warn "DIEHOOK called in main context, Coro bug?\n";#d#
268 return;#d# 275 return;#d#
269 }#d# 276 }#d#
270 277
271 # kill coroutine otherwise 278 # kill coroutine otherwise
1188 1195
1189 sync_job { 1196 sync_job {
1190 if (length $$rdata) { 1197 if (length $$rdata) {
1191 utf8::decode (my $decname = $filename); 1198 utf8::decode (my $decname = $filename);
1192 warn sprintf "saving %s (%d,%d)\n", 1199 warn sprintf "saving %s (%d,%d)\n",
1193 $decname, length $$rdata, scalar @$objs; 1200 $decname, length $$rdata, scalar @$objs
1201 if $VERBOSE_IO;
1194 1202
1195 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1203 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1196 aio_chmod $fh, SAVE_MODE; 1204 aio_chmod $fh, SAVE_MODE;
1197 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1205 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1198 if ($cf::USE_FSYNC) { 1206 if ($cf::USE_FSYNC) {
1255 $av = $st->{objs}; 1263 $av = $st->{objs};
1256 } 1264 }
1257 1265
1258 utf8::decode (my $decname = $filename); 1266 utf8::decode (my $decname = $filename);
1259 warn sprintf "loading %s (%d,%d)\n", 1267 warn sprintf "loading %s (%d,%d)\n",
1260 $decname, length $data, scalar @{$av || []}; 1268 $decname, length $data, scalar @{$av || []}
1269 if $VERBOSE_IO;
1261 1270
1262 ($data, $av) 1271 ($data, $av)
1263} 1272}
1264 1273
1265=head2 COMMAND CALLBACKS 1274=head2 COMMAND CALLBACKS
1436 if (length $@) { 1445 if (length $@) {
1437 warn "$v->{path}: $@\n"; 1446 warn "$v->{path}: $@\n";
1438 1447
1439 cf::cleanup "mandatory extension '$k' failed to load, exiting." 1448 cf::cleanup "mandatory extension '$k' failed to load, exiting."
1440 if exists $v->{meta}{mandatory}; 1449 if exists $v->{meta}{mandatory};
1450
1451 warn "$v->{base}: optional extension cannot be loaded, skipping.\n";
1452 delete $todo{$k};
1441 } else { 1453 } else {
1442 $done{$k} = delete $todo{$k}; 1454 $done{$k} = delete $todo{$k};
1443 push @EXTS, $v->{pkg}; 1455 push @EXTS, $v->{pkg};
1444 $progress = 1; 1456 $progress = 1;
1445 1457
1688 \@logins 1700 \@logins
1689} 1701}
1690 1702
1691=item $player->maps 1703=item $player->maps
1692 1704
1705=item cf::player::maps $login
1706
1693Returns an arrayref of map paths that are private for this 1707Returns an arrayref of map paths that are private for this
1694player. May block. 1708player. May block.
1695 1709
1696=cut 1710=cut
1697 1711
1758 1772
1759=cut 1773=cut
1760 1774
1761sub find_by_path($) { 1775sub find_by_path($) {
1762 my ($path) = @_; 1776 my ($path) = @_;
1777
1778 $path =~ s/^~[^\/]*//; # skip ~login
1763 1779
1764 my ($match, $specificity); 1780 my ($match, $specificity);
1765 1781
1766 for my $region (list) { 1782 for my $region (list) {
1767 if ($region->{match} && $path =~ $region->{match}) { 1783 if ($region->{match} && $path =~ $region->{match}) {
1831 1847
1832 $EXT_MAP{$pkg} = [$prio, qr<$regex>]; 1848 $EXT_MAP{$pkg} = [$prio, qr<$regex>];
1833} 1849}
1834 1850
1835# also paths starting with '/' 1851# also paths starting with '/'
1836$EXT_MAP{"cf::map"} = [0, qr{^(?=/)}]; 1852$EXT_MAP{"cf::map::wrap"} = [0, qr{^(?=/)}];
1837 1853
1838sub thawer_merge { 1854sub thawer_merge {
1839 my ($self, $merge) = @_; 1855 my ($self, $merge) = @_;
1840 1856
1841 # we have to keep some variables in memory intact 1857 # we have to keep some variables in memory intact
2151 or next; 2167 or next;
2152 $neigh = find $neigh, $map 2168 $neigh = find $neigh, $map
2153 or next; 2169 or next;
2154 $neigh->load; 2170 $neigh->load;
2155 2171
2172 # now find the diagonal neighbours
2156 push @neigh, 2173 push @neigh,
2157 [$neigh->tile_path (($_ + 3) % 4), $neigh], 2174 [$neigh->tile_path (($_ + 3) % 4), $neigh],
2158 [$neigh->tile_path (($_ + 1) % 4), $neigh]; 2175 [$neigh->tile_path (($_ + 1) % 4), $neigh];
2159 } 2176 }
2160 2177
2332 2349
2333 delete $cf::MAP{$self->path}; 2350 delete $cf::MAP{$self->path};
2334 2351
2335 $self->unlink_save; 2352 $self->unlink_save;
2336 2353
2337 bless $self, "cf::map"; 2354 bless $self, "cf::map::wrap";
2338 delete $self->{deny_reset}; 2355 delete $self->{deny_reset};
2339 $self->{deny_save} = 1; 2356 $self->{deny_save} = 1;
2340 $self->reset_timeout (1); 2357 $self->reset_timeout (1);
2341 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++)); 2358 $self->path ($self->{path} = "{nuke}/" . ($nuke_counter++));
2342 2359
2572 2589
2573Freezes the player and moves him/her to a special map (C<{link}>). 2590Freezes the player and moves him/her to a special map (C<{link}>).
2574 2591
2575The player should be reasonably safe there for short amounts of time (e.g. 2592The player should be reasonably safe there for short amounts of time (e.g.
2576for loading a map). You I<MUST> call C<leave_link> as soon as possible, 2593for loading a map). You I<MUST> call C<leave_link> as soon as possible,
2577though, as the palyer cannot control the character while it is on the link 2594though, as the player cannot control the character while it is on the link
2578map. 2595map.
2579 2596
2580Will never block. 2597Will never block.
2581 2598
2582=item $player_object->leave_link ($map, $x, $y) 2599=item $player_object->leave_link ($map, $x, $y)
2603sub cf::object::player::enter_link { 2620sub cf::object::player::enter_link {
2604 my ($self) = @_; 2621 my ($self) = @_;
2605 2622
2606 $self->deactivate_recursive; 2623 $self->deactivate_recursive;
2607 2624
2625 ++$self->{_link_recursion};
2626
2608 return if UNIVERSAL::isa $self->map, "ext::map_link"; 2627 return if UNIVERSAL::isa $self->map, "ext::map_link";
2609 2628
2610 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y] 2629 $self->{_link_pos} ||= [$self->map->{path}, $self->x, $self->y]
2611 if $self->map && $self->map->{path} ne "{link}"; 2630 if $self->map && $self->map->{path} ne "{link}";
2612 2631
2643 $map->load_neighbours; 2662 $map->load_neighbours;
2644 2663
2645 return unless $self->contr->active; 2664 return unless $self->contr->active;
2646 2665
2647 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2666 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2648 $self->enter_map ($map, $x, $y); 2667 if ($self->enter_map ($map, $x, $y)) {
2649 2668 # entering was successful
2669 delete $self->{_link_recursion};
2650 # only activate afterwards, to support waiting in hooks 2670 # only activate afterwards, to support waiting in hooks
2651 $self->activate_recursive; 2671 $self->activate_recursive;
2652} 2672 }
2653 2673
2674}
2675
2654=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)]])
2655 2677
2656Moves the player to the given map-path and coordinates by first freezing 2678Moves the player to the given map-path and coordinates by first freezing
2657her, loading and preparing them map, calling the provided $check callback 2679her, loading and preparing them map, calling the provided $check callback
2658that has to return the map if sucecssful, and then unfreezes the player on 2680that has to return the map if sucecssful, and then unfreezes the player on
2659the new (success) or old (failed) map position. In either case, $done will 2681the new (success) or old (failed) map position. In either case, $done will
2666 2688
2667our $GOTOGEN; 2689our $GOTOGEN;
2668 2690
2669sub cf::object::player::goto { 2691sub cf::object::player::goto {
2670 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 }
2671 2699
2672 # 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
2673 my $gen = $self->{_goto_generation} = ++$GOTOGEN; 2701 my $gen = $self->{_goto_generation} = ++$GOTOGEN;
2674 2702
2675 $self->enter_link; 2703 $self->enter_link;
2699 my $map = eval { 2727 my $map = eval {
2700 my $map = defined $path ? cf::map::find $path : undef; 2728 my $map = defined $path ? cf::map::find $path : undef;
2701 2729
2702 if ($map) { 2730 if ($map) {
2703 $map = $map->customise_for ($self); 2731 $map = $map->customise_for ($self);
2704 $map = $check->($map) if $check && $map; 2732 $map = $check->($map, $x, $y, $self) if $check && $map;
2705 } else { 2733 } else {
2706 $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);
2707 } 2735 }
2708 2736
2709 $map 2737 $map
2717 if ($gen == $self->{_goto_generation}) { 2745 if ($gen == $self->{_goto_generation}) {
2718 delete $self->{_goto_generation}; 2746 delete $self->{_goto_generation};
2719 $self->leave_link ($map, $x, $y); 2747 $self->leave_link ($map, $x, $y);
2720 } 2748 }
2721 2749
2722 $done->() if $done; 2750 $done->($self) if $done;
2723 })->prio (1); 2751 })->prio (1);
2724} 2752}
2725 2753
2726=item $player_object->enter_exit ($exit_object) 2754=item $player_object->enter_exit ($exit_object)
2727 2755
3500 or return; 3528 or return;
3501 3529
3502 local $/; 3530 local $/;
3503 *CFG = YAML::XS::Load scalar <$fh>; 3531 *CFG = YAML::XS::Load scalar <$fh>;
3504 3532
3505 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_105_115", 5, 37]; 3533 $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38];
3506 3534
3507 $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};
3508 $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};
3509 3537
3510 if (exists $CFG{mlockall}) { 3538 if (exists $CFG{mlockall}) {
3785 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH}; 3813 my $leaf_symtab = *{$stem_symtab->{$leaf}}{HASH};
3786 for my $name (keys %$leaf_symtab) { 3814 for my $name (keys %$leaf_symtab) {
3787 _gv_clear *{"$pkg$name"}; 3815 _gv_clear *{"$pkg$name"};
3788# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"}; 3816# use PApp::Util; PApp::Util::sv_dump *{"$pkg$name"};
3789 } 3817 }
3790 warn "cleared package $pkg\n";#d#
3791} 3818}
3792 3819
3793sub do_reload_perl() { 3820sub do_reload_perl() {
3794 # can/must only be called in main 3821 # can/must only be called in main
3795 if ($Coro::current != $Coro::main) { 3822 if (in_main) {
3796 warn "can only reload from main coroutine"; 3823 warn "can only reload from main coroutine";
3797 return; 3824 return;
3798 } 3825 }
3799 3826
3800 return if $RELOAD++; 3827 return if $RELOAD++;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines