… | |
… | |
116 | # delete a player directory, be non-blocking AND synchronous... |
116 | # delete a player directory, be non-blocking AND synchronous... |
117 | # (thats hard, so we crap out and fork). |
117 | # (thats hard, so we crap out and fork). |
118 | sub nuke_playerdir { |
118 | sub nuke_playerdir { |
119 | my ($user) = @_; |
119 | my ($user) = @_; |
120 | |
120 | |
121 | aio_rename "$PLAYERDIR/$user", "$PLAYERDIR/~$Coro::current~deleting~"; |
|
|
122 | system "rm -rf \Q$PLAYERDIR/~$Coro::current~deleting~\E &"; |
121 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
|
|
122 | |
|
|
123 | cf::fork_call { |
|
|
124 | rename "$PLAYERDIR/$user", $temp; |
|
|
125 | system "rm", "-rf", $temp; |
|
|
126 | }; |
123 | } |
127 | } |
124 | |
128 | |
125 | cf::client->attach (on_addme => sub { |
129 | cf::client->attach (on_addme => sub { |
126 | my ($ns) = @_; |
130 | my ($ns) = @_; |
127 | |
131 | |
… | |
… | |
171 | } |
175 | } |
172 | |
176 | |
173 | $ns->pl and return $ns->destroy; |
177 | $ns->pl and return $ns->destroy; |
174 | |
178 | |
175 | $ns->async (sub { |
179 | $ns->async (sub { |
|
|
180 | $Coro::current->{desc} = "addme init"; |
|
|
181 | |
176 | my ($user, $pass); |
182 | my ($user, $pass); |
177 | |
183 | |
178 | $ns->send_packet ("addme_success"); |
184 | $ns->send_packet ("addme_success"); |
179 | |
185 | |
180 | for (;;) { |
186 | for (;;) { |
… | |
… | |
207 | } |
213 | } |
208 | Coro::Timer::sleep 0.4; |
214 | Coro::Timer::sleep 0.4; |
209 | } |
215 | } |
210 | |
216 | |
211 | check_playing $ns, $user and next; |
217 | check_playing $ns, $user and next; |
|
|
218 | |
|
|
219 | $Coro::current->{desc} = "addme($user) pass"; |
212 | |
220 | |
213 | $ns->send_drawinfo ( |
221 | $ns->send_drawinfo ( |
214 | "Welcome $user, please enter your password now. " |
222 | "Welcome $user, please enter your password now. " |
215 | . "New users should now choose a password. " |
223 | . "New users should now choose a password. " |
216 | . "Anything your client lets you enter is fine.", |
224 | . "Anything your client lets you enter is fine.", |
… | |
… | |
240 | } |
248 | } |
241 | local $cf::LOGIN_LOCK{$user} = 1; |
249 | local $cf::LOGIN_LOCK{$user} = 1; |
242 | |
250 | |
243 | check_playing $ns, $user and next; |
251 | check_playing $ns, $user and next; |
244 | |
252 | |
|
|
253 | $Coro::current->{desc} = "addme($user) check"; |
|
|
254 | |
245 | # try to read the user file and check the password |
255 | # try to read the user file and check the password |
246 | if (my $pl = cf::player::find $user) { |
256 | if (my $pl = cf::player::find $user) { |
247 | aio_stat $pl->path and next; |
257 | aio_stat $pl->path and next; |
248 | my $mtime = (stat _)[9]; |
258 | my $mtime = (stat _)[9]; |
249 | my $hash = $pl->password; |
259 | my $hash = $pl->password; |
… | |
… | |
302 | next; |
312 | next; |
303 | } |
313 | } |
304 | } |
314 | } |
305 | |
315 | |
306 | # the rest of this function is character creation |
316 | # the rest of this function is character creation |
|
|
317 | $Coro::current->{desc} = "addme($user) chargen"; |
307 | |
318 | |
308 | # just to make sure nothing is left over |
319 | # just to make sure nothing is left over |
309 | nuke_playerdir $user; |
320 | nuke_playerdir $user; |
310 | |
321 | |
311 | 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."; |
… | |
… | |
479 | |
490 | |
480 | our $SCHEDULE_INTERVAL = $cf::CFG{player_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 |
481 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
492 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
482 | |
493 | |
483 | our $SCHEDULER = cf::async_ext { |
494 | our $SCHEDULER = cf::async_ext { |
484 | my $schedule_interval = Coro::Event->timer (after => 1); |
495 | $Coro::current->{desc} = "player scheduler"; |
|
|
496 | |
485 | while () { |
497 | while () { |
486 | $schedule_interval->interval ($SCHEDULE_INTERVAL); |
498 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
487 | $schedule_interval->next; |
|
|
488 | |
499 | |
489 | # this weird form of iteration over values is used because |
500 | # this weird form of iteration over values is used because |
490 | # the hash changes underneath us frequently, and for |
501 | # the hash changes underneath us frequently, and for |
491 | # keeps a direct reference to the value without (in 5.8 perls) |
502 | # keeps a direct reference to the value without (in 5.8 perls) |
492 | # keeping a reference, so this is prone to crashes or worse. |
503 | # keeping a reference, so this is prone to crashes or worse. |