… | |
… | |
86 | cf::NDI_RED |
86 | cf::NDI_RED |
87 | ); |
87 | ); |
88 | # kill them. |
88 | # kill them. |
89 | # reminds me of the famous badness 10000 syndrome... |
89 | # reminds me of the famous badness 10000 syndrome... |
90 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
90 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
|
|
91 | $pl->killer ("a cave-in"); |
91 | } else { |
92 | } else { |
92 | $ob->message ( |
93 | $ob->message ( |
93 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
94 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
94 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
95 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
95 | . "Better use a savebed next time, much worse things could have happened... " |
96 | . "Better use a savebed next time, much worse things could have happened... " |
… | |
… | |
115 | # delete a player directory, be non-blocking AND synchronous... |
116 | # delete a player directory, be non-blocking AND synchronous... |
116 | # (thats hard, so we crap out and fork). |
117 | # (thats hard, so we crap out and fork). |
117 | sub nuke_playerdir { |
118 | sub nuke_playerdir { |
118 | my ($user) = @_; |
119 | my ($user) = @_; |
119 | |
120 | |
120 | aio_stat "$PLAYERDIR/$user"; |
121 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
121 | system "cd \Q$PLAYERDIR\E " |
122 | |
122 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
123 | cf::fork_call { |
123 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
124 | rename "$PLAYERDIR/$user", $temp; |
|
|
125 | system "rm", "-rf", $temp; |
|
|
126 | }; |
124 | } |
127 | } |
125 | |
128 | |
126 | cf::client->attach (on_addme => sub { |
129 | cf::client->attach (on_addme => sub { |
127 | my ($ns) = @_; |
130 | my ($ns) = @_; |
128 | |
131 | |
… | |
… | |
141 | *** |
144 | *** |
142 | *** CFPlus: all known versions automatically enable the facecache. |
145 | *** CFPlus: all known versions automatically enable the facecache. |
143 | *** cfclient: use the -cache commandline option. |
146 | *** cfclient: use the -cache commandline option. |
144 | *** cfclient: map will not redraw automatically (bug). |
147 | *** cfclient: map will not redraw automatically (bug). |
145 | *** gcfclient: use -cache commandline option, or enable |
148 | *** gcfclient: use -cache commandline option, or enable |
146 | *** gcfclient: Client=>Configure=>Map & Image=>Cache Images. |
149 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
147 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
150 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
148 | *** |
151 | *** |
149 | *** |
152 | *** |
150 | EOF |
153 | EOF |
151 | if ($ns->version =~ /jcrossclient/) { |
154 | if ($ns->version =~ /jcrossclient/) { |
… | |
… | |
172 | } |
175 | } |
173 | |
176 | |
174 | $ns->pl and return $ns->destroy; |
177 | $ns->pl and return $ns->destroy; |
175 | |
178 | |
176 | $ns->async (sub { |
179 | $ns->async (sub { |
|
|
180 | $Coro::current->{desc} = "addme init"; |
|
|
181 | |
177 | my ($user, $pass); |
182 | my ($user, $pass); |
178 | |
183 | |
179 | $ns->send_packet ("addme_success"); |
184 | $ns->send_packet ("addme_success"); |
180 | |
185 | |
181 | for (;;) { |
186 | for (;;) { |
… | |
… | |
208 | } |
213 | } |
209 | Coro::Timer::sleep 0.4; |
214 | Coro::Timer::sleep 0.4; |
210 | } |
215 | } |
211 | |
216 | |
212 | check_playing $ns, $user and next; |
217 | check_playing $ns, $user and next; |
|
|
218 | |
|
|
219 | $Coro::current->{desc} = "addme($user) pass"; |
213 | |
220 | |
214 | $ns->send_drawinfo ( |
221 | $ns->send_drawinfo ( |
215 | "Welcome $user, please enter your password now. " |
222 | "Welcome $user, please enter your password now. " |
216 | . "New users should now choose a password. " |
223 | . "New users should now choose a password. " |
217 | . "Anything your client lets you enter is fine.", |
224 | . "Anything your client lets you enter is fine.", |
… | |
… | |
241 | } |
248 | } |
242 | local $cf::LOGIN_LOCK{$user} = 1; |
249 | local $cf::LOGIN_LOCK{$user} = 1; |
243 | |
250 | |
244 | check_playing $ns, $user and next; |
251 | check_playing $ns, $user and next; |
245 | |
252 | |
|
|
253 | $Coro::current->{desc} = "addme($user) check"; |
|
|
254 | |
246 | # try to read the user file and check the password |
255 | # try to read the user file and check the password |
247 | if (my $pl = cf::player::find $user) { |
256 | if (my $pl = cf::player::find $user) { |
248 | aio_stat $pl->path and next; |
257 | aio_stat $pl->path and next; |
249 | my $mtime = (stat _)[9]; |
258 | my $mtime = (stat _)[9]; |
250 | my $hash = $pl->password; |
259 | my $hash = $pl->password; |
… | |
… | |
303 | next; |
312 | next; |
304 | } |
313 | } |
305 | } |
314 | } |
306 | |
315 | |
307 | # the rest of this function is character creation |
316 | # the rest of this function is character creation |
|
|
317 | $Coro::current->{desc} = "addme($user) chargen"; |
308 | |
318 | |
309 | # just to make sure nothing is left over |
319 | # just to make sure nothing is left over |
310 | nuke_playerdir $user; |
320 | nuke_playerdir $user; |
311 | |
321 | |
312 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
322 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
… | |
… | |
356 | |
366 | |
357 | $ob->set_animation (2); |
367 | $ob->set_animation (2); |
358 | $ob->add_statbonus; |
368 | $ob->add_statbonus; |
359 | |
369 | |
360 | while () { |
370 | while () { |
361 | $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); |
371 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
362 | my $msg = $ob->msg; |
372 | my $msg = $ob->msg; |
363 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
373 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
364 | $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); |
374 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
365 | |
375 | |
366 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
376 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
367 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
377 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
368 | |
378 | |
369 | last if $res =~ /[dD]/; |
379 | last if $res =~ /[dD]/; |
… | |
… | |
476 | }, |
486 | }, |
477 | ); |
487 | ); |
478 | |
488 | |
479 | ############################################################################# |
489 | ############################################################################# |
480 | |
490 | |
481 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
491 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
482 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
492 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
483 | |
493 | |
484 | our $SCHEDULER = cf::async_ext { |
494 | our $SCHEDULER = cf::async_ext { |
|
|
495 | $Coro::current->{desc} = "player scheduler"; |
|
|
496 | |
485 | my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); |
497 | my $schedule_interval = Coro::Event->timer (after => 1); |
486 | while () { |
498 | while () { |
|
|
499 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
487 | $schedule_interval->next; |
500 | $schedule_interval->next; |
488 | |
501 | |
489 | # this weird form of iteration over values is used because |
502 | # this weird form of iteration over values is used because |
490 | # the hash changes underneath us frequently, and for |
503 | # the hash changes underneath us frequently, and for |
491 | # keeps a direct reference to the value without (in 5.8 perls) |
504 | # keeps a direct reference to the value without (in 5.8 perls) |
… | |
… | |
496 | or next; |
509 | or next; |
497 | $pl->valid or next; |
510 | $pl->valid or next; |
498 | |
511 | |
499 | eval { |
512 | eval { |
500 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
513 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
501 | cf::wait_for_tick_begin; |
|
|
502 | $pl->save; |
514 | $pl->save; |
503 | |
515 | |
504 | unless ($pl->active || $pl->ns) { |
516 | unless ($pl->active || $pl->ns) { |
505 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
517 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
506 | my $ob = $pl->ob; |
518 | my $ob = $pl->ob; |