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.468 by root, Thu Jan 8 19:23:44 2009 UTC vs.
Revision 1.479 by root, Thu Oct 8 05:04:27 2009 UTC

72 72
73# make sure c-lzf reinitialises itself 73# make sure c-lzf reinitialises itself
74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve"; 74Compress::LZF::set_serializer "Storable", "Storable::net_mstore", "Storable::mretrieve";
75Compress::LZF::sfreeze_cr { }; # prime Compress::LZF so it does not use require later 75Compress::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
77sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload 80sub WF_AUTOCANCEL () { 1 } # automatically cancel this watcher on reload
78 81
79our %COMMAND = (); 82our %COMMAND = ();
80our %COMMAND_TIME = (); 83our %COMMAND_TIME = ();
81 84
85our %EXT_CORO = (); # coroutines bound to extensions 88our %EXT_CORO = (); # coroutines bound to extensions
86our %EXT_MAP = (); # pluggable maps 89our %EXT_MAP = (); # pluggable maps
87 90
88our $RELOAD; # number of reloads so far, non-zero while in reload 91our $RELOAD; # number of reloads so far, non-zero while in reload
89our @EVENT; 92our @EVENT;
93our @REFLECT; # set by XS
94our %REFLECT; # set by us
90 95
91our $CONFDIR = confdir; 96our $CONFDIR = confdir;
92our $DATADIR = datadir; 97our $DATADIR = datadir;
93our $LIBDIR = "$DATADIR/ext"; 98our $LIBDIR = "$DATADIR/ext";
94our $PODDIR = "$DATADIR/pod"; 99our $PODDIR = "$DATADIR/pod";
105our %RESOURCE; 110our %RESOURCE;
106 111
107our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!) 112our $TICK = MAX_TIME * 1e-6; # this is a CONSTANT(!)
108our $NEXT_RUNTIME_WRITE; # when should the runtime file be written 113our $NEXT_RUNTIME_WRITE; # when should the runtime file be written
109our $NEXT_TICK; 114our $NEXT_TICK;
110our $USE_FSYNC = 1; # use fsync to write maps - default off 115our $USE_FSYNC = 1; # use fsync to write maps - default on
111 116
112our $BDB_DEADLOCK_WATCHER; 117our $BDB_DEADLOCK_WATCHER;
113our $BDB_CHECKPOINT_WATCHER; 118our $BDB_CHECKPOINT_WATCHER;
114our $BDB_TRICKLE_WATCHER; 119our $BDB_TRICKLE_WATCHER;
115our $DB_ENV; 120our $DB_ENV;
134our $JITTER; # average jitter 139our $JITTER; # average jitter
135our $TICK_START; # for load detecting purposes 140our $TICK_START; # for load detecting purposes
136 141
137our @POST_INIT; 142our @POST_INIT;
138 143
139our $REATTACH_ON_RELOAD; # ste to true to force object reattach on reload (slow) 144our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow)
145our $REALLY_UNLOOP; # never set to true, please :)
140 146
141binmode STDOUT; 147binmode STDOUT;
142binmode STDERR; 148binmode STDERR;
143 149
144# read virtual server time, if available 150# read virtual server time, if available
157 163
158sub cf::map::normalise; 164sub cf::map::normalise;
159 165
160############################################################################# 166#############################################################################
161 167
168%REFLECT = ();
169for (@REFLECT) {
170 my $reflect = JSON::XS::decode_json $_;
171 $REFLECT{$reflect->{class}} = $reflect;
172}
173
174#############################################################################
175
162=head2 GLOBAL VARIABLES 176=head2 GLOBAL VARIABLES
163 177
164=over 4 178=over 4
165 179
166=item $cf::UPTIME 180=item $cf::UPTIME
214 228
215This array contains the results of the last C<invoke ()> call. When 229This array contains the results of the last C<invoke ()> call. When
216C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of 230C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of
217that call. 231that call.
218 232
233=item %cf::REFLECT
234
235Contains, for each (C++) class name, a hash reference with information
236about object members (methods, scalars and arrays) and other metadata,
237which is useful for introspection.
238
219=back 239=back
220 240
221=cut 241=cut
222 242
223BEGIN { 243$Coro::State::WARNHOOK = sub {
224 *CORE::GLOBAL::warn = sub {
225 my $msg = join "", @_; 244 my $msg = join "", @_;
226 245
227 $msg .= "\n" 246 $msg .= "\n"
228 unless $msg =~ /\n$/; 247 unless $msg =~ /\n$/;
229 248
230 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 249 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
231 250
232 LOG llevError, $msg; 251 LOG llevError, $msg;
233 }; 252};
234}
235 253
236$Coro::State::DIEHOOK = sub { 254$Coro::State::DIEHOOK = sub {
237 return unless $^S eq 0; # "eq", not "==" 255 return unless $^S eq 0; # "eq", not "=="
256
257 warn Carp::longmess $_[0];
238 258
239 if ($Coro::current == $Coro::main) {#d# 259 if ($Coro::current == $Coro::main) {#d#
240 warn "DIEHOOK called in main context, Coro bug?\n";#d# 260 warn "DIEHOOK called in main context, Coro bug?\n";#d#
241 return;#d# 261 return;#d#
242 }#d# 262 }#d#
243 263
244 # kill coroutine otherwise 264 # kill coroutine otherwise
245 warn Carp::longmess $_[0];
246 Coro::terminate 265 Coro::terminate
247}; 266};
248
249$SIG{__DIE__} = sub { }; #d#?
250 267
251@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 268@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
252@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 269@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
253@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 270@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
254@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 271@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
1151 $decname, length $$rdata, scalar @$objs; 1168 $decname, length $$rdata, scalar @$objs;
1152 1169
1153 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1170 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1154 aio_chmod $fh, SAVE_MODE; 1171 aio_chmod $fh, SAVE_MODE;
1155 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1172 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1156 aio_fsync $fh if $cf::USE_FSYNC; 1173 if ($cf::USE_FSYNC) {
1174 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;
1175 aio_fsync $fh;
1176 }
1157 aio_close $fh; 1177 aio_close $fh;
1158 1178
1159 if (@$objs) { 1179 if (@$objs) {
1160 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1180 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1161 aio_chmod $fh, SAVE_MODE; 1181 aio_chmod $fh, SAVE_MODE;
1162 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; 1182 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1163 aio_write $fh, 0, (length $data), $data, 0; 1183 aio_write $fh, 0, (length $data), $data, 0;
1164 aio_fsync $fh if $cf::USE_FSYNC; 1184 if ($cf::USE_FSYNC) {
1185 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;
1186 aio_fsync $fh;
1187 }
1165 aio_close $fh; 1188 aio_close $fh;
1166 aio_rename "$filename.pst~", "$filename.pst"; 1189 aio_rename "$filename.pst~", "$filename.pst";
1167 } 1190 }
1168 } else { 1191 } else {
1169 aio_unlink "$filename.pst"; 1192 aio_unlink "$filename.pst";
1320 1343
1321# "readahead" all extensions 1344# "readahead" all extensions
1322sub cache_extensions { 1345sub cache_extensions {
1323 my $grp = IO::AIO::aio_group; 1346 my $grp = IO::AIO::aio_group;
1324 1347
1325 add $grp IO::AIO::aio_readdir $LIBDIR, sub { 1348 add $grp IO::AIO::aio_readdirx $LIBDIR, IO::AIO::READDIR_STAT_ORDER, sub {
1326 for (grep /\.ext$/, @{$_[0]}) { 1349 for (grep /\.ext$/, @{$_[0]}) {
1327 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data; 1350 add $grp IO::AIO::aio_load "$LIBDIR/$_", my $data;
1328 } 1351 }
1329 }; 1352 };
1330 1353
2213 2236
2214 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2237 my $lock = cf::lock_acquire "map_data:$self->{path}";
2215 2238
2216 return if $self->players; 2239 return if $self->players;
2217 2240
2218 warn "resetting map ", $self->path; 2241 warn "resetting map ", $self->path, "\n";
2219 2242
2220 $self->in_memory (cf::MAP_SWAPPED); 2243 $self->in_memory (cf::MAP_SWAPPED);
2221 2244
2222 # need to save uniques path 2245 # need to save uniques path
2223 unless ($self->{deny_save}) { 2246 unless ($self->{deny_save}) {
2524 2547
2525 $map->load; 2548 $map->load;
2526 $map->load_neighbours; 2549 $map->load_neighbours;
2527 2550
2528 return unless $self->contr->active; 2551 return unless $self->contr->active;
2529 $self->flag (cf::FLAG_DEBUG, 0);#d# temp
2530 $self->activate_recursive;
2531 2552
2532 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2553 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2533 $self->enter_map ($map, $x, $y); 2554 $self->enter_map ($map, $x, $y);
2555
2556 # only activate afterwards, to support waiting in hooks
2557 $self->activate_recursive;
2534} 2558}
2535 2559
2536=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) 2560=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]])
2537 2561
2538Moves the player to the given map-path and coordinates by first freezing 2562Moves the player to the given map-path and coordinates by first freezing
2785 id => "infobox", 2809 id => "infobox",
2786 title => "Skills", 2810 title => "Skills",
2787 reply => undef, 2811 reply => undef,
2788 tooltip => "Shows your experience per skill and item power", 2812 tooltip => "Shows your experience per skill and item power",
2789 }, 2813 },
2814 "c/shopitems" => {
2815 id => "infobox",
2816 title => "Shop Items",
2817 reply => undef,
2818 tooltip => "Shows the items currently for sale in this shop",
2819 },
2790 "c/resistances" => { 2820 "c/resistances" => {
2791 id => "infobox", 2821 id => "infobox",
2792 title => "Resistances", 2822 title => "Resistances",
2793 reply => undef, 2823 reply => undef,
2794 tooltip => "Shows your resistances", 2824 tooltip => "Shows your resistances",
2796 "c/pets" => { 2826 "c/pets" => {
2797 id => "infobox", 2827 id => "infobox",
2798 title => "Pets", 2828 title => "Pets",
2799 reply => undef, 2829 reply => undef,
2800 tooltip => "Shows information abotu your pets/a specific pet", 2830 tooltip => "Shows information abotu your pets/a specific pet",
2831 },
2832 "c/perceiveself" => {
2833 id => "infobox",
2834 title => "Perceive Self",
2835 reply => undef,
2836 tooltip => "You gained detailed knowledge about yourself",
2801 }, 2837 },
2802 "c/uptime" => { 2838 "c/uptime" => {
2803 id => "infobox", 2839 id => "infobox",
2804 title => "Uptime", 2840 title => "Uptime",
2805 reply => undef, 2841 reply => undef,
3382 3418
3383 seek $fh, 0, 0; 3419 seek $fh, 0, 0;
3384 print $fh $$; 3420 print $fh $$;
3385} 3421}
3386 3422
3423sub main_loop {
3424 warn "EV::loop starting\n";
3425 if (1) {
3426 EV::loop;
3427 }
3428 warn "EV::loop returned\n";
3429 goto &main_loop unless $REALLY_UNLOOP;
3430}
3431
3387sub main { 3432sub main {
3388 cf::init_globals; # initialise logging 3433 cf::init_globals; # initialise logging
3389 3434
3390 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3435 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3391 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3436 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3429 load_extensions; 3474 load_extensions;
3430 3475
3431 utime time, time, $RUNTIMEFILE; 3476 utime time, time, $RUNTIMEFILE;
3432 3477
3433 # no (long-running) fork's whatsoever before this point(!) 3478 # no (long-running) fork's whatsoever before this point(!)
3479 use POSIX ();
3434 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3480 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3435 3481
3436 (pop @POST_INIT)->(0) while @POST_INIT; 3482 (pop @POST_INIT)->(0) while @POST_INIT;
3437 }; 3483 };
3438 3484
3439 EV::loop; 3485 main_loop;
3440} 3486}
3441 3487
3442############################################################################# 3488#############################################################################
3443# initialisation and cleanup 3489# initialisation and cleanup
3444 3490

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines