… | |
… | |
52 | ); |
52 | ); |
53 | |
53 | |
54 | 1 |
54 | 1 |
55 | } |
55 | } |
56 | |
56 | |
57 | sub safe_spot($$$) { |
57 | sub safe_spot($) { |
58 | my ($m, $x, $y) = @_; |
58 | my ($pl) = @_; |
|
|
59 | |
|
|
60 | my $ob = $pl->ob; |
59 | |
61 | |
|
|
62 | my $m = $ob->map |
|
|
63 | or return; |
|
|
64 | my $x = $ob->x; |
|
|
65 | my $y = $ob->y; |
|
|
66 | |
60 | return 0; |
67 | # return 0;#d# |
61 | warn join ":", $m->at ($x, $y);#d# |
68 | # warn join ":", $m->at ($x, $y);#d# |
62 | warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
69 | # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
63 | return 0; |
70 | # return 0; |
64 | |
71 | |
65 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
72 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
66 | } |
73 | } |
67 | |
74 | |
68 | sub enter_map { |
75 | sub enter_map { |
69 | my ($pl) = @_; |
76 | my ($pl) = @_; |
70 | |
77 | |
|
|
78 | warn $pl->ob->name, ": enter map 1\n";#d# |
71 | my $ob = $pl->ob; |
79 | my $ob = $pl->ob; |
72 | |
80 | |
73 | my ($map, $x, $y) |
81 | my ($map, $x, $y) |
74 | = $ob->{_link_pos} |
82 | = $ob->{_link_pos} |
75 | ? @{delete $ob->{_link_pos}} |
83 | ? @{delete $ob->{_link_pos}} |
76 | : ($pl->maplevel, $ob->x, $ob->y); |
84 | : ($pl->maplevel, $ob->x, $ob->y); |
77 | |
85 | |
|
|
86 | warn $pl->ob->name, ": enter map 2\n";#d# |
78 | $ob->enter_link; |
87 | $ob->enter_link; |
|
|
88 | warn $pl->ob->name, ": enter map 3\n";#d# |
79 | |
89 | |
80 | my $m = cf::map::find $map; |
90 | my $m = cf::map::find $map; |
81 | my $time = delete $pl->{unclean_save}; |
91 | my $time = delete $pl->{unclean_save}; |
|
|
92 | warn $pl->ob->name, ": enter map 4\n";#d# |
82 | |
93 | |
83 | if ($time && $m && !safe_spot $m, $x, $y) { |
94 | if ($time && $m) { |
84 | if ($time < $m->{instantiate_time}) { |
95 | if ($time < $m->{instantiate_time}) { |
85 | # the map was reset in the meantime |
96 | # the map was reset in the meantime |
86 | my $age = $cf::RUNTIME - $time; |
97 | my $age = $cf::RUNTIME - $time; |
87 | |
98 | |
88 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
99 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
89 | |
|
|
90 | ($map, $x, $y) = $pl->savebed; |
|
|
91 | |
100 | |
92 | if ($age >= $MAX_DISCONNECT_TIME) { |
101 | if ($age >= $MAX_DISCONNECT_TIME) { |
93 | $ob->message ( |
102 | $ob->message ( |
94 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
103 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
95 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
104 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
… | |
… | |
98 | cf::NDI_RED |
107 | cf::NDI_RED |
99 | ); |
108 | ); |
100 | # kill them. |
109 | # kill them. |
101 | # reminds me of the famous badness 10000 syndrome... |
110 | # reminds me of the famous badness 10000 syndrome... |
102 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
111 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
103 | $pl->killer ("a cave-in"); |
112 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
104 | } else { |
113 | } else { |
|
|
114 | ($map, $x, $y) = $pl->savebed; |
|
|
115 | |
105 | $ob->message ( |
116 | $ob->message ( |
106 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
117 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
107 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
118 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
108 | . "Better use a savebed next time, much worse things could have happened... " |
119 | . "Better use a savebed next time, much worse things could have happened... " |
109 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
120 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
… | |
… | |
119 | cf::NDI_RED |
130 | cf::NDI_RED |
120 | ); |
131 | ); |
121 | } |
132 | } |
122 | } |
133 | } |
123 | |
134 | |
|
|
135 | warn $pl->ob->name, ": enter map 5\n";#d# |
124 | $ob->goto ($map, $x, $y); |
136 | #$ob->goto ($map, $x, $y); |
|
|
137 | $ob->goto ($map, $x, $y, sub { |
|
|
138 | warn $pl->ob->name, ": enter map check\n";#d# |
|
|
139 | $_[0] |
|
|
140 | }, sub { |
|
|
141 | warn $pl->ob->name, ": enter map done\n";#d# |
|
|
142 | }); |
|
|
143 | warn $pl->ob->name, ": enter map 6\n";#d# |
|
|
144 | |
125 | } |
145 | } |
126 | |
146 | |
127 | # delete a player directory, be non-blocking AND synchronous... |
147 | # delete a player directory, be non-blocking AND synchronous... |
128 | # (thats hard, so we crap out and fork). |
148 | # (thats hard, so we crap out and fork). |
129 | sub nuke_playerdir { |
149 | sub nuke_playerdir { |
… | |
… | |
151 | *** or it has been disabled. Face caching is mandatory |
171 | *** or it has been disabled. Face caching is mandatory |
152 | *** so please enable it or use a newer client. |
172 | *** so please enable it or use a newer client. |
153 | *** |
173 | *** |
154 | *** Look at your client preferences: |
174 | *** Look at your client preferences: |
155 | *** |
175 | *** |
156 | *** CFPlus: all known versions automatically enable the facecache. |
176 | *** deliantra: all known versions automatically enable the facecache. |
157 | *** cfclient: use the -cache commandline option. |
177 | *** cfclient: use the -cache commandline option. |
158 | *** cfclient: map will not redraw automatically (bug). |
178 | *** cfclient: map will not redraw automatically (bug). |
159 | *** gcfclient: use -cache commandline option, or enable |
179 | *** gcfclient: use -cache commandline option, or enable |
160 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
180 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
161 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
181 | *** jcrossclient: your client is broken, use deliantra or gcfclient. |
162 | *** |
182 | *** |
163 | *** |
183 | *** |
164 | EOF |
184 | EOF |
165 | if ($ns->version =~ /jcrossclient/) { |
185 | if ($ns->version =~ /jcrossclient/) { |
166 | # let them, for now |
186 | # let them, for now |
… | |
… | |
202 | cf::NDI_BLUE |
222 | cf::NDI_BLUE |
203 | ); |
223 | ); |
204 | |
224 | |
205 | # read username |
225 | # read username |
206 | while () { |
226 | while () { |
207 | $user = query $ns, 0, "What is your name?\n:"; |
227 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
208 | |
228 | |
209 | if ($cf::LOGIN_LOCK{$user}) { |
229 | if ($cf::LOGIN_LOCK{$user}) { |
210 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
211 | "That username is currently used in another login session. " |
231 | "That username is currently used in another login session. " |
212 | . "Chose another, or wait till the other session has ended.", |
232 | . "Chose another, or wait till the other session has ended.", |
213 | cf::NDI_RED |
233 | cf::NDI_RED |
214 | ); |
234 | ); |
215 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { |
235 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) { |
216 | last; |
236 | last; |
217 | } else { |
237 | } else { |
218 | $ns->send_drawinfo ( |
238 | $ns->send_drawinfo ( |
219 | "Your username contains illegal characters " |
239 | "Your username contains illegal characters " |
220 | . "(only a-z, A-Z and 0-9 are allowed), " |
240 | . "(only a-z, A-Z and 0-9 are allowed), " |
221 | . "or is not between 3 and 18 characters in length.", |
241 | . "or is not between 3 and 20 characters in length.", |
222 | cf::NDI_RED |
242 | cf::NDI_RED |
223 | ); |
243 | ); |
224 | } |
244 | } |
225 | Coro::Timer::sleep 0.4; |
245 | Coro::Timer::sleep 0.4; |
226 | } |
246 | } |
… | |
… | |
272 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
292 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
273 | nuke_str $pass; |
293 | nuke_str $pass; |
274 | # password matches, wonderful |
294 | # password matches, wonderful |
275 | my $pl = cf::player::find $user or next; |
295 | my $pl = cf::player::find $user or next; |
276 | $pl->connect ($ns); |
296 | $pl->connect ($ns); |
|
|
297 | $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp |
277 | enter_map $pl; |
298 | enter_map $pl; |
278 | last; |
299 | last; |
279 | } elsif (can_cleanup $pl, $mtime) { |
300 | } elsif (can_cleanup $pl, $mtime) { |
280 | Coro::Timer::sleep 1; |
301 | Coro::Timer::sleep 1; |
281 | |
302 | |
… | |
… | |
370 | } |
391 | } |
371 | } else { |
392 | } else { |
372 | $ob->roll_stats; |
393 | $ob->roll_stats; |
373 | } |
394 | } |
374 | |
395 | |
375 | Coro::Timer::sleep 0.2; |
396 | Coro::Timer::sleep 0.05; |
376 | } |
397 | } |
377 | |
398 | |
378 | $ob->set_animation (2); |
399 | $ob->set_animation (2); |
379 | $ob->add_statbonus; |
400 | $ob->add_statbonus; |
380 | |
401 | |
… | |
… | |
391 | |
412 | |
392 | $pl->chargen_race_next; |
413 | $pl->chargen_race_next; |
393 | Coro::Timer::sleep 0.2; |
414 | Coro::Timer::sleep 0.2; |
394 | } |
415 | } |
395 | |
416 | |
|
|
417 | # create the playerdir, if necessary, as chargen_race_done did it before |
|
|
418 | # presumably because of unique maps |
|
|
419 | aio_mkdir playerdir $pl, 0770; |
396 | $pl->chargen_race_done; |
420 | $pl->chargen_race_done; |
397 | |
421 | |
398 | while () { |
422 | while () { |
399 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
423 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
400 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
424 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
… | |
… | |
408 | } |
432 | } |
409 | Coro::Timer::sleep 0.2; |
433 | Coro::Timer::sleep 0.2; |
410 | } |
434 | } |
411 | |
435 | |
412 | $ob->reply (undef, "Welcome to Deliantra!"); |
436 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
437 | |
|
|
438 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
439 | $pl->esrv_new_player; |
413 | |
440 | |
414 | delete $pl->{deny_save}; |
441 | delete $pl->{deny_save}; |
415 | |
442 | |
416 | last; |
443 | last; |
417 | } |
444 | } |
… | |
… | |
458 | |
485 | |
459 | # update respawn position |
486 | # update respawn position |
460 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
487 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
461 | cf::async { $pl->save }; |
488 | cf::async { $pl->save }; |
462 | |
489 | |
463 | $pl->killer ("left"); |
490 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
464 | $ob->check_score; |
491 | $ob->check_score; |
465 | |
492 | |
466 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
493 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
467 | |
494 | |
468 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
495 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
… | |
… | |
490 | |
517 | |
491 | if ($cleanly) { |
518 | if ($cleanly) { |
492 | $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
519 | $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
493 | } else { |
520 | } else { |
494 | $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
521 | $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
495 | $pl->{unclean_save} = $cf::RUNTIME; |
522 | $pl->{unclean_save} = $cf::RUNTIME |
|
|
523 | unless safe_spot $pl; |
496 | } |
524 | } |
497 | }, |
525 | }, |
498 | ); |
526 | ); |
499 | |
527 | |
500 | ############################################################################# |
|
|
501 | |
528 | |
502 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
|
|
503 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
|
|
504 | |
|
|
505 | our $SCHEDULER = cf::async_ext { |
|
|
506 | $Coro::current->{desc} = "player scheduler"; |
|
|
507 | |
|
|
508 | while () { |
|
|
509 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
|
|
510 | |
|
|
511 | # this weird form of iteration over values is used because |
|
|
512 | # the hash changes underneath us frequently, and for |
|
|
513 | # keeps a direct reference to the value without (in 5.8 perls) |
|
|
514 | # keeping a reference, so this is prone to crashes or worse. |
|
|
515 | my @players = keys %cf::PLAYER; |
|
|
516 | for (@players) { |
|
|
517 | my $pl = $cf::PLAYER{$_} |
|
|
518 | or next; |
|
|
519 | $pl->valid or next; |
|
|
520 | |
|
|
521 | eval { |
|
|
522 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
523 | $pl->save; |
|
|
524 | |
|
|
525 | unless ($pl->active || $pl->ns) { |
|
|
526 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
|
|
527 | my $ob = $pl->ob; |
|
|
528 | |
|
|
529 | my $pl_ref = $pl->refcnt_cnt; |
|
|
530 | my $ob_ref = $ob->refcnt_cnt; |
|
|
531 | |
|
|
532 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
|
|
533 | ## ob_ref == $ob + pl->observe + simply being an object |
|
|
534 | if ($pl_ref == 3 && $ob_ref == 3) { |
|
|
535 | warn "player-scheduler destroy ", $ob->name;#d# |
|
|
536 | |
|
|
537 | # remove from sight and get fresh "copies" |
|
|
538 | $pl = delete $cf::PLAYER{$ob->name}; |
|
|
539 | $ob = $pl->ob; |
|
|
540 | |
|
|
541 | $pl->destroy; # destroys $ob |
|
|
542 | } else { |
|
|
543 | my $a_ = $pl->refcnt;#d# |
|
|
544 | my $b_ = $ob->refcnt;#d# |
|
|
545 | |
|
|
546 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d# |
|
|
547 | } |
|
|
548 | } |
|
|
549 | } |
|
|
550 | }; |
|
|
551 | warn $@ if $@; |
|
|
552 | Coro::cede; |
|
|
553 | }; |
|
|
554 | } |
|
|
555 | }; |
|
|
556 | |
|
|
557 | $SCHEDULER->prio (1); |
|
|
558 | |
|
|