… | |
… | |
52 | ); |
52 | ); |
53 | |
53 | |
54 | 1 |
54 | 1 |
55 | } |
55 | } |
56 | |
56 | |
|
|
57 | sub safe_spot($$$) { |
|
|
58 | my ($m, $x, $y) = @_; |
|
|
59 | |
|
|
60 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
|
|
61 | } |
|
|
62 | |
57 | sub enter_map { |
63 | sub enter_map { |
58 | my ($pl) = @_; |
64 | my ($pl) = @_; |
59 | |
65 | |
60 | my $ob = $pl->ob; |
66 | my $ob = $pl->ob; |
61 | |
67 | |
… | |
… | |
72 | # the map was reset in the meantime |
78 | # the map was reset in the meantime |
73 | my $age = $cf::RUNTIME - $time; |
79 | my $age = $cf::RUNTIME - $time; |
74 | |
80 | |
75 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
81 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
76 | |
82 | |
77 | # for now, just go back to savebed |
|
|
78 | ($map, $x, $y) = $pl->savebed; |
83 | ($map, $x, $y) = $pl->savebed; |
79 | |
84 | |
|
|
85 | if (safe_spot $m, $x, $y) { |
|
|
86 | # do nothing, this is simply ok without a special scary message |
80 | if ($age >= $MAX_DISCONNECT_TIME) { |
87 | } elsif ($age >= $MAX_DISCONNECT_TIME) { |
81 | $ob->message ( |
88 | $ob->message ( |
82 | "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. " |
83 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
90 | . "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... " |
91 | . "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.>", |
92 | . "H<You disconnected too long without having used a savebed.>", |
… | |
… | |
96 | . "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... " |
97 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
104 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
98 | cf::NDI_RED |
105 | cf::NDI_RED |
99 | ); |
106 | ); |
100 | } |
107 | } |
|
|
108 | } elsif (safe_spot $m, $x, $y) { |
|
|
109 | # do nothing, this is simply ok without a special scary message |
101 | } else { |
110 | } else { |
102 | $ob->message ( |
111 | $ob->message ( |
103 | "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, " |
104 | . "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, " |
105 | . "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. " |
… | |
… | |
116 | # delete a player directory, be non-blocking AND synchronous... |
125 | # delete a player directory, be non-blocking AND synchronous... |
117 | # (thats hard, so we crap out and fork). |
126 | # (thats hard, so we crap out and fork). |
118 | sub nuke_playerdir { |
127 | sub nuke_playerdir { |
119 | my ($user) = @_; |
128 | my ($user) = @_; |
120 | |
129 | |
121 | aio_rename "$PLAYERDIR/$user", "$PLAYERDIR/~$Coro::current~deleting~"; |
|
|
122 | system "rm -rf \Q$PLAYERDIR/~$Coro::current~deleting~\E &"; |
130 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
|
|
131 | |
|
|
132 | cf::fork_call { |
|
|
133 | rename "$PLAYERDIR/$user", $temp; |
|
|
134 | system "rm", "-rf", $temp; |
|
|
135 | }; |
123 | } |
136 | } |
124 | |
137 | |
125 | cf::client->attach (on_addme => sub { |
138 | cf::client->attach (on_addme => sub { |
126 | my ($ns) = @_; |
139 | my ($ns) = @_; |
127 | |
140 | |
… | |
… | |
171 | } |
184 | } |
172 | |
185 | |
173 | $ns->pl and return $ns->destroy; |
186 | $ns->pl and return $ns->destroy; |
174 | |
187 | |
175 | $ns->async (sub { |
188 | $ns->async (sub { |
|
|
189 | $Coro::current->{desc} = "addme init"; |
|
|
190 | |
176 | my ($user, $pass); |
191 | my ($user, $pass); |
177 | |
192 | |
178 | $ns->send_packet ("addme_success"); |
193 | $ns->send_packet ("addme_success"); |
179 | |
194 | |
180 | for (;;) { |
195 | for (;;) { |
… | |
… | |
207 | } |
222 | } |
208 | Coro::Timer::sleep 0.4; |
223 | Coro::Timer::sleep 0.4; |
209 | } |
224 | } |
210 | |
225 | |
211 | check_playing $ns, $user and next; |
226 | check_playing $ns, $user and next; |
|
|
227 | |
|
|
228 | $Coro::current->{desc} = "addme($user) pass"; |
212 | |
229 | |
213 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
214 | "Welcome $user, please enter your password now. " |
231 | "Welcome $user, please enter your password now. " |
215 | . "New users should now choose a password. " |
232 | . "New users should now choose a password. " |
216 | . "Anything your client lets you enter is fine.", |
233 | . "Anything your client lets you enter is fine.", |
… | |
… | |
240 | } |
257 | } |
241 | local $cf::LOGIN_LOCK{$user} = 1; |
258 | local $cf::LOGIN_LOCK{$user} = 1; |
242 | |
259 | |
243 | check_playing $ns, $user and next; |
260 | check_playing $ns, $user and next; |
244 | |
261 | |
|
|
262 | $Coro::current->{desc} = "addme($user) check"; |
|
|
263 | |
245 | # try to read the user file and check the password |
264 | # try to read the user file and check the password |
246 | if (my $pl = cf::player::find $user) { |
265 | if (my $pl = cf::player::find $user) { |
247 | aio_stat $pl->path and next; |
266 | aio_stat $pl->path and next; |
248 | my $mtime = (stat _)[9]; |
267 | my $mtime = (stat _)[9]; |
249 | my $hash = $pl->password; |
268 | my $hash = $pl->password; |
… | |
… | |
302 | next; |
321 | next; |
303 | } |
322 | } |
304 | } |
323 | } |
305 | |
324 | |
306 | # the rest of this function is character creation |
325 | # the rest of this function is character creation |
|
|
326 | $Coro::current->{desc} = "addme($user) chargen"; |
307 | |
327 | |
308 | # just to make sure nothing is left over |
328 | # just to make sure nothing is left over |
309 | nuke_playerdir $user; |
329 | nuke_playerdir $user; |
310 | |
330 | |
311 | 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."; |
… | |
… | |
385 | last; |
405 | last; |
386 | } |
406 | } |
387 | Coro::Timer::sleep 0.2; |
407 | Coro::Timer::sleep 0.2; |
388 | } |
408 | } |
389 | |
409 | |
390 | $ob->reply (undef, "Welcome to Crossfire!"); |
410 | $ob->reply (undef, "Welcome to Deliantra!"); |
391 | |
411 | |
392 | delete $pl->{deny_save}; |
412 | delete $pl->{deny_save}; |
393 | |
413 | |
394 | last; |
414 | last; |
395 | } |
415 | } |
… | |
… | |
479 | |
499 | |
480 | our $SCHEDULE_INTERVAL = $cf::CFG{player_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 |
481 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
501 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
482 | |
502 | |
483 | our $SCHEDULER = cf::async_ext { |
503 | our $SCHEDULER = cf::async_ext { |
484 | my $schedule_interval = Coro::Event->timer (after => 1); |
504 | $Coro::current->{desc} = "player scheduler"; |
|
|
505 | |
485 | while () { |
506 | while () { |
486 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
507 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
487 | $schedule_interval->next; |
|
|
488 | |
508 | |
489 | # this weird form of iteration over values is used because |
509 | # this weird form of iteration over values is used because |
490 | # the hash changes underneath us frequently, and for |
510 | # the hash changes underneath us frequently, and for |
491 | # 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) |
492 | # keeping a reference, so this is prone to crashes or worse. |
512 | # keeping a reference, so this is prone to crashes or worse. |