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.472 by root, Sat Jun 6 21:43:13 2009 UTC vs.
Revision 1.482 by root, Sun Oct 11 05:31:54 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";
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;
116 121
117our @EXTRA_MODULES = qw(pod mapscript); 122our @EXTRA_MODULES = qw(pod match mapscript);
118 123
119our %CFG; 124our %CFG;
120 125
121our $UPTIME; $UPTIME ||= time; 126our $UPTIME; $UPTIME ||= time;
122our $RUNTIME; 127our $RUNTIME;
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# this is decidedly evil
175$REFLECT{object}{flags} = { map +($_ => undef), grep $_, map /^FLAG_([A-Z0-9_]+)$/ && lc $1, keys %{"cf::"} };
176
177#############################################################################
178
162=head2 GLOBAL VARIABLES 179=head2 GLOBAL VARIABLES
163 180
164=over 4 181=over 4
165 182
166=item $cf::UPTIME 183=item $cf::UPTIME
214 231
215This array contains the results of the last C<invoke ()> call. When 232This 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 233C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of
217that call. 234that call.
218 235
236=item %cf::REFLECT
237
238Contains, for each (C++) class name, a hash reference with information
239about object members (methods, scalars, arrays and flags) and other
240metadata, which is useful for introspection.
241
219=back 242=back
220 243
221=cut 244=cut
222 245
223BEGIN { 246$Coro::State::WARNHOOK = sub {
224 *CORE::GLOBAL::warn = sub {
225 my $msg = join "", @_; 247 my $msg = join "", @_;
226 248
227 $msg .= "\n" 249 $msg .= "\n"
228 unless $msg =~ /\n$/; 250 unless $msg =~ /\n$/;
229 251
230 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge; 252 $msg =~ s/([\x00-\x08\x0b-\x1f])/sprintf "\\x%02x", ord $1/ge;
231 253
232 LOG llevError, $msg; 254 LOG llevError, $msg;
233 }; 255};
234}
235 256
236$Coro::State::DIEHOOK = sub { 257$Coro::State::DIEHOOK = sub {
237 return unless $^S eq 0; # "eq", not "==" 258 return unless $^S eq 0; # "eq", not "=="
259
260 warn Carp::longmess $_[0];
238 261
239 if ($Coro::current == $Coro::main) {#d# 262 if ($Coro::current == $Coro::main) {#d#
240 warn "DIEHOOK called in main context, Coro bug?\n";#d# 263 warn "DIEHOOK called in main context, Coro bug?\n";#d#
241 return;#d# 264 return;#d#
242 }#d# 265 }#d#
243 266
244 # kill coroutine otherwise 267 # kill coroutine otherwise
245 warn Carp::longmess $_[0];
246 Coro::terminate 268 Coro::terminate
247}; 269};
248
249$SIG{__DIE__} = sub { }; #d#?
250 270
251@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; 271@safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable';
252@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; 272@safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable';
253@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; 273@safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable';
254@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; 274@safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable';
1151 $decname, length $$rdata, scalar @$objs; 1171 $decname, length $$rdata, scalar @$objs;
1152 1172
1153 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) { 1173 if (my $fh = aio_open "$filename~", O_WRONLY | O_CREAT, 0600) {
1154 aio_chmod $fh, SAVE_MODE; 1174 aio_chmod $fh, SAVE_MODE;
1155 aio_write $fh, 0, (length $$rdata), $$rdata, 0; 1175 aio_write $fh, 0, (length $$rdata), $$rdata, 0;
1156 aio_fsync $fh if $cf::USE_FSYNC; 1176 if ($cf::USE_FSYNC) {
1177 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;
1178 aio_fsync $fh;
1179 }
1157 aio_close $fh; 1180 aio_close $fh;
1158 1181
1159 if (@$objs) { 1182 if (@$objs) {
1160 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) { 1183 if (my $fh = aio_open "$filename.pst~", O_WRONLY | O_CREAT, 0600) {
1161 aio_chmod $fh, SAVE_MODE; 1184 aio_chmod $fh, SAVE_MODE;
1162 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs }; 1185 my $data = Coro::Storable::nfreeze { version => 1, objs => $objs };
1163 aio_write $fh, 0, (length $data), $data, 0; 1186 aio_write $fh, 0, (length $data), $data, 0;
1164 aio_fsync $fh if $cf::USE_FSYNC; 1187 if ($cf::USE_FSYNC) {
1188 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;
1189 aio_fsync $fh;
1190 }
1165 aio_close $fh; 1191 aio_close $fh;
1166 aio_rename "$filename.pst~", "$filename.pst"; 1192 aio_rename "$filename.pst~", "$filename.pst";
1167 } 1193 }
1168 } else { 1194 } else {
1169 aio_unlink "$filename.pst"; 1195 aio_unlink "$filename.pst";
2213 2239
2214 my $lock = cf::lock_acquire "map_data:$self->{path}"; 2240 my $lock = cf::lock_acquire "map_data:$self->{path}";
2215 2241
2216 return if $self->players; 2242 return if $self->players;
2217 2243
2218 warn "resetting map ", $self->path; 2244 warn "resetting map ", $self->path, "\n";
2219 2245
2220 $self->in_memory (cf::MAP_SWAPPED); 2246 $self->in_memory (cf::MAP_SWAPPED);
2221 2247
2222 # need to save uniques path 2248 # need to save uniques path
2223 unless ($self->{deny_save}) { 2249 unless ($self->{deny_save}) {
2524 2550
2525 $map->load; 2551 $map->load;
2526 $map->load_neighbours; 2552 $map->load_neighbours;
2527 2553
2528 return unless $self->contr->active; 2554 return unless $self->contr->active;
2529 $self->flag (cf::FLAG_DEBUG, 0);#d# temp
2530 $self->activate_recursive;
2531 2555
2532 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext 2556 local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext
2533 $self->enter_map ($map, $x, $y); 2557 $self->enter_map ($map, $x, $y);
2558
2559 # only activate afterwards, to support waiting in hooks
2560 $self->activate_recursive;
2534} 2561}
2535 2562
2536=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) 2563=item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]])
2537 2564
2538Moves the player to the given map-path and coordinates by first freezing 2565Moves the player to the given map-path and coordinates by first freezing
3394 3421
3395 seek $fh, 0, 0; 3422 seek $fh, 0, 0;
3396 print $fh $$; 3423 print $fh $$;
3397} 3424}
3398 3425
3426sub main_loop {
3427 warn "EV::loop starting\n";
3428 if (1) {
3429 EV::loop;
3430 }
3431 warn "EV::loop returned\n";
3432 goto &main_loop unless $REALLY_UNLOOP;
3433}
3434
3399sub main { 3435sub main {
3400 cf::init_globals; # initialise logging 3436 cf::init_globals; # initialise logging
3401 3437
3402 LOG llevInfo, "Welcome to Deliantra, v" . VERSION; 3438 LOG llevInfo, "Welcome to Deliantra, v" . VERSION;
3403 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team."; 3439 LOG llevInfo, "Copyright (C) 2005-2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team.";
3441 load_extensions; 3477 load_extensions;
3442 3478
3443 utime time, time, $RUNTIMEFILE; 3479 utime time, time, $RUNTIMEFILE;
3444 3480
3445 # no (long-running) fork's whatsoever before this point(!) 3481 # no (long-running) fork's whatsoever before this point(!)
3482 use POSIX ();
3446 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD}; 3483 POSIX::close delete $ENV{LOCKUTIL_LOCK_FD} if exists $ENV{LOCKUTIL_LOCK_FD};
3447 3484
3448 (pop @POST_INIT)->(0) while @POST_INIT; 3485 (pop @POST_INIT)->(0) while @POST_INIT;
3449 }; 3486 };
3450 3487
3451 EV::loop; 3488 main_loop;
3452} 3489}
3453 3490
3454############################################################################# 3491#############################################################################
3455# initialisation and cleanup 3492# initialisation and cleanup
3456 3493

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines