… | |
… | |
158 | nuke_str $pass; |
158 | nuke_str $pass; |
159 | # password matches, wonderful |
159 | # password matches, wonderful |
160 | my $pl = cf::player::find $user or next; |
160 | my $pl = cf::player::find $user or next; |
161 | $pl->connect ($ns); |
161 | $pl->connect ($ns); |
162 | check_clean_save $pl; |
162 | check_clean_save $pl; |
|
|
163 | $pl->{clean_save} = 1; |
163 | last; |
164 | last; |
164 | } elsif (can_cleanup $buf, $mtime) { |
165 | } elsif (can_cleanup $buf, $mtime) { |
165 | Coro::Timer::sleep 1; |
166 | Coro::Timer::sleep 1; |
166 | |
167 | |
167 | $ns->send_drawinfo ( |
168 | $ns->send_drawinfo ( |
… | |
… | |
255 | last; |
256 | last; |
256 | } |
257 | } |
257 | }); |
258 | }); |
258 | } |
259 | } |
259 | |
260 | |
260 | # "Quitting will delete your character PERMANENTLY. If you are sure you want to do this, then use the quit_character command instead of quit." |
261 | cf::register_command quit => sub { |
261 | # "Quitting will delete your character.\nAre you sure you want to quit (y/n):" |
262 | my ($ob, $arg) = @_; |
262 | # quit, quit_character, save |
263 | |
|
|
264 | $ob->reply (undef, |
|
|
265 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
|
|
266 | . "If you are sure you want to do this, then use the quit_character command instead of quit.", |
|
|
267 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
268 | }; |
|
|
269 | |
|
|
270 | cf::register_command quit_character => sub { |
|
|
271 | my ($ob, $arg) = @_; |
|
|
272 | |
|
|
273 | my $pl = $ob->contr; |
|
|
274 | |
|
|
275 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
|
|
276 | if ($_[0] !~ /^[yY]/) { |
|
|
277 | $ob->reply (undef, |
|
|
278 | "Ok, not not quitting then.", |
|
|
279 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
280 | } else { |
|
|
281 | $ob->reply (undef, |
|
|
282 | "Ok, quitting, hope to see you again.", |
|
|
283 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
284 | $pl->ns->flush; |
|
|
285 | $pl->quit_character; |
|
|
286 | } |
|
|
287 | }); |
|
|
288 | }; |
263 | |
289 | |
264 | cf::object->attach ( |
290 | cf::object->attach ( |
265 | type => cf::SAVEBED, |
291 | type => cf::SAVEBED, |
266 | on_apply => sub { |
292 | on_apply => sub { |
267 | my ($bed, $ob) = @_; |
293 | my ($bed, $ob) = @_; |
268 | |
294 | |
269 | return cf::override 0 unless $ob->type == cf::PLAYER; |
295 | return cf::override 0 unless $ob->type == cf::PLAYER; |
270 | |
296 | |
271 | my $pl = $ob->pl; |
297 | my $pl = $ob->contr; |
272 | |
298 | |
273 | # update respawn position |
299 | # update respawn position |
274 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
300 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
275 | |
301 | |
276 | $pl->killer ("left"); |
302 | $pl->killer ("left"); |
… | |
… | |
282 | if ($_[0] !~ /^[yY]/) { |
308 | if ($_[0] !~ /^[yY]/) { |
283 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
309 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
284 | $pl->deactivate; |
310 | $pl->deactivate; |
285 | $pl->ns->destroy; |
311 | $pl->ns->destroy; |
286 | } else { |
312 | } else { |
287 | cf::async { |
313 | cf::async { $pl->save }; |
288 | $pl->{clean_save} = 1; |
|
|
289 | $pl->save; |
|
|
290 | }; |
|
|
291 | } |
314 | } |
292 | }); |
315 | }); |
293 | }, |
316 | }, |
294 | ); |
317 | ); |
295 | |
318 | |
… | |
… | |
340 | eval { |
363 | eval { |
341 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
364 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
342 | $pl->save; |
365 | $pl->save; |
343 | Coro::Timer::sleep $SAVE_INTERVAL; |
366 | Coro::Timer::sleep $SAVE_INTERVAL; |
344 | } |
367 | } |
|
|
368 | my $ob = $pl->ob; |
|
|
369 | Scalar::Util::weaken $pl; # 2 == from object + from perl |
|
|
370 | Scalar::Util::weaken $ob; # 2 == one from being an object + ??? |
|
|
371 | my $a_ = $pl->refcnt; |
|
|
372 | my $b_ = $ob->refcnt; |
|
|
373 | my $a = $pl->refcnt_cnt; |
|
|
374 | my $b = $ob->refcnt_cnt; |
|
|
375 | warn "rc $a,$a_ $b,$b_\n";#d# |
345 | }; |
376 | }; |
346 | warn $@ if $@; |
377 | warn $@ if $@; |
347 | Coro::cede; |
378 | Coro::cede; |
348 | }; |
379 | }; |
349 | } |
380 | } |