ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.118 by root, Thu Nov 8 00:16:07 2012 UTC vs.
Revision 1.120 by root, Thu Nov 15 06:00:16 2012 UTC

2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7use Deliantra::Util ();
7 8
8CONF MAX_DISCONNECT_TIME = 3600; 9CONF MAX_DISCONNECT_TIME = 3600;
9
10# paranoia function to overwrite a string-in-place
11sub nuke_str {
12 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
13}
14 10
15sub query { 11sub query {
16 my ($ns, $flags, $text) = @_; 12 my ($ns, $flags, $text) = @_;
17 13
18 $ns->query ($flags, $text, Coro::rouse_cb); 14 $ns->query ($flags, $text, Coro::rouse_cb);
131 127
132 $ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
133} 129}
134 130
135sub encode_password($) { 131sub encode_password($) {
136# crypt $_[0],
137# join '',
138# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
139 "!" . unpack "H*", $_[0] 132 "!" . unpack "H*", $_[0]
140} 133}
141 134
142sub compare_password($$) { 135sub compare_password($$) {
143 my ($pass, $token) = @_; 136 my ($pass, $token) = @_;
158 my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; 151 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
159 152
160 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
161 aio_rename "$PLAYERDIR/$user", $temp; 154 aio_rename "$PLAYERDIR/$user", $temp;
162 IO::AIO::aio_rmtree $temp; 155 IO::AIO::aio_rmtree $temp;
156}
157
158sub login_done {
159 my ($pl) = @_;
160
161 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
162 $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
163 }
164}
165
166sub chargen {
167 my ($ns, $user, $pass) = @_;
168
169 # the rest of this function is character creation
170 $Coro::current->{desc} = "addme($user) chargen";
171
172 # just to make sure nothing is left over
173 # normally, nothing is there.
174 nuke_playerdir $user;
175
176 my $pl = cf::player::new $user;
177 $pl->password (encode_password $pass);
178 $pl->connect ($ns);
179 my $ob = $pl->ob;
180
181 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
182
183 while () {
184 $ob->update_stats;
185 $pl->save_stats;
186
187 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
188 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?";
189
190 if ($res =~ /^[Nn]/) {
191 last;
192 } elsif ($res > 0 && $res <= 7) {
193 my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?";
194
195 if ($swap > 0 && $swap <= 7) {
196 $ob->swap_stats ($res - 1, $swap - 1);
197 }
198 } else {
199 $ob->roll_stats;
200 }
201
202 Coro::Timer::sleep 0.05;
203 }
204
205 $ob->set_animation (2);
206 $ob->add_statbonus;
207
208 while () {
209 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
210 my $msg = $ob->msg;
211 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
212 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
213
214 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
215 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
216
217 last if $res =~ /[dD]/;
218
219 $pl->chargen_race_next;
220 Coro::Timer::sleep 0.05;
221 }
222
223 # create the playerdir, if necessary, as chargen_race_done did it before
224 # presumably because of unique maps
225 aio_mkdir playerdir $pl, 0770;
226 $pl->chargen_race_done;
227
228 while () {
229 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
230 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
231
232 if ($res =~ /^[fF]/) {
233 $pl->gender (1);
234 last;
235 } elsif ($res =~ /^[mM]/) {
236 $pl->gender (0);
237 last;
238 }
239 Coro::Timer::sleep 0.05;
240 }
241
242 $ob->reply (undef, "Welcome to Deliantra!");
243
244 # XXX: Workaround for delayed client ext protocol handshake
245 $pl->esrv_new_player;
246
247 delete $pl->{deny_save};
163} 248}
164 249
165cf::client->attach (on_addme => sub { 250cf::client->attach (on_addme => sub {
166 my ($ns) = @_; 251 my ($ns) = @_;
167 252
248 aio_stat $pl->path and next; 333 aio_stat $pl->path and next;
249 my $mtime = (stat _)[9]; 334 my $mtime = (stat _)[9];
250 my $token = $pl->password; 335 my $token = $pl->password;
251 336
252 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { 337 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
338 # player exists and passwords match - we can proceed
339
253 $pl->password (encode_password $pass); # make sure we store the new encoding #d# 340 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
254 nuke_str $pass;
255 # password matches, wonderful 341 # password matches, wonderful
256 my $pl = cf::player::find $user or next; 342 my $pl = cf::player::find $user or next;
257 $pl->connect ($ns); 343 $pl->connect ($ns);
258 enter_map $pl; 344 enter_map $pl;
345 login_done $pl;
259 last; 346 return;
260 } elsif (can_cleanup $pl, $mtime) { 347 } elsif (can_cleanup $pl, $mtime) {
261 Coro::Timer::sleep 1; 348 Coro::Timer::sleep 1;
262 349
263 $ns->send_drawinfo ( 350 $ns->send_drawinfo (
264 "Player exists, but password does not match. If this is your account, " 351 "Player exists, but password does not match. If this is your account, "
265 . "please try again. If not, you can now decide to take over this account " 352 . "please try again. If not, you can now decide to take over this account "
266 . "because it has not been in-use for some time.", 353 . "because it has not been in-use for some time.",
267 cf::NDI_RED 354 cf::NDI_RED
268 ); 355 );
269 356
270 #TODO: nuke_str
271 (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ 357 (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/
272 or next; 358 or next;
273 359
274 # check if the file hasn't changed 360 # check if the file hasn't changed
275 aio_stat cf::player::path $user and next; 361 aio_stat cf::player::path $user and next;
277 363
278 $pl->quit_character; 364 $pl->quit_character;
279 365
280 # fall through to creation 366 # fall through to creation
281 } else { 367 } else {
282 nuke_str $pass;
283
284 Coro::Timer::sleep 1; 368 Coro::Timer::sleep 1;
285 369
286 $ns->send_drawinfo ( 370 $ns->send_drawinfo (
287 "Wrong username or password. Please try again " 371 "Wrong username or password. Please try again "
288 . "(check for Numlock and other semi-obvious error sources).", 372 . "(check for Numlock and other semi-obvious error sources).",
303 ); 387 );
304 next; 388 next;
305 } 389 }
306 } 390 }
307 391
308 # the rest of this function is character creation
309 $Coro::current->{desc} = "addme($user) chargen";
310
311 # just to make sure nothing is left over
312 # normally, nothing is there.
313 nuke_playerdir $user;
314
315 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 392 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
316 393
317 if ($pass2 ne $pass) { 394 if ($pass2 ne $pass) {
318 nuke_str $pass;
319 nuke_str $pass2;
320 $ns->send_drawinfo ( 395 $ns->send_drawinfo (
321 "The passwords do not match, please try again.", 396 "The passwords do not match, please try again.",
322 cf::NDI_RED 397 cf::NDI_RED
323 ); 398 );
324 Coro::Timer::sleep 0.5; 399 Coro::Timer::sleep 0.5;
325 next; 400 next;
326 } 401 }
327 402
328 nuke_str $pass2;
329
330 my $pl = cf::player::new $user;
331 $pl->password (encode_password $pass);
332 nuke_str $pass;
333 $pl->connect ($ns);
334 my $ob = $pl->ob;
335
336 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
337
338 while () {
339 $ob->update_stats;
340 $pl->save_stats;
341
342 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
343 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?";
344
345 if ($res =~ /^[Nn]/) {
346 last;
347 } elsif ($res > 0 && $res <= 7) {
348 my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?";
349
350 if ($swap > 0 && $swap <= 7) {
351 $ob->swap_stats ($res - 1, $swap - 1);
352 }
353 } else {
354 $ob->roll_stats;
355 }
356
357 Coro::Timer::sleep 0.05;
358 }
359
360 $ob->set_animation (2);
361 $ob->add_statbonus;
362
363 while () {
364 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
365 my $msg = $ob->msg;
366 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
367 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
368
369 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
370 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
371
372 last if $res =~ /[dD]/;
373
374 $pl->chargen_race_next;
375 Coro::Timer::sleep 0.05;
376 }
377
378 # create the playerdir, if necessary, as chargen_race_done did it before
379 # presumably because of unique maps
380 aio_mkdir playerdir $pl, 0770;
381 $pl->chargen_race_done;
382
383 while () {
384 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
385 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
386
387 if ($res =~ /^[fF]/) {
388 $pl->gender (1);
389 last;
390 } elsif ($res =~ /^[mM]/) {
391 $pl->gender (0);
392 last;
393 }
394 Coro::Timer::sleep 0.05;
395 }
396
397 $ob->reply (undef, "Welcome to Deliantra!");
398
399 # XXX: Workaround for delayed client ext protocol handshake
400 $pl->esrv_new_player;
401
402 delete $pl->{deny_save};
403
404 last; 403 last;
405 } 404 }
406 405
407 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { 406 # lock again, too layz to make this nicer
408 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); 407 local $cf::LOGIN_LOCK{$user} = 1;
409 } 408
409 chargen $ns, $user, $pass;
410 login_done $ns->pl;
410 }); 411 });
411}); 412});
412 413
413cf::register_command password => sub { 414cf::register_command password => sub {
414 my ($pl, $arg) = @_; 415 my ($pl, $arg) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines