… | |
… | |
72 | |
72 | |
73 | # make sure c-lzf reinitialises itself |
73 | # make sure c-lzf reinitialises itself |
74 | Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; |
74 | Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; |
75 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
75 | Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later |
76 | |
76 | |
|
|
77 | # strictly for debugging |
|
|
78 | $SIG{QUIT} = sub { Carp::cluck "SIGQUIT" }; |
|
|
79 | |
77 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
80 | sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload |
78 | |
81 | |
79 | our %COMMAND = (); |
82 | our %COMMAND = (); |
80 | our %COMMAND_TIME = (); |
83 | our %COMMAND_TIME = (); |
81 | |
84 | |
… | |
… | |
105 | our %RESOURCE; |
108 | our %RESOURCE; |
106 | |
109 | |
107 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
110 | our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) |
108 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
111 | our $NEXT_RUNTIME_WRITE; # when should the runtime file be written |
109 | our $NEXT_TICK; |
112 | our $NEXT_TICK; |
110 | our $USE_FSYNC = 1; # use fsync to write maps - default off |
113 | our $USE_FSYNC = 1; # use fsync to write maps - default on |
111 | |
114 | |
112 | our $BDB_DEADLOCK_WATCHER; |
115 | our $BDB_DEADLOCK_WATCHER; |
113 | our $BDB_CHECKPOINT_WATCHER; |
116 | our $BDB_CHECKPOINT_WATCHER; |
114 | our $BDB_TRICKLE_WATCHER; |
117 | our $BDB_TRICKLE_WATCHER; |
115 | our $DB_ENV; |
118 | our $DB_ENV; |
… | |
… | |
134 | our $JITTER; # average jitter |
137 | our $JITTER; # average jitter |
135 | our $TICK_START; # for load detecting purposes |
138 | our $TICK_START; # for load detecting purposes |
136 | |
139 | |
137 | our @POST_INIT; |
140 | our @POST_INIT; |
138 | |
141 | |
139 | our $REATTACH_ON_RELOAD; # ste to true to force object reattach on reload (slow) |
142 | our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow) |
|
|
143 | our $REALLY_UNLOOP; # never set to true, please :) |
140 | |
144 | |
141 | binmode STDOUT; |
145 | binmode STDOUT; |
142 | binmode STDERR; |
146 | binmode STDERR; |
143 | |
147 | |
144 | # read virtual server time, if available |
148 | # read virtual server time, if available |
… | |
… | |
1151 | $decname, length $$rdata, scalar @$objs; |
1155 | $decname, length $$rdata, scalar @$objs; |
1152 | |
1156 | |
1153 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1157 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1154 | aio_chmod $fh, SAVE_MODE; |
1158 | aio_chmod $fh, SAVE_MODE; |
1155 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1159 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1156 | aio_fsync $fh if $cf::USE_FSYNC; |
1160 | if ($cf::USE_FSYNC) { |
|
|
1161 | aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER; |
|
|
1162 | aio_fsync $fh; |
|
|
1163 | } |
1157 | aio_close $fh; |
1164 | aio_close $fh; |
1158 | |
1165 | |
1159 | if (@$objs) { |
1166 | if (@$objs) { |
1160 | if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { |
1167 | if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { |
1161 | aio_chmod $fh, SAVE_MODE; |
1168 | aio_chmod $fh, SAVE_MODE; |
1162 | my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; |
1169 | my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; |
1163 | aio_write $fh, 0, (length $data), $data, 0; |
1170 | aio_write $fh, 0, (length $data), $data, 0; |
1164 | aio_fsync $fh if $cf::USE_FSYNC; |
1171 | if ($cf::USE_FSYNC) { |
|
|
1172 | aio_sync_file_range $fh, 0, 0, IO::AIO::SYNC_FILE_RANGE_WAIT_BEFORE | IO::AIO::SYNC_FILE_RANGE_WRITE | IO::AIO::SYNC_FILE_RANGE_WAIT_AFTER; |
|
|
1173 | aio_fsync $fh; |
|
|
1174 | } |
1165 | aio_close $fh; |
1175 | aio_close $fh; |
1166 | aio_rename "$filename.pst~", "$filename.pst"; |
1176 | aio_rename "$filename.pst~", "$filename.pst"; |
1167 | } |
1177 | } |
1168 | } else { |
1178 | } else { |
1169 | aio_unlink "$filename.pst"; |
1179 | aio_unlink "$filename.pst"; |
… | |
… | |
1320 | |
1330 | |
1321 | # "readahead" all extensions |
1331 | # "readahead" all extensions |
1322 | sub cache_extensions { |
1332 | sub cache_extensions { |
1323 | my $grp = IO::AIO::aio_group; |
1333 | my $grp = IO::AIO::aio_group; |
1324 | |
1334 | |
1325 | add $grp IO::AIO::aio_readdir $LIBDIR, sub { |
1335 | add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub { |
1326 | for (grep /\.ext$/, @{$_[0]}) { |
1336 | for (grep /\.ext$/, @{$_[0]}) { |
1327 | add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; |
1337 | add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; |
1328 | } |
1338 | } |
1329 | }; |
1339 | }; |
1330 | |
1340 | |
… | |
… | |
2524 | |
2534 | |
2525 | $map->load; |
2535 | $map->load; |
2526 | $map->load_neighbours; |
2536 | $map->load_neighbours; |
2527 | |
2537 | |
2528 | return unless $self->contr->active; |
2538 | return unless $self->contr->active; |
2529 | $self->flag (cf::FLAG_DEBUG, 0);#d# temp |
|
|
2530 | $self->activate_recursive; |
|
|
2531 | |
2539 | |
2532 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2540 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2533 | $self->enter_map ($map, $x, $y); |
2541 | $self->enter_map ($map, $x, $y); |
|
|
2542 | |
|
|
2543 | # only activate afterwards, to support waiting in hooks |
|
|
2544 | $self->activate_recursive; |
2534 | } |
2545 | } |
2535 | |
2546 | |
2536 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2547 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2537 | |
2548 | |
2538 | Moves the player to the given map-path and coordinates by first freezing |
2549 | Moves the player to the given map-path and coordinates by first freezing |
… | |
… | |
2785 | id => "infobox", |
2796 | id => "infobox", |
2786 | title => "Skills", |
2797 | title => "Skills", |
2787 | reply => undef, |
2798 | reply => undef, |
2788 | tooltip => "Shows your experience per skill and item power", |
2799 | tooltip => "Shows your experience per skill and item power", |
2789 | }, |
2800 | }, |
|
|
2801 | "c/shopitems" => { |
|
|
2802 | id => "infobox", |
|
|
2803 | title => "Shop Items", |
|
|
2804 | reply => undef, |
|
|
2805 | tooltip => "Shows the items currently for sale in this shop", |
|
|
2806 | }, |
2790 | "c/resistances" => { |
2807 | "c/resistances" => { |
2791 | id => "infobox", |
2808 | id => "infobox", |
2792 | title => "Resistances", |
2809 | title => "Resistances", |
2793 | reply => undef, |
2810 | reply => undef, |
2794 | tooltip => "Shows your resistances", |
2811 | tooltip => "Shows your resistances", |
… | |
… | |
2796 | "c/pets" => { |
2813 | "c/pets" => { |
2797 | id => "infobox", |
2814 | id => "infobox", |
2798 | title => "Pets", |
2815 | title => "Pets", |
2799 | reply => undef, |
2816 | reply => undef, |
2800 | tooltip => "Shows information abotu your pets/a specific pet", |
2817 | tooltip => "Shows information abotu your pets/a specific pet", |
|
|
2818 | }, |
|
|
2819 | "c/perceiveself" => { |
|
|
2820 | id => "infobox", |
|
|
2821 | title => "Perceive Self", |
|
|
2822 | reply => undef, |
|
|
2823 | tooltip => "You gained detailed knowledge about yourself", |
2801 | }, |
2824 | }, |
2802 | "c/uptime" => { |
2825 | "c/uptime" => { |
2803 | id => "infobox", |
2826 | id => "infobox", |
2804 | title => "Uptime", |
2827 | title => "Uptime", |
2805 | reply => undef, |
2828 | reply => undef, |
… | |
… | |
3382 | |
3405 | |
3383 | seek $fh, 0, 0; |
3406 | seek $fh, 0, 0; |
3384 | print $fh $$; |
3407 | print $fh $$; |
3385 | } |
3408 | } |
3386 | |
3409 | |
|
|
3410 | sub main_loop { |
|
|
3411 | warn "EV::loop starting\n"; |
|
|
3412 | if (1) { |
|
|
3413 | EV::loop; |
|
|
3414 | } |
|
|
3415 | warn "EV::loop returned\n"; |
|
|
3416 | goto &main_loop unless $REALLY_UNLOOP; |
|
|
3417 | } |
|
|
3418 | |
3387 | sub main { |
3419 | sub main { |
3388 | cf::init_globals; # initialise logging |
3420 | cf::init_globals; # initialise logging |
3389 | |
3421 | |
3390 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3422 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3391 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3423 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
… | |
… | |
3429 | load_extensions; |
3461 | load_extensions; |
3430 | |
3462 | |
3431 | utime time, time, $RUNTIMEFILE; |
3463 | utime time, time, $RUNTIMEFILE; |
3432 | |
3464 | |
3433 | # no (long-running) fork's whatsoever before this point(!) |
3465 | # no (long-running) fork's whatsoever before this point(!) |
|
|
3466 | use POSIX (); |
3434 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3467 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3435 | |
3468 | |
3436 | (pop @POST_INIT)->(0) while @POST_INIT; |
3469 | (pop @POST_INIT)->(0) while @POST_INIT; |
3437 | }; |
3470 | }; |
3438 | |
3471 | |
3439 | EV::loop; |
3472 | main_loop; |
3440 | } |
3473 | } |
3441 | |
3474 | |
3442 | ############################################################################# |
3475 | ############################################################################# |
3443 | # initialisation and cleanup |
3476 | # initialisation and cleanup |
3444 | |
3477 | |