… | |
… | |
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 |
145 | unless ($RUNTIME || !-e $RUNTIMEFILE) { |
149 | unless ($RUNTIME || !-e $RUNTIMEFILE) { |
146 | open my $fh, "<", $RUNTIMEFILE |
150 | open my $fh, "<", $RUNTIMEFILE |
147 | or die "unable to read $RUNTIMEFILE file: $!"; |
151 | or die "unable to read $RUNTIMEFILE file: $!"; |
148 | $RUNTIME = <$fh> + 0.; |
152 | $RUNTIME = <$fh> + 0.; |
149 | } |
153 | } |
|
|
154 | |
|
|
155 | eval "sub TICK() { $TICK } 1" or die; |
150 | |
156 | |
151 | mkdir $_ |
157 | mkdir $_ |
152 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
158 | for $LOCALDIR, $TMPDIR, $UNIQUEDIR, $PLAYERDIR, $RANDOMDIR, $BDBDIR; |
153 | |
159 | |
154 | our $EMERGENCY_POSITION; |
160 | our $EMERGENCY_POSITION; |
… | |
… | |
1149 | $decname, length $$rdata, scalar @$objs; |
1155 | $decname, length $$rdata, scalar @$objs; |
1150 | |
1156 | |
1151 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1157 | if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { |
1152 | aio_chmod $fh, SAVE_MODE; |
1158 | aio_chmod $fh, SAVE_MODE; |
1153 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1159 | aio_write $fh, 0, (length $$rdata), $$rdata, 0; |
1154 | 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 | } |
1155 | aio_close $fh; |
1164 | aio_close $fh; |
1156 | |
1165 | |
1157 | if (@$objs) { |
1166 | if (@$objs) { |
1158 | 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) { |
1159 | aio_chmod $fh, SAVE_MODE; |
1168 | aio_chmod $fh, SAVE_MODE; |
1160 | my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; |
1169 | my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; |
1161 | aio_write $fh, 0, (length $data), $data, 0; |
1170 | aio_write $fh, 0, (length $data), $data, 0; |
1162 | 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 | } |
1163 | aio_close $fh; |
1175 | aio_close $fh; |
1164 | aio_rename "$filename.pst~", "$filename.pst"; |
1176 | aio_rename "$filename.pst~", "$filename.pst"; |
1165 | } |
1177 | } |
1166 | } else { |
1178 | } else { |
1167 | aio_unlink "$filename.pst"; |
1179 | aio_unlink "$filename.pst"; |
… | |
… | |
1318 | |
1330 | |
1319 | # "readahead" all extensions |
1331 | # "readahead" all extensions |
1320 | sub cache_extensions { |
1332 | sub cache_extensions { |
1321 | my $grp = IO::AIO::aio_group; |
1333 | my $grp = IO::AIO::aio_group; |
1322 | |
1334 | |
1323 | add $grp IO::AIO::aio_readdir $LIBDIR, sub { |
1335 | add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub { |
1324 | for (grep /\.ext$/, @{$_[0]}) { |
1336 | for (grep /\.ext$/, @{$_[0]}) { |
1325 | add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; |
1337 | add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; |
1326 | } |
1338 | } |
1327 | }; |
1339 | }; |
1328 | |
1340 | |
… | |
… | |
2386 | |
2398 | |
2387 | our $SAY_CHANNEL = { |
2399 | our $SAY_CHANNEL = { |
2388 | id => "say", |
2400 | id => "say", |
2389 | title => "Map", |
2401 | title => "Map", |
2390 | reply => "say ", |
2402 | reply => "say ", |
2391 | tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
2403 | tooltip => "Things said to and replied from NPCs near you and other players on the same map only.", |
2392 | }; |
2404 | }; |
2393 | |
2405 | |
2394 | our $CHAT_CHANNEL = { |
2406 | our $CHAT_CHANNEL = { |
2395 | id => "chat", |
2407 | id => "chat", |
2396 | title => "Chat", |
2408 | title => "Chat", |
… | |
… | |
2783 | id => "infobox", |
2795 | id => "infobox", |
2784 | title => "Skills", |
2796 | title => "Skills", |
2785 | reply => undef, |
2797 | reply => undef, |
2786 | tooltip => "Shows your experience per skill and item power", |
2798 | tooltip => "Shows your experience per skill and item power", |
2787 | }, |
2799 | }, |
|
|
2800 | "c/shopitems" => { |
|
|
2801 | id => "infobox", |
|
|
2802 | title => "Shop Items", |
|
|
2803 | reply => undef, |
|
|
2804 | tooltip => "Shows the items currently for sale in this shop", |
|
|
2805 | }, |
2788 | "c/resistances" => { |
2806 | "c/resistances" => { |
2789 | id => "infobox", |
2807 | id => "infobox", |
2790 | title => "Resistances", |
2808 | title => "Resistances", |
2791 | reply => undef, |
2809 | reply => undef, |
2792 | tooltip => "Shows your resistances", |
2810 | tooltip => "Shows your resistances", |
… | |
… | |
2794 | "c/pets" => { |
2812 | "c/pets" => { |
2795 | id => "infobox", |
2813 | id => "infobox", |
2796 | title => "Pets", |
2814 | title => "Pets", |
2797 | reply => undef, |
2815 | reply => undef, |
2798 | tooltip => "Shows information abotu your pets/a specific pet", |
2816 | tooltip => "Shows information abotu your pets/a specific pet", |
|
|
2817 | }, |
|
|
2818 | "c/perceiveself" => { |
|
|
2819 | id => "infobox", |
|
|
2820 | title => "Perceive Self", |
|
|
2821 | reply => undef, |
|
|
2822 | tooltip => "You gained detailed knowledge about yourself", |
2799 | }, |
2823 | }, |
2800 | "c/uptime" => { |
2824 | "c/uptime" => { |
2801 | id => "infobox", |
2825 | id => "infobox", |
2802 | title => "Uptime", |
2826 | title => "Uptime", |
2803 | reply => undef, |
2827 | reply => undef, |
… | |
… | |
3380 | |
3404 | |
3381 | seek $fh, 0, 0; |
3405 | seek $fh, 0, 0; |
3382 | print $fh $$; |
3406 | print $fh $$; |
3383 | } |
3407 | } |
3384 | |
3408 | |
|
|
3409 | sub main_loop { |
|
|
3410 | warn "EV::loop starting\n"; |
|
|
3411 | if (1) { |
|
|
3412 | EV::loop; |
|
|
3413 | } |
|
|
3414 | warn "EV::loop returned\n"; |
|
|
3415 | goto &main_loop unless $REALLY_UNLOOP; |
|
|
3416 | } |
|
|
3417 | |
3385 | sub main { |
3418 | sub main { |
3386 | cf::init_globals; # initialise logging |
3419 | cf::init_globals; # initialise logging |
3387 | |
3420 | |
3388 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3421 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3389 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
3422 | LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; |
… | |
… | |
3427 | load_extensions; |
3460 | load_extensions; |
3428 | |
3461 | |
3429 | utime time, time, $RUNTIMEFILE; |
3462 | utime time, time, $RUNTIMEFILE; |
3430 | |
3463 | |
3431 | # no (long-running) fork's whatsoever before this point(!) |
3464 | # no (long-running) fork's whatsoever before this point(!) |
|
|
3465 | use POSIX (); |
3432 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3466 | POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; |
3433 | |
3467 | |
3434 | (pop @POST_INIT)->(0) while @POST_INIT; |
3468 | (pop @POST_INIT)->(0) while @POST_INIT; |
3435 | }; |
3469 | }; |
3436 | |
3470 | |
3437 | EV::loop; |
3471 | main_loop; |
3438 | } |
3472 | } |
3439 | |
3473 | |
3440 | ############################################################################# |
3474 | ############################################################################# |
3441 | # initialisation and cleanup |
3475 | # initialisation and cleanup |
3442 | |
3476 | |
… | |
… | |
3925 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3959 | LOG llevInfo, "[ABT] [suppressed]\n"; |
3926 | } |
3960 | } |
3927 | } |
3961 | } |
3928 | |
3962 | |
3929 | # load additional modules |
3963 | # load additional modules |
3930 | eval "use cf::$_" for @EXTRA_MODULES; |
3964 | require "cf/$_.pm" for @EXTRA_MODULES; |
3931 | |
3965 | |
3932 | END { cf::emergency_save } |
3966 | END { cf::emergency_save } |
3933 | |
3967 | |
3934 | 1 |
3968 | 1 |
3935 | |
3969 | |