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,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | # Copyright (©) 2006,2007,2008,2009,2010,2011,2012 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. |
… | |
… | |
108 | our $RANDOMDIR = "$LOCALDIR/random"; |
108 | our $RANDOMDIR = "$LOCALDIR/random"; |
109 | our $BDBDIR = "$LOCALDIR/db"; |
109 | our $BDBDIR = "$LOCALDIR/db"; |
110 | our $PIDFILE = "$LOCALDIR/pid"; |
110 | our $PIDFILE = "$LOCALDIR/pid"; |
111 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
111 | our $RUNTIMEFILE = "$LOCALDIR/runtime"; |
112 | |
112 | |
113 | our %RESOURCE; # unused |
113 | #our %RESOURCE; # unused |
114 | |
114 | |
115 | our $OUTPUT_RATE_MIN = 3000; |
115 | our $OUTPUT_RATE_MIN = 3000; |
116 | our $OUTPUT_RATE_MAX = 1000000; |
116 | our $OUTPUT_RATE_MAX = 1000000; |
117 | |
117 | |
118 | our $MAX_LINKS = 32; # how many chained exits to follow |
118 | our $MAX_LINKS = 32; # how many chained exits to follow |
… | |
… | |
1461 | my ($pl, $buf) = @_; |
1461 | my ($pl, $buf) = @_; |
1462 | |
1462 | |
1463 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1463 | my $msg = eval { $pl->ns->{json_coder}->decode ($buf) }; |
1464 | |
1464 | |
1465 | if (ref $msg) { |
1465 | if (ref $msg) { |
1466 | my ($type, $reply, @payload) = |
1466 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
1467 | "ARRAY" eq ref $msg |
|
|
1468 | ? @$msg |
|
|
1469 | : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove |
|
|
1470 | |
1467 | |
1471 | my @reply; |
1468 | my @reply; |
1472 | |
1469 | |
1473 | if (my $cb = $EXTCMD{$type}) { |
1470 | if (my $cb = $EXTCMD{$type}) { |
1474 | @reply = $cb->($pl, @payload); |
1471 | @reply = $cb->($pl, @payload); |
… | |
… | |
2239 | |
2236 | |
2240 | unless ($self->{deny_activate}) { |
2237 | unless ($self->{deny_activate}) { |
2241 | $self->decay_objects; |
2238 | $self->decay_objects; |
2242 | $self->fix_auto_apply; |
2239 | $self->fix_auto_apply; |
2243 | $self->update_buttons; |
2240 | $self->update_buttons; |
2244 | $self->post_load_physics; |
|
|
2245 | cf::cede_to_tick; |
2241 | cf::cede_to_tick; |
2246 | #$self->activate; # no longer activate maps automatically |
2242 | #$self->activate; # no longer activate maps automatically |
2247 | } |
2243 | } |
2248 | |
2244 | |
2249 | $self->{last_save} = $cf::RUNTIME; |
2245 | $self->{last_save} = $cf::RUNTIME; |
… | |
… | |
2268 | # if $self->per_party; |
2264 | # if $self->per_party; |
2269 | |
2265 | |
2270 | $self |
2266 | $self |
2271 | } |
2267 | } |
2272 | |
2268 | |
2273 | # find and load all maps in the 3x3 area around a map |
|
|
2274 | sub load_neighbours { |
|
|
2275 | my ($map) = @_; |
|
|
2276 | |
|
|
2277 | my @neigh; # diagonal neighbours |
|
|
2278 | |
|
|
2279 | for (0 .. 3) { |
|
|
2280 | my $neigh = $map->tile_path ($_) |
|
|
2281 | or next; |
|
|
2282 | $neigh = find $neigh, $map |
|
|
2283 | or next; |
|
|
2284 | $neigh->load; |
|
|
2285 | |
|
|
2286 | # now find the diagonal neighbours |
|
|
2287 | push @neigh, |
|
|
2288 | [$neigh->tile_path (($_ + 3) % 4), $neigh], |
|
|
2289 | [$neigh->tile_path (($_ + 1) % 4), $neigh]; |
|
|
2290 | } |
|
|
2291 | |
|
|
2292 | for (grep defined $_->[0], @neigh) { |
|
|
2293 | my ($path, $origin) = @$_; |
|
|
2294 | my $neigh = find $path, $origin |
|
|
2295 | or next; |
|
|
2296 | $neigh->load; |
|
|
2297 | } |
|
|
2298 | } |
|
|
2299 | |
|
|
2300 | sub find_sync { |
2269 | sub find_sync { |
2301 | my ($path, $origin) = @_; |
2270 | my ($path, $origin) = @_; |
2302 | |
2271 | |
2303 | # it's a bug to call this from the main context |
2272 | # it's a bug to call this from the main context |
2304 | return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" |
2273 | return cf::LOG cf::llevError | cf::logBacktrace, "do_find_sync" |
… | |
… | |
2322 | |
2291 | |
2323 | sub find_async { |
2292 | sub find_async { |
2324 | my ($path, $origin, $load) = @_; |
2293 | my ($path, $origin, $load) = @_; |
2325 | |
2294 | |
2326 | $path = normalise $path, $origin; |
2295 | $path = normalise $path, $origin; |
2327 | |
2296 | |
2328 | if (my $map = $cf::MAP{$path}) { |
2297 | if (my $map = $cf::MAP{$path}) { |
2329 | return $map if !$load || $map->linkable; |
2298 | return $map if !$load || $map->linkable; |
2330 | } |
2299 | } |
2331 | |
2300 | |
2332 | $MAP_PREFETCH{$path} |= $load; |
2301 | $MAP_PREFETCH{$path} |= $load; |
… | |
… | |
2776 | # use -1 or undef as default coordinates, not 0, 0 |
2745 | # use -1 or undef as default coordinates, not 0, 0 |
2777 | ($x, $y) = ($map->enter_x, $map->enter_y) |
2746 | ($x, $y) = ($map->enter_x, $map->enter_y) |
2778 | if $x <= 0 && $y <= 0; |
2747 | if $x <= 0 && $y <= 0; |
2779 | |
2748 | |
2780 | $map->load; |
2749 | $map->load; |
2781 | $map->load_neighbours; |
|
|
2782 | |
2750 | |
2783 | return unless $self->contr->active; |
2751 | return unless $self->contr->active; |
2784 | |
2752 | |
2785 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2753 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2786 | if ($self->enter_map ($map, $x, $y)) { |
2754 | if ($self->enter_map ($map, $x, $y)) { |
… | |
… | |
3219 | =cut |
3187 | =cut |
3220 | |
3188 | |
3221 | sub cf::client::ext_reply($$@) { |
3189 | sub cf::client::ext_reply($$@) { |
3222 | my ($self, $id, @msg) = @_; |
3190 | my ($self, $id, @msg) = @_; |
3223 | |
3191 | |
3224 | if ($self->extcmd == 2) { |
3192 | return unless $self->extcmd == 2; |
|
|
3193 | |
3225 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3194 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3226 | } elsif ($self->extcmd == 1) { |
|
|
3227 | #TODO: version 1, remove |
|
|
3228 | unshift @msg, msgtype => "reply", msgid => $id; |
|
|
3229 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
|
|
3230 | } |
|
|
3231 | } |
3195 | } |
3232 | |
3196 | |
3233 | =item $success = $client->query ($flags, "text", \&cb) |
3197 | =item $success = $client->query ($flags, "text", \&cb) |
3234 | |
3198 | |
3235 | Queues a query to the client, calling the given callback with |
3199 | Queues a query to the client, calling the given callback with |
… | |
… | |
3290 | my ($ns, $buf) = @_; |
3254 | my ($ns, $buf) = @_; |
3291 | |
3255 | |
3292 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3256 | my $msg = eval { $ns->{json_coder}->decode ($buf) }; |
3293 | |
3257 | |
3294 | if (ref $msg) { |
3258 | if (ref $msg) { |
3295 | my ($type, $reply, @payload) = |
3259 | my ($type, $reply, @payload) = @$msg; # version 1 used %type, $id, %$hash |
3296 | "ARRAY" eq ref $msg |
|
|
3297 | ? @$msg |
|
|
3298 | : ($msg->{msgtype}, $msg->{msgid}, %$msg); # TODO: version 1, remove |
|
|
3299 | |
3260 | |
3300 | my @reply; |
3261 | my @reply; |
3301 | |
3262 | |
3302 | if (my $cb = $EXTICMD{$type}) { |
3263 | if (my $cb = $EXTICMD{$type}) { |
3303 | @reply = $cb->($ns, @payload); |
3264 | @reply = $cb->($ns, @payload); |
… | |
… | |
3553 | |
3514 | |
3554 | { |
3515 | { |
3555 | my $res = $facedata->{resource}; |
3516 | my $res = $facedata->{resource}; |
3556 | |
3517 | |
3557 | while (my ($name, $info) = each %$res) { |
3518 | while (my ($name, $info) = each %$res) { |
3558 | if (defined $info->{type}) { |
3519 | if (defined (my $type = $info->{type})) { |
|
|
3520 | # TODO: different hash - must free and use new index, or cache ixface data queue |
3559 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3521 | my $idx = (cf::face::find $name) || cf::face::alloc $name; |
3560 | |
3522 | |
3561 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3523 | cf::face::set_data $idx, 0, $info->{data}, $info->{hash}; |
3562 | cf::face::set_type $idx, $info->{type}; |
3524 | cf::face::set_type $idx, $type; |
|
|
3525 | cf::face::set_meta $idx, $type & 1 ? undef : $info->{meta}; # preserve meta unless prepended already |
3563 | } else { |
3526 | } else { |
3564 | $RESOURCE{$name} = $info; # unused |
3527 | # $RESOURCE{$name} = $info; # unused |
3565 | } |
3528 | } |
3566 | |
3529 | |
3567 | cf::cede_to_tick; |
3530 | cf::cede_to_tick; |
3568 | } |
3531 | } |
3569 | } |
3532 | } |
… | |
… | |
3705 | |
3668 | |
3706 | sub main { |
3669 | sub main { |
3707 | cf::init_globals; # initialise logging |
3670 | cf::init_globals; # initialise logging |
3708 | |
3671 | |
3709 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3672 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3710 | LOG llevInfo, "Copyright (C) 2005-2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3673 | LOG llevInfo, "Copyright (C) 2005-2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3711 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3674 | LOG llevInfo, "Copyright (C) 1994 Mark Wedel."; |
3712 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3675 | LOG llevInfo, "Copyright (C) 1992 Frank Tore Johansen."; |
3713 | |
3676 | |
3714 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3677 | $Coro::current->prio (Coro::PRIO_MAX); # give the main loop max. priority |
3715 | |
3678 | |
… | |
… | |
3757 | }; |
3720 | }; |
3758 | |
3721 | |
3759 | cf::object::thawer::errors_are_fatal 0; |
3722 | cf::object::thawer::errors_are_fatal 0; |
3760 | info "parse errors in files are no longer fatal from this point on.\n"; |
3723 | info "parse errors in files are no longer fatal from this point on.\n"; |
3761 | |
3724 | |
3762 | my $free_main; $free_main = EV::idle sub { |
3725 | AE::postpone { |
3763 | undef $free_main; |
|
|
3764 | undef &main; # free gobs of memory :) |
3726 | undef &main; # free gobs of memory :) |
3765 | }; |
3727 | }; |
3766 | |
3728 | |
3767 | goto &main_loop; |
3729 | goto &main_loop; |
3768 | } |
3730 | } |
… | |
… | |
3925 | |
3887 | |
3926 | cf::write_runtime_sync; # external watchdog should not bark |
3888 | cf::write_runtime_sync; # external watchdog should not bark |
3927 | |
3889 | |
3928 | trace "emergency_perl_save: flushing outstanding aio requests"; |
3890 | trace "emergency_perl_save: flushing outstanding aio requests"; |
3929 | while (IO::AIO::nreqs || BDB::nreqs) { |
3891 | while (IO::AIO::nreqs || BDB::nreqs) { |
3930 | Coro::EV::timer_once 0.01; # let the sync_job do it's thing |
3892 | Coro::AnyEvent::sleep 0.01; # let the sync_job do it's thing |
3931 | } |
3893 | } |
3932 | |
3894 | |
3933 | cf::write_runtime_sync; # external watchdog should not bark |
3895 | cf::write_runtime_sync; # external watchdog should not bark |
3934 | }; |
3896 | }; |
3935 | |
3897 | |
… | |
… | |
4172 | { |
4134 | { |
4173 | # configure BDB |
4135 | # configure BDB |
4174 | |
4136 | |
4175 | BDB::min_parallel 16; |
4137 | BDB::min_parallel 16; |
4176 | BDB::max_poll_reqs $TICK * 0.1; |
4138 | BDB::max_poll_reqs $TICK * 0.1; |
4177 | $AnyEvent::BDB::WATCHER->priority (1); |
4139 | #$AnyEvent::BDB::WATCHER->priority (1); |
4178 | |
4140 | |
4179 | unless ($DB_ENV) { |
4141 | unless ($DB_ENV) { |
4180 | $DB_ENV = BDB::db_env_create; |
4142 | $DB_ENV = BDB::db_env_create; |
4181 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT); |
4143 | $DB_ENV->set_flags (BDB::AUTO_COMMIT | BDB::REGION_INIT); |
4182 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
4144 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |