… | |
… | |
13 | } |
13 | } |
14 | |
14 | |
15 | sub query { |
15 | sub query { |
16 | my ($ns, $flags, $text) = @_; |
16 | my ($ns, $flags, $text) = @_; |
17 | |
17 | |
18 | my $current = $Coro::current; |
18 | $ns->query ($flags, $text, Coro::rouse_cb); |
19 | $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); |
19 | Coro::rouse_wait |
20 | Coro::schedule while ref $current; |
|
|
21 | |
|
|
22 | $current |
|
|
23 | } |
20 | } |
24 | |
21 | |
25 | sub can_cleanup { |
22 | sub can_cleanup { |
26 | my ($pl, $mtime) = @_; |
23 | my ($pl, $mtime) = @_; |
27 | |
24 | |
… | |
… | |
73 | } |
70 | } |
74 | |
71 | |
75 | sub enter_map { |
72 | sub enter_map { |
76 | my ($pl) = @_; |
73 | my ($pl) = @_; |
77 | |
74 | |
|
|
75 | warn $pl->ob->name, ": enter map 1\n";#d# |
78 | my $ob = $pl->ob; |
76 | my $ob = $pl->ob; |
79 | |
77 | |
80 | my ($map, $x, $y) |
78 | my ($map, $x, $y) |
81 | = $ob->{_link_pos} |
79 | = $ob->{_link_pos} |
82 | ? @{delete $ob->{_link_pos}} |
80 | ? @{delete $ob->{_link_pos}} |
83 | : ($pl->maplevel, $ob->x, $ob->y); |
81 | : ($pl->maplevel, $ob->x, $ob->y); |
84 | |
82 | |
|
|
83 | warn $pl->ob->name, ": enter map 2\n";#d# |
85 | $ob->enter_link; |
84 | $ob->enter_link; |
|
|
85 | warn $pl->ob->name, ": enter map 3\n";#d# |
86 | |
86 | |
87 | my $m = cf::map::find $map; |
87 | my $m = cf::map::find $map; |
88 | my $time = delete $pl->{unclean_save}; |
88 | my $time = delete $pl->{unclean_save}; |
|
|
89 | warn $pl->ob->name, ": enter map 4\n";#d# |
89 | |
90 | |
90 | if ($time && $m) { |
91 | if ($time && $m) { |
91 | if ($time < $m->{instantiate_time}) { |
92 | if ($time < $m->{instantiate_time}) { |
92 | # the map was reset in the meantime |
93 | # the map was reset in the meantime |
93 | my $age = $cf::RUNTIME - $time; |
94 | my $age = $cf::RUNTIME - $time; |
… | |
… | |
103 | cf::NDI_RED |
104 | cf::NDI_RED |
104 | ); |
105 | ); |
105 | # kill them. |
106 | # kill them. |
106 | # reminds me of the famous badness 10000 syndrome... |
107 | # reminds me of the famous badness 10000 syndrome... |
107 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
108 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
108 | $pl->killer ("a cave-in"); |
109 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
109 | } else { |
110 | } else { |
110 | ($map, $x, $y) = $pl->savebed; |
111 | ($map, $x, $y) = $pl->savebed; |
111 | |
112 | |
112 | $ob->message ( |
113 | $ob->message ( |
113 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
114 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
… | |
… | |
126 | cf::NDI_RED |
127 | cf::NDI_RED |
127 | ); |
128 | ); |
128 | } |
129 | } |
129 | } |
130 | } |
130 | |
131 | |
|
|
132 | warn $pl->ob->name, ": enter map 5\n";#d# |
131 | $ob->goto ($map, $x, $y); |
133 | #$ob->goto ($map, $x, $y); |
|
|
134 | $ob->goto ($map, $x, $y, sub { |
|
|
135 | warn $pl->ob->name, ": enter map check\n";#d# |
|
|
136 | $_[0] |
|
|
137 | }, sub { |
|
|
138 | warn $pl->ob->name, ": enter map done\n";#d# |
|
|
139 | }); |
|
|
140 | warn $pl->ob->name, ": enter map 6\n";#d# |
|
|
141 | |
132 | } |
142 | } |
133 | |
143 | |
134 | # delete a player directory, be non-blocking AND synchronous... |
144 | # delete a player directory, be non-blocking AND synchronous... |
135 | # (thats hard, so we crap out and fork). |
145 | # (that's hard, so we crap out and fork). |
136 | sub nuke_playerdir { |
146 | sub nuke_playerdir { |
137 | my ($user) = @_; |
147 | my ($user) = @_; |
138 | |
148 | |
139 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
149 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
140 | |
150 | |
… | |
… | |
144 | }; |
154 | }; |
145 | } |
155 | } |
146 | |
156 | |
147 | cf::client->attach (on_addme => sub { |
157 | cf::client->attach (on_addme => sub { |
148 | my ($ns) = @_; |
158 | my ($ns) = @_; |
149 | |
|
|
150 | if (!$ns->facecache) |
|
|
151 | { |
|
|
152 | $ns->send_drawinfo (<<EOF, cf::NDI_RED); |
|
|
153 | |
|
|
154 | |
|
|
155 | *** |
|
|
156 | *** WARNING: |
|
|
157 | *** Your client does not support face/image caching, |
|
|
158 | *** or it has been disabled. Face caching is mandatory |
|
|
159 | *** so please enable it or use a newer client. |
|
|
160 | *** |
|
|
161 | *** Look at your client preferences: |
|
|
162 | *** |
|
|
163 | *** deliantra: all known versions automatically enable the facecache. |
|
|
164 | *** cfclient: use the -cache commandline option. |
|
|
165 | *** cfclient: map will not redraw automatically (bug). |
|
|
166 | *** gcfclient: use -cache commandline option, or enable |
|
|
167 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
|
|
168 | *** jcrossclient: your client is broken, use deliantra or gcfclient. |
|
|
169 | *** |
|
|
170 | *** |
|
|
171 | EOF |
|
|
172 | if ($ns->version =~ /jcrossclient/) { |
|
|
173 | # let them, for now |
|
|
174 | } else { |
|
|
175 | $ns->flush; |
|
|
176 | return $ns->destroy; |
|
|
177 | } |
|
|
178 | |
|
|
179 | # $ns->facecache = true; |
|
|
180 | } |
|
|
181 | |
|
|
182 | if ($ns->mapmode < cf::Map1aCmd) { |
|
|
183 | $ns->send_drawinfo (<<EOF, cf::NDI_RED); |
|
|
184 | |
|
|
185 | |
|
|
186 | *** |
|
|
187 | *** WARNING: |
|
|
188 | *** Your client is too old. Please upgrade to a newer version. |
|
|
189 | EOF |
|
|
190 | |
|
|
191 | $ns->flush; |
|
|
192 | return $ns->destroy; |
|
|
193 | } |
|
|
194 | |
159 | |
195 | $ns->pl and return $ns->destroy; |
160 | $ns->pl and return $ns->destroy; |
196 | |
161 | |
197 | $ns->async (sub { |
162 | $ns->async (sub { |
198 | $Coro::current->{desc} = "addme init"; |
163 | $Coro::current->{desc} = "addme init"; |
… | |
… | |
209 | cf::NDI_BLUE |
174 | cf::NDI_BLUE |
210 | ); |
175 | ); |
211 | |
176 | |
212 | # read username |
177 | # read username |
213 | while () { |
178 | while () { |
214 | $user = query $ns, 0, "What is your name?\n:"; |
179 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
215 | |
180 | |
216 | if ($cf::LOGIN_LOCK{$user}) { |
181 | if ($cf::LOGIN_LOCK{$user}) { |
217 | $ns->send_drawinfo ( |
182 | $ns->send_drawinfo ( |
218 | "That username is currently used in another login session. " |
183 | "That username is currently used in another login session. " |
219 | . "Chose another, or wait till the other session has ended.", |
184 | . "Chose another, or wait till the other session has ended.", |
220 | cf::NDI_RED |
185 | cf::NDI_RED |
221 | ); |
186 | ); |
222 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { |
187 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) { |
223 | last; |
188 | last; |
224 | } else { |
189 | } else { |
225 | $ns->send_drawinfo ( |
190 | $ns->send_drawinfo ( |
226 | "Your username contains illegal characters " |
191 | "Your username contains illegal characters " |
227 | . "(only a-z, A-Z and 0-9 are allowed), " |
192 | . "(only a-z, A-Z and 0-9 are allowed), " |
228 | . "or is not between 3 and 18 characters in length.", |
193 | . "or is not between 3 and 20 characters in length.", |
229 | cf::NDI_RED |
194 | cf::NDI_RED |
230 | ); |
195 | ); |
231 | } |
196 | } |
232 | Coro::Timer::sleep 0.4; |
197 | Coro::Timer::sleep 0.4; |
233 | } |
198 | } |
… | |
… | |
279 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
244 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
280 | nuke_str $pass; |
245 | nuke_str $pass; |
281 | # password matches, wonderful |
246 | # password matches, wonderful |
282 | my $pl = cf::player::find $user or next; |
247 | my $pl = cf::player::find $user or next; |
283 | $pl->connect ($ns); |
248 | $pl->connect ($ns); |
|
|
249 | $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp |
284 | enter_map $pl; |
250 | enter_map $pl; |
285 | last; |
251 | last; |
286 | } elsif (can_cleanup $pl, $mtime) { |
252 | } elsif (can_cleanup $pl, $mtime) { |
287 | Coro::Timer::sleep 1; |
253 | Coro::Timer::sleep 1; |
288 | |
254 | |
… | |
… | |
377 | } |
343 | } |
378 | } else { |
344 | } else { |
379 | $ob->roll_stats; |
345 | $ob->roll_stats; |
380 | } |
346 | } |
381 | |
347 | |
382 | Coro::Timer::sleep 0.2; |
348 | Coro::Timer::sleep 0.05; |
383 | } |
349 | } |
384 | |
350 | |
385 | $ob->set_animation (2); |
351 | $ob->set_animation (2); |
386 | $ob->add_statbonus; |
352 | $ob->add_statbonus; |
387 | |
353 | |
… | |
… | |
398 | |
364 | |
399 | $pl->chargen_race_next; |
365 | $pl->chargen_race_next; |
400 | Coro::Timer::sleep 0.2; |
366 | Coro::Timer::sleep 0.2; |
401 | } |
367 | } |
402 | |
368 | |
|
|
369 | # create the playerdir, if necessary, as chargen_race_done did it before |
|
|
370 | # presumably because of unique maps |
|
|
371 | aio_mkdir playerdir $pl, 0770; |
403 | $pl->chargen_race_done; |
372 | $pl->chargen_race_done; |
404 | |
373 | |
405 | while () { |
374 | while () { |
406 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
375 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
407 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
376 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
… | |
… | |
416 | Coro::Timer::sleep 0.2; |
385 | Coro::Timer::sleep 0.2; |
417 | } |
386 | } |
418 | |
387 | |
419 | $ob->reply (undef, "Welcome to Deliantra!"); |
388 | $ob->reply (undef, "Welcome to Deliantra!"); |
420 | |
389 | |
|
|
390 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
391 | $pl->esrv_new_player; |
|
|
392 | |
421 | delete $pl->{deny_save}; |
393 | delete $pl->{deny_save}; |
422 | |
394 | |
423 | last; |
395 | last; |
424 | } |
396 | } |
425 | }); |
397 | }); |
426 | }); |
398 | }); |
427 | |
399 | |
428 | cf::register_command quit => sub { |
400 | cf::register_command quit => sub { |
429 | my ($ob, $arg) = @_; |
401 | my ($ob, $arg) = @_; |
430 | |
402 | |
431 | $ob->reply (undef, |
403 | $ob->send_msg (undef, |
432 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
404 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
433 | . "If you are sure you want to do this, then use the quit_character command instead of quit.", |
405 | . "If you are sure you want to do this, then use the quit_character command instead of quit.", |
434 | cf::NDI_UNIQUE | cf::NDI_RED); |
406 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
435 | }; |
407 | }; |
436 | |
408 | |
437 | cf::register_command quit_character => sub { |
409 | cf::register_command quit_character => sub { |
438 | my ($ob, $arg) = @_; |
410 | my ($ob, $arg) = @_; |
439 | |
411 | |
440 | my $pl = $ob->contr; |
412 | my $pl = $ob->contr; |
441 | |
413 | |
442 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
414 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
443 | if ($_[0] !~ /^[yY]/) { |
415 | if ($_[0] !~ /^[yY]/) { |
444 | $ob->reply (undef, |
416 | $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
445 | "Ok, not not quitting then.", |
|
|
446 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
447 | } else { |
417 | } else { |
448 | $ob->reply (undef, |
418 | $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
449 | "Ok, quitting, hope to see you again.", |
|
|
450 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
451 | $pl->ns->flush; |
419 | $pl->ns->flush; |
452 | cf::async { $pl->quit_character }; |
420 | cf::async { $pl->quit_character }; |
453 | } |
421 | } |
454 | }); |
422 | }); |
455 | }; |
423 | }; |
… | |
… | |
465 | |
433 | |
466 | # update respawn position |
434 | # update respawn position |
467 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
435 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
468 | cf::async { $pl->save }; |
436 | cf::async { $pl->save }; |
469 | |
437 | |
470 | $pl->killer ("left"); |
438 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
471 | $ob->check_score; |
439 | $ob->check_score; |
472 | |
440 | |
473 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
441 | $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); |
474 | |
442 | |
475 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
443 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
476 | if ($_[0] !~ /^[yY]/) { |
444 | if ($_[0] !~ /^[yY]/) { |
477 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
445 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
478 | $pl->deactivate; |
446 | $pl->deactivate; |
… | |
… | |
503 | unless safe_spot $pl; |
471 | unless safe_spot $pl; |
504 | } |
472 | } |
505 | }, |
473 | }, |
506 | ); |
474 | ); |
507 | |
475 | |
508 | ############################################################################# |
|
|
509 | |
476 | |
510 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
|
|
511 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
|
|
512 | |
|
|
513 | our $SCHEDULER = cf::async_ext { |
|
|
514 | $Coro::current->{desc} = "player scheduler"; |
|
|
515 | |
|
|
516 | while () { |
|
|
517 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
|
|
518 | |
|
|
519 | # this weird form of iteration over values is used because |
|
|
520 | # the hash changes underneath us frequently, and for |
|
|
521 | # keeps a direct reference to the value without (in 5.8 perls) |
|
|
522 | # keeping a reference, so this is prone to crashes or worse. |
|
|
523 | my @players = keys %cf::PLAYER; |
|
|
524 | for (@players) { |
|
|
525 | my $pl = $cf::PLAYER{$_} |
|
|
526 | or next; |
|
|
527 | $pl->valid or next; |
|
|
528 | |
|
|
529 | eval { |
|
|
530 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
531 | $pl->save; |
|
|
532 | |
|
|
533 | unless ($pl->active || $pl->ns) { |
|
|
534 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
|
|
535 | my $ob = $pl->ob; |
|
|
536 | |
|
|
537 | my $pl_ref = $pl->refcnt_cnt; |
|
|
538 | my $ob_ref = $ob->refcnt_cnt; |
|
|
539 | |
|
|
540 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
|
|
541 | ## ob_ref == $ob + pl->observe + simply being an object |
|
|
542 | if ($pl_ref == 3 && $ob_ref == 3) { |
|
|
543 | warn "player-scheduler destroy ", $ob->name;#d# |
|
|
544 | |
|
|
545 | # remove from sight and get fresh "copies" |
|
|
546 | $pl = delete $cf::PLAYER{$ob->name}; |
|
|
547 | $ob = $pl->ob; |
|
|
548 | |
|
|
549 | $pl->destroy; # destroys $ob |
|
|
550 | } else { |
|
|
551 | my $a_ = $pl->refcnt;#d# |
|
|
552 | my $b_ = $ob->refcnt;#d# |
|
|
553 | |
|
|
554 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d# |
|
|
555 | } |
|
|
556 | } |
|
|
557 | } |
|
|
558 | }; |
|
|
559 | warn $@ if $@; |
|
|
560 | cf::cede_to_tick; |
|
|
561 | }; |
|
|
562 | } |
|
|
563 | }; |
|
|
564 | |
|
|
565 | $SCHEDULER->prio (1); |
|
|
566 | |
|
|