… | |
… | |
2 | |
2 | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
|
|
7 | |
|
|
8 | our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; |
7 | |
9 | |
8 | # paranoia function to overwrite a string-in-place |
10 | # paranoia function to overwrite a string-in-place |
9 | sub nuke_str { |
11 | sub nuke_str { |
10 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
12 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
11 | } |
13 | } |
… | |
… | |
64 | |
66 | |
65 | $ob->enter_link; |
67 | $ob->enter_link; |
66 | |
68 | |
67 | if (my $time = delete $pl->{unclean_save}) { |
69 | if (my $time = delete $pl->{unclean_save}) { |
68 | if (my $m = cf::map::find $map) { |
70 | if (my $m = cf::map::find $map) { |
69 | if ($time < $m->{instantiate_time} || 1) {#d# |
71 | if ($time < $m->{instantiate_time}) { |
70 | # the map was reset in the meantime |
72 | # the map was reset in the meantime |
71 | my $age = $cf::RUNTIME - $time; |
73 | my $age = $cf::RUNTIME - $time; |
|
|
74 | |
72 | warn $ob->name, " map reset after logout, logout age $age\n";#d# |
75 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
73 | |
76 | |
74 | # for now, just go back to savebed |
77 | # for now, just go back to savebed |
75 | ($map, $x, $y) = $pl->savebed; |
78 | ($map, $x, $y) = $pl->savebed; |
76 | |
79 | |
77 | $pl->ns->send_drawinfo ( |
80 | if ($age >= $MAX_DISCONNECT_TIME) { |
|
|
81 | $ob->message ( |
78 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
82 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
|
|
83 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
|
|
84 | . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " |
|
|
85 | . "H<You disconnected too long without having used a savebed.>", |
|
|
86 | cf::NDI_RED |
|
|
87 | ); |
|
|
88 | # kill them. |
|
|
89 | # reminds me of the famous badness 10000 syndrome... |
|
|
90 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
|
|
91 | $pl->killer ("a cave-in"); |
|
|
92 | } else { |
|
|
93 | $ob->message ( |
|
|
94 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
79 | . "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. " |
80 | . "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... " |
|
|
97 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
81 | cf::NDI_RED |
98 | cf::NDI_RED |
82 | ); |
99 | ); |
|
|
100 | } |
83 | } else { |
101 | } else { |
84 | $pl->ns->send_drawinfo ( |
102 | $ob->message ( |
85 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
103 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
86 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
104 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
87 | . "or monsters suddenly snapping your body. Better use a savebed next time.", |
105 | . "or monsters suddenly snapping your body. Better use a savebed next time. " |
|
|
106 | . "H<Always apply a bed of reality to disconnect from the server.>", |
88 | cf::NDI_RED |
107 | cf::NDI_RED |
89 | ); |
108 | ); |
90 | } |
109 | } |
91 | } |
110 | } |
92 | } |
111 | } |
… | |
… | |
97 | # delete a player directory, be non-blocking AND synchronous... |
116 | # delete a player directory, be non-blocking AND synchronous... |
98 | # (thats hard, so we crap out and fork). |
117 | # (thats hard, so we crap out and fork). |
99 | sub nuke_playerdir { |
118 | sub nuke_playerdir { |
100 | my ($user) = @_; |
119 | my ($user) = @_; |
101 | |
120 | |
102 | aio_stat "$PLAYERDIR/$user"; |
121 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
103 | system "cd \Q$PLAYERDIR\E " |
122 | |
104 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
123 | cf::fork_call { |
105 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
124 | rename "$PLAYERDIR/$user", $temp; |
|
|
125 | system "rm", "-rf", $temp; |
|
|
126 | }; |
106 | } |
127 | } |
107 | |
128 | |
108 | cf::client->attach (on_addme => sub { |
129 | cf::client->attach (on_addme => sub { |
109 | my ($ns) = @_; |
130 | my ($ns) = @_; |
110 | |
131 | |
… | |
… | |
123 | *** |
144 | *** |
124 | *** CFPlus: all known versions automatically enable the facecache. |
145 | *** CFPlus: all known versions automatically enable the facecache. |
125 | *** cfclient: use the -cache commandline option. |
146 | *** cfclient: use the -cache commandline option. |
126 | *** cfclient: map will not redraw automatically (bug). |
147 | *** cfclient: map will not redraw automatically (bug). |
127 | *** gcfclient: use -cache commandline option, or enable |
148 | *** gcfclient: use -cache commandline option, or enable |
128 | *** gcfclient: Client=>Configure=>Map & Image=>Cache Images. |
149 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
129 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
150 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
130 | *** |
151 | *** |
131 | *** |
152 | *** |
132 | EOF |
153 | EOF |
133 | if ($ns->version =~ /jcrossclient/) { |
154 | if ($ns->version =~ /jcrossclient/) { |
… | |
… | |
154 | } |
175 | } |
155 | |
176 | |
156 | $ns->pl and return $ns->destroy; |
177 | $ns->pl and return $ns->destroy; |
157 | |
178 | |
158 | $ns->async (sub { |
179 | $ns->async (sub { |
|
|
180 | $Coro::current->{desc} = "addme init"; |
|
|
181 | |
159 | my ($user, $pass); |
182 | my ($user, $pass); |
160 | |
183 | |
161 | $ns->send_packet ("addme_success"); |
184 | $ns->send_packet ("addme_success"); |
162 | |
185 | |
163 | for (;;) { |
186 | for (;;) { |
… | |
… | |
190 | } |
213 | } |
191 | Coro::Timer::sleep 0.4; |
214 | Coro::Timer::sleep 0.4; |
192 | } |
215 | } |
193 | |
216 | |
194 | check_playing $ns, $user and next; |
217 | check_playing $ns, $user and next; |
|
|
218 | |
|
|
219 | $Coro::current->{desc} = "addme($user) pass"; |
195 | |
220 | |
196 | $ns->send_drawinfo ( |
221 | $ns->send_drawinfo ( |
197 | "Welcome $user, please enter your password now. " |
222 | "Welcome $user, please enter your password now. " |
198 | . "New users should now choose a password. " |
223 | . "New users should now choose a password. " |
199 | . "Anything your client lets you enter is fine.", |
224 | . "Anything your client lets you enter is fine.", |
… | |
… | |
223 | } |
248 | } |
224 | local $cf::LOGIN_LOCK{$user} = 1; |
249 | local $cf::LOGIN_LOCK{$user} = 1; |
225 | |
250 | |
226 | check_playing $ns, $user and next; |
251 | check_playing $ns, $user and next; |
227 | |
252 | |
|
|
253 | $Coro::current->{desc} = "addme($user) check"; |
|
|
254 | |
228 | # try to read the user file and check the password |
255 | # try to read the user file and check the password |
229 | if (my $pl = cf::player::find $user) { |
256 | if (my $pl = cf::player::find $user) { |
230 | aio_stat $pl->path and next; |
257 | aio_stat $pl->path and next; |
231 | my $mtime = (stat _)[9]; |
258 | my $mtime = (stat _)[9]; |
232 | my $hash = $pl->password; |
259 | my $hash = $pl->password; |
… | |
… | |
285 | next; |
312 | next; |
286 | } |
313 | } |
287 | } |
314 | } |
288 | |
315 | |
289 | # the rest of this function is character creation |
316 | # the rest of this function is character creation |
|
|
317 | $Coro::current->{desc} = "addme($user) chargen"; |
290 | |
318 | |
291 | # just to make sure nothing is left over |
319 | # just to make sure nothing is left over |
292 | nuke_playerdir $user; |
320 | nuke_playerdir $user; |
293 | |
321 | |
294 | 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."; |
… | |
… | |
338 | |
366 | |
339 | $ob->set_animation (2); |
367 | $ob->set_animation (2); |
340 | $ob->add_statbonus; |
368 | $ob->add_statbonus; |
341 | |
369 | |
342 | while () { |
370 | while () { |
343 | $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); |
371 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
344 | my $msg = $ob->msg; |
372 | my $msg = $ob->msg; |
345 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
373 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
346 | $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); |
374 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
347 | |
375 | |
348 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
376 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
349 | "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"; |
350 | |
378 | |
351 | last if $res =~ /[dD]/; |
379 | last if $res =~ /[dD]/; |
… | |
… | |
458 | }, |
486 | }, |
459 | ); |
487 | ); |
460 | |
488 | |
461 | ############################################################################# |
489 | ############################################################################# |
462 | |
490 | |
463 | 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 |
464 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
492 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
465 | |
493 | |
466 | our $SCHEDULER = cf::async_ext { |
494 | our $SCHEDULER = cf::async_ext { |
|
|
495 | $Coro::current->{desc} = "player scheduler"; |
|
|
496 | |
467 | my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); |
497 | my $schedule_interval = Coro::Event->timer (after => 1); |
468 | while () { |
498 | while () { |
|
|
499 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
469 | $schedule_interval->next; |
500 | $schedule_interval->next; |
470 | |
501 | |
471 | # this weird form of iteration over values is used because |
502 | # this weird form of iteration over values is used because |
472 | # the hash changes underneath us frequently, and for |
503 | # the hash changes underneath us frequently, and for |
473 | # 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) |
… | |
… | |
478 | or next; |
509 | or next; |
479 | $pl->valid or next; |
510 | $pl->valid or next; |
480 | |
511 | |
481 | eval { |
512 | eval { |
482 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
513 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
483 | cf::wait_for_tick_begin; |
|
|
484 | $pl->save; |
514 | $pl->save; |
485 | |
515 | |
486 | unless ($pl->active || $pl->ns) { |
516 | unless ($pl->active || $pl->ns) { |
487 | # 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 |
488 | my $ob = $pl->ob; |
518 | my $ob = $pl->ob; |