… | |
… | |
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 | |
… | |
… | |
85 | our %EXT_CORO = (); # coroutines bound to extensions |
88 | our %EXT_CORO = (); # coroutines bound to extensions |
86 | our %EXT_MAP = (); # pluggable maps |
89 | our %EXT_MAP = (); # pluggable maps |
87 | |
90 | |
88 | our $RELOAD; # number of reloads so far, non-zero while in reload |
91 | our $RELOAD; # number of reloads so far, non-zero while in reload |
89 | our @EVENT; |
92 | our @EVENT; |
|
|
93 | our @REFLECT; # set by XS |
|
|
94 | our %REFLECT; # set by us |
90 | |
95 | |
91 | our $CONFDIR = confdir; |
96 | our $CONFDIR = confdir; |
92 | our $DATADIR = datadir; |
97 | our $DATADIR = datadir; |
93 | our $LIBDIR = "$DATADIR/ext"; |
98 | our $LIBDIR = "$DATADIR/ext"; |
94 | our $PODDIR = "$DATADIR/pod"; |
99 | our $PODDIR = "$DATADIR/pod"; |
… | |
… | |
112 | our $BDB_DEADLOCK_WATCHER; |
117 | our $BDB_DEADLOCK_WATCHER; |
113 | our $BDB_CHECKPOINT_WATCHER; |
118 | our $BDB_CHECKPOINT_WATCHER; |
114 | our $BDB_TRICKLE_WATCHER; |
119 | our $BDB_TRICKLE_WATCHER; |
115 | our $DB_ENV; |
120 | our $DB_ENV; |
116 | |
121 | |
117 | our @EXTRA_MODULES = qw(pod mapscript); |
122 | our @EXTRA_MODULES = qw(pod match mapscript); |
118 | |
123 | |
119 | our %CFG; |
124 | our %CFG; |
120 | |
125 | |
121 | our $UPTIME; $UPTIME ||= time; |
126 | our $UPTIME; $UPTIME ||= time; |
122 | our $RUNTIME; |
127 | our $RUNTIME; |
… | |
… | |
134 | our $JITTER; # average jitter |
139 | our $JITTER; # average jitter |
135 | our $TICK_START; # for load detecting purposes |
140 | our $TICK_START; # for load detecting purposes |
136 | |
141 | |
137 | our @POST_INIT; |
142 | our @POST_INIT; |
138 | |
143 | |
139 | our $REATTACH_ON_RELOAD; # ste to true to force object reattach on reload (slow) |
144 | our $REATTACH_ON_RELOAD; # set to true to force object reattach on reload (slow) |
|
|
145 | our $REALLY_UNLOOP; # never set to true, please :) |
140 | |
146 | |
141 | binmode STDOUT; |
147 | binmode STDOUT; |
142 | binmode STDERR; |
148 | binmode STDERR; |
143 | |
149 | |
144 | # read virtual server time, if available |
150 | # read virtual server time, if available |
… | |
… | |
157 | |
163 | |
158 | sub cf::map::normalise; |
164 | sub cf::map::normalise; |
159 | |
165 | |
160 | ############################################################################# |
166 | ############################################################################# |
161 | |
167 | |
|
|
168 | %REFLECT = (); |
|
|
169 | for (@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 | |
215 | This array contains the results of the last C<invoke ()> call. When |
232 | This array contains the results of the last C<invoke ()> call. When |
216 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
233 | C<cf::override> is called C<@cf::INVOKE_RESULTS> is set to the parameters of |
217 | that call. |
234 | that call. |
218 | |
235 | |
|
|
236 | =item %cf::REFLECT |
|
|
237 | |
|
|
238 | Contains, for each (C++) class name, a hash reference with information |
|
|
239 | about object members (methods, scalars, arrays and flags) and other |
|
|
240 | metadata, which is useful for introspection. |
|
|
241 | |
219 | =back |
242 | =back |
220 | |
243 | |
221 | =cut |
244 | =cut |
222 | |
245 | |
223 | BEGIN { |
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'; |
… | |
… | |
2219 | |
2239 | |
2220 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2240 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2221 | |
2241 | |
2222 | return if $self->players; |
2242 | return if $self->players; |
2223 | |
2243 | |
2224 | warn "resetting map ", $self->path; |
2244 | warn "resetting map ", $self->path, "\n"; |
2225 | |
2245 | |
2226 | $self->in_memory (cf::MAP_SWAPPED); |
2246 | $self->in_memory (cf::MAP_SWAPPED); |
2227 | |
2247 | |
2228 | # need to save uniques path |
2248 | # need to save uniques path |
2229 | unless ($self->{deny_save}) { |
2249 | unless ($self->{deny_save}) { |
… | |
… | |
2530 | |
2550 | |
2531 | $map->load; |
2551 | $map->load; |
2532 | $map->load_neighbours; |
2552 | $map->load_neighbours; |
2533 | |
2553 | |
2534 | return unless $self->contr->active; |
2554 | return unless $self->contr->active; |
2535 | $self->flag (cf::FLAG_DEBUG, 0);#d# temp |
|
|
2536 | $self->activate_recursive; |
|
|
2537 | |
2555 | |
2538 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2556 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2539 | $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; |
2540 | } |
2561 | } |
2541 | |
2562 | |
2542 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2563 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2543 | |
2564 | |
2544 | Moves the player to the given map-path and coordinates by first freezing |
2565 | Moves the player to the given map-path and coordinates by first freezing |
… | |
… | |
3400 | |
3421 | |
3401 | seek $fh, 0, 0; |
3422 | seek $fh, 0, 0; |
3402 | print $fh $$; |
3423 | print $fh $$; |
3403 | } |
3424 | } |
3404 | |
3425 | |
|
|
3426 | sub 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 | |
3405 | sub main { |
3435 | sub main { |
3406 | cf::init_globals; # initialise logging |
3436 | cf::init_globals; # initialise logging |
3407 | |
3437 | |
3408 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3438 | LOG llevInfo, "Welcome to Deliantra, v" . VERSION; |
3409 | 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."; |
… | |
… | |
3447 | load_extensions; |
3477 | load_extensions; |
3448 | |
3478 | |
3449 | utime time, time, $RUNTIMEFILE; |
3479 | utime time, time, $RUNTIMEFILE; |
3450 | |
3480 | |
3451 | # no (long-running) fork's whatsoever before this point(!) |
3481 | # no (long-running) fork's whatsoever before this point(!) |
|
|
3482 | use POSIX (); |
3452 | 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}; |
3453 | |
3484 | |
3454 | (pop @POST_INIT)->(0) while @POST_INIT; |
3485 | (pop @POST_INIT)->(0) while @POST_INIT; |
3455 | }; |
3486 | }; |
3456 | |
3487 | |
3457 | EV::loop; |
3488 | main_loop; |
3458 | } |
3489 | } |
3459 | |
3490 | |
3460 | ############################################################################# |
3491 | ############################################################################# |
3461 | # initialisation and cleanup |
3492 | # initialisation and cleanup |
3462 | |
3493 | |
… | |
… | |
3728 | |
3759 | |
3729 | warn "unload completed, starting to reload now"; |
3760 | warn "unload completed, starting to reload now"; |
3730 | |
3761 | |
3731 | warn "reloading cf.pm"; |
3762 | warn "reloading cf.pm"; |
3732 | require cf; |
3763 | require cf; |
3733 | cf::_connect_to_perl; # nominally unnecessary, but cannot hurt |
3764 | cf::_connect_to_perl_1; |
3734 | |
3765 | |
3735 | warn "loading config and database again"; |
3766 | warn "loading config and database again"; |
3736 | cf::reload_config; |
3767 | cf::reload_config; |
3737 | |
3768 | |
3738 | warn "loading extensions"; |
3769 | warn "loading extensions"; |
… | |
… | |
3946 | } |
3977 | } |
3947 | } |
3978 | } |
3948 | |
3979 | |
3949 | # load additional modules |
3980 | # load additional modules |
3950 | require "cf/$_.pm" for @EXTRA_MODULES; |
3981 | require "cf/$_.pm" for @EXTRA_MODULES; |
|
|
3982 | cf::_connect_to_perl_2; |
3951 | |
3983 | |
3952 | END { cf::emergency_save } |
3984 | END { cf::emergency_save } |
3953 | |
3985 | |
3954 | 1 |
3986 | 1 |
3955 | |
3987 | |