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.96 by pippijn, Tue Dec 23 18:52:57 2008 UTC vs.
Revision 1.115 by root, Sun Jan 23 23:37:55 2011 UTC

1#! perl # mandatory 1#! perl # mandatory depends=highscore
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
59 my $m = $ob->map 59 my $m = $ob->map
60 or return; 60 or return;
61 my $x = $ob->x; 61 my $x = $ob->x;
62 my $y = $ob->y; 62 my $y = $ob->y;
63 63
64 # never happens normally, but helps when shell users make mistakes
65 $m->in_memory == cf::MAP_ACTIVE
66 or return 1;
67
64# return 0;#d# 68# return 0;#d#
65# warn join ":", $m->at ($x, $y);#d# 69# warn join ":", $m->at ($x, $y);#d#
66# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; 70# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n";
67# return 0; 71# return 0;
68 72
70} 74}
71 75
72sub enter_map { 76sub enter_map {
73 my ($pl) = @_; 77 my ($pl) = @_;
74 78
75 warn $pl->ob->name, ": enter map 1\n";#d#
76 my $ob = $pl->ob; 79 my $ob = $pl->ob;
77 80
78 my ($map, $x, $y) 81 my ($map, $x, $y)
79 = $ob->{_link_pos} 82 = $ob->{_link_pos}
80 ? @{delete $ob->{_link_pos}} 83 ? @{delete $ob->{_link_pos}}
81 : ($pl->maplevel, $ob->x, $ob->y); 84 : ($pl->maplevel, $ob->x, $ob->y);
82 85
83 warn $pl->ob->name, ": enter map 2\n";#d#
84 $ob->enter_link; 86 $ob->enter_link;
85 warn $pl->ob->name, ": enter map 3\n";#d#
86 87
87 my $m = cf::map::find $map; 88 my $m = cf::map::find $map;
88 my $time = delete $pl->{unclean_save}; 89 my $time = delete $pl->{unclean_save};
89 warn $pl->ob->name, ": enter map 4\n";#d#
90 90
91 if ($time && $m) { 91 if ($time && $m) {
92 if ($time < $m->{instantiate_time}) { 92 if ($time < $m->{instantiate_time}) {
93 # the map was reset in the meantime 93 # the map was reset in the meantime
94 my $age = $cf::RUNTIME - $time; 94 my $age = $cf::RUNTIME - $time;
95 95
96 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 96 cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
97 97
98 if ($age >= $MAX_DISCONNECT_TIME) { 98 if ($age >= $MAX_DISCONNECT_TIME) {
99 $ob->message ( 99 $ob->message (
100 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 100 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
101 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " 101 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
127 cf::NDI_RED 127 cf::NDI_RED
128 ); 128 );
129 } 129 }
130 } 130 }
131 131
132 warn $pl->ob->name, ": enter map 5\n";#d#
133 #$ob->goto ($map, $x, $y); 132 $ob->goto ($map, $x, $y);
134 $ob->goto ($map, $x, $y, sub { 133}
135 warn $pl->ob->name, ": enter map check\n";#d# 134
136 $_[0] 135sub encode_password($) {
137 }, sub { 136# crypt $_[0],
138 warn $pl->ob->name, ": enter map done\n";#d# 137# join '',
138# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
139 "!" . unpack "H*", $_[0]
140}
141
142sub compare_password($$) {
143 my ($pass, $token) = @_;
144
145 if ($token =~ /\!(.*)/) {
146 return $pass eq pack "H*", $1;
147 } else {
148 return $token eq crypt $pass, $token;
139 }); 149 }
140 warn $pl->ob->name, ": enter map 6\n";#d#
141
142} 150}
143 151
144# delete a player directory, be non-blocking AND synchronous... 152# delete a player directory
145# (that's hard, so we crap out and fork).
146sub nuke_playerdir { 153sub nuke_playerdir {
147 my ($user) = @_; 154 my ($user) = @_;
148 155
156 my $lock = cf::lock_acquire "ext::login::nuke_playerdir";
157
149 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 158 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
150
151 cf::fork_call {
152 rename "$PLAYERDIR/$user", $temp; 159 aio_rename "$PLAYERDIR/$user", $temp;
153 system "rm", "-rf", $temp; 160 IO::AIO::aio_rmtree $temp;
154 };
155} 161}
156 162
157cf::client->attach (on_addme => sub { 163cf::client->attach (on_addme => sub {
158 my ($ns) = @_; 164 my ($ns) = @_;
159
160 if (!$ns->facecache)
161 {
162 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
163
164
165***
166*** WARNING:
167*** Your client does not support face/image caching,
168*** or it has been disabled. Face caching is mandatory
169*** so please enable it or use a newer client.
170***
171*** Look at your client preferences:
172***
173*** deliantra: all known versions automatically enable the facecache.
174*** cfclient: use the -cache commandline option.
175*** cfclient: map will not redraw automatically (bug).
176*** gcfclient: use -cache commandline option, or enable
177*** gcfclient: Client => Configure => Map & Image => Cache Images.
178*** jcrossclient: your client is broken, use deliantra or gcfclient.
179***
180***
181EOF
182 if ($ns->version =~ /jcrossclient/) {
183 # let them, for now
184 } else {
185 $ns->flush;
186 return $ns->destroy;
187 }
188
189 # $ns->facecache = true;
190 }
191
192 if ($ns->mapmode < cf::Map1aCmd) {
193 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
194
195
196***
197*** WARNING:
198*** Your client is too old. Please upgrade to a newer version.
199EOF
200
201 $ns->flush;
202 return $ns->destroy;
203 }
204 165
205 $ns->pl and return $ns->destroy; 166 $ns->pl and return $ns->destroy;
206 167
207 $ns->async (sub { 168 $ns->async (sub {
208 $Coro::current->{desc} = "addme init"; 169 $Coro::current->{desc} = "addme init";
282 243
283 # try to read the user file and check the password 244 # try to read the user file and check the password
284 if (my $pl = cf::player::find $user) { 245 if (my $pl = cf::player::find $user) {
285 aio_stat $pl->path and next; 246 aio_stat $pl->path and next;
286 my $mtime = (stat _)[9]; 247 my $mtime = (stat _)[9];
287 my $hash = $pl->password; 248 my $token = $pl->password;
288 249
289 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 250 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
251 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
290 nuke_str $pass; 252 nuke_str $pass;
291 # password matches, wonderful 253 # password matches, wonderful
292 my $pl = cf::player::find $user or next; 254 my $pl = cf::player::find $user or next;
293 $pl->connect ($ns); 255 $pl->connect ($ns);
294 $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp
295 enter_map $pl; 256 enter_map $pl;
296 last; 257 last;
297 } elsif (can_cleanup $pl, $mtime) { 258 } elsif (can_cleanup $pl, $mtime) {
298 Coro::Timer::sleep 1; 259 Coro::Timer::sleep 1;
299 260
327 ); 288 );
328 next; 289 next;
329 } 290 }
330 } else { 291 } else {
331 # unable to load the playerfile: 292 # unable to load the playerfile:
332 # check wether the player dir exists, which means the file is corrupted or 293 # check whether the player dir exists, which means the file is corrupted or
333 # something very similar. 294 # something very similar.
334 if (!aio_stat cf::player::playerdir $user) { 295 if (!aio_stat cf::player::playerdir $user) {
335 $ns->send_drawinfo ( 296 $ns->send_drawinfo (
336 "Unable to retrieve this player. It might be a locked or broken account. " 297 "Unable to retrieve this player. It might be a locked or broken account. "
337 . "If this is your account, ask a dungeon master for assistance. " 298 . "If this is your account, ask a dungeon master for assistance. "
344 305
345 # the rest of this function is character creation 306 # the rest of this function is character creation
346 $Coro::current->{desc} = "addme($user) chargen"; 307 $Coro::current->{desc} = "addme($user) chargen";
347 308
348 # just to make sure nothing is left over 309 # just to make sure nothing is left over
310 # normally, nothing is there.
349 nuke_playerdir $user; 311 nuke_playerdir $user;
350 312
351 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 313 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
352 314
353 if ($pass2 ne $pass) { 315 if ($pass2 ne $pass) {
362 } 324 }
363 325
364 nuke_str $pass2; 326 nuke_str $pass2;
365 327
366 my $pl = cf::player::new $user; 328 my $pl = cf::player::new $user;
367 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 329 $pl->password (encode_password $pass);
368 nuke_str $pass; 330 nuke_str $pass;
369 $pl->connect ($ns); 331 $pl->connect ($ns);
370 my $ob = $pl->ob; 332 my $ob = $pl->ob;
371 333
372 $ob->goto ($pl->maplevel, $ob->x, $ob->y); 334 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
406 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 368 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
407 369
408 last if $res =~ /[dD]/; 370 last if $res =~ /[dD]/;
409 371
410 $pl->chargen_race_next; 372 $pl->chargen_race_next;
411 Coro::Timer::sleep 0.2; 373 Coro::Timer::sleep 0.05;
412 } 374 }
413 375
414 # create the playerdir, if necessary, as chargen_race_done did it before 376 # create the playerdir, if necessary, as chargen_race_done did it before
415 # presumably because of unique maps 377 # presumably because of unique maps
416 aio_mkdir playerdir $pl, 0770; 378 aio_mkdir playerdir $pl, 0770;
425 last; 387 last;
426 } elsif ($res =~ /^[mM]/) { 388 } elsif ($res =~ /^[mM]/) {
427 $pl->gender (0); 389 $pl->gender (0);
428 last; 390 last;
429 } 391 }
430 Coro::Timer::sleep 0.2; 392 Coro::Timer::sleep 0.05;
431 } 393 }
432 394
433 $ob->reply (undef, "Welcome to Deliantra!"); 395 $ob->reply (undef, "Welcome to Deliantra!");
434 396
435 # XXX: Workaround for delayed client ext protocol handshake 397 # XXX: Workaround for delayed client ext protocol handshake
436 $pl->esrv_new_player; 398 $pl->esrv_new_player;
437 399
438 delete $pl->{deny_save}; 400 delete $pl->{deny_save};
439 401
440 last; 402 last;
403 }
404
405 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
406 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
441 } 407 }
442 }); 408 });
443}); 409});
410
411cf::register_command password => sub {
412 my ($pl, $arg) = @_;
413
414 unless ($pl->flag (cf::FLAG_WIZ)) {
415 $pl->message (
416 "The password can currently only changed by a DM.",
417 cf::NDI_UNIQUE | cf::NDI_REPLY);
418 return;
419 }
420
421 my (@args) = split /\s+/, $arg;
422 my ($player, $new_pw) = @args;
423
424 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
425 $pl->message (
426 "Usage: password <player> [<new password>]",
427 cf::NDI_UNIQUE | cf::NDI_REPLY);
428 return;
429 }
430
431 if ($new_pw eq '') {
432 $new_pw =
433 join '',
434 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
435 1..9;
436 }
437
438 cf::async {
439 my $plc = cf::player::find $player;
440 if ($plc) {
441 $plc->password (encode_password $new_pw);
442 $pl->message (
443 "Ok, changed password of '$player' to '$new_pw'!",
444 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
445 } else {
446 $pl->message (
447 "Fail! Couldn't set password for '$player', "
448 . "he doesn't seem to exist!",
449 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
450 }
451 };
452};
444 453
445cf::register_command quit => sub { 454cf::register_command quit => sub {
446 my ($ob, $arg) = @_; 455 my ($ob, $arg) = @_;
447 456
448 $ob->send_msg (undef, 457 $ob->send_msg (undef,
459 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { 468 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub {
460 if ($_[0] !~ /^[yY]/) { 469 if ($_[0] !~ /^[yY]/) {
461 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 470 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 } else { 471 } else {
463 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 472 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
464 $pl->ns->flush; 473 cf::async {
465 cf::async { $pl->quit_character }; 474 $pl->quit_character;
475 };
466 } 476 }
467 }); 477 });
468}; 478};
469 479
470cf::object->attach ( 480cf::object->attach (
476 486
477 my $pl = $ob->contr; 487 my $pl = $ob->contr;
478 488
479 # update respawn position 489 # update respawn position
480 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 490 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
481 cf::async { $pl->save };
482 491
492 cf::async {
483 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 493 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
484 $ob->check_score; 494 ext::highscore::check $ob;
485 495
496 $pl->save;
497
486 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 498 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
487 499
500 my $ns = $pl->ns
501 or return;
502
488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 503 $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
489 if ($_[0] !~ /^[yY]/) { 504 if ($_[0] !~ /^[yY]/) {
490 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); 505 $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1);
491 $pl->deactivate; 506 $pl->deactivate;
492 $pl->ns->destroy; 507 $pl->ns->destroy;
493 } else { 508 }
494 cf::async { $pl->save };
495 } 509 });
496 }); 510 };
497 }, 511 },
498); 512);
499 513
500cf::player->attach ( 514cf::player->attach (
501 on_login => sub { 515 on_login => sub {
516 unless safe_spot $pl; 530 unless safe_spot $pl;
517 } 531 }
518 }, 532 },
519); 533);
520 534
521

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines