1 | # |
1 | # |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | # |
3 | # |
4 | # Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | # |
5 | # |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
7 | # the terms of the Affero GNU General Public License as published by the |
7 | # the terms of the Affero GNU General Public License as published by the |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
8 | # Free Software Foundation, either version 3 of the License, or (at your |
9 | # option) any later version. |
9 | # option) any later version. |
… | |
… | |
93 | our @EVENT; |
93 | our @EVENT; |
94 | our @REFLECT; # set by XS |
94 | our @REFLECT; # set by XS |
95 | our %REFLECT; # set by us |
95 | our %REFLECT; # set by us |
96 | |
96 | |
97 | our $CONFDIR = confdir; |
97 | our $CONFDIR = confdir; |
|
|
98 | |
98 | our $DATADIR = datadir; |
99 | our $DATADIR = datadir; |
99 | our $LIBDIR = "$DATADIR/ext"; |
100 | our $LIBDIR = "$DATADIR/ext"; |
100 | our $PODDIR = "$DATADIR/pod"; |
101 | our $PODDIR = "$DATADIR/pod"; |
101 | our $MAPDIR = "$DATADIR/" . mapdir; |
102 | our $MAPDIR = "$DATADIR/" . mapdir; |
|
|
103 | |
102 | our $LOCALDIR = localdir; |
104 | our $LOCALDIR = localdir; |
103 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
105 | our $TMPDIR = "$LOCALDIR/" . tmpdir; |
104 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
106 | our $UNIQUEDIR = "$LOCALDIR/" . uniquedir; |
105 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
107 | our $PLAYERDIR = "$LOCALDIR/" . playerdir; |
106 | our $RANDOMDIR = "$LOCALDIR/random"; |
108 | our $RANDOMDIR = "$LOCALDIR/random"; |
… | |
… | |
312 | } |
314 | } |
313 | |
315 | |
314 | $EV::DIED = sub { |
316 | $EV::DIED = sub { |
315 | Carp::cluck "error in event callback: @_"; |
317 | Carp::cluck "error in event callback: @_"; |
316 | }; |
318 | }; |
|
|
319 | |
|
|
320 | ############################################################################# |
|
|
321 | |
|
|
322 | sub fork_call(&@); |
|
|
323 | sub get_slot($;$$); |
317 | |
324 | |
318 | ############################################################################# |
325 | ############################################################################# |
319 | |
326 | |
320 | =head2 UTILITY FUNCTIONS |
327 | =head2 UTILITY FUNCTIONS |
321 | |
328 | |
… | |
… | |
342 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
349 | $d =~ s/([\x00-\x07\x09\x0b\x0c\x0e-\x1f])/sprintf "\\x%02x", ord($1)/ge; |
343 | $d |
350 | $d |
344 | } || "[unable to dump $_[0]: '$@']"; |
351 | } || "[unable to dump $_[0]: '$@']"; |
345 | } |
352 | } |
346 | |
353 | |
|
|
354 | =item $scalar = load_file $path |
|
|
355 | |
|
|
356 | Loads the given file from path and returns its contents. Croaks on error |
|
|
357 | and can block. |
|
|
358 | |
|
|
359 | =cut |
|
|
360 | |
|
|
361 | sub load_file($) { |
|
|
362 | 0 <= aio_load $_[0], my $data |
|
|
363 | or Carp::croak "$_[0]: $!"; |
|
|
364 | |
|
|
365 | $data |
|
|
366 | } |
|
|
367 | |
347 | =item $ref = cf::decode_json $json |
368 | =item $ref = cf::decode_json $json |
348 | |
369 | |
349 | Converts a JSON string into the corresponding perl data structure. |
370 | Converts a JSON string into the corresponding perl data structure. |
350 | |
371 | |
351 | =item $json = cf::encode_json $ref |
372 | =item $json = cf::encode_json $ref |
… | |
… | |
357 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
378 | our $json_coder = JSON::XS->new->utf8->max_size (1e6); # accept ~1mb max |
358 | |
379 | |
359 | sub encode_json($) { $json_coder->encode ($_[0]) } |
380 | sub encode_json($) { $json_coder->encode ($_[0]) } |
360 | sub decode_json($) { $json_coder->decode ($_[0]) } |
381 | sub decode_json($) { $json_coder->decode ($_[0]) } |
361 | |
382 | |
|
|
383 | =item $ref = cf::decode_storable $scalar |
|
|
384 | |
|
|
385 | Same as Coro::Storable::thaw, so blocks. |
|
|
386 | |
|
|
387 | =cut |
|
|
388 | |
|
|
389 | BEGIN { *decode_storable = \&Coro::Storable::thaw } |
|
|
390 | |
362 | =item $ref = cf::yaml_load $scalar |
391 | =item $ref = cf::decode_yaml $scalar |
363 | |
392 | |
364 | Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks). |
393 | Same as YAML::XS::Load, but doesn't leak, because it forks (and thus blocks). |
365 | |
394 | |
366 | =cut |
395 | =cut |
367 | |
396 | |
368 | sub fork_call(&@); |
397 | sub decode_yaml($) { |
369 | |
|
|
370 | sub yaml_load($) { |
|
|
371 | fork_call { YAML::XS::Load $_[0] } @_ |
398 | fork_call { YAML::XS::Load $_[0] } @_ |
|
|
399 | } |
|
|
400 | |
|
|
401 | =item $scalar = cf::unlzf $scalar |
|
|
402 | |
|
|
403 | Same as Compress::LZF::compress, but takes server ticks into account, so |
|
|
404 | blocks. |
|
|
405 | |
|
|
406 | =cut |
|
|
407 | |
|
|
408 | sub unlzf($) { |
|
|
409 | # we assume 100mb/s minimum decompression speed (noncompressible data on a ~2ghz machine) |
|
|
410 | cf::get_slot +(length $_[0]) / 100_000_000, 0, "unlzf"; |
|
|
411 | Compress::LZF::decompress $_[0] |
372 | } |
412 | } |
373 | |
413 | |
374 | =item cf::post_init { BLOCK } |
414 | =item cf::post_init { BLOCK } |
375 | |
415 | |
376 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
416 | Execute the given codeblock, I<after> all extensions have been (re-)loaded, |
… | |
… | |
460 | EV::periodic $start, $interval, 0, $cb |
500 | EV::periodic $start, $interval, 0, $cb |
461 | } |
501 | } |
462 | |
502 | |
463 | =item cf::get_slot $time[, $priority[, $name]] |
503 | =item cf::get_slot $time[, $priority[, $name]] |
464 | |
504 | |
465 | Allocate $time seconds of blocking CPU time at priority C<$priority>: |
505 | Allocate $time seconds of blocking CPU time at priority C<$priority> |
466 | This call blocks and returns only when you have at least C<$time> seconds |
506 | (default: 0): This call blocks and returns only when you have at least |
467 | of cpu time till the next tick. The slot is only valid till the next cede. |
507 | C<$time> seconds of cpu time till the next tick. The slot is only valid |
|
|
508 | till the next cede. |
|
|
509 | |
|
|
510 | Background jobs should use a priority les than zero, interactive jobs |
|
|
511 | should use 100 or more. |
468 | |
512 | |
469 | The optional C<$name> can be used to identify the job to run. It might be |
513 | The optional C<$name> can be used to identify the job to run. It might be |
470 | used for statistical purposes and should identify the same time-class. |
514 | used for statistical purposes and should identify the same time-class. |
471 | |
515 | |
472 | Useful for short background jobs. |
516 | Useful for short background jobs. |
… | |
… | |
767 | |
811 | |
768 | my @data; |
812 | my @data; |
769 | my $md5; |
813 | my $md5; |
770 | |
814 | |
771 | for (0 .. $#$src) { |
815 | for (0 .. $#$src) { |
772 | 0 <= aio_load $src->[$_], $data[$_] |
816 | $data[$_] = load_file $src->[$_]; |
773 | or Carp::croak "$src->[$_]: $!"; |
|
|
774 | } |
817 | } |
775 | |
818 | |
776 | # if processing is expensive, check |
819 | # if processing is expensive, check |
777 | # checksum first |
820 | # checksum first |
778 | if (1) { |
821 | if (1) { |
… | |
… | |
1512 | |
1555 | |
1513 | while (my ($k, $v) = each %todo) { |
1556 | while (my ($k, $v) = each %todo) { |
1514 | cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." |
1557 | cf::cleanup "mandatory extension '$k' has unresolved dependencies, exiting." |
1515 | if exists $v->{meta}{mandatory}; |
1558 | if exists $v->{meta}{mandatory}; |
1516 | } |
1559 | } |
|
|
1560 | |
|
|
1561 | last; |
1517 | } |
1562 | } |
1518 | } |
1563 | } |
1519 | }; |
1564 | }; |
1520 | } |
1565 | } |
1521 | |
1566 | |
… | |
… | |
1861 | sub generate_random_map { |
1906 | sub generate_random_map { |
1862 | my ($self, $rmp) = @_; |
1907 | my ($self, $rmp) = @_; |
1863 | |
1908 | |
1864 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1909 | my $lock = cf::lock_acquire "generate_random_map"; # the random map generator is NOT reentrant ATM |
1865 | |
1910 | |
1866 | # mit "rum" bekleckern, nicht |
|
|
1867 | $self->_create_random_map ( |
1911 | $self->_create_random_map ($rmp); |
1868 | $rmp->{wallstyle}, $rmp->{wall_name}, $rmp->{floorstyle}, $rmp->{monsterstyle}, |
|
|
1869 | $rmp->{treasurestyle}, $rmp->{layoutstyle}, $rmp->{doorstyle}, $rmp->{decorstyle}, $rmp->{miningstyle}, |
|
|
1870 | $rmp->{origin_map}, $rmp->{final_map}, $rmp->{exitstyle}, $rmp->{this_map}, |
|
|
1871 | $rmp->{exit_on_final_map}, |
|
|
1872 | $rmp->{xsize}, $rmp->{ysize}, |
|
|
1873 | $rmp->{expand2x}, $rmp->{layoutoptions1}, $rmp->{layoutoptions2}, $rmp->{layoutoptions3}, |
|
|
1874 | $rmp->{symmetry}, $rmp->{difficulty}, $rmp->{difficulty_given}, $rmp->{difficulty_increase}, |
|
|
1875 | $rmp->{dungeon_level}, $rmp->{dungeon_depth}, $rmp->{decoroptions}, $rmp->{orientation}, |
|
|
1876 | $rmp->{origin_y}, $rmp->{origin_x}, $rmp->{random_seed}, $rmp->{total_map_hp}, |
|
|
1877 | $rmp->{map_layout_style}, $rmp->{treasureoptions}, $rmp->{symmetry_used}, |
|
|
1878 | (cf::region::find $rmp->{region}), $rmp->{custom} |
|
|
1879 | ) |
|
|
1880 | } |
1912 | } |
1881 | |
1913 | |
1882 | =item cf::map->register ($regex, $prio) |
1914 | =item cf::map->register ($regex, $prio) |
1883 | |
1915 | |
1884 | Register a handler for the map path matching the given regex at the |
1916 | Register a handler for the map path matching the given regex at the |
… | |
… | |
1922 | # {... are special paths that are not being touched |
1954 | # {... are special paths that are not being touched |
1923 | # ?xxx/... are special absolute paths |
1955 | # ?xxx/... are special absolute paths |
1924 | # ?random/... random maps |
1956 | # ?random/... random maps |
1925 | # /... normal maps |
1957 | # /... normal maps |
1926 | # ~user/... per-player map of a specific user |
1958 | # ~user/... per-player map of a specific user |
|
|
1959 | # !up !down for quad maps, or other maps with up/down layers |
1927 | |
1960 | |
1928 | $path =~ s/$PATH_SEP/\//go; |
1961 | $path =~ s/$PATH_SEP/\//go; |
1929 | |
1962 | |
1930 | # treat it as relative path if it starts with |
1963 | # treat it as relative path if it starts with |
1931 | # something that looks reasonable |
1964 | # something that looks reasonable |
1932 | if ($path =~ m{^(?:\./|\.\./|\w)}) { |
1965 | if ($path =~ m{^(?:\./|\.\./|\w)}) { |
1933 | $base or Carp::carp "normalise called with relative path and no base: '$path'"; |
1966 | $base or Carp::carp "normalise called with relative path and no base: '$path'"; |
1934 | |
1967 | |
1935 | $base =~ s{[^/]+/?$}{}; |
1968 | $base =~ s{[^/]+/?$}{}; |
1936 | $path = "$base/$path"; |
1969 | $path = "$base/$path"; |
|
|
1970 | |
|
|
1971 | } elsif ($path eq '!up') { |
|
|
1972 | $base && ref $base |
|
|
1973 | or Carp::carp "normalise called with relative tile path and no base: '$path'"; |
|
|
1974 | |
|
|
1975 | my $uppth = $base->tile_path (cf::TILE_UP); |
|
|
1976 | $path = $uppth if $uppth; |
|
|
1977 | |
|
|
1978 | } elsif ($path eq '!down') { |
|
|
1979 | $base && ref $base |
|
|
1980 | or Carp::carp "normalise called with relative tile path and no base: '$path'"; |
|
|
1981 | |
|
|
1982 | my $dpth = $base->tile_path (cf::TILE_DOWN); |
|
|
1983 | $path = $dpth if $dpth; |
1937 | } |
1984 | } |
1938 | |
1985 | |
1939 | for ($path) { |
1986 | for ($path) { |
1940 | redo if s{/\.?/}{/}; |
1987 | redo if s{/\.?/}{/}; |
1941 | redo if s{/[^/]+/\.\./}{/}; |
1988 | redo if s{/[^/]+/\.\./}{/}; |
… | |
… | |
1962 | |
2009 | |
1963 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
2010 | Carp::cluck "unable to resolve path '$path' (base '$base')"; |
1964 | () |
2011 | () |
1965 | } |
2012 | } |
1966 | |
2013 | |
|
|
2014 | # may re-bless or do other evil things |
1967 | sub init { |
2015 | sub init { |
1968 | my ($self) = @_; |
2016 | my ($self) = @_; |
1969 | |
2017 | |
1970 | $self |
2018 | $self |
1971 | } |
2019 | } |
… | |
… | |
2093 | sub find { |
2141 | sub find { |
2094 | my ($path, $origin) = @_; |
2142 | my ($path, $origin) = @_; |
2095 | |
2143 | |
2096 | cf::cede_to_tick; |
2144 | cf::cede_to_tick; |
2097 | |
2145 | |
2098 | $path = normalise $path, $origin && $origin->path; |
2146 | $path = normalise $path, $origin; |
2099 | |
2147 | |
2100 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2148 | my $guard1 = cf::lock_acquire "map_data:$path";#d#remove |
2101 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2149 | my $guard2 = cf::lock_acquire "map_find:$path"; |
2102 | |
2150 | |
2103 | $cf::MAP{$path} || do { |
2151 | $cf::MAP{$path} || do { |
… | |
… | |
2143 | $self->alloc; |
2191 | $self->alloc; |
2144 | |
2192 | |
2145 | $self->pre_load; |
2193 | $self->pre_load; |
2146 | cf::cede_to_tick; |
2194 | cf::cede_to_tick; |
2147 | |
2195 | |
|
|
2196 | if (exists $self->{load_path}) { |
2148 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2197 | my $f = new_from_file cf::object::thawer $self->{load_path}; |
2149 | $f->skip_block; |
2198 | $f->skip_block; |
2150 | $self->_load_objects ($f) |
2199 | $self->_load_objects ($f) |
2151 | or return; |
2200 | or return; |
2152 | |
2201 | |
2153 | $self->post_load_original |
2202 | $self->post_load_original |
2154 | if delete $self->{load_original}; |
2203 | if delete $self->{load_original}; |
2155 | |
2204 | |
2156 | if (my $uniq = $self->uniq_path) { |
2205 | if (my $uniq = $self->uniq_path) { |
2157 | utf8::encode $uniq; |
2206 | utf8::encode $uniq; |
2158 | unless (aio_stat $uniq) { |
2207 | unless (aio_stat $uniq) { |
2159 | if (my $f = new_from_file cf::object::thawer $uniq) { |
2208 | if (my $f = new_from_file cf::object::thawer $uniq) { |
2160 | $self->clear_unique_items; |
2209 | $self->clear_unique_items; |
2161 | $self->_load_objects ($f); |
2210 | $self->_load_objects ($f); |
2162 | $f->resolve_delayed_derefs; |
2211 | $f->resolve_delayed_derefs; |
|
|
2212 | } |
2163 | } |
2213 | } |
2164 | } |
2214 | } |
2165 | } |
|
|
2166 | |
2215 | |
2167 | $f->resolve_delayed_derefs; |
2216 | $f->resolve_delayed_derefs; |
|
|
2217 | } |
2168 | |
2218 | |
2169 | cf::cede_to_tick; |
2219 | cf::cede_to_tick; |
2170 | # now do the right thing for maps |
2220 | # now do the right thing for maps |
2171 | $self->link_multipart_objects; |
2221 | $self->link_multipart_objects; |
2172 | $self->difficulty ($self->estimate_difficulty) |
2222 | $self->difficulty ($self->estimate_difficulty) |
… | |
… | |
2186 | |
2236 | |
2187 | $self->in_memory (cf::MAP_ACTIVE); |
2237 | $self->in_memory (cf::MAP_ACTIVE); |
2188 | } |
2238 | } |
2189 | |
2239 | |
2190 | $self->post_load; |
2240 | $self->post_load; |
|
|
2241 | |
|
|
2242 | 1 |
2191 | } |
2243 | } |
2192 | |
2244 | |
2193 | # customize the map for a given player, i.e. |
2245 | # customize the map for a given player, i.e. |
2194 | # return the _real_ map. used by e.g. per-player |
2246 | # return the _real_ map. used by e.g. per-player |
2195 | # maps to change the path to ~playername/mappath |
2247 | # maps to change the path to ~playername/mappath |
… | |
… | |
2254 | our $MAP_PREFETCHER = undef; |
2306 | our $MAP_PREFETCHER = undef; |
2255 | |
2307 | |
2256 | sub find_async { |
2308 | sub find_async { |
2257 | my ($path, $origin, $load) = @_; |
2309 | my ($path, $origin, $load) = @_; |
2258 | |
2310 | |
2259 | $path = normalise $path, $origin && $origin->{path}; |
2311 | $path = normalise $path, $origin; |
2260 | |
2312 | |
2261 | if (my $map = $cf::MAP{$path}) { |
2313 | if (my $map = $cf::MAP{$path}) { |
2262 | return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; |
2314 | return $map if !$load || $map->in_memory == cf::MAP_ACTIVE; |
2263 | } |
2315 | } |
2264 | |
2316 | |
… | |
… | |
2775 | ($path, $x, $y) = (undef, undef, undef); |
2827 | ($path, $x, $y) = (undef, undef, undef); |
2776 | } |
2828 | } |
2777 | } |
2829 | } |
2778 | |
2830 | |
2779 | my $map = eval { |
2831 | my $map = eval { |
2780 | my $map = defined $path ? cf::map::find $path : undef; |
2832 | my $map = defined $path ? cf::map::find $path, $self->map : undef; |
2781 | |
2833 | |
2782 | if ($map) { |
2834 | if ($map) { |
2783 | $map = $map->customise_for ($self); |
2835 | $map = $map->customise_for ($self); |
2784 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2836 | $map = $check->($map, $x, $y, $self) if $check && $map; |
2785 | } else { |
2837 | } else { |
… | |
… | |
2883 | |
2935 | |
2884 | prepare_random_map $exit |
2936 | prepare_random_map $exit |
2885 | if $exit->slaying eq "/!"; |
2937 | if $exit->slaying eq "/!"; |
2886 | } |
2938 | } |
2887 | |
2939 | |
2888 | my $map = cf::map::normalise $exit->slaying, $exit->map && $exit->map->path; |
2940 | my $map = cf::map::normalise $exit->slaying, $exit->map; |
2889 | my $x = $exit->stats->hp; |
2941 | my $x = $exit->stats->hp; |
2890 | my $y = $exit->stats->sp; |
2942 | my $y = $exit->stats->sp; |
2891 | |
2943 | |
2892 | $self->goto ($map, $x, $y); |
2944 | $self->goto ($map, $x, $y); |
2893 | |
2945 | |
… | |
… | |
3410 | |
3462 | |
3411 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3463 | my $enc = JSON::XS->new->utf8->canonical->relaxed; |
3412 | |
3464 | |
3413 | trace "loading facedata from $path\n"; |
3465 | trace "loading facedata from $path\n"; |
3414 | |
3466 | |
3415 | 0 < aio_load $path, my $facedata |
3467 | my $facedata = decode_storable load_file $path; |
3416 | or die "$path: $!"; |
|
|
3417 | |
|
|
3418 | $facedata = Coro::Storable::thaw $facedata; |
|
|
3419 | |
3468 | |
3420 | $facedata->{version} == 2 |
3469 | $facedata->{version} == 2 |
3421 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3470 | or cf::cleanup "$path: version mismatch, cannot proceed."; |
3422 | |
3471 | |
3423 | # patch in the exptable |
3472 | # patch in the exptable |
… | |
… | |
3437 | |
3486 | |
3438 | cf::face::set_visibility $idx, $info->{visibility}; |
3487 | cf::face::set_visibility $idx, $info->{visibility}; |
3439 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3488 | cf::face::set_magicmap $idx, $info->{magicmap}; |
3440 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3489 | cf::face::set_data $idx, 0, $info->{data32}, $info->{hash32}; |
3441 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
3490 | cf::face::set_data $idx, 1, $info->{data64}, $info->{hash64}; |
|
|
3491 | cf::face::set_data $idx, 2, $info->{glyph} , $info->{glyph} ; |
3442 | |
3492 | |
3443 | cf::cede_to_tick; |
3493 | cf::cede_to_tick; |
3444 | } |
3494 | } |
3445 | |
3495 | |
3446 | while (my ($face, $info) = each %$faces) { |
3496 | while (my ($face, $info) = each %$faces) { |
… | |
… | |
3541 | } |
3591 | } |
3542 | |
3592 | |
3543 | sub reload_sound { |
3593 | sub reload_sound { |
3544 | trace "loading sound config from $DATADIR/sound\n"; |
3594 | trace "loading sound config from $DATADIR/sound\n"; |
3545 | |
3595 | |
3546 | 0 < Coro::AIO::aio_load "$DATADIR/sound", my $data |
|
|
3547 | or die "$DATADIR/sound $!"; |
|
|
3548 | |
|
|
3549 | my $soundconf = JSON::XS->new->utf8->relaxed->decode ($data); |
3596 | my $soundconf = JSON::XS->new->utf8->relaxed->decode (load_file "$DATADIR/sound"); |
3550 | |
3597 | |
3551 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
3598 | for (0 .. SOUND_CAST_SPELL_0 - 1) { |
3552 | my $sound = $soundconf->{compat}[$_] |
3599 | my $sound = $soundconf->{compat}[$_] |
3553 | or next; |
3600 | or next; |
3554 | |
3601 | |
… | |
… | |
3578 | } |
3625 | } |
3579 | |
3626 | |
3580 | sub reload_config { |
3627 | sub reload_config { |
3581 | trace "reloading config file...\n"; |
3628 | trace "reloading config file...\n"; |
3582 | |
3629 | |
3583 | 0 < aio_load "$CONFDIR/config", my $config |
3630 | my $config = load_file "$CONFDIR/config"; |
3584 | or die "$CONFDIR/config: $!"; |
|
|
3585 | |
|
|
3586 | utf8::decode $config; |
3631 | utf8::decode $config; |
3587 | *CFG = yaml_load $config; |
3632 | *CFG = decode_yaml $config; |
3588 | |
3633 | |
3589 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3634 | $EMERGENCY_POSITION = $CFG{emergency_position} || ["/world/world_104_115", 49, 38]; |
3590 | |
3635 | |
3591 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3636 | $cf::map::MAX_RESET = $CFG{map_max_reset} if exists $CFG{map_max_reset}; |
3592 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
3637 | $cf::map::DEFAULT_RESET = $CFG{map_default_reset} if exists $CFG{map_default_reset}; |
… | |
… | |
3630 | |
3675 | |
3631 | sub main { |
3676 | sub main { |
3632 | cf::init_globals; # initialise logging |
3677 | cf::init_globals; # initialise logging |
3633 | |
3678 | |
3634 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3679 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3635 | LOG llevInfo, "Copyright (C) 2005-2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3680 | LOG llevInfo, "Copyright (C) 2005-2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3636 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3681 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3637 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3682 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3638 | |
3683 | |
3639 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3684 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3640 | |
3685 | |
… | |
… | |
4149 | IO::AIO::min_parallel 8; |
4194 | IO::AIO::min_parallel 8; |
4150 | IO::AIO::max_poll_time $TICK * 0.1; |
4195 | IO::AIO::max_poll_time $TICK * 0.1; |
4151 | undef $AnyEvent::AIO::WATCHER; |
4196 | undef $AnyEvent::AIO::WATCHER; |
4152 | } |
4197 | } |
4153 | |
4198 | |
4154 | my $_log_backtrace; |
4199 | our $_log_backtrace; |
|
|
4200 | our $_log_backtrace_last; |
4155 | |
4201 | |
4156 | sub _log_backtrace { |
4202 | sub _log_backtrace { |
4157 | my ($msg, @addr) = @_; |
4203 | my ($msg, @addr) = @_; |
4158 | |
4204 | |
4159 | $msg =~ s/\n//; |
4205 | $msg =~ s/\n$//; |
4160 | |
4206 | |
|
|
4207 | if ($_log_backtrace_last eq $msg) { |
|
|
4208 | LOG llevInfo, "[ABT] $msg\n"; |
|
|
4209 | LOG llevInfo, "[ABT] [duplicate, suppressed]\n"; |
4161 | # limit the # of concurrent backtraces |
4210 | # limit the # of concurrent backtraces |
4162 | if ($_log_backtrace < 2) { |
4211 | } elsif ($_log_backtrace < 2) { |
|
|
4212 | $_log_backtrace_last = $msg; |
4163 | ++$_log_backtrace; |
4213 | ++$_log_backtrace; |
4164 | my $perl_bt = Carp::longmess $msg; |
4214 | my $perl_bt = Carp::longmess $msg; |
4165 | async { |
4215 | async { |
4166 | $Coro::current->{desc} = "abt $msg"; |
4216 | $Coro::current->{desc} = "abt $msg"; |
4167 | |
4217 | |
… | |
… | |
4187 | LOG llevInfo, "[ABT] $_\n" for @bt; |
4237 | LOG llevInfo, "[ABT] $_\n" for @bt; |
4188 | --$_log_backtrace; |
4238 | --$_log_backtrace; |
4189 | }; |
4239 | }; |
4190 | } else { |
4240 | } else { |
4191 | LOG llevInfo, "[ABT] $msg\n"; |
4241 | LOG llevInfo, "[ABT] $msg\n"; |
4192 | LOG llevInfo, "[ABT] [suppressed]\n"; |
4242 | LOG llevInfo, "[ABT] [overload, suppressed]\n"; |
4193 | } |
4243 | } |
4194 | } |
4244 | } |
4195 | |
4245 | |
4196 | # load additional modules |
4246 | # load additional modules |
4197 | require "cf/$_.pm" for @EXTRA_MODULES; |
4247 | require "cf/$_.pm" for @EXTRA_MODULES; |