… | |
… | |
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_stat "$PLAYERDIR/$user"; |
130 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
122 | system "cd \Q$PLAYERDIR\E " |
131 | |
123 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
132 | cf::fork_call { |
124 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
133 | rename "$PLAYERDIR/$user", $temp; |
|
|
134 | system "rm", "-rf", $temp; |
|
|
135 | }; |
125 | } |
136 | } |
126 | |
137 | |
127 | cf::client->attach (on_addme => sub { |
138 | cf::client->attach (on_addme => sub { |
128 | my ($ns) = @_; |
139 | my ($ns) = @_; |
129 | |
140 | |
… | |
… | |
142 | *** |
153 | *** |
143 | *** CFPlus: all known versions automatically enable the facecache. |
154 | *** CFPlus: all known versions automatically enable the facecache. |
144 | *** cfclient: use the -cache commandline option. |
155 | *** cfclient: use the -cache commandline option. |
145 | *** cfclient: map will not redraw automatically (bug). |
156 | *** cfclient: map will not redraw automatically (bug). |
146 | *** gcfclient: use -cache commandline option, or enable |
157 | *** gcfclient: use -cache commandline option, or enable |
147 | *** gcfclient: Client=>Configure=>Map & Image=>Cache Images. |
158 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
148 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
159 | *** jcrossclient: your client is broken, use CFPlus or gcfclient. |
149 | *** |
160 | *** |
150 | *** |
161 | *** |
151 | EOF |
162 | EOF |
152 | if ($ns->version =~ /jcrossclient/) { |
163 | if ($ns->version =~ /jcrossclient/) { |
… | |
… | |
173 | } |
184 | } |
174 | |
185 | |
175 | $ns->pl and return $ns->destroy; |
186 | $ns->pl and return $ns->destroy; |
176 | |
187 | |
177 | $ns->async (sub { |
188 | $ns->async (sub { |
|
|
189 | $Coro::current->{desc} = "addme init"; |
|
|
190 | |
178 | my ($user, $pass); |
191 | my ($user, $pass); |
179 | |
192 | |
180 | $ns->send_packet ("addme_success"); |
193 | $ns->send_packet ("addme_success"); |
181 | |
194 | |
182 | for (;;) { |
195 | for (;;) { |
… | |
… | |
209 | } |
222 | } |
210 | Coro::Timer::sleep 0.4; |
223 | Coro::Timer::sleep 0.4; |
211 | } |
224 | } |
212 | |
225 | |
213 | check_playing $ns, $user and next; |
226 | check_playing $ns, $user and next; |
|
|
227 | |
|
|
228 | $Coro::current->{desc} = "addme($user) pass"; |
214 | |
229 | |
215 | $ns->send_drawinfo ( |
230 | $ns->send_drawinfo ( |
216 | "Welcome $user, please enter your password now. " |
231 | "Welcome $user, please enter your password now. " |
217 | . "New users should now choose a password. " |
232 | . "New users should now choose a password. " |
218 | . "Anything your client lets you enter is fine.", |
233 | . "Anything your client lets you enter is fine.", |
… | |
… | |
242 | } |
257 | } |
243 | local $cf::LOGIN_LOCK{$user} = 1; |
258 | local $cf::LOGIN_LOCK{$user} = 1; |
244 | |
259 | |
245 | check_playing $ns, $user and next; |
260 | check_playing $ns, $user and next; |
246 | |
261 | |
|
|
262 | $Coro::current->{desc} = "addme($user) check"; |
|
|
263 | |
247 | # try to read the user file and check the password |
264 | # try to read the user file and check the password |
248 | if (my $pl = cf::player::find $user) { |
265 | if (my $pl = cf::player::find $user) { |
249 | aio_stat $pl->path and next; |
266 | aio_stat $pl->path and next; |
250 | my $mtime = (stat _)[9]; |
267 | my $mtime = (stat _)[9]; |
251 | my $hash = $pl->password; |
268 | my $hash = $pl->password; |
… | |
… | |
304 | next; |
321 | next; |
305 | } |
322 | } |
306 | } |
323 | } |
307 | |
324 | |
308 | # the rest of this function is character creation |
325 | # the rest of this function is character creation |
|
|
326 | $Coro::current->{desc} = "addme($user) chargen"; |
309 | |
327 | |
310 | # just to make sure nothing is left over |
328 | # just to make sure nothing is left over |
311 | nuke_playerdir $user; |
329 | nuke_playerdir $user; |
312 | |
330 | |
313 | 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."; |
… | |
… | |
387 | last; |
405 | last; |
388 | } |
406 | } |
389 | Coro::Timer::sleep 0.2; |
407 | Coro::Timer::sleep 0.2; |
390 | } |
408 | } |
391 | |
409 | |
392 | $ob->reply (undef, "Welcome to Crossfire!"); |
410 | $ob->reply (undef, "Welcome to Deliantra!"); |
393 | |
411 | |
394 | delete $pl->{deny_save}; |
412 | delete $pl->{deny_save}; |
395 | |
413 | |
396 | last; |
414 | last; |
397 | } |
415 | } |
… | |
… | |
481 | |
499 | |
482 | 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 |
483 | 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 |
484 | |
502 | |
485 | our $SCHEDULER = cf::async_ext { |
503 | our $SCHEDULER = cf::async_ext { |
486 | my $schedule_interval = Coro::Event->timer (after => 1); |
504 | $Coro::current->{desc} = "player scheduler"; |
|
|
505 | |
487 | while () { |
506 | while () { |
488 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
507 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
489 | $schedule_interval->next; |
|
|
490 | |
508 | |
491 | # this weird form of iteration over values is used because |
509 | # this weird form of iteration over values is used because |
492 | # the hash changes underneath us frequently, and for |
510 | # the hash changes underneath us frequently, and for |
493 | # 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) |
494 | # keeping a reference, so this is prone to crashes or worse. |
512 | # keeping a reference, so this is prone to crashes or worse. |