… | |
… | |
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 | } |
… | |
… | |
50 | ); |
52 | ); |
51 | |
53 | |
52 | 1 |
54 | 1 |
53 | } |
55 | } |
54 | |
56 | |
|
|
57 | sub safe_spot($$$) { |
|
|
58 | my ($m, $x, $y) = @_; |
|
|
59 | |
|
|
60 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
|
|
61 | } |
|
|
62 | |
55 | sub enter_map { |
63 | sub enter_map { |
56 | my ($pl) = @_; |
64 | my ($pl) = @_; |
57 | |
65 | |
58 | my $ob = $pl->ob; |
66 | my $ob = $pl->ob; |
59 | |
67 | |
… | |
… | |
64 | |
72 | |
65 | $ob->enter_link; |
73 | $ob->enter_link; |
66 | |
74 | |
67 | if (my $time = delete $pl->{unclean_save}) { |
75 | if (my $time = delete $pl->{unclean_save}) { |
68 | if (my $m = cf::map::find $map) { |
76 | if (my $m = cf::map::find $map) { |
69 | if ($time < $m->{instantiate_time} || 1) {#d# |
77 | if ($time < $m->{instantiate_time}) { |
70 | # the map was reset in the meantime |
78 | # the map was reset in the meantime |
71 | my $age = $cf::RUNTIME - $time; |
79 | my $age = $cf::RUNTIME - $time; |
|
|
80 | |
72 | warn $ob->name, " map reset after logout, logout age $age\n";#d# |
81 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
73 | |
82 | |
74 | # for now, just go back to savebed |
|
|
75 | ($map, $x, $y) = $pl->savebed; |
83 | ($map, $x, $y) = $pl->savebed; |
76 | |
84 | |
77 | $pl->ns->send_drawinfo ( |
85 | if (safe_spot $m, $x, $y) { |
|
|
86 | # do nothing, this is simply ok without a special scary message |
|
|
87 | } elsif ($age >= $MAX_DISCONNECT_TIME) { |
|
|
88 | $ob->message ( |
78 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
89 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
|
|
90 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
|
|
91 | . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " |
|
|
92 | . "H<You disconnected too long without having used a savebed.>", |
|
|
93 | cf::NDI_RED |
|
|
94 | ); |
|
|
95 | # kill them. |
|
|
96 | # reminds me of the famous badness 10000 syndrome... |
|
|
97 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
|
|
98 | $pl->killer ("a cave-in"); |
|
|
99 | } else { |
|
|
100 | $ob->message ( |
|
|
101 | "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. " |
102 | . "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...", |
103 | . "Better use a savebed next time, much worse things could have happened... " |
|
|
104 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
81 | cf::NDI_RED |
105 | cf::NDI_RED |
82 | ); |
106 | ); |
|
|
107 | } |
|
|
108 | } elsif (safe_spot $m, $x, $y) { |
|
|
109 | # do nothing, this is simply ok without a special scary message |
83 | } else { |
110 | } else { |
84 | $pl->ns->send_drawinfo ( |
111 | $ob->message ( |
85 | "You didn't use a bed to reality to leave this realm. This is very dangerous, " |
112 | "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, " |
113 | . "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.", |
114 | . "or monsters suddenly snapping your body. Better use a savebed next time. " |
|
|
115 | . "H<Always apply a bed of reality to disconnect from the server.>", |
88 | cf::NDI_RED |
116 | cf::NDI_RED |
89 | ); |
117 | ); |
90 | } |
118 | } |
91 | } |
119 | } |
92 | } |
120 | } |
… | |
… | |
97 | # delete a player directory, be non-blocking AND synchronous... |
125 | # delete a player directory, be non-blocking AND synchronous... |
98 | # (thats hard, so we crap out and fork). |
126 | # (thats hard, so we crap out and fork). |
99 | sub nuke_playerdir { |
127 | sub nuke_playerdir { |
100 | my ($user) = @_; |
128 | my ($user) = @_; |
101 | |
129 | |
102 | aio_stat "$PLAYERDIR/$user"; |
130 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
103 | system "cd \Q$PLAYERDIR\E " |
131 | |
104 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
132 | cf::fork_call { |
105 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
133 | rename "$PLAYERDIR/$user", $temp; |
|
|
134 | system "rm", "-rf", $temp; |
|
|
135 | }; |
106 | } |
136 | } |
107 | |
137 | |
108 | cf::client->attach (on_addme => sub { |
138 | cf::client->attach (on_addme => sub { |
109 | my ($ns) = @_; |
139 | my ($ns) = @_; |
110 | |
140 | |
… | |
… | |
123 | *** |
153 | *** |
124 | *** CFPlus: all known versions automatically enable the facecache. |
154 | *** CFPlus: all known versions automatically enable the facecache. |
125 | *** cfclient: use the -cache commandline option. |
155 | *** cfclient: use the -cache commandline option. |
126 | *** cfclient: map will not redraw automatically (bug). |
156 | *** cfclient: map will not redraw automatically (bug). |
127 | *** gcfclient: use -cache commandline option, or enable |
157 | *** gcfclient: use -cache commandline option, or enable |
128 | *** gcfclient: Client=>Configure=>Map & Image=>Cache Images. |
158 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
129 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
159 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
130 | *** |
160 | *** |
131 | *** |
161 | *** |
132 | EOF |
162 | EOF |
133 | if ($ns->version =~ /jcrossclient/) { |
163 | if ($ns->version =~ /jcrossclient/) { |
… | |
… | |
154 | } |
184 | } |
155 | |
185 | |
156 | $ns->pl and return $ns->destroy; |
186 | $ns->pl and return $ns->destroy; |
157 | |
187 | |
158 | $ns->async (sub { |
188 | $ns->async (sub { |
|
|
189 | $Coro::current->{desc} = "addme init"; |
|
|
190 | |
159 | my ($user, $pass); |
191 | my ($user, $pass); |
160 | |
192 | |
161 | $ns->send_packet ("addme_success"); |
193 | $ns->send_packet ("addme_success"); |
162 | |
194 | |
163 | for (;;) { |
195 | for (;;) { |
… | |
… | |
190 | } |
222 | } |
191 | Coro::Timer::sleep 0.4; |
223 | Coro::Timer::sleep 0.4; |
192 | } |
224 | } |
193 | |
225 | |
194 | check_playing $ns, $user and next; |
226 | check_playing $ns, $user and next; |
|
|
227 | |
|
|
228 | $Coro::current->{desc} = "addme($user) pass"; |
195 | |
229 | |
196 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
197 | "Welcome $user, please enter your password now. " |
231 | "Welcome $user, please enter your password now. " |
198 | . "New users should now choose a password. " |
232 | . "New users should now choose a password. " |
199 | . "Anything your client lets you enter is fine.", |
233 | . "Anything your client lets you enter is fine.", |
… | |
… | |
223 | } |
257 | } |
224 | local $cf::LOGIN_LOCK{$user} = 1; |
258 | local $cf::LOGIN_LOCK{$user} = 1; |
225 | |
259 | |
226 | check_playing $ns, $user and next; |
260 | check_playing $ns, $user and next; |
227 | |
261 | |
|
|
262 | $Coro::current->{desc} = "addme($user) check"; |
|
|
263 | |
228 | # try to read the user file and check the password |
264 | # try to read the user file and check the password |
229 | if (my $pl = cf::player::find $user) { |
265 | if (my $pl = cf::player::find $user) { |
230 | aio_stat $pl->path and next; |
266 | aio_stat $pl->path and next; |
231 | my $mtime = (stat _)[9]; |
267 | my $mtime = (stat _)[9]; |
232 | my $hash = $pl->password; |
268 | my $hash = $pl->password; |
… | |
… | |
285 | next; |
321 | next; |
286 | } |
322 | } |
287 | } |
323 | } |
288 | |
324 | |
289 | # the rest of this function is character creation |
325 | # the rest of this function is character creation |
|
|
326 | $Coro::current->{desc} = "addme($user) chargen"; |
290 | |
327 | |
291 | # just to make sure nothing is left over |
328 | # just to make sure nothing is left over |
292 | nuke_playerdir $user; |
329 | nuke_playerdir $user; |
293 | |
330 | |
294 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
331 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
… | |
… | |
338 | |
375 | |
339 | $ob->set_animation (2); |
376 | $ob->set_animation (2); |
340 | $ob->add_statbonus; |
377 | $ob->add_statbonus; |
341 | |
378 | |
342 | while () { |
379 | while () { |
343 | $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); |
380 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
344 | my $msg = $ob->msg; |
381 | my $msg = $ob->msg; |
345 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
382 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
346 | $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); |
383 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
347 | |
384 | |
348 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
385 | 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"; |
386 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
350 | |
387 | |
351 | last if $res =~ /[dD]/; |
388 | last if $res =~ /[dD]/; |
… | |
… | |
368 | last; |
405 | last; |
369 | } |
406 | } |
370 | Coro::Timer::sleep 0.2; |
407 | Coro::Timer::sleep 0.2; |
371 | } |
408 | } |
372 | |
409 | |
373 | $ob->reply (undef, "Welcome to Crossfire!"); |
410 | $ob->reply (undef, "Welcome to Deliantra!"); |
374 | |
411 | |
375 | delete $pl->{deny_save}; |
412 | delete $pl->{deny_save}; |
376 | |
413 | |
377 | last; |
414 | last; |
378 | } |
415 | } |
… | |
… | |
458 | }, |
495 | }, |
459 | ); |
496 | ); |
460 | |
497 | |
461 | ############################################################################# |
498 | ############################################################################# |
462 | |
499 | |
463 | our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs |
500 | 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 |
501 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
465 | |
502 | |
466 | our $SCHEDULER = cf::async_ext { |
503 | our $SCHEDULER = cf::async_ext { |
467 | my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); |
504 | $Coro::current->{desc} = "player scheduler"; |
|
|
505 | |
468 | while () { |
506 | while () { |
469 | $schedule_interval->next; |
507 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
470 | |
508 | |
471 | # this weird form of iteration over values is used because |
509 | # this weird form of iteration over values is used because |
472 | # the hash changes underneath us frequently, and for |
510 | # the hash changes underneath us frequently, and for |
473 | # keeps a direct reference to the value without (in 5.8 perls) |
511 | # keeps a direct reference to the value without (in 5.8 perls) |
474 | # keeping a reference, so this is prone to crashes or worse. |
512 | # keeping a reference, so this is prone to crashes or worse. |
… | |
… | |
478 | or next; |
516 | or next; |
479 | $pl->valid or next; |
517 | $pl->valid or next; |
480 | |
518 | |
481 | eval { |
519 | eval { |
482 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
520 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
483 | cf::wait_for_tick_begin; |
|
|
484 | $pl->save; |
521 | $pl->save; |
485 | |
522 | |
486 | unless ($pl->active || $pl->ns) { |
523 | unless ($pl->active || $pl->ns) { |
487 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
524 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
488 | my $ob = $pl->ob; |
525 | my $ob = $pl->ob; |