… | |
… | |
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 | } |
… | |
… | |
53 | } |
55 | } |
54 | |
56 | |
55 | sub enter_map { |
57 | sub enter_map { |
56 | my ($pl) = @_; |
58 | my ($pl) = @_; |
57 | |
59 | |
|
|
60 | my $ob = $pl->ob; |
|
|
61 | |
58 | my ($map, $x, $y) |
62 | my ($map, $x, $y) |
59 | = $pl->ob->{_link_pos} |
63 | = $ob->{_link_pos} |
60 | ? @{delete $pl->ob->{_link_pos}} |
64 | ? @{delete $ob->{_link_pos}} |
61 | : ($pl->maplevel, $pl->ob->x, $pl->ob->y); |
65 | : ($pl->maplevel, $ob->x, $ob->y); |
62 | |
66 | |
63 | $pl->ob->enter_link; |
67 | $ob->enter_link; |
64 | |
68 | |
65 | if (my $time = delete $pl->{unclean_save}) { |
69 | if (my $time = delete $pl->{unclean_save}) { |
66 | if (my $m = cf::map::find $map) { |
70 | if (my $m = cf::map::find $map) { |
67 | if ($time < $m->{instantiate_time}) { |
71 | if ($time < $m->{instantiate_time}) { |
68 | # the map was reset in the meantime |
72 | # the map was reset in the meantime |
69 | my $age = $cf::RUNTIME - $time; |
73 | my $age = $cf::RUNTIME - $time; |
|
|
74 | |
70 | warn $pl->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# |
71 | |
76 | |
72 | # for now, just go back to savebed |
77 | # for now, just go back to savebed |
73 | ($map, $x, $y) = $pl->savebed; |
78 | ($map, $x, $y) = $pl->savebed; |
74 | |
79 | |
75 | $pl->ns->send_drawinfo ( |
80 | if ($age >= $MAX_DISCONNECT_TIME) { |
|
|
81 | $ob->message ( |
76 | "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. " |
77 | . "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. " |
78 | . "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.>", |
|
|
98 | cf::NDI_RED |
|
|
99 | ); |
|
|
100 | } |
|
|
101 | } else { |
|
|
102 | $ob->message ( |
|
|
103 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
|
|
104 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
|
|
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.>", |
79 | cf::NDI_RED |
107 | cf::NDI_RED |
80 | ); |
108 | ); |
81 | } else { |
|
|
82 | $pl->ns->send_drawinfo ( |
|
|
83 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
|
|
84 | . "as lots of things could happen when you leave by other means, such as cave-ins, " |
|
|
85 | . "or monsters suddenly snapping your body. Better use a savebed next time.", |
|
|
86 | cf::NDI_RED |
|
|
87 | ); |
|
|
88 | } |
109 | } |
89 | } |
110 | } |
90 | } |
111 | } |
91 | |
112 | |
92 | $pl->ob->goto ($map, $x, $y); |
113 | $ob->goto ($map, $x, $y); |
93 | } |
114 | } |
94 | |
115 | |
95 | # delete a player directory, be non-blocking AND synchronous... |
116 | # delete a player directory, be non-blocking AND synchronous... |
96 | # (thats hard, so we crap out and fork). |
117 | # (thats hard, so we crap out and fork). |
97 | sub nuke_playerdir { |
118 | sub nuke_playerdir { |
98 | my ($user) = @_; |
119 | my ($user) = @_; |
99 | |
120 | |
100 | aio_stat "$PLAYERDIR/$user"; |
121 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
101 | system "cd \Q$PLAYERDIR\E " |
122 | |
102 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
123 | cf::fork_call { |
103 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
124 | rename "$PLAYERDIR/$user", $temp; |
|
|
125 | system "rm", "-rf", $temp; |
|
|
126 | }; |
104 | } |
127 | } |
105 | |
128 | |
106 | cf::client->attach (on_addme => sub { |
129 | cf::client->attach (on_addme => sub { |
107 | my ($ns) = @_; |
130 | my ($ns) = @_; |
108 | |
131 | |
… | |
… | |
121 | *** |
144 | *** |
122 | *** CFPlus: all known versions automatically enable the facecache. |
145 | *** CFPlus: all known versions automatically enable the facecache. |
123 | *** cfclient: use the -cache commandline option. |
146 | *** cfclient: use the -cache commandline option. |
124 | *** cfclient: map will not redraw automatically (bug). |
147 | *** cfclient: map will not redraw automatically (bug). |
125 | *** gcfclient: use -cache commandline option, or enable |
148 | *** gcfclient: use -cache commandline option, or enable |
126 | *** gcfclient: Client=>Configure=>Map & Image=>Cache Images. |
149 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
127 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
150 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
128 | *** |
151 | *** |
129 | *** |
152 | *** |
130 | EOF |
153 | EOF |
131 | if ($ns->version =~ /jcrossclient/) { |
154 | if ($ns->version =~ /jcrossclient/) { |
… | |
… | |
152 | } |
175 | } |
153 | |
176 | |
154 | $ns->pl and return $ns->destroy; |
177 | $ns->pl and return $ns->destroy; |
155 | |
178 | |
156 | $ns->async (sub { |
179 | $ns->async (sub { |
|
|
180 | $Coro::current->{desc} = "addme init"; |
|
|
181 | |
157 | my ($user, $pass); |
182 | my ($user, $pass); |
158 | |
183 | |
159 | $ns->send_packet ("addme_success"); |
184 | $ns->send_packet ("addme_success"); |
160 | |
185 | |
161 | for (;;) { |
186 | for (;;) { |
… | |
… | |
184 | . "(only a-z, A-Z and 0-9 are allowed), " |
209 | . "(only a-z, A-Z and 0-9 are allowed), " |
185 | . "or is not between 3 and 18 characters in length.", |
210 | . "or is not between 3 and 18 characters in length.", |
186 | cf::NDI_RED |
211 | cf::NDI_RED |
187 | ); |
212 | ); |
188 | } |
213 | } |
|
|
214 | Coro::Timer::sleep 0.4; |
189 | } |
215 | } |
190 | |
216 | |
191 | check_playing $ns, $user and next; |
217 | check_playing $ns, $user and next; |
|
|
218 | |
|
|
219 | $Coro::current->{desc} = "addme($user) pass"; |
192 | |
220 | |
193 | $ns->send_drawinfo ( |
221 | $ns->send_drawinfo ( |
194 | "Welcome $user, please enter your password now. " |
222 | "Welcome $user, please enter your password now. " |
195 | . "New users should now choose a password. " |
223 | . "New users should now choose a password. " |
196 | . "Anything your client lets you enter is fine.", |
224 | . "Anything your client lets you enter is fine.", |
… | |
… | |
204 | $ns->send_drawinfo ( |
232 | $ns->send_drawinfo ( |
205 | "Try to use at least three characters as your password please, " |
233 | "Try to use at least three characters as your password please, " |
206 | . "that cannot be too much to ask for :)", |
234 | . "that cannot be too much to ask for :)", |
207 | cf::NDI_RED |
235 | cf::NDI_RED |
208 | ); |
236 | ); |
|
|
237 | Coro::Timer::sleep 0.4; |
209 | } |
238 | } |
210 | |
239 | |
211 | # lock this username for the remainder of this login session |
240 | # lock this username for the remainder of this login session |
212 | if ($cf::LOGIN_LOCK{$user}) { |
241 | if ($cf::LOGIN_LOCK{$user}) { |
213 | $ns->send_drawinfo ( |
242 | $ns->send_drawinfo ( |
… | |
… | |
218 | next; |
247 | next; |
219 | } |
248 | } |
220 | local $cf::LOGIN_LOCK{$user} = 1; |
249 | local $cf::LOGIN_LOCK{$user} = 1; |
221 | |
250 | |
222 | check_playing $ns, $user and next; |
251 | check_playing $ns, $user and next; |
|
|
252 | |
|
|
253 | $Coro::current->{desc} = "addme($user) check"; |
223 | |
254 | |
224 | # try to read the user file and check the password |
255 | # try to read the user file and check the password |
225 | if (my $pl = cf::player::find $user) { |
256 | if (my $pl = cf::player::find $user) { |
226 | aio_stat $pl->path and next; |
257 | aio_stat $pl->path and next; |
227 | my $mtime = (stat _)[9]; |
258 | my $mtime = (stat _)[9]; |
… | |
… | |
281 | next; |
312 | next; |
282 | } |
313 | } |
283 | } |
314 | } |
284 | |
315 | |
285 | # the rest of this function is character creation |
316 | # the rest of this function is character creation |
|
|
317 | $Coro::current->{desc} = "addme($user) chargen"; |
286 | |
318 | |
287 | # just to make sure nothing is left over |
319 | # just to make sure nothing is left over |
288 | nuke_playerdir $user; |
320 | nuke_playerdir $user; |
289 | |
321 | |
290 | 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."; |
… | |
… | |
294 | nuke_str $pass2; |
326 | nuke_str $pass2; |
295 | $ns->send_drawinfo ( |
327 | $ns->send_drawinfo ( |
296 | "The passwords do not match, please try again.", |
328 | "The passwords do not match, please try again.", |
297 | cf::NDI_RED |
329 | cf::NDI_RED |
298 | ); |
330 | ); |
|
|
331 | Coro::Timer::sleep 0.5; |
299 | next; |
332 | next; |
300 | } |
333 | } |
301 | |
334 | |
302 | nuke_str $pass2; |
335 | nuke_str $pass2; |
303 | |
336 | |
… | |
… | |
325 | $ob->swap_stats ($res - 1, $swap - 1); |
358 | $ob->swap_stats ($res - 1, $swap - 1); |
326 | } |
359 | } |
327 | } else { |
360 | } else { |
328 | $ob->roll_stats; |
361 | $ob->roll_stats; |
329 | } |
362 | } |
|
|
363 | |
|
|
364 | Coro::Timer::sleep 0.2; |
330 | } |
365 | } |
331 | |
366 | |
332 | $ob->set_animation (2); |
367 | $ob->set_animation (2); |
333 | $ob->add_statbonus; |
368 | $ob->add_statbonus; |
334 | |
369 | |
335 | while () { |
370 | while () { |
336 | $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); |
371 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
337 | my $msg = $ob->msg; |
372 | my $msg = $ob->msg; |
338 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
373 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
339 | $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); |
374 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
340 | |
375 | |
341 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
376 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
342 | "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"; |
343 | |
378 | |
344 | last if $res =~ /[dD]/; |
379 | last if $res =~ /[dD]/; |
345 | |
380 | |
346 | $pl->chargen_race_next; |
381 | $pl->chargen_race_next; |
|
|
382 | Coro::Timer::sleep 0.2; |
347 | } |
383 | } |
348 | |
384 | |
349 | $pl->chargen_race_done; |
385 | $pl->chargen_race_done; |
350 | |
386 | |
351 | while () { |
387 | while () { |
… | |
… | |
357 | last; |
393 | last; |
358 | } elsif ($res =~ /^[mM]/) { |
394 | } elsif ($res =~ /^[mM]/) { |
359 | $pl->gender (0); |
395 | $pl->gender (0); |
360 | last; |
396 | last; |
361 | } |
397 | } |
|
|
398 | Coro::Timer::sleep 0.2; |
362 | } |
399 | } |
363 | |
400 | |
364 | $ob->reply (undef, "Welcome to Crossfire!"); |
401 | $ob->reply (undef, "Welcome to Crossfire!"); |
365 | |
402 | |
366 | delete $pl->{deny_save}; |
403 | delete $pl->{deny_save}; |
… | |
… | |
449 | }, |
486 | }, |
450 | ); |
487 | ); |
451 | |
488 | |
452 | ############################################################################# |
489 | ############################################################################# |
453 | |
490 | |
454 | 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 |
455 | our $SAVE_TIMEOUT = 20; # save players every n seconds |
492 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
456 | |
493 | |
457 | our $SCHEDULER = cf::async_ext { |
494 | our $SCHEDULER = cf::async_ext { |
|
|
495 | $Coro::current->{desc} = "player scheduler"; |
|
|
496 | |
458 | my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); |
497 | my $schedule_interval = Coro::Event->timer (after => 1, data => cf::WF_AUTOCANCEL); |
459 | while () { |
498 | while () { |
|
|
499 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
460 | $schedule_interval->next; |
500 | $schedule_interval->next; |
461 | |
501 | |
462 | # this weird form of iteration over values is used because |
502 | # this weird form of iteration over values is used because |
463 | # the hash changes underneath us frequently, and for |
503 | # the hash changes underneath us frequently, and for |
464 | # 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) |
… | |
… | |
469 | or next; |
509 | or next; |
470 | $pl->valid or next; |
510 | $pl->valid or next; |
471 | |
511 | |
472 | eval { |
512 | eval { |
473 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
513 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
474 | cf::wait_for_tick_begin; |
|
|
475 | $pl->save; |
514 | $pl->save; |
476 | |
515 | |
477 | unless ($pl->active || $pl->ns) { |
516 | unless ($pl->active || $pl->ns) { |
478 | # 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 |
479 | my $ob = $pl->ob; |
518 | my $ob = $pl->ob; |