… | |
… | |
88 | our %EXT_CORO = (); # coroutines bound to extensions |
88 | our %EXT_CORO = (); # coroutines bound to extensions |
89 | our %EXT_MAP = (); # pluggable maps |
89 | our %EXT_MAP = (); # pluggable maps |
90 | |
90 | |
91 | 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 |
92 | our @EVENT; |
92 | our @EVENT; |
|
|
93 | our @REFLECT; # set by XS |
|
|
94 | our %REFLECT; # set by us |
93 | |
95 | |
94 | our $CONFDIR = confdir; |
96 | our $CONFDIR = confdir; |
95 | our $DATADIR = datadir; |
97 | our $DATADIR = datadir; |
96 | our $LIBDIR = "$DATADIR/ext"; |
98 | our $LIBDIR = "$DATADIR/ext"; |
97 | our $PODDIR = "$DATADIR/pod"; |
99 | our $PODDIR = "$DATADIR/pod"; |
… | |
… | |
115 | our $BDB_DEADLOCK_WATCHER; |
117 | our $BDB_DEADLOCK_WATCHER; |
116 | our $BDB_CHECKPOINT_WATCHER; |
118 | our $BDB_CHECKPOINT_WATCHER; |
117 | our $BDB_TRICKLE_WATCHER; |
119 | our $BDB_TRICKLE_WATCHER; |
118 | our $DB_ENV; |
120 | our $DB_ENV; |
119 | |
121 | |
120 | our @EXTRA_MODULES = qw(pod mapscript); |
122 | our @EXTRA_MODULES = qw(pod match mapscript); |
121 | |
123 | |
122 | our %CFG; |
124 | our %CFG; |
123 | |
125 | |
124 | our $UPTIME; $UPTIME ||= time; |
126 | our $UPTIME; $UPTIME ||= time; |
125 | our $RUNTIME; |
127 | our $RUNTIME; |
… | |
… | |
161 | |
163 | |
162 | sub cf::map::normalise; |
164 | sub cf::map::normalise; |
163 | |
165 | |
164 | ############################################################################# |
166 | ############################################################################# |
165 | |
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 | |
166 | =head2 GLOBAL VARIABLES |
179 | =head2 GLOBAL VARIABLES |
167 | |
180 | |
168 | =over 4 |
181 | =over 4 |
169 | |
182 | |
170 | =item $cf::UPTIME |
183 | =item $cf::UPTIME |
… | |
… | |
218 | |
231 | |
219 | 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 |
220 | 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 |
221 | that call. |
234 | that call. |
222 | |
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 | |
223 | =back |
242 | =back |
224 | |
243 | |
225 | =cut |
244 | =cut |
226 | |
245 | |
227 | BEGIN { |
246 | $Coro::State::WARNHOOK = sub { |
228 | *CORE::GLOBAL::warn = sub { |
|
|
229 | my $msg = join "", @_; |
247 | my $msg = join "", @_; |
230 | |
248 | |
231 | $msg .= "\n" |
249 | $msg .= "\n" |
232 | unless $msg =~ /\n$/; |
250 | unless $msg =~ /\n$/; |
233 | |
251 | |
234 | $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; |
235 | |
253 | |
236 | LOG llevError, $msg; |
254 | LOG llevError, $msg; |
237 | }; |
255 | }; |
238 | } |
|
|
239 | |
256 | |
240 | $Coro::State::DIEHOOK = sub { |
257 | $Coro::State::DIEHOOK = sub { |
241 | return unless $^S eq 0; # "eq", not "==" |
258 | return unless $^S eq 0; # "eq", not "==" |
|
|
259 | |
|
|
260 | warn Carp::longmess $_[0]; |
242 | |
261 | |
243 | if ($Coro::current == $Coro::main) {#d# |
262 | if ($Coro::current == $Coro::main) {#d# |
244 | warn "DIEHOOK called in main context, Coro bug?\n";#d# |
263 | warn "DIEHOOK called in main context, Coro bug?\n";#d# |
245 | return;#d# |
264 | return;#d# |
246 | }#d# |
265 | }#d# |
247 | |
266 | |
248 | # kill coroutine otherwise |
267 | # kill coroutine otherwise |
249 | warn Carp::longmess $_[0]; |
|
|
250 | Coro::terminate |
268 | Coro::terminate |
251 | }; |
269 | }; |
252 | |
|
|
253 | $SIG{__DIE__} = sub { }; #d#? |
|
|
254 | |
270 | |
255 | @safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; |
271 | @safe::cf::global::ISA = @cf::global::ISA = 'cf::attachable'; |
256 | @safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; |
272 | @safe::cf::object::ISA = @cf::object::ISA = 'cf::attachable'; |
257 | @safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; |
273 | @safe::cf::player::ISA = @cf::player::ISA = 'cf::attachable'; |
258 | @safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; |
274 | @safe::cf::client::ISA = @cf::client::ISA = 'cf::attachable'; |
… | |
… | |
2223 | |
2239 | |
2224 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2240 | my $lock = cf::lock_acquire "map_data:$self->{path}"; |
2225 | |
2241 | |
2226 | return if $self->players; |
2242 | return if $self->players; |
2227 | |
2243 | |
2228 | warn "resetting map ", $self->path; |
2244 | warn "resetting map ", $self->path, "\n"; |
2229 | |
2245 | |
2230 | $self->in_memory (cf::MAP_SWAPPED); |
2246 | $self->in_memory (cf::MAP_SWAPPED); |
2231 | |
2247 | |
2232 | # need to save uniques path |
2248 | # need to save uniques path |
2233 | unless ($self->{deny_save}) { |
2249 | unless ($self->{deny_save}) { |
… | |
… | |
2534 | |
2550 | |
2535 | $map->load; |
2551 | $map->load; |
2536 | $map->load_neighbours; |
2552 | $map->load_neighbours; |
2537 | |
2553 | |
2538 | return unless $self->contr->active; |
2554 | return unless $self->contr->active; |
2539 | $self->flag (cf::FLAG_DEBUG, 0);#d# temp |
|
|
2540 | $self->activate_recursive; |
|
|
2541 | |
2555 | |
2542 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2556 | local $self->{_prev_pos} = $link_pos; # ugly hack for rent.ext |
2543 | $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; |
2544 | } |
2561 | } |
2545 | |
2562 | |
2546 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2563 | =item $player_object->goto ($path, $x, $y[, $check->($map)[, $done->()]]) |
2547 | |
2564 | |
2548 | 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 |
… | |
… | |
3742 | |
3759 | |
3743 | warn "unload completed, starting to reload now"; |
3760 | warn "unload completed, starting to reload now"; |
3744 | |
3761 | |
3745 | warn "reloading cf.pm"; |
3762 | warn "reloading cf.pm"; |
3746 | require cf; |
3763 | require cf; |
3747 | cf::_connect_to_perl; # nominally unnecessary, but cannot hurt |
3764 | cf::_connect_to_perl_1; |
3748 | |
3765 | |
3749 | warn "loading config and database again"; |
3766 | warn "loading config and database again"; |
3750 | cf::reload_config; |
3767 | cf::reload_config; |
3751 | |
3768 | |
3752 | warn "loading extensions"; |
3769 | warn "loading extensions"; |
… | |
… | |
3960 | } |
3977 | } |
3961 | } |
3978 | } |
3962 | |
3979 | |
3963 | # load additional modules |
3980 | # load additional modules |
3964 | require "cf/$_.pm" for @EXTRA_MODULES; |
3981 | require "cf/$_.pm" for @EXTRA_MODULES; |
|
|
3982 | cf::_connect_to_perl_2; |
3965 | |
3983 | |
3966 | END { cf::emergency_save } |
3984 | END { cf::emergency_save } |
3967 | |
3985 | |
3968 | 1 |
3986 | 1 |
3969 | |
3987 | |